<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
  <channel>
    <title>valenrc&apos;s blog</title>
    <description>valenrc, Computer Science at UBA.
</description>
    <link>http://valenrc.github.io/</link>
    <atom:link href="http://valenrc.github.io/feed.xml" rel="self" type="application/rss+xml"/>
    <pubDate>Tue, 04 Mar 2025 23:42:15 +0000</pubDate>
    <lastBuildDate>Tue, 04 Mar 2025 23:42:15 +0000</lastBuildDate>
    <generator>Jekyll v3.10.0</generator>
    
      <item>
        <title>conexión SSH desde Windows a Termux</title>
        <description>&lt;h2 id=&quot;configuración-de-un-servidor-ssh-en-termux-y-conección-desde-windows&quot;&gt;Configuración de un servidor SSH en Termux y conección desde Windows&lt;/h2&gt;

&lt;p&gt;En este post voy a configurar un servidor SSH en Termux y conectarnos a él desde Windows usando Powershell.
Esto es útil para acceder a Termux desde Windows sin tener que usar la terminal de Termux desde el telefono.
&lt;img src=&quot;/assets/img/posts/powershell-termux.jpg&quot; alt=&quot;screenshot&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;ssh-server-en-termux&quot;&gt;SSH server en Termux&lt;/h3&gt;

&lt;p&gt;Instalar el paquete &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;openssh&lt;/code&gt; en Termux, esto instala y configura el servidor SSH automaticamente.
La configuración y las claves se encuentran en &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/data/data/com.termux/files/usr/etc/ssh/&lt;/code&gt;.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pkg upgrade &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; pkg &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;openssh
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Nos conectamos al servidor con &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;USUARIO@IP&lt;/code&gt; en el puerto por defecto &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;8022&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Para obtener el nombre de usuario:&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;nb&quot;&gt;whoami&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Para obtener la dirección IP del host:
(Buscar la etiqueta wlan0)&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pkg &lt;span class=&quot;nb&quot;&gt;install &lt;/span&gt;iproute2 &lt;span class=&quot;o&quot;&gt;&amp;amp;&amp;amp;&lt;/span&gt; ip addr
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;iniciar el servidor SSH. Opcionalmente con el flag &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;-d&lt;/code&gt; para ver mensajes de debug.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;sshd &lt;span class=&quot;nt&quot;&gt;-d&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Mas detalles en &lt;a href=&quot;https://wiki.termux.com/wiki/Remote_Access&quot;&gt;Termux Wiki - Remote Access&lt;/a&gt;&lt;/p&gt;

&lt;h3 id=&quot;conectarse-al-servidor-desde-powershell&quot;&gt;Conectarse al servidor desde Powershell&lt;/h3&gt;

&lt;p&gt;Usamos el cliente SSH de Windows que viene instalado por defecto en &lt;em&gt;optional features&lt;/em&gt;
Nos va a pedir una &lt;em&gt;passphrase&lt;/em&gt; si es que la configuramos.&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh &amp;lt;USUARIO&amp;gt;@IP &lt;span class=&quot;nt&quot;&gt;-p&lt;/span&gt; 8022
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Mas información en &lt;a href=&quot;https://learn.microsoft.com/es-mx/windows/terminal/tutorials/ssh#access-windows-ssh-client-and-ssh-server&quot;&gt;SSH in Windows Terminal&lt;/a&gt;&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;autentificación&quot;&gt;Autentificación&lt;/h2&gt;
&lt;p&gt;La autentificación por defecto es mediante la contraseña del usuario en Termux, pero se puede configurar para que sea mediante una clave pública (mucho mas seguro).&lt;/p&gt;

&lt;h3 id=&quot;contraseña&quot;&gt;Contraseña&lt;/h3&gt;
&lt;p&gt;Para cambiar la contraseña de Termux:&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;passwd
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Cada vez que nos conectemos al servidor SSH nos va a pedir la contraseña del usuario.&lt;/p&gt;

&lt;h3 id=&quot;clave-pública&quot;&gt;Clave pública&lt;/h3&gt;
&lt;p&gt;Tenemos que generar claves en el cliente (Windows) y copiar la clave pública en el host (Termux)&lt;/p&gt;

&lt;p&gt;Generar el par de claves en la dirección &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;C:\Users\&amp;lt;USUARIO&amp;gt;\.ssh\&lt;/code&gt;
(En powershell)&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;ssh-keygen &lt;span class=&quot;nt&quot;&gt;-t&lt;/span&gt; rsa &lt;span class=&quot;nt&quot;&gt;-b&lt;/span&gt; 2048 &lt;span class=&quot;nt&quot;&gt;-f&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$env&lt;/span&gt;:USERPROFILE&lt;span class=&quot;se&quot;&gt;\.&lt;/span&gt;ssh&lt;span class=&quot;se&quot;&gt;\i&lt;/span&gt;d_rsa
&lt;span class=&quot;nb&quot;&gt;cat&lt;/span&gt; &lt;span class=&quot;nv&quot;&gt;$env&lt;/span&gt;:USERPROFILE&lt;span class=&quot;se&quot;&gt;\.&lt;/span&gt;ssh&lt;span class=&quot;se&quot;&gt;\i&lt;/span&gt;d_rsa.pub
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;el comando &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;cat&lt;/code&gt; muestra el contenido del archivo, lo copiamos. Ahora hay que pegarlo en el archivo &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.ssh/authorized_keys&lt;/code&gt; en Termux.&lt;/p&gt;

&lt;p&gt;Para eso nos conectamos por ssh (ver &lt;a href=&quot;#conectarse-al-servidor-desde-powershell&quot;&gt;Conectarse al servidor desde Powershell&lt;/a&gt;) y dentro del host (terminal de termux) copiamos el contenido del portapapeles dentro de &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;~/.ssh/authorized_keys&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/rsa_public.jpg&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Ahora queda deshabilitar la conexión por contraseña en el host:
Dentro de termux, ir a &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;/data/data/com.termux/files/usr/etc/ssh/sshd_config&lt;/code&gt;, descomentar la linea &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PasswordAuthentication yes&lt;/code&gt; y cambiarla por &lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;PasswordAuthentication no&lt;/code&gt;.&lt;/p&gt;

&lt;hr /&gt;

&lt;p&gt;Listo, ya podemos empezar a usar Termux desde Windows.&lt;/p&gt;
</description>
        <pubDate>Tue, 04 Mar 2025 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2025-03/sshwindows</link>
        <guid isPermaLink="true">http://valenrc.github.io/2025-03/sshwindows</guid>
        
        
        <category>termux</category>
        
      </item>
    
      <item>
        <title>Resumen de x86_64 - System V ABI</title>
        <description>&lt;h2 id=&quot;resumen-de-x86_64-y-system-v-abi-para-el-primer-parcial-de-arquitectura-y-organización-de-computadoras&quot;&gt;Resumen de x86_64 y System V ABI para el primer parcial de Arquitectura y Organización de Computadoras&lt;/h2&gt;

&lt;!-- Index --&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;#registros&quot;&gt;Registros&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#registros-volátiles-caller-saved&quot;&gt;Registros volátiles (caller saved)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#registros-no-volátiles-callee-saved&quot;&gt;Registros no volátiles (callee saved)&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#valores-de-retorno-de-funciones&quot;&gt;Valores de retorno de funciones&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#llamadas-a-funciones-de-c&quot;&gt;Llamadas a funciones de C&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#pasaje-de-parámetros-a-funciones&quot;&gt;Pasaje de parámetros a funciones&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#direccionamiento&quot;&gt;Direccionamiento&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#alineación-de-structs&quot;&gt;Alineación de structs&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;#gdb&quot;&gt;GDB&lt;/a&gt;
    &lt;ul&gt;
      &lt;li&gt;&lt;a href=&quot;#imprimir-registros-xmm&quot;&gt;Imprimir registros xmm&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#examinar-memoria&quot;&gt;Examinar memoria&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#examinar-la-pila&quot;&gt;Examinar la pila&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#imprimir-punteros-a-structs&quot;&gt;Imprimir punteros a structs&lt;/a&gt;&lt;/li&gt;
      &lt;li&gt;&lt;a href=&quot;#imprimir-arrays&quot;&gt;Imprimir arrays&lt;/a&gt;
        &lt;ul&gt;
          &lt;li&gt;&lt;a href=&quot;#arrays-de-tipos-simples&quot;&gt;Arrays de tipos simples&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#arrays-de-structs&quot;&gt;Arrays de structs&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href=&quot;#arrays-de-punteros-a-structs&quot;&gt;Arrays de punteros a structs&lt;/a&gt;&lt;/li&gt;
        &lt;/ul&gt;
      &lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;registros&quot;&gt;Registros&lt;/h2&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;64 bits&lt;/th&gt;
      &lt;th&gt;32 bits&lt;/th&gt;
      &lt;th&gt;16 bits&lt;/th&gt;
      &lt;th&gt;8 bits&lt;/th&gt;
      &lt;th&gt;Description&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;rax&lt;/td&gt;
      &lt;td&gt;eax&lt;/td&gt;
      &lt;td&gt;ax&lt;/td&gt;
      &lt;td&gt;al&lt;/td&gt;
      &lt;td&gt;return value&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;rbx&lt;/td&gt;
      &lt;td&gt;ebx&lt;/td&gt;
      &lt;td&gt;bx&lt;/td&gt;
      &lt;td&gt;bl&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;rcx&lt;/td&gt;
      &lt;td&gt;ecx&lt;/td&gt;
      &lt;td&gt;cx&lt;/td&gt;
      &lt;td&gt;cl&lt;/td&gt;
      &lt;td&gt;4th argument&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;rdx&lt;/td&gt;
      &lt;td&gt;edx&lt;/td&gt;
      &lt;td&gt;dx&lt;/td&gt;
      &lt;td&gt;dl&lt;/td&gt;
      &lt;td&gt;3rd argument&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;rsi&lt;/td&gt;
      &lt;td&gt;esi&lt;/td&gt;
      &lt;td&gt;si&lt;/td&gt;
      &lt;td&gt;sil&lt;/td&gt;
      &lt;td&gt;2nd argument&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;rdi&lt;/td&gt;
      &lt;td&gt;edi&lt;/td&gt;
      &lt;td&gt;di&lt;/td&gt;
      &lt;td&gt;dil&lt;/td&gt;
      &lt;td&gt;1st argument&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r8&lt;/td&gt;
      &lt;td&gt;r8d&lt;/td&gt;
      &lt;td&gt;r8w&lt;/td&gt;
      &lt;td&gt;r8b&lt;/td&gt;
      &lt;td&gt;5th argument&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r9&lt;/td&gt;
      &lt;td&gt;r9d&lt;/td&gt;
      &lt;td&gt;r9w&lt;/td&gt;
      &lt;td&gt;r9b&lt;/td&gt;
      &lt;td&gt;6th argument&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r10&lt;/td&gt;
      &lt;td&gt;r10d&lt;/td&gt;
      &lt;td&gt;r10w&lt;/td&gt;
      &lt;td&gt;r10b&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r11&lt;/td&gt;
      &lt;td&gt;r11d&lt;/td&gt;
      &lt;td&gt;r11w&lt;/td&gt;
      &lt;td&gt;r11b&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r12&lt;/td&gt;
      &lt;td&gt;r12d&lt;/td&gt;
      &lt;td&gt;r12w&lt;/td&gt;
      &lt;td&gt;r12b&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r13&lt;/td&gt;
      &lt;td&gt;r13d&lt;/td&gt;
      &lt;td&gt;r13w&lt;/td&gt;
      &lt;td&gt;r13b&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r14&lt;/td&gt;
      &lt;td&gt;r14d&lt;/td&gt;
      &lt;td&gt;r14w&lt;/td&gt;
      &lt;td&gt;r14b&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;r15&lt;/td&gt;
      &lt;td&gt;r15d&lt;/td&gt;
      &lt;td&gt;r15w&lt;/td&gt;
      &lt;td&gt;r15b&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;registros-volátiles-caller-saved&quot;&gt;Registros volátiles (caller saved)&lt;/h2&gt;

&lt;p&gt;Pushearlos si se usan en una función y se quiere preservar su valor después de una llamada a otra función:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;RAX, RCX, RDX, RSI, RDI, R8, R9, R10, R11, XMM0-15&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;registros-no-volátiles-callee-saved&quot;&gt;Registros no volátiles (callee saved)&lt;/h2&gt;

&lt;p&gt;Pushearlos siempre que se usan desde dentro de cualquier función:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;RBX, RSP, RBP, R12, R13, R14, R15&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;valores-de-retorno-de-funciones&quot;&gt;Valores de retorno de funciones&lt;/h2&gt;

&lt;ul&gt;
  &lt;li&gt;RAX -&amp;gt; enteros/punteros&lt;/li&gt;
  &lt;li&gt;RAX -&amp;gt; floats&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;llamadas-a-funciones-de-c&quot;&gt;Llamadas a funciones de C&lt;/h2&gt;

&lt;p&gt;La pila debe estar alineada a 16 bytes (&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;sub rsp, X&lt;/code&gt;).&lt;br /&gt;
Cuando se entra a una función en asm, la pila siempre está desalineada (alineada a 8 bytes).&lt;/p&gt;
&lt;h2 id=&quot;pasaje-de-parámetros-a-funciones&quot;&gt;Pasaje de parámetros a funciones&lt;/h2&gt;
&lt;h3 id=&quot;primeros-6-argumentos&quot;&gt;Primeros 6 argumentos:&lt;/h3&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Regsitro&lt;/th&gt;
      &lt;th&gt;N° arg&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;RDI&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;RSI&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;RDX&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg3&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;RCX&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg4&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;R8&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg5&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;R9&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg6&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;argumentos-siguientes&quot;&gt;Argumentos siguientes:&lt;/h3&gt;
&lt;p&gt;se pushean de derecha a izquierda en la pila&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Memoria&lt;/th&gt;
      &lt;th&gt;N° arg&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;rbp + 8&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;(&lt;strong&gt;rip caller&lt;/strong&gt;)&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;rbp + 16&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg1&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;strong&gt;rbp + 24&lt;/strong&gt;&lt;/td&gt;
      &lt;td&gt;arg2&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;…&lt;/td&gt;
      &lt;td&gt; &lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;direccionamiento&quot;&gt;Direccionamiento&lt;/h2&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[ Base + ( Index * Scale ) + Displacement ]
   ^         ^       ^            ^
   |         |       |            |
  RAX       RAX      1        Cte. 32 bits
  ...       ...      2
  R15       R15      4
          (No RSP)   8
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Size directives:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;BYTE&lt;/strong&gt;   1 byte		8 bits&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;WORD&lt;/strong&gt;   2 bytes	16 bits&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;DWORD&lt;/strong&gt;  4 bytes	32 bits&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;QWORD&lt;/strong&gt;  8 bytes	64 bits&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;OWORD&lt;/strong&gt;  16 btyes	128 bits&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;alineación-de-structs&quot;&gt;Alineación de structs&lt;/h2&gt;
&lt;p&gt;Cada campo en un struct tiene un requisito de alineacion que por lo general es igual a su tamaño en bytes.&lt;/p&gt;

&lt;p&gt;Cada campo debe estar alineado en direcciones de memoria que sean múltiplos de su requisito de alineacion. El compilador puede añadir padding entre los miembros del struct para hacer cumplir estos requisitos de alineación.&lt;/p&gt;

&lt;p&gt;Al final, el tamaño total del struct debe ser múltiplo del mayor requisito de alineacion de sus campos, el compilador puede añadir padding al final del struct para hacer cumplir esto, haciendo que el tamaño del struct aumente.&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;/p&gt;
&lt;div class=&quot;language-c highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;k&quot;&gt;typedef&lt;/span&gt; &lt;span class=&quot;k&quot;&gt;struct&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;char&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;// 1 byte&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;uint32_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// 4 bytes&lt;/span&gt;
    &lt;span class=&quot;kt&quot;&gt;uint16_t&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;c&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;// 2 bytes&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;example_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Asi queda el struct en memoria:&lt;/p&gt;

&lt;table&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;a (1 byte)&lt;/td&gt;
      &lt;td&gt;Padding (3 bytes)&lt;/td&gt;
      &lt;td&gt;b (4 bytes)&lt;/td&gt;
      &lt;td&gt;c (2 bytes)&lt;/td&gt;
      &lt;td&gt;Padding (2 bytes)&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h2 id=&quot;gdb&quot;&gt;GDB&lt;/h2&gt;
&lt;p&gt;Machete de gdb: https://macapiaggio.github.io/gdb-guide/&lt;/p&gt;

&lt;h3 id=&quot;imprimir-registros-xmm&quot;&gt;Imprimir registros xmm&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p/b $xmmn.f&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;b: base
    &lt;ul&gt;
      &lt;li&gt;/d: base 10 signed&lt;/li&gt;
      &lt;li&gt;/u: base 10 unsigned&lt;/li&gt;
      &lt;li&gt;/t: base 2&lt;/li&gt;
      &lt;li&gt;/x: base 16&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;f: formato
    &lt;ul&gt;
      &lt;li&gt;.v4_int32: 4 registros de 32 bits c/u&lt;/li&gt;
      &lt;li&gt;.v2_int64: 2 registros de 64 bits c/u&lt;/li&gt;
      &lt;li&gt;.v8_int16: 8 registros de 16 bits c/u&lt;/li&gt;
      &lt;li&gt;.v16_int8: 16 registros de 8 bits c/u&lt;/li&gt;
      &lt;li&gt;.v4_float: 4 registros de single-precision float (32 bits)&lt;/li&gt;
      &lt;li&gt;.v2_double: 2 registros de double-precision float (64 bits)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;examinar-memoria&quot;&gt;Examinar memoria&lt;/h3&gt;
&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x /Nuf expression&lt;/code&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;N: units to display&lt;/li&gt;
  &lt;li&gt;u: unit size
    &lt;ul&gt;
      &lt;li&gt;b: byte&lt;/li&gt;
      &lt;li&gt;h: halfwords (2 bytes)&lt;/li&gt;
      &lt;li&gt;w: words (4 bytes)&lt;/li&gt;
      &lt;li&gt;g: giant words (8 bytes)&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;f: formato
    &lt;ul&gt;
      &lt;li&gt;x: hexa&lt;/li&gt;
      &lt;li&gt;d: signed decimal&lt;/li&gt;
      &lt;li&gt;u: unsigned decimal&lt;/li&gt;
      &lt;li&gt;t: binary&lt;/li&gt;
      &lt;li&gt;a: address&lt;/li&gt;
      &lt;li&gt;c: char&lt;/li&gt;
      &lt;li&gt;f: float&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;examinar-la-pila&quot;&gt;Examinar la pila&lt;/h3&gt;
&lt;p&gt;Acceder a un elemento específico en &lt;strong&gt;[rbp - offset]&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;x /1gx $rbp-offset&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;imprimir-punteros-a-structs&quot;&gt;Imprimir punteros a structs&lt;/h3&gt;
&lt;p&gt;Ejemplo:
rdi tiene un puntero a un struct de tipo struct_t:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p *(struct_t*) $rdi&lt;/code&gt;&lt;/p&gt;

&lt;h3 id=&quot;imprimir-arrays&quot;&gt;&lt;strong&gt;Imprimir arrays&lt;/strong&gt;&lt;/h3&gt;

&lt;h4 id=&quot;arrays-de-tipos-simples&quot;&gt;&lt;strong&gt;Arrays de tipos simples&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Ejemplo: rdi tiene la direccion de un array de n enteros de tipo uint16_t:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p *(uint16_t(*)[n]) $rdi&lt;/code&gt;&lt;/p&gt;

&lt;h4 id=&quot;arrays-de-structs&quot;&gt;&lt;strong&gt;Arrays de structs&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Ejemplo: rdi apunta a un array de tamaño n de structs de tipo struct_t:&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p *(struc_t(*)[n]) $rdi&lt;/code&gt;&lt;/p&gt;

&lt;h4 id=&quot;arrays-de-punteros-a-structs&quot;&gt;&lt;strong&gt;Arrays de punteros a structs&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Ejemplo: rdi es un array de n punteros a structs&lt;/p&gt;

&lt;p&gt;&lt;code class=&quot;language-plaintext highlighter-rouge&quot;&gt;p *(struct_t**(*)[n]) $rdi&lt;/code&gt;&lt;/p&gt;
</description>
        <pubDate>Mon, 25 Nov 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-11/macheteorga2-1</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-11/macheteorga2-1</guid>
        
        
        <category>facultad</category>
        
      </item>
    
      <item>
        <title>github copilot gratis siendo alumno de la UBA</title>
        <description>&lt;p&gt;Con la llegada del &lt;a href=&quot;https://code.visualstudio.com/updates/v1_95&quot;&gt;update 1.95&lt;/a&gt; VSCode mejoró notablemente su integración con Github copilot. Y ahora que lo pude probar (al fin), puedo decir que vale la pena totalmente. Aún mas con las restricciones de tokens diarios que imponen ChatGPT o Claude a los usuarios gratuitos.&lt;/p&gt;

&lt;p&gt;En este post voy a explicar los pasos que seguí para tener acceso al programa &lt;a href=&quot;https://github.com/education&quot;&gt;Github Education&lt;/a&gt;, con el cual nos dan acceso al &lt;a href=&quot;https://education.github.com/pack&quot;&gt;Student developer pack&lt;/a&gt;. Este pack contiene acceso completo a Copilot totalmente gratis:&lt;/p&gt;

&lt;p&gt;Requisitos:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;Tener un mail con dominio uba: Preferentemente &lt;strong&gt;dc.uba.ar&lt;/strong&gt; (departamento de computación, i.e. DC), aunque debería funcionar con cualquier mail que GitHub detecte como perteneciente a la Universidad de Buenos Aires (terminado en &lt;strong&gt;uba.ar&lt;/strong&gt;).&lt;/li&gt;
  &lt;li&gt;Tener un certificado de alumno regular: Se consigue generalemente a través de SIU Guaraní, se genera instantaneamente.
&lt;img src=&quot;/assets/img/posts/certificado.png&quot; alt=&quot;&quot; /&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;El mail del Departamento de Computación se consigue abriendo ticket en soporte (&lt;a href=&quot;https://soporte.dc.uba.ar/&quot;&gt;https://soporte.dc.uba.ar/&lt;/a&gt;) y enviando tu LU y certificado de alumno regular.&lt;/p&gt;

&lt;p&gt;Lo siguiente va a ser configuar tu cuenta de GitHub en &lt;a href=&quot;https://github.com/settings/profile&quot;&gt;https://github.com/settings/profile&lt;/a&gt;:&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;En &lt;strong&gt;Public Profile&lt;/strong&gt; completar con tu nombre real&lt;/li&gt;
  &lt;li&gt;En &lt;strong&gt;Billing and Plans -&amp;gt; Payment information&lt;/strong&gt; completar los campos obligatorios (Nombre completo y Ubicación)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Es importante que el nombre coincida con el mismo que aparece en el certificado de la facultad.&lt;/p&gt;

&lt;p&gt;Ahora queda enviar la solicitud a Github:
Logeate en &lt;a href=&quot;https://education.github.com/pack&quot;&gt;https://education.github.com/pack&lt;/a&gt;, ingresá el mail de alumno de la uba y van a pedirte una foto de tu certificado (en &lt;strong&gt;Proof Type&lt;/strong&gt; elegí la segunda opcion &lt;em&gt;signed transcript&lt;/em&gt; o algo así). Si hay algo mal, debería llegar un mail casi al instante de enviar la solicitud. Si no, entonces queda esperar a que llegue un mail de aprobación.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/githubstudent.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Despues de esto, queda reclamar el beneficio en la &lt;a href=&quot;https://education.github.com/pack&quot;&gt;pagina principal de Student Developer Pack&lt;/a&gt; en la seccion &lt;em&gt;All offers&lt;/em&gt;, te va a redirigir a configuración de Copilot y se va a activar automaticamente despues de completar la configuracion (Deshabilita la opcion &lt;em&gt;Allow GitHub to use my code snippets from the code editor for product improvements&lt;/em&gt; :p y habilitá &lt;em&gt;Anthropic Claude 3.5 Sonnet in Copilot&lt;/em&gt; si está disponible)&lt;/p&gt;

&lt;p&gt;Listo, ahora tenemos Copilot + otros beneficios (GitLens, Github Pro, etc, etc)&lt;/p&gt;
</description>
        <pubDate>Mon, 18 Nov 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-11/copilot1</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-11/copilot1</guid>
        
        
        <category>facultad</category>
        
      </item>
    
      <item>
        <title>apuntes de la facultad</title>
        <description>&lt;h2 id=&quot;organización-del-computador&quot;&gt;&lt;strong&gt;Organización del computador&lt;/strong&gt;&lt;/h2&gt;
&lt;p&gt;&lt;a href=&quot;/2024-11/macheteorga2-1&quot;&gt;Resumen de assembler x86_64&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;plp&quot;&gt;&lt;strong&gt;PLP&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;/2024-10/apunteplp1&quot;&gt;Apunte para el primer parcial de PLP&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/2024-10/apunteplp2&quot;&gt;Apunte para el segundo parcial de PLP&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;sistemas-digitales&quot;&gt;&lt;strong&gt;Sistemas Digitales&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;a href=&quot;/2024-10/apuntefinalorga1&quot;&gt;Apunte para el final de Orga I&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 20 Oct 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-10/apuntes</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-10/apuntes</guid>
        
        
        <category>facultad</category>
        
      </item>
    
      <item>
        <title>apunte para el final de Orga I</title>
        <description>&lt;p&gt;Apunte para el final de Organización del computador I&lt;/p&gt;

&lt;p&gt;- Arq. Von Neumann, Entrada/salida, Memoria –&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/pdf/apunteorga1.pdf&quot;&gt;versión en pdf&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;1-contenido&quot;&gt;1. &lt;strong&gt;Contenido&lt;/strong&gt;&lt;/h1&gt;

&lt;p&gt;&lt;a href=&quot;#von-neumann&quot;&gt;2	Von Neumann	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#que-es-una-arquitectura&quot;&gt;2.1	Que es una arquitectura	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#características-del-modelo-von-neumann&quot;&gt;2.2	Características del modelo Von Neumann	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#estructura-del-modelo-von-neumann&quot;&gt;2.3	Estructura del modelo Von Neumann	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#system-bus-model&quot;&gt;2.4	System bus model	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#ciclo-de-instrucciones&quot;&gt;2.5	Ciclo de instrucciones	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#entradasalida&quot;&gt;3	Entrada/Salida	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#interfaz-de-entradasalida&quot;&gt;3.1	Interfaz de entrada/salida	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#arquitectura-de-entradasalida&quot;&gt;3.2	Arquitectura de entrada/salida	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#métodos-de-acceso-a-es&quot;&gt;3.3	Métodos de acceso a E/S	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#polling-programmed-io:&quot;&gt;3.3.1	Polling (programmed I/O)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#interrupciones:&quot;&gt;3.3.2	Interrupciones&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#mapeo-en-memoria:&quot;&gt;3.3.3	Mapeo en memoria&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#acceso-directo-a-memoria-dma:&quot;&gt;3.3.4	Acceso directo a memoria (DMA)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#canal-de-es-channel-attached-io:&quot;&gt;3.3.5	Canal de E/S (Channel-attached I/O)&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#comparación-de-métodos-de-acceso-a-es&quot;&gt;3.4	Comparación de métodos de acceso a E/S&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#conversión-de-señales&quot;&gt;4	Conversión de señales&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#conversión-analógicodigital&quot;&gt;4.1	Conversión Analógico/digital	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#muestreo-de-la-señal:&quot;&gt;4.1.1	Muestreo de la señal&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#cuantificación&quot;&gt;4.1.2	Cuantificación	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#conversión-digitalanalógico&quot;&gt;4.2	Conversión digital/analógico	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#memoria&quot;&gt;5	Memoria	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#introducción-a-memorias&quot;&gt;5.1	Introducción a memorias	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#jerarquía-de-memorias&quot;&gt;5.2	Jerarquía de memorias&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#tipos-de-memoria&quot;&gt;5.3	Tipos de memoria&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#ram&quot;&gt;5.3.1	RAM	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#rom&quot;&gt;5.3.2	ROM	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#memoria-caché&quot;&gt;5.4	Memoria caché	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#principio-de-localidad&quot;&gt;5.4.1	Principio de localidad	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#niveles-de-caché&quot;&gt;5.4.2	Niveles de caché&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#operación-de-lectura-de-memoria&quot;&gt;5.4.3	Operación de lectura de memoria	&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#hit-rate&quot;&gt;5.4.4	Hit rate&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#algoritmos-de-reemplazo-de-contenido&quot;&gt;5.4.5	Algoritmos de reemplazo de contenido&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;#bibliografia&quot;&gt;6	Bibliografia&lt;/a&gt;&lt;/p&gt;

&lt;h1 id=&quot;von-neumann&quot;&gt;2.  Von Neumann&lt;/h1&gt;

&lt;h2 id=&quot;que-es-una-arquitectura&quot;&gt;2.1  &lt;strong&gt;Que es una arquitectura&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;La arquitectura de una computadora se refiere a los atributos de un sistema visibles para un programador, aquellos que tienen un impacto directo en la ejecución lógica de un programa. Estos atributos incluyen: la ISA, el número de bits que se usan para representar los datos, mecanismos de E/S y modos de direccionamiento de la memoria.&lt;/p&gt;

&lt;p&gt;El estudio de la arquitectura se encarga de la estructura y el comportamiento de la computadora.&lt;/p&gt;

&lt;h2 id=&quot;características-del-modelo-von-neumann&quot;&gt;2.2 &lt;strong&gt;Características del modelo Von Neumann&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;strong&gt;Programa Almacenado&lt;/strong&gt;: mantiene las instrucciones y los datos en una memoria de acceso aleatorio (RAM). Se diferencia de la arquitectura Harvard en que los datos e instrucciones de programa se almacenan en una única memoria.&lt;/p&gt;

&lt;p&gt;Cada celda de memoria tiene una &lt;strong&gt;dirección&lt;/strong&gt;: un numero único que la representa.&lt;/p&gt;

&lt;p&gt;Los datos y las instrucciones tienen distintos tipos de uso, sin embargo, su estructura no se representa de forma &lt;strong&gt;codificada&lt;/strong&gt; (la memoria no puede saber si en una posición tiene un dato o un comando)&lt;/p&gt;

&lt;p&gt;Cada programa se ejecuta de &lt;strong&gt;forma secuencial&lt;/strong&gt;, a menos que se indique lo contrario mediante instrucciones de control de transferencia.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/vonneumann.jpg&quot; alt=&quot;Arquitecturas Von-Newman VS Harvard Compilando Conocimiento&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/vonneumann.jpg&quot; alt=&quot;Computo Integrado: Arquitectura von Neumann y arquitectura Harvard&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;estructura-del-modelo-von-neumann&quot;&gt;2.3 &lt;strong&gt;Estructura del modelo Von Neumann&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Consta de tres componentes principales:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Unidad central de procesamiento (CPU):&lt;/strong&gt; Controla el funcionamiento de la computadora y realiza funciones de procesamiento de datos. Consta de otros cuatro componentes:
    &lt;ul&gt;
      &lt;li&gt;&lt;strong&gt;Unidad de control:&lt;/strong&gt; Se encarga de ejecutar los microinstrucciones que contienen las señales de control de los demás componentes de la CPU.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Unidad aritmético-lógica (ALU):&lt;/strong&gt; Realiza las funciones de procesamiento de datos de la computadora.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Registros&lt;/strong&gt;: Proporciona almacenamiento interno a la CPU, Pueden ser de propósito específico como el Program Counter o de uso general.&lt;/li&gt;
      &lt;li&gt;&lt;strong&gt;Interconexión de la CPU&lt;/strong&gt;: Mecanismo que permite la comunicación entre todos los demás componentes de la CPU&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Memoria principal:&lt;/strong&gt; Almacena los datos y las instrucciones de programas.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Sistema de entrada/salida (I/O):&lt;/strong&gt; Mueve datos entre la computadora y aparatos externos como sensores o periféricos. Parte de lo que llega de datos a la memoria es resuelto por este subsistema.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;La arquitectura tiene la particularidad de que existe un único camino (físico o lógico) desde donde se conecta la CPU con la memoria. En la mayoría de computadoras la velocidad de comunicación ente memoria y procesador es menor a la velocidad a la que puede trabajar el procesador, esto fuerza a la CPU a esperar continuamente a que lleguen los datos desde o hacia la memoria, limitando el rendimiento de la computadora. Esto se conoce como &lt;strong&gt;CUELLO DE BOTELLA DE VON NEUMANN&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/vonneumannarch.jpg&quot; alt=&quot;https://upload.wikimedia.org/wikipedia/commons/thumb/5/50/Arquitecturaneumann.jpg/330px-Arquitecturaneumann.jpg&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;system-bus-model&quot;&gt;2.4  &lt;strong&gt;System bus model&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;La arquitectura de Von Neumann se puede extender a un modelo llamado “System bus” o &lt;strong&gt;modelo de bus de sistema&lt;/strong&gt;. &lt;br /&gt;
El bus de datos mueve datos desde la memoria principal a los registros de la CPU (y viceversa).&lt;br /&gt;
El bus de direcciones contiene la dirección de los datos que el bus de datos está accediendo actualmente.&lt;br /&gt;
El bus de control lleva las señales de control necesarias que especifican como se llevara a cabo la transferencia de información.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/systembus.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;ciclo-de-instrucciones&quot;&gt;2.5.  &lt;strong&gt;Ciclo de instrucciones&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;La arquitectura de Von Neumann ejecuta programas siguiendo el ciclo de instrucción &lt;strong&gt;fetch-decode-execute.&lt;/strong&gt; Funciona de la siguiente manera:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Fetch&lt;/strong&gt;: Se obtiene la instrucción almacenada en la dirección de memoria que indica el PC y se incrementa el PC, con la ALU o con un incrementador propio; se traen las instrucciones para que la CPU pueda ejecutarlas.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decode&lt;/strong&gt;: Se decodifica la instrucción traída de memoria en un lenguaje que la ALU pueda entender; en caso de que sea necesario, se buscan y obtienen los operandos faltantes desde la memoria y se los coloca en los registros correspondientes para poder realizar la operación.&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;Execute&lt;/strong&gt;: La CPU utiliza los distintos componentes internos para procesar la instrucción correspondiente. De ser necesario almacena el resultado en memoria o en registros.&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/cycle.png&quot; alt=&quot;What is a Machine Cycle?&quot; /&gt;&lt;/p&gt;

    &lt;p&gt;&lt;em&gt;Ciclo de instrucciones&lt;/em&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h1 id=&quot;entradasalida&quot;&gt;3.  &lt;strong&gt;Entrada/Salida&lt;/strong&gt;&lt;/h1&gt;

&lt;h2 id=&quot;interfaz-de-entradasalida&quot;&gt;3.1  &lt;strong&gt;Interfaz de entrada/salida&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Los dispositivos de entrada y salida permiten la comunicación bidireccional entre la computadora y el mundo exterior.&lt;/p&gt;

&lt;p&gt;Entrada/salida (I/O) es la transferencia de datos entre la memoria principal y varios periféricos de entrada o salida. Los dispositivos de entrada, como teclado y mouse, nos permiten ingresar datos. Los de salida, como monitor o impresora, permiten obtener información de la computadora.&lt;/p&gt;

&lt;p&gt;La interfaz de entrada/salida se encarga de esta transmisión de datos, ya que los dispositivos no están conectados directamente a la CPU. La interfaz convierte las señales del sistema de bus a un formato entendible para el dispositivo al cual tiene que llegar. La CPU se comunica con estos dispositivos externos a través de los registros de entrada/salida.&lt;/p&gt;

&lt;h2 id=&quot;arquitectura-de-entradasalida&quot;&gt;3.2 &lt;strong&gt;Arquitectura de entrada/salida&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;I/O es un subsistema de componentes que transfieren información codificada entre dispositivos externos, la CPU y la memoria.&lt;/p&gt;

&lt;p&gt;Los subsistemas de E/S incluyen:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Direcciones de memoria principal exclusivas para funciones de I/O.&lt;/li&gt;
  &lt;li&gt;Buses que proporciona los medios para mover datos dentro y fuera del subsistema.&lt;/li&gt;
  &lt;li&gt;Módulos de control dentro de la CPU o dentro de los dispositivos de entrada/salida.&lt;/li&gt;
  &lt;li&gt;Interfaces para componentes externos como teclados o discos que permiten la transferencia de datos (por ejemplo, un teclado se conecta a través de interfaces como SATA, USB, etc.)&lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;Cableado o enlaces de comunicación entre la CPU y los periféricos.&lt;/p&gt;

    &lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/ioarch.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

    &lt;p&gt;&lt;em&gt;Modelo de configuración I/O&lt;/em&gt;&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Los &lt;strong&gt;módulos&lt;/strong&gt; de I/O se encargan de la transferencia de datos desde la memoria principal hacia una interfaz especifica.&lt;/p&gt;

&lt;p&gt;Las &lt;strong&gt;interfaces&lt;/strong&gt; están diseñadas para comunicarse con un tipo de dispositivos en particular, como teclados, discos o impresoras. Pueden ser de diferentes tipos como puertos USB, puertos Ethernet, interfaces HDMI, etc. Se diseñan para un propósito específico y para soportar diferentes tipos de periféricos.&lt;/p&gt;

&lt;h2 id=&quot;métodos-de-acceso-a-es&quot;&gt;3.3  &lt;strong&gt;Métodos de acceso a E/S&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Los módulos de E/S sirven para comunicar a los dispositivos con el bus de sistema (memoria y CPU). &lt;br /&gt;
Los métodos con los cuales los módulos de E/S se comunican con la CPU son cinco:&lt;/p&gt;

&lt;h3 id=&quot;polling-programmed-io:&quot;&gt;3.3.1  &lt;strong&gt;Polling (programmed I/O):&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;La CPU monitorea continuamente un registro de control asociado con cada puerto de E/S para determinar cuándo hay datos disponibles y cuando puede realizar operaciones de lectura o escritura.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ventaja&lt;/strong&gt;: Se puede controlar mediante código el comportamiento de cada dispositivo, el intervalo y las prioridades de polling.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Desventaja&lt;/strong&gt;: La CPU queda en un bucle continuo llamado &lt;em&gt;busy waiting&lt;/em&gt; y no hace ningún trabajo hasta que hay algún dato de E/S para procesar.&lt;/p&gt;

&lt;h3 id=&quot;interrupciones:&quot;&gt;3.3.2 &lt;strong&gt;Interrupciones:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;En lugar de estar constantemente monitoreando a los dispositivos de E/S, los dispositivos le indican a la CPU cuando tienen datos para enviar e interrumpen su tarea actual.&lt;/p&gt;

&lt;p&gt;La CPU también puede decidir si acepta interrupciones o no dependiendo de la tarea que esté procesando.&lt;/p&gt;

&lt;p&gt;Cuando se termina de ejecutar la rutina de interrupciones, se reestablece el estado de la CPU, regresa al programa que había sido interrumpido y continua con el ciclo fetch-decode-execute hasta la siguiente interrupción.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/intdiagram.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;La comunicación entre la CPU y los dispositivos se lleva a cabo mediante un &lt;strong&gt;controlador de interrupciones&lt;/strong&gt;, el cual maneja las señales de interrupción de todos los dispositivos de E/S.&lt;/p&gt;

&lt;p&gt;Cuando el controlador de interrupciones detecta una señal de interrupción de los dispositivos de E/S conectados, manda una única señal de interrupción que activa una línea de control en el bus de sistema. Por lo general, esta línea de control se conecta directamente a la CPU.&lt;/p&gt;

&lt;p&gt;Cada dispositivo de E/S en el sistema tiene acceso a una línea de solicitud de interrupción y el controlador de interrupciones tiene una entrada para cada línea de solicitud de interrupción. Cuando se activa una solicitud de interrupción, el controlador decodifica la interrupción y envía un 1 a la entrada &lt;strong&gt;INT&lt;/strong&gt; del procesador.&lt;/p&gt;

&lt;p&gt;Cuando el procesador está listo para procesar la interrupción, activa la señal &lt;strong&gt;INTA&lt;/strong&gt; (Interrupt Acknowledge) que llega al controlador para que pueda desactivar la señal &lt;strong&gt;INT&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Cuando dos dispositivos activan su solicitud de interrupción al mismo tiempo, el controlador determina cual tiene prioridad basándose en el diseño del sistema. Las prioridades de interrupción se “cablean” físicamente en el controlador &lt;em&gt;(hardwired),&lt;/em&gt; lo que las hace prácticamente imposibles de cambiar.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/interruptions.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ventaja&lt;/strong&gt;: Libera a la CPU de realizar polling y le permite realizar otras tareas, mejorando el rendimiento y optimizando los recursos y tiempos del procesador.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Desventaja&lt;/strong&gt;: Es menos simple de implementar y gestionar que el método de polling.&lt;/p&gt;

&lt;h3 id=&quot;mapeo-en-memoria:&quot;&gt;3.3.3  &lt;strong&gt;Mapeo en memoria:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Se reserva una porción de memoria para recibir y mandar datos a los dispositivos. Para usarlo, se usan instrucciones de lectura y escritura en memoria. De esta manera, cada dispositivo de E/S tiene su propio bloque de memoria reservado.&lt;/p&gt;

&lt;p&gt;La E/S mapeada a memoria se ve exactamente como un acceso a memoria normal desde el punto de vista de la CPU. Esto significa que se pueden usar las mismas instrucciones para mover datos desde y hacia la E/S y la memoria.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ventaja&lt;/strong&gt;: Se simplifica enormemente el diseño del sistema.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Desventaja&lt;/strong&gt;: Se limita el espacio de direcciones disponibles al ser compartido con los dispositivos de E/S y la memoria principal.&lt;/p&gt;

&lt;h3 id=&quot;acceso-directo-a-memoria-dma:&quot;&gt;3.3.4 &lt;strong&gt;Acceso directo a memoria (DMA):&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;El proceso de E/S se programa en un chip dedicado llamado controlador de DMA, el cual es mucho más sencillo que una CPU.&lt;/p&gt;

&lt;p&gt;La CPU delega la ejecución de instrucciones de E/S en el controlador de DMA.&lt;/p&gt;

&lt;p&gt;El controlador de DMA toma el control del bus de sistema (bus de direcciones y de datos) sin intervención de la CPU y transfiere los datos entre los dispositivos de E/S y la memoria. Cuando termina, notifica a la CPU con una interrupción para que pueda procesar los datos transferidos.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ventajas&lt;/strong&gt;: Libera a la CPU de la transferencia de datos entre los dispositivos de E/S. Aumenta la eficiencia a la hora de transferir grandes volúmenes de datos y al manejar dispositivos de E/S de alta velocidad como controladores de video.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Desventajas&lt;/strong&gt;: Tener otro chip que se encargue de la E/S es más costoso y agrega complejidad al diseño de la computadora. Además, el CPU es generalmente más rápido que el chip de DMA, por lo que puede hacer el trabajo más rápido.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/dma.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Configuración de DMA&lt;/em&gt;&lt;/p&gt;

&lt;h3 id=&quot;canal-de-es-channel-attached-io:&quot;&gt;3.3.5 &lt;strong&gt;Canal de E/S (Channel-attached I/O):&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;La mayoría de computadoras que se usan para aplicaciones más críticas (almacenamiento o procesamiento de datos a gran escala o servidores) utilizan un tipo de interfaz de DMA llamada I/O channel.&lt;/p&gt;

&lt;p&gt;El canal de E/S funciona como intermediario entre los dispositivos de E/S y la CPU. Los dispositivos se conectan directamente al canal de E/S.&lt;/p&gt;

&lt;p&gt;Los canales de E/S son controlados por procesadores optimizados para E/S llamados I/O processors (IOPs). A diferencia de los controladores de DMA, los IOPs tienen la capacidad de ejecutar instrucciones aritmético-lógicas y de saltos condicionales o branches (bifurcaciones) que permiten controlar directamente a los dispositivos de E/S.&lt;/p&gt;

&lt;p&gt;Las instrucciones para el control de los dispositivos y la transferencia de datos son puestos en la memoria por la CPU y ejecutados por los IOPs.&lt;/p&gt;

&lt;p&gt;Cada IOP puede controlar varias rutas del canal de E/S, permitiendo el control de varios dispositivos de E/S en un solo IOP.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/iochannel.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Ventaja&lt;/strong&gt;: Mejora el rendimiento de sistemas grandes que requieren una mayor eficiencia al gestionar dispositivos de E/S.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Desventaja&lt;/strong&gt;: Aumenta notablemente el costo y la complejidad de implementación y mantenimiento.&lt;/p&gt;

&lt;h2 id=&quot;comparación-de-métodos-de-acceso-a-es&quot;&gt;3.4  	&lt;strong&gt;Comparación de métodos de acceso a E/S&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;La Velocidad de cada método de I/O depende del hardware dedicado. Lo que no hace el hardware, lo tendrá que hacer el software.&lt;/p&gt;

&lt;p&gt;El hardware dedicado a E/S logra una mayor eficiencia por que libera a la CPU de la mayoría de operaciones que se harían con software.&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th&gt;Método de E/S&lt;/th&gt;
      &lt;th&gt;Hardware&lt;/th&gt;
      &lt;th&gt;Software&lt;/th&gt;
      &lt;th&gt;Velocidad&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td&gt;Polling&lt;/td&gt;
      &lt;td&gt;*&lt;/td&gt;
      &lt;td&gt;***&lt;/td&gt;
      &lt;td&gt;*&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;Interrupciones&lt;/td&gt;
      &lt;td&gt;**&lt;/td&gt;
      &lt;td&gt;**&lt;/td&gt;
      &lt;td&gt;**&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td&gt;DMA&lt;/td&gt;
      &lt;td&gt;***&lt;/td&gt;
      &lt;td&gt;*&lt;/td&gt;
      &lt;td&gt;***&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h1 id=&quot;conversión-de-señales&quot;&gt;4.  &lt;strong&gt;Conversión de señales&lt;/strong&gt;&lt;/h1&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/conversionseñales.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;La conversión de señales se usa para permitir la interacción entre el mundo físico (analógico) y el mundo digital de las computadoras.&lt;/p&gt;

&lt;p&gt;Las &lt;strong&gt;señales analógicas&lt;/strong&gt; son aquellas que varían de manera continua en el tiempo y pueden tener un rango infinito de valores dentro de un intervalo dado. Son generadas por algún fenómeno, con cierta amplitud y frecuencia, que es representable por una función continua.&lt;/p&gt;

&lt;p&gt;Las &lt;strong&gt;señales digitales&lt;/strong&gt; son representadas mediante valores discretos (generalmente en forma binaria) donde solamente pueden tener un conjunto finito de valores.&lt;/p&gt;

&lt;p&gt;Algunos dispositivos de entrada/salida (sensores, micrófonos, cámaras, etc.) generan &lt;strong&gt;señales analógicas&lt;/strong&gt;, estas señales no pueden ser directamente procesadas por una computadora ya que no hay manera de representar los infinitos posibles valores de estas señales.  La manera de poder manipular y procesar las señales analógicas en una computadora es convirtiéndolas a formato digital.&lt;/p&gt;

&lt;p&gt;Por otro lado, otros dispositivos necesitan que las &lt;strong&gt;señales digitales&lt;/strong&gt; almacenadas en forma de datos binarios se conviertan a señales analógicas para ser reproducidas por dispositivos de salida, como parlantes o pantallas.&lt;/p&gt;

&lt;h2 id=&quot;conversión-analógicodigital&quot;&gt;4.1 &lt;strong&gt;Conversión Analógico/digital&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/adconverter.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Diagrama de un conversor A/D&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;La digitalización de una señal analógica consta de dos etapas: Muestreo de la señal y Cuantificación de las muestras.&lt;/p&gt;

&lt;h3 id=&quot;muestreo-de-la-señal:&quot;&gt;4.1.1 &lt;strong&gt;Muestreo de la señal:&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consiste en tomar muestras del valor de la señal de forma periódica, el periodo entre dos muestras consecutivas se conoce como periodo de muestreo (Ts) o intervalo de muestreo (Δt) y a partir de este valor se puede calcular la frecuencia de muestreo:&lt;/p&gt;

\[Fs = \frac{1}{Δ_t}\]

&lt;p&gt;Teorema del muestreo: Cuando se muestrea una señal analógica x(t), la frecuencia de muestreo debe ser mayor o igual que dos veces el valor de frecuencia máxima Fmax de la señal x(t), para poder reconstruirla a partir de las muestras.&lt;/p&gt;

\[Fs ≥ 2*Fmax\]

&lt;h3 id=&quot;cuantificación&quot;&gt;4.1.2  &lt;strong&gt;Cuantificación&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Consiste en ajustar el valor real de cada una de las muestras al valor más parecido del conjunto de valores posibles para cada muestra.&lt;/p&gt;

&lt;p&gt;La cantidad de bits del conversor A/D determina el rango dinámico (Xmin, Xmáx). Cuando se muestrea una señal analógica, se asigna a cada muestra el valor de amplitud más cercano a la amplitud de la onda original. (por ejemplo, un conversor de 16 bits puede cuantificar una muestra y asignarle un valor digital de entre 216 = 65536 valores posibles). Una profundidad de bits más alta proporciona más valores de amplitud posibles, lo que produce un rango dinámico más grande.&lt;/p&gt;

&lt;p&gt;El intervalo Δx está dado por la siguiente formula, donde N es la cantidad de bits del conversor A/D:&lt;/p&gt;

\[∆x= \frac{X_{max}-X_{min}}{2^N}\]

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/cuantificacion.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;conversión-digitalanalógico&quot;&gt;4.2  &lt;strong&gt;Conversión digital/analógico&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/daconverter.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Diagrama de un conversor D/A&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;El conversor digital/analógico realiza el proceso inverso al que realiza el conversor analógico/digital. Se parte de muestras en formato digital (valores discretos) y estas se deben convertir en una señal analógica (valores continuos).&lt;/p&gt;

&lt;p&gt;Para cada combinación de los bits de entrada, el DAC proporciona un valor analógico de salida distinto.&lt;/p&gt;

&lt;p&gt;La implementación básica de un DAC es mediante un circuito de resistencias ponderadas usando un amplificador operacional en configuración de lazo cerrado.&lt;/p&gt;

&lt;p&gt;Cada bit sucesivo en la palabra digital representa un nivel que es dos veces más grande que el bit anterior. La idea es tomar las señales digitales de entradas y asignarles un peso relativo mediante el uso de resistencias (el bit más significativo (&lt;strong&gt;MSB&lt;/strong&gt;) tiene la menor resistencia mientras que el menos significativo (&lt;strong&gt;LSB&lt;/strong&gt;) tiene la mayor resistencia, por lo que el peso del MSB es mayor que el del LSB) para luego sumarlas usando el amplificador operacional y obtener una señal analógica entre 0V y un valor máximo dado por la cantidad de bits y el valor de las resistencias.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/dac.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h1 id=&quot;memoria&quot;&gt;5. &lt;strong&gt;Memoria&lt;/strong&gt;&lt;/h1&gt;

&lt;h2 id=&quot;introducción-a-memorias&quot;&gt;5.1.  &lt;strong&gt;Introducción a memorias&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Las computadoras basadas en la arquitectura de Von Neumann almacenan los programas y los datos en la memoria.&lt;/p&gt;

&lt;p&gt;La estructura lógica de la memoria se puede ver como un &lt;strong&gt;array lineal de direcciones&lt;/strong&gt;, desde 0 hasta el tamaño máximo de memoria a la que el procesador puede direccionar.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/cpumemory.png&quot; alt=&quot;Javanotes 9, Section 1.1 -- The Fetch and Execute Cycle: Machine Language&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;jerarquía-de-memorias&quot;&gt;5.2.  &lt;strong&gt;Jerarquía de memorias&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;No todas las memorias son iguales, algunas son mucho menos eficientes que otras (y, por lo tanto, más baratas). Para hacer frente a esta disparidad, los sistemas informáticos actuales utilizan una combinación de tipos de memoria para proporcionar el mejor rendimiento al mejor costo. Este enfoque se llama &lt;strong&gt;memoria jerárquica&lt;/strong&gt;. Cuanto más rápida es la memoria, más cara es por bit de almacenamiento. Mediante el uso de una jerarquía de memorias, cada una con diferentes velocidades de acceso y capacidades de almacenamiento, un sistema informático puede exhibir un rendimiento superior al que sería posible sin una combinación de los distintos tipos.&lt;/p&gt;

&lt;p&gt;La memoria se suele clasificar en función de su “distancia” desde el procesador, con la distancia medida por la cantidad de ciclos de máquina necesarios para el acceso. Cuanto más cerca esté la memoria del procesador, más rápida debería ser. Por lo tanto, se utilizan tecnologías más lentas para las memorias más lejanas y tecnologías más rápidas para memorias más cercanas a la CPU.&lt;/p&gt;

&lt;p&gt;Los &lt;strong&gt;registros&lt;/strong&gt; son ubicaciones de almacenamiento disponibles en el propio procesador. La memoria &lt;strong&gt;caché&lt;/strong&gt; es una memoria de alta velocidad donde se pueden almacenar temporalmente los datos de la memoria principal utilizados con frecuencia. Esta memoria &lt;strong&gt;principal&lt;/strong&gt; que suele ser de velocidad media es complementada por otra memoria &lt;strong&gt;secundaria&lt;/strong&gt; de mayor tamaño compuesta generalmente por unidades de disco duro o de estado sólido y que contienen datos que la CPU solo puede acceder si se transfieren primero a la memoria principal.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/jerarquiadememoria.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h2 id=&quot;tipos-de-memoria&quot;&gt;5.3. &lt;strong&gt;Tipos de memoria&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Existen dos tipos básicos de memoria: ROM (read-only memory) y RAM (random access memory).&lt;/p&gt;

&lt;h3 id=&quot;ram&quot;&gt;5.3.1. &lt;strong&gt;RAM&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Es el tipo de memoria que se utiliza para la memoria principal de la computadora. Es usada para almacenar los programas y los datos que necesita la CPU para ejecutar programas.&lt;/p&gt;

&lt;p&gt;La memoria RAM es &lt;strong&gt;volátil&lt;/strong&gt;, ya que pierde la información almacenada una vez que la computadora deja de recibir energía.&lt;/p&gt;

&lt;p&gt;Hay dos tipos generales de chips que se usan para construir memorias RAM: &lt;strong&gt;SRAM&lt;/strong&gt; (RAM Estática) y &lt;strong&gt;DRAM&lt;/strong&gt; (RAM Dinámica)&lt;/p&gt;

&lt;h4 id=&quot;5311--dram&quot;&gt;5.3.1.1.  &lt;strong&gt;&lt;em&gt;DRAM&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;En este diseño, un bit se almacena en un capacitor, de manera que un capacitor descargado representa un 0 y un capacitor cargado representa un 1.&lt;/p&gt;

&lt;p&gt;La lectura en DRAM es destructiva, al leer un bit el capacitor se descarga y pierde la información, por lo que necesita regenerar la carga para cada lectura.&lt;/p&gt;

&lt;p&gt;El capacitor junto con el transistor de acceso, consume muy poca energía en comparación con otras tecnologías.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/dram.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Celda de DRAM&lt;/em&gt;&lt;/p&gt;

&lt;h4 id=&quot;5312--sram&quot;&gt;5.3.1.2.  &lt;strong&gt;&lt;em&gt;SRAM&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Las celdas de SRAM están construidas con circuitos de transistores llamados &lt;strong&gt;biestables&lt;/strong&gt; (flip-flops o latches).&lt;/p&gt;

&lt;p&gt;La lectura es &lt;strong&gt;directa&lt;/strong&gt; y &lt;strong&gt;no es destructiva&lt;/strong&gt; ya que se puede leer el estado de un bit sin afectar al estado del circuito.&lt;/p&gt;

&lt;p&gt;Es más eficiente que DRAM, pero también mucho más costoso en términos de consumo de energía, ya que contiene más componentes por celda.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/sram.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Celda de SRAM&lt;/em&gt;&lt;/p&gt;

&lt;h4 id=&quot;5313-comparación-entre-dram-y-sram&quot;&gt;5.3.1.3. &lt;strong&gt;&lt;em&gt;Comparación entre DRAM y SRAM&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;
&lt;p&gt;Tabla comparativa:&lt;/p&gt;

&lt;table&gt;
  &lt;thead&gt;
    &lt;tr&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Ram Dinámica (DRAM)&lt;/th&gt;
      &lt;th style=&quot;text-align: center&quot;&gt;Ram Estática (SRAM)&lt;/th&gt;
    &lt;/tr&gt;
  &lt;/thead&gt;
  &lt;tbody&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Consumo mínimo&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Alto consumo relativo&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Capacidad de almacenamiento comparativamente alta&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Capacidad de almacenamiento comparativamente baja&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Costo por bit bajo (almacenar un bit es menos costoso que en SRAM)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Costo por bit alto&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Tiempo de acceso lento (regeneración de carga por cada lectura)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Tiempo de acceso más rápido&lt;/td&gt;
    &lt;/tr&gt;
    &lt;tr&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Si se construye el banco de memoria con DRAM no se aprovecha la velocidad del procesador (cuello de botella)&lt;/td&gt;
      &lt;td style=&quot;text-align: center&quot;&gt;Si se construye el banco de memoria con SRAM el costo y el consumo de la computadora son altos&lt;/td&gt;
    &lt;/tr&gt;
  &lt;/tbody&gt;
&lt;/table&gt;

&lt;h3 id=&quot;rom&quot;&gt;5.3.2.  &lt;strong&gt;ROM&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;La mayoría de computadoras contienen una memoria de &lt;strong&gt;solo lectura&lt;/strong&gt; que sirve para almacenar información crítica (por ejemplo, las microinstrucciones de la unidad de control).&lt;/p&gt;

&lt;p&gt;Las memorias ROM &lt;strong&gt;no son volátiles&lt;/strong&gt;, por lo que siempre retienen su información, incluso si se apaga el sistema.&lt;/p&gt;

&lt;p&gt;Son también usadas en sistemas embebidos o en cualquier sistema en donde no es necesario cambiar su programación.&lt;/p&gt;

&lt;p&gt;Existen cinco tipos básicos de memoria ROM: &lt;strong&gt;ROM&lt;/strong&gt;, &lt;strong&gt;PROM&lt;/strong&gt; (programmable ROM), &lt;strong&gt;EPROM&lt;/strong&gt; (erasable PROM), &lt;strong&gt;EEPROM&lt;/strong&gt; (electrically erasable PROM) y &lt;strong&gt;memoria flash&lt;/strong&gt;.&lt;/p&gt;

&lt;h4 id=&quot;5321--prom&quot;&gt;5.3.2.1.  &lt;strong&gt;&lt;em&gt;PROM&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Es una variación de las memorias ROM en donde la información de un bit depende del estado de un fusible (el valor de fábrica de todos los bits de un PROM es 1; el quemado de cada fusible cambia el valor del correspondiente bit a 0). Una vez programado un PROM, los datos e instrucciones no se pueden cambiar.&lt;/p&gt;

&lt;h4 id=&quot;5322-eprom&quot;&gt;5.3.2.2. &lt;strong&gt;&lt;em&gt;EPROM&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Las memorias EPROM también son programables, pero tienen la característica de que se puede borrar todo su contenido para reprogramarlas (borrar una EPROM requiere un dispositivo especial que emite luz ultravioleta)&lt;/p&gt;

&lt;h4 id=&quot;5323-eeprom&quot;&gt;5.3.2.3. &lt;strong&gt;&lt;em&gt;EEPROM&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Las EEPROM eliminan algunas de las desventajas de EPROM ya que no se necesitan herramientas especiales para el borrado de sus datos y solo se puede borrar partes de la información, un byte a la vez.&lt;/p&gt;

&lt;h4 id=&quot;5324-memoria-flash&quot;&gt;5.3.2.4. &lt;strong&gt;&lt;em&gt;Memoria Flash&lt;/em&gt;&lt;/strong&gt;&lt;/h4&gt;

&lt;p&gt;Las memorias flash son esencialmente memorias EEPROM con el beneficio adicional de que los datos se pueden escribir o borrar en bloques, eliminando la limitación de un byte a la vez. Esto hace que la memoria flash sea más rápida que EEPROM.&lt;/p&gt;

&lt;h2 id=&quot;memoria-caché&quot;&gt;5.4. &lt;strong&gt;Memoria caché&lt;/strong&gt;&lt;/h2&gt;

&lt;p&gt;Al momento de diseñar la memoria principal, tenemos que lidiar con el problema de la &lt;strong&gt;asimetría&lt;/strong&gt; en la tasa de crecimiento de la velocidad de los procesadores con respecto a la tasa de crecimiento de la velocidad de las memorias.&lt;/p&gt;

&lt;p&gt;Como actualmente la velocidad de las memorias no son capaces de seguir el ritmo de la velocidad de los procesadores, se utilizan las memorias caché como una &lt;strong&gt;memoria auxiliar&lt;/strong&gt; que sirven para que el procesador reduzca el tiempo de acceso a datos ubicados en la memoria principal que se utilizan con más frecuencia.&lt;/p&gt;

&lt;p&gt;Como la CPU no tiene forma de saber que datos son más probables que se accedan, se utiliza el &lt;strong&gt;principio de localidad&lt;/strong&gt; para transferir los bloques a caché siempre que se haga un acceso a la memoria principal.&lt;/p&gt;

&lt;h3 id=&quot;principio-de-localidad&quot;&gt;5.4.1.  &lt;strong&gt;Principio de localidad&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Para cualquier dato dado, el procesador envía una solicitud a la memoria caché. Si los datos se encuentran en caché (&lt;strong&gt;hit&lt;/strong&gt;), pueden cargarse rápidamente a la CPU. En caso contrario (&lt;strong&gt;miss&lt;/strong&gt;), la solicitud se envía al siguiente nivel más bajo con respecto a la jerarquía de memoria y comienza nuevamente este proceso de búsqueda.&lt;/p&gt;

&lt;p&gt;Si los datos se encuentran en el nivel actual, se transfiere todo el bloque en el que residen los datos a la caché.&lt;/p&gt;

&lt;p&gt;La idea es que cuando los niveles inferiores responden a una solicitud de los niveles superiores para acceder al contenido de la ubicación X, envían un bloque con el dato de X y los datos ubicados “alrededor” de X &lt;strong&gt;(…, X-2, X-1, X, X+1, X+2, …)&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Esto se hace porque es probable que los datos adicionales que incluye el bloque sean utilizados por el procesador en un futuro cercano al pedido del dato original, entonces la transferencia del bloque entero ahorra tiempo de acceso.&lt;/p&gt;

&lt;p&gt;Hay tres formas de localidad:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Localidad temporal:&lt;/strong&gt; Los ítems accedidos recientemente tienden a ser accedidos de vuelta en el futuro cercano.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Localidad espacial:&lt;/strong&gt; Los accesos tienden a agruparse en el espacio de la dirección (por ej. Arrays o ciclos)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Localidad secuencial:&lt;/strong&gt; Las instrucciones o datos tienden a accederse secuencialmente.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;niveles-de-caché&quot;&gt;5.4.2. &lt;strong&gt;Niveles de caché&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Los datos en la memoria caché se alojan en distintos niveles según la frecuencia de uso que tengan. La información puede transferirse entre los distintos niveles de forma inclusiva (se mantiene una copia de los datos en dos o más niveles) o exclusiva (una vez transferidos los datos, se eliminan del nivel de procedencia)&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;L1 (nivel 1):&lt;/strong&gt; Se encuentra dentro del procesador y tiene un tamaño y un tiempo de respuesta menor a los siguientes niveles.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;L2 (nivel 2):&lt;/strong&gt; Puede encontrarse dentro o fuera del procesador dependiendo de la arquitectura. Tiene mayor tamaño, pero es más lenta que caché L1. Puede tener una copia de L1 además de información extra o exclusiva.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;L3 (nivel 3):&lt;/strong&gt; Se encuentra fuera del procesador y es más grande y de acceso más lento que L1 y L2. También puede contener una copia de L2.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/cachelevel.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;operación-de-lectura-de-memoria&quot;&gt;5.4.3. &lt;strong&gt;Operación de lectura de memoria&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Resumen de la operación de lectura en memoria de la CPU:&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/orga/lecturadememoria.png&quot; alt=&quot;&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;hit-rate&quot;&gt;5.4.4. &lt;strong&gt;Hit rate&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Hit rate= Cantidad de accesos a memoria con presencia en cachéCantidad total de accesos a memoria = hittotal&lt;/p&gt;

&lt;p&gt;El &lt;strong&gt;hit rate&lt;/strong&gt; de la memoria caché es la medida de que tan seguido la CPU solicita datos que ya están presentes en la caché en lugar de tener que acceder a la memoria principal.&lt;br /&gt;
Idealmente, el hit rate debe ser lo más alto posible ya que indica una utilización eficiente de la caché y una optimización en tiempos de lectura, lo que mejora el rendimiento del sistema.&lt;/p&gt;

&lt;h3 id=&quot;algoritmos-de-reemplazo-de-contenido&quot;&gt;5.4.4 &lt;strong&gt;Algoritmos de reemplazo de contenido&lt;/strong&gt;&lt;/h3&gt;

&lt;p&gt;Existen algoritmos para determinar qué datos se eliminan de la memoria caché cuando se necesita liberar espacio para nuevos datos.&lt;/p&gt;

&lt;p&gt;La elección del algoritmo depende de factores como el tamaño de la caché o la complejidad de implementación y tiene un impacto directo en el &lt;strong&gt;hit rate&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Algunos algoritmos son:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;LRU&lt;/strong&gt; (Least recently used): Elimina los datos que no han sido accedidos durante más tiempo. Se corresponde con el principio de localidad temporal.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;LFU&lt;/strong&gt; (Least frequently used): Elimina los datos que han sido accedidos con menos frecuencia.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Random:&lt;/strong&gt; Elimina los datos aleatoriamente.&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;FIFO;&lt;/strong&gt; Elimina los datos más antiguos de la caché.&lt;/li&gt;
&lt;/ul&gt;

&lt;h1 id=&quot;bibliografia&quot;&gt;6. &lt;strong&gt;Bibliografia&lt;/strong&gt;&lt;/h1&gt;

&lt;p&gt;Null L., Lobur J. – The essentials of computer organization and Architecture. Capitulos 6 y 7.&lt;/p&gt;

&lt;p&gt;All About Circuits - Introduction to Digital-Analog Conversion - &lt;a href=&quot;https://www.allaboutcircuits.com/textbook/digital/chpt-13/digital-analog-conversion/&quot;&gt;Link&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;David J. Eck - Introduction to Programming Using Java – Sección 1.1 (The Fetch and Execute Cycle)&lt;/p&gt;

&lt;p&gt;James M. Fiore – Operational Amplifiers &amp;amp; Linear Integrated Circuits:&lt;/p&gt;

&lt;p&gt;Theory and Application – Sección 12.4 (DACs).&lt;/p&gt;

&lt;p&gt;Andrew Scholer – Welcome to CS – Sección 6.5 (Memory Hierarchy)&lt;/p&gt;

&lt;p&gt;The FurfiOS Corporation - Resumen Final de Orga 1 (Parte 2).&lt;/p&gt;

&lt;p&gt;Ramiro Sánchez Posadas y Martino Simón – Q\&amp;amp;A para final de Orga I.&lt;/p&gt;

&lt;p&gt;Diapositivas de las clases teóricas del Dr. Marcelo Risk. ☺&lt;/p&gt;
</description>
        <pubDate>Sun, 20 Oct 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-10/apuntefinalorga1</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-10/apuntefinalorga1</guid>
        
        
        <category>facultad</category>
        
      </item>
    
      <item>
        <title>PLP - apunte para el segundo parcial</title>
        <description>&lt;h1 id=&quot;ii-paradigmas-de-programación---1c2024&quot;&gt;II. Paradigmas de programación - 1C2024&lt;/h1&gt;
&lt;h3 id=&quot;resumen-para-el-segundo-parcial&quot;&gt;Resumen para el segundo parcial&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;LPO, Resolución, Prolog, Smalltalk&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Todo el contenido de este archivo es una recopilación/resumen del contenido de las teóricas/prácticas del campus de la materia, que fue transcrito en Latex por mi. Puede contener errores.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/pdf/apunteplp2.pdf&quot;&gt;versión en pdf&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;lógica-de-primer-orden-lpo&quot;&gt;Lógica de primer orden (LPO)&lt;/h2&gt;

&lt;h3 id=&quot;sintaxis-de-lpo&quot;&gt;Sintaxis de LPO&lt;/h3&gt;

&lt;p&gt;Sea P un símbolo de predicado de aridad n y X una variable ligada por los cuantificadores ∀ y ∃, la gramática de la lógica de primer orden es la siguiente:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- Términos
σ ::= P(t1, ..., tn)  -- Formula atómica
    | ⊥               -- Contradicción
    | σ -&amp;gt; σ
    | σ ∧ σ
    | σ ∨ σ
    | ¬σ
    | ∀X. σ           -- Cuantificación universal
    | ∃X. σ           -- Cuantificación existencial
		
		
-- Ejemplo: (= es un simbolo de predicado) 
σ := succ(X) = Y -&amp;gt; ∃Z. X + Z = Y
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;deducción-natural&quot;&gt;Deducción natural&lt;/h3&gt;

&lt;p&gt;Se extiende la deducción natural de la lógica proposicional a primer orden:&lt;/p&gt;

&lt;p&gt;Reglas para el cuantificador universal:&lt;/p&gt;

\[\frac{\Gamma \vdash \forall X.\sigma}{\Gamma \vdash \sigma\{X := \text{t}\}}\forall_E \\ \ \\
\frac{\Gamma \vdash \sigma \quad X \notin \text{fv}(\Gamma)}{\Gamma \vdash \forall X.\sigma}\forall_{I}\]

&lt;p&gt;Reglas para el cuantificador existencial:&lt;/p&gt;

\[\frac{\Gamma \vdash \exists X.\sigma \quad \Gamma , \sigma \vdash \tau \quad X \notin \text{fv} (\Gamma, \tau)}{\Gamma \vdash \tau}\exists_E \\ \ \\
\frac{\Gamma \vdash \sigma\{\text{X := t}\}}{\Gamma \vdash \exists X.\sigma}\exists_{I}\]

&lt;h3 id=&quot;algoritmo-de-unificación&quot;&gt;Algoritmo de unificación:&lt;/h3&gt;

&lt;p&gt;Es el mismo algoritmo de unificación (Martelli-Montanari) para cálculo lambda pero adaptado a términos de primer orden.&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Delete&lt;br /&gt;
${X\stackrel{?}{=}X} \ \cup E \phantom{llllllllllllllllllllllllllllllll}\to \quad E$&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decompose&lt;/strong&gt;&lt;br /&gt;
$\text{{ f ($t_1,…,t_n$) $\stackrel{?}{=}$ f ($s_1,…,s_n$) } $\cup E$} \quad \to \quad
{t_1 \stackrel{?}{=} s_1,…, t_n \stackrel{?}{=}s_n} \cup E$&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Swap&lt;br /&gt;
${\text{t}\stackrel{?}{=}\ X} \ \cup E \phantom{lllllllllllllllllllllllllllllllll} \to \quad {X \stackrel{?}{=} \text{t} } \cup E$&lt;/strong&gt;            &lt;br /&gt;
                                                                               (Si $\text{t}$ no es una variable)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elim&lt;br /&gt;
${X\stackrel{?}{=}\text{t}} \ \cup E \phantom{lllllllllllllllllllllllll} \to_{{X\ := \ \text{t}}} \quad E’ = E{{ X} := \text{t} }$&lt;/strong&gt;
                                                                                            (Si $X$ $\notin$ $\text{fv(t)}$)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Clash&lt;br /&gt;
${\text{f}(\tau_1, …,\tau_n)\stackrel{?}{=}\text{g}(\sigma_1,…,\sigma_n)} \ \cup \ E \phantom{lll}\to \quad \text{falla}$&lt;/strong&gt;      (Si $\text{f} \neq \text{g})$&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Occurs-Check&lt;/strong&gt;&lt;br /&gt;
${X\stackrel{?}{=}\text{t}} \ \cup E \phantom{lllllllllllllllllllllllllllllllll}\to \quad \text{falla}$      (Si $X \neq \text{t y } X \in \text{fv(t)}$ )&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;resolución-general-para-lógica-de-primer-orden&quot;&gt;Resolución general para lógica de primer orden&lt;/h2&gt;

&lt;p&gt;Entrada: fórmula $\sigma$ de LPO
Salida: booleano que indica si $\sigma$ es válida&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Procedimiento:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Escribir $\neg \sigma$ como conjunto $C$ de &lt;strong&gt;claúsulas.&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Buscar una &lt;strong&gt;refutación&lt;/strong&gt; de $C$:
    &lt;ul&gt;
      &lt;li&gt;Si existe, el método encuentra &lt;strong&gt;alguna.&lt;/strong&gt;&lt;/li&gt;
      &lt;li&gt;Si no, el método puede colgarse.&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;1-pasaje-a-forma-clausal&quot;&gt;1. Pasaje a forma clausal&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;Reescribir $\to$ usando $\boxed{a \to b = \neg a \lor b }$&lt;/li&gt;
  &lt;li&gt;Pasar a forma normal &lt;strong&gt;negada&lt;/strong&gt;, empujando &lt;strong&gt;$\neg$&lt;/strong&gt; “hacia adentro”.
    &lt;ul&gt;
      &lt;li&gt;Forma normal negada: una fórmula está en &lt;strong&gt;FNN&lt;/strong&gt; si todos sus $\neg$ afectan solo a fórmulas atómicas.&lt;/li&gt;
    &lt;/ul&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; -- Reglas para pasar a FNP
 ¬(σ ∧ τ)  -&amp;gt;  ¬σ ∨ ¬τ
 ¬(σ ∨ τ)  -&amp;gt;  ¬σ ∧ ¬τ
 ¬¬σ       -&amp;gt;  σ
 ¬∀X.σ     -&amp;gt;  ∃X.¬σ
 ¬∃X.σ     -&amp;gt;  ∀X.¬σ
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Pasar a forma normal &lt;strong&gt;prenexa&lt;/strong&gt;, extrayendo $\forall$, $\exists$ “hacia afuera”
    &lt;ul&gt;
      &lt;li&gt;Forma normal prenexa: una fórmula está en &lt;strong&gt;FNP&lt;/strong&gt; si está escrita con únicamente cuantificadores ($\exists$ y/o $\forall$) seguido de una fórmula sin cuantificadores.&lt;/li&gt;
    &lt;/ul&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; -- Reglas para pasar a FNP
 (∀X.σ) ∧ τ  -&amp;gt; ∀X.(σ ∧ τ)
 (∀X.σ) ∨ τ  -&amp;gt; ∀X.(σ ∨ τ)
 (∃X.σ) ∧ τ  -&amp;gt; ∃X.(σ ∧ τ)
 (∃X.σ) ∨ τ  -&amp;gt; ∃X.(σ ∨ τ)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Pasar a forma normal de &lt;strong&gt;Skolem&lt;/strong&gt; (eliminar los $\exists$)
    &lt;ul&gt;
      &lt;li&gt;Forma normal de Skolem: Una fórmula está skolemizada si está en FNP y solo contiene $\forall$.&lt;/li&gt;
    &lt;/ul&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; -- Regla para pasar a forma normal de skolem
 ∀X1 ... ∀Xn.∃Y.σ   -&amp;gt;   ∀X1 ... ∀Xn.σ{Y := f(X1,...,Xn)}
 con f un nuevo simbolo de funcion de aridad n&amp;gt;=0
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;Pasar a forma normal &lt;strong&gt;conjuntiva&lt;/strong&gt;, distribuyendo $\lor$ sobre $\land$.
    &lt;ul&gt;
      &lt;li&gt;Forma normal conjuntiva: Una fórmula está en &lt;strong&gt;FNC&lt;/strong&gt; cuando está escrita enteramente como una conjunción de &lt;strong&gt;cláusulas&lt;/strong&gt; (disyunción de literales).&lt;/li&gt;
    &lt;/ul&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt; -- Reglas para pasar a forma normal conjuntiva
 σ ∨ (τ ∧ ρ)   -&amp;gt;   (σ ∨ τ) ∧ (σ ∨ ρ)  
 (τ ∧ ρ) ∨ σ   -&amp;gt;   (σ ∨ τ) ∧ (σ ∨ ρ)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;“Empujar” los cuantificadores universales hacia adentro de las conjunciones.
De esta manera obtenemos un conjunto $C = { k_1,…, k_n}$ que representa una conjunción de cláusulas.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;2-refutación&quot;&gt;2. Refutación&lt;/h3&gt;

&lt;p&gt;Regla de resolución para lógica de primer orden:&lt;/p&gt;

\[\boxed{\frac{\begin{matrix}\{\color{red}{\sigma_1,...,\sigma_p},\ell_1,...,\ell_n\} \quad \{\color{red}{\neg\tau_1,...,\neg\tau_q},...,\ell_1^{\ &apos;},...,\ell_m^{\ &apos;}\} \\ S = \text{mgu}(\color{red}{\sigma_1} \stackrel{?}{=}... \stackrel{?}{=} \color{red}{\sigma_p} \stackrel{?}{=} \color{red}{\neg\tau_1} \stackrel{?}{=} ...\stackrel{?}{=} \color{red}{\neg\tau_q}) \end{matrix}}{S(\{ \ell_1,...,\ell_n,\ell_1^{\ &apos;},...,\ell_m^{\ &apos;} \})}}\]

&lt;ul&gt;
  &lt;li&gt;(Con $p &amp;gt; 0$ y $q&amp;gt;0$)&lt;/li&gt;
&lt;/ul&gt;

&lt;h2 id=&quot;resolución-sld&quot;&gt;Resolución SLD&lt;/h2&gt;

&lt;p&gt;El método de resolución SLD (Selective Linear Definite) es un método de resolución &lt;strong&gt;lineal&lt;/strong&gt; eficiente que solo puede aplicarse a un conjunto de cláusulas dadas:&lt;/p&gt;

&lt;h3 id=&quot;cláusulas-de-horn&quot;&gt;Cláusulas de Horn&lt;/h3&gt;

&lt;p&gt;Son cláusulas de la forma $\forall X_1 \ … \ \forall X_m .\ C$ tal que la disyunción de literales C solamente tiene uno o ningún &lt;strong&gt;literal positivo&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Ejemplo :
${P(\text{x}), P(\text{y}), \neg Q(\text{y,z})}$     no es una cláusula de horn
${P(\text{x}), \neg P(\text{y}), \neg Q(\text{y,z})}$  es una cláusula de horn&lt;/p&gt;

&lt;p&gt;Cláusulas de definición:&lt;/p&gt;

&lt;p&gt;Son cláusulas de la forma $\forall X_1 \ … \ \forall X_m .\ C$ tal que la disyunción de literales C tiene &lt;strong&gt;exactamente un&lt;/strong&gt; literal positivo.&lt;/p&gt;

&lt;p&gt;Cláusulas objetivo:&lt;/p&gt;

&lt;p&gt;Son cláusulas de la forma $\forall X_1 \ … \ \forall X_m .\ C$ tal que la disyunción de literales C &lt;strong&gt;no tiene ningún&lt;/strong&gt; literal positivo.&lt;/p&gt;

&lt;p&gt;Cláusulas de entrada:&lt;/p&gt;

&lt;p&gt;Es un conjunto de cláusulas de Horn de la forma $\boxed{H = P \cup {G}}$
$P$: conjunto de cláusulas de definición. (se lo llama &lt;strong&gt;programa&lt;/strong&gt; o &lt;strong&gt;base de conocimiento&lt;/strong&gt;)
$C$: cláusula objetivo. (se lo llama &lt;strong&gt;goal&lt;/strong&gt; o &lt;strong&gt;meta&lt;/strong&gt;)&lt;/p&gt;

&lt;h3 id=&quot;secuencia-de-pasos-para-resolución-sld&quot;&gt;Secuencia de pasos para resolución SLD&lt;/h3&gt;

&lt;p&gt;Una secuencia de pasos de resolución SLD para un conjunto de cláusulas de Horn $H$ (cláusulas de entrada) es una secuencia de &lt;strong&gt;cláusulas objetivo&lt;/strong&gt; de la forma: $&amp;lt;N_0, N_1, …,N_p&amp;gt;$ tal que satisfacen las siguientes condiciones:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;$N_0 \in H$ ($N_0$ es la única cláusula objetivo de H).&lt;/li&gt;
  &lt;li&gt;Para todo $0 &amp;lt; \text{i} &amp;lt; \text{p}$, si $N_{\text{i}}$ es:
$\phantom{llllllllllllllllllllllll}{\neg A_{1},…,\neg A_{k-1},\neg A_{k},\neg A_{k+1},…,\neg A_{n}}$o
Entonces hay &lt;strong&gt;alguna cláusula de definición&lt;/strong&gt; $C_{\text{i}}$ de la forma ${A, \neg B_1,…,\neg B_m}$ en $H$, tal que $A_{\text{k}}$ y $A$ son unificables con MGU S y $N_{\text{i+1}}$ es:
$\phantom{llllllllllllllllllll}S{(\neg A_{1},…,\neg B_{1},…,\neg B_{m}, \neg A_{k+1},…,\neg A_{n})}$&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;En resumen:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Resolvemos la cláusula objetivo $N_{\text{i}}$ con las cláusulas de definición en $H$.&lt;/li&gt;
  &lt;li&gt;El resultado es otra cláusula objetivo $N_{\text{i+1}}$.&lt;/li&gt;
  &lt;li&gt;Repetimos el proceso hasta llegar a $N_{\text{p}} = \varnothing$.&lt;/li&gt;
  &lt;li&gt;El resultado es la sustitución compuesta de todas las sustituciones que se fueron realizando&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;La regla es la siguiente:&lt;/p&gt;

\[\boxed{\frac{ \overbrace{ {\{\color{red}A, \neg B_{1},...,\neg B_{n} \}}}^{\text{definición}} \quad \overbrace{\{\neg A_{1},...,\neg A_{k-1},\color{red}{\neg A_{k}},\neg A_{k+1},...,\neg A_{m}\}}^{\text{objetivo}}}{\underbrace{S(\{\neg A_{1},...,\neg A_{k-1},B_{1},...,\neg B_{n},\neg A_{k+1},...,\neg A_{m} \})}_{\text{nuevo objetivo}}}}\]

&lt;p&gt;Con $S$ = $\text{mgu}{\color{red}A \stackrel{?}{=}\color{red}{A_k}}$&lt;/p&gt;

&lt;p&gt;La resolución es SLD cuando:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;La estrategia es lineal (utilizando en cada paso el resolvente obtenido en el paso anterior)&lt;/li&gt;
  &lt;li&gt;Se usan solamente cláusulas de Horn.&lt;/li&gt;
  &lt;li&gt;Se empieza por una cláusula objetivo.&lt;/li&gt;
  &lt;li&gt;La selección es binaria (un literal de cada cláusula)&lt;/li&gt;
  &lt;li&gt;La resolvente (nuevo objetivo) es una nueva cláusula objetivo&lt;/li&gt;
&lt;/ol&gt;

&lt;h2 id=&quot;prolog&quot;&gt;Prolog&lt;/h2&gt;

&lt;h3 id=&quot;semántica-de-prolog&quot;&gt;Semántica de Prolog&lt;/h3&gt;

&lt;p&gt;Un programa en Prolog es un conjunto de &lt;strong&gt;cláusulas de definición&lt;/strong&gt;.
Una consulta en Prolog es una &lt;strong&gt;cláusula objetivo&lt;/strong&gt;.&lt;/p&gt;

&lt;div class=&quot;language-prolog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;% Ejemplo:&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% Para las siguientes clausulas:&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;% {a(0,X,X)}&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% {a(s(X),Y,s(Z)) , ¬a(X,Y,Z)}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;% {¬a(s(0),X,s(s(0)))}      %% goal&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;% el programa en prolog es el siguiente:&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;:-&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;).&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;?-&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;),&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;X&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;s&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;m&quot;&gt;0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)))&lt;/span&gt;        &lt;span class=&quot;c1&quot;&gt;%% consulta&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;La ejecución de un programa se basa en la &lt;strong&gt;resolución SLD.
Criterio de búsqueda:&lt;/strong&gt; busca las cláusulas objetivo por orden de aparición (desde la primera hasta la última) haciendo DFS.
&lt;strong&gt;Criterio de selección:&lt;/strong&gt; elegir siempre el primer literal de la cláusula objetivo elegida.&lt;/p&gt;

&lt;h3 id=&quot;predicados&quot;&gt;Predicados&lt;/h3&gt;

&lt;p&gt;sort, msort, length, nth1, nth0, member, append, last, between, is_list, list_to_set, is_set, union, intersection, subset, subtract, select, delete, reverse, atom, number, numlist, sum_list, flatten.&lt;/p&gt;

&lt;div class=&quot;language-prolog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;ss&quot;&gt;sort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% ordena List de forma creciente, remueve duplicados&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;msort&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Sorted&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% igual a sort pero no elimina repetidos&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Length&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Length representa la cantidad de elementos en List&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;nth1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Elem es el n(Index)-esimo elemento de List&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;nth0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Index&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% igual que nth1 pero indexa desde cero&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;member&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Elem pertenece a List&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;ListOfLists&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;%concatena en List todas la listas que pertenecen a ListOfLists&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;append&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List1AndList2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% List1AndList2 es la concatenacion de List1 y List2&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;between&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Low&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;High&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% Value se unifica con todos los valores entre Low y High&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;subset&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;SubSet&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si SubSet es un subconjunto de Set (todo elemento en SubSet pertenece a Set)&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;subtract&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Set&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Delete&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Result&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% elimina todos los elementos de Delete que se encuentren en Set (todas las apariciones)&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;select&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Elem&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si List2 resulta en eliminar una aparicion de Elem en List1&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;atom&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;@&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Term&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Term esta ligado a un átomo&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;numlist&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Low&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;High&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% List es una lista creciente [Low, Low+1, ..., High]&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;sum_list&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;List&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Sum&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% Sum es la suma de todos los elementos de List&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;flatten&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;NestedList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;FlatList&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% FlatList es el resultado de aplanar la lista de listas NestedList&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;motor-aritmético-de-prolog&quot;&gt;Motor aritmético de Prolog&lt;/h3&gt;

&lt;p&gt;Predicados:&lt;/p&gt;

&lt;div class=&quot;language-prolog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;ss&quot;&gt;between&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Low&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;High&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Value&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% Value se unifica con todos los valores entre Low y High&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Int1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Int2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Int2 = Int1 +1 , alguno de los dos arg. debe estar instanciado&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;plus&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Int1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Int2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;?&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Int3&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Int3 = Int1 + Int2, al menos 2 de los 3 arg. debe estar instanciado&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;divmod&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Dividend&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Divisor&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Quotient&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Remainder&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% computa el cociente y resto de Dividend/Divisor&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Operadores&lt;/p&gt;

&lt;div class=&quot;language-prolog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;% Evaluan de ambos lados las expresiones&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;lt;&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=:=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;-&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Number&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;is&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Number es el valor el cual Expr evalúa&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% solo se evalúa Expr&lt;/span&gt;

&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr1&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;mod&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% Res = IntExpr1 modulo IntExpr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr1&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;rem&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% Res = resto de la IntExpr1 // IntExpr2&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;//&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% division entera&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr1&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;gcd&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% maximo comun divisor&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr1&lt;/span&gt; &lt;span class=&quot;ss&quot;&gt;lcm&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;IntExpr2&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% minimo comun multiplo&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;abs&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% valor absoluto&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;max&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;ss&quot;&gt;min&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr1&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Expr2&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;meta-predicados&quot;&gt;Meta-predicados&lt;/h3&gt;

&lt;div class=&quot;language-prolog highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;ss&quot;&gt;not&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;**&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;nv&quot;&gt;Goal&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;% true si Goal no puede ser satisfacido&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;smalltalk&quot;&gt;Smalltalk&lt;/h2&gt;

&lt;h3 id=&quot;objetos&quot;&gt;Objetos&lt;/h3&gt;

&lt;p&gt;Un objeto es una entidad con:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;Estado&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Comportamiento&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Identidad&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Ejemplo:&lt;/p&gt;

&lt;p&gt;Un objeto ‘archivo’ es una entidad que consta de:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Estado: dirección, contenido&lt;/li&gt;
  &lt;li&gt;Comportamiento: mostrar contenido, cambiar su contenido, renombrar&lt;/li&gt;
  &lt;li&gt;Identidad: cada archivo es distinto uno del otro&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;mensajes&quot;&gt;Mensajes&lt;/h3&gt;

&lt;p&gt;Los objetos se comunican a través de mensajes, cada mensaje invoca un método.&lt;/p&gt;

&lt;p&gt;Distintos objetos pueden “&lt;strong&gt;entender&lt;/strong&gt;” el mismo mensaje, pero pueden tener distinta respuesta a determinado mensaje.&lt;/p&gt;

&lt;div class=&quot;language-fortran highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;aWindow&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aFile&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aZip&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Un mensaje tiene &lt;strong&gt;receptores&lt;/strong&gt; y &lt;strong&gt;colaboradores.&lt;/strong&gt;&lt;/p&gt;

&lt;div class=&quot;language-fortran highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;objeto&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;mensaje&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;colaborador&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;

&lt;/span&gt;&lt;span class=&quot;c1&quot;&gt;!Ejemplos:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aCar&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;goTo&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aLocation&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aWindow&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;aFile&lt;/span&gt;&lt;span class=&quot;w&quot;&gt; &lt;/span&gt;&lt;span class=&quot;k&quot;&gt;open&lt;/span&gt;&lt;span class=&quot;w&quot;&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;métodos&quot;&gt;Métodos&lt;/h3&gt;

&lt;p&gt;Un método es una secuencia de instrucciones a ser ejecutadas por el receptor de un mensaje. Operan con los datos encapsulados en los objetos y pueden modificar el estado de un objeto o realizar otras operaciones.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Clase &amp;gt;&amp;gt; nombre_método
   ...
   ... (def del metodo)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;En resumen:
&lt;strong&gt;Mensaje&lt;/strong&gt;: Indican a un objeto &lt;strong&gt;QUE&lt;/strong&gt; hacer.
&lt;strong&gt;Método&lt;/strong&gt;: Indican a un objeto &lt;strong&gt;COMO&lt;/strong&gt; implementar determinado mensaje.&lt;/p&gt;

&lt;h3 id=&quot;clases&quot;&gt;Clases&lt;/h3&gt;

&lt;p&gt;Una clase es una &lt;strong&gt;plantilla&lt;/strong&gt; o &lt;strong&gt;molde&lt;/strong&gt; a partir de la cual se crean instancias de un objeto.
Definen las &lt;strong&gt;variables&lt;/strong&gt; y el &lt;strong&gt;comportamiento&lt;/strong&gt; de todas sus instancias. 
Una clase puede &lt;strong&gt;heredar características&lt;/strong&gt; de otras clases.
Las clases también son objetos, por lo que pueden recibir mensajes y tener su propio comportamiento.&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- La respuesta de la clase Car al mensaje new es una nueva instancia de Car
Car new
&amp;gt;&amp;gt;&amp;gt; aCar 
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;pseudo-variables&quot;&gt;Pseudo-variables&lt;/h3&gt;

&lt;p&gt;Son variables que vienen predefinidas en Smalltalk y no pueden ser redefinidas.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;self:&lt;/strong&gt; se refiere siempre al objeto del método en donde se define, se pueden enviar mensajes a self y puede ser enviado como colaborador de otros mensajes
Ejemplo:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;self computeTaxes

phoneBook at:self put: i
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;super:&lt;/strong&gt; se refiere al mismo objeto que self (self == super). La diferencia está en que cuando super recibe un mensaje, la búsqueda del método empieza en la superclase de la clase que contiene el  método que se está definiendo.
Ejemplo:&lt;/p&gt;

&lt;p&gt;Cuando se envíe el mensaje show a una instancia de BorderedPanedWindow, va a buscar el método en su propia clase, como no lo encuentra, sigue buscando en su superclase (PanedWindow), donde efectivamente lo encuentra.
Evalúa &lt;strong&gt;super show,&lt;/strong&gt; buscando el método show primero en la superclase de PanedWindow (el objeto receptor sigue siendo aBorderedPanedWindow).
Encuentra show en Window y evalúa self drawBorder (Ahora la búsqueda empieza en la clase del objeto al que se refiere self, o sea, BorderedPanedWindow).&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- Jerarquía:
-- Window --&amp;gt; PanedWindow --&amp;gt; BorderedPanedWindow

Window
	show
		self drawBorder
		self showTitle
	
PanedWindow
	show
		super show
		self showPanes
		
BorderedPanedWindow
	drawBorder
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;nil&lt;/strong&gt;: &lt;strong&gt;**es la única instancia de la clase UndefinedObject. Todas las variables de instancias, clases, y variables locales son inicializadas como **nil.&lt;/strong&gt;&lt;/p&gt;

&lt;h3 id=&quot;block-closures&quot;&gt;Block closures&lt;/h3&gt;

&lt;p&gt;Un bloque es una &lt;strong&gt;función anónima.&lt;/strong&gt; Es evaluada al enviarle el mensaje &lt;strong&gt;#value,&lt;/strong&gt; #&lt;strong&gt;value&lt;/strong&gt;:, #&lt;strong&gt;value:value:,&lt;/strong&gt; #&lt;strong&gt;value:value:value,&lt;/strong&gt; #&lt;strong&gt;value:value:value:value&lt;/strong&gt; (solo hasta cuatro parámetros) o &lt;strong&gt;#valueWithArguments:&lt;/strong&gt; (cualquier número de parámetros, el colaborador es un array de parametros). También pueden ser pasados como colaboradores de otros mensajes (como cualquier objeto)&lt;/p&gt;

&lt;p&gt;Ejemplos:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;[:x | 1 + x] value: 2
-&amp;gt; 3

|z|
[:x :y | z:= x + y. z+1] value:3 value:5
-&amp;gt; 9

| n m |
n := 60
m := 45
(1 to n) select: [:d | n//d == 0].
-&amp;gt; #(1 2 3 4 5 6 10 12 15 20 30 60)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;condicionales-y-estructuras-de-control&quot;&gt;Condicionales y estructuras de control&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;If&lt;/strong&gt;
Hay tres mensajes para el condicional if: &lt;strong&gt;#ifTrue: - #ifFalse: - #ifTrue:ifFalse:&lt;/strong&gt;
Los colaboradores de los tres mensajes deben ser block closures. 
Ejemplo:&lt;/p&gt;

    &lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;  -- Codigo en java/c++
  if(x&amp;gt;y){
  	max = x;
  	i = j
  }else{
  	max = y;
  	i = k
  }
    
  -- Codigo en smalltalk
  (x&amp;gt;y) ifTrue: [max := x. i := k] ifFalse : [max := y. i := k]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;    &lt;/div&gt;
  &lt;/li&gt;
  &lt;li&gt;
    &lt;p&gt;&lt;strong&gt;While&lt;/strong&gt;
Dos mensajes: &lt;strong&gt;#whileTrue:, #whileFalse:&lt;/strong&gt;
La expresión condicional tiene que estar en un bloque debido a que en cada iteración vamos a tener que reevaluarla.&lt;/p&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- Codigo en c++/java
while(i&amp;lt;100){
	sum = sum + 1;
	i = i + 1;
}

-- Codigo en smalltalk
[i &amp;lt; 100] whileTrue: [sum := sum + i. i := i+1]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;ul&gt;
  &lt;li&gt;For
Dos tipos de mensajes (aunque hay más mensajes que implementan estructuras similares): 
&lt;strong&gt;#to:do: - #timesRepeat:&lt;/strong&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;-- Codigo en c++/java
for(i = 0; i&amp;lt;n; i++){
	sum = sum + i
}

-- Codigo en smalltalk
|sum n|
sum := 0
n := 5
1 **to**: n **do**: [:i | sum := sum + i]

sum := 0
n:= 1
5 **timesRepeat**: [sum := sum+n. n := n + 1]
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;colecciones&quot;&gt;Colecciones&lt;/h3&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;Collection
	|__ Bag                     -- coleccion no-ordenada - permite repetidos
	|__ Set                     -- coleccion no-ordenada - no hay repetidos
	|   |__ Dictionary
	|
	|__ SequenceableCollection  -- collecciones ordenadas
			|__ SortedCollection    -- internamente ordenadas
			|__ OrderedCollection   -- ordenadas por aparicion
			|__ Interval
			|__ ArrayedCollection   -- ordenadas por indice
					|__ Array
					|__ String
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Principales métodos en la clase Collection:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;add: newObject
	&quot;añade newObject al receptor del msj&quot;
	
addAll : aCollection
	&quot;añade todos los objetos en aCollection al receptor del msj&quot;
	
remove: oldObj
	&quot;elimina oldObj del receptor del msj&quot;

remove: oldObj ifAbsent: aBlock
	&quot;elimina oldObj, evalua aBlock si no encuentra oldObj en el receptor del msj&quot;

removeAll: aCollection
	&quot;elimina todos los objetos de aCollection en el receptor del msj&quot;

isEmpty
	&quot;true si la colleccion está vacía&quot;

size
	&quot;devuelve la cantidad de objetos en la colección&quot;
	
	
do: aBlock
	&quot;aplica aBlock para cada elemento&quot;

collect: aBlock
	&quot;devuelve una nueva coleccion aplicando aBlock a cada elemento&quot;
	
select: aBlock
	&quot;devuelve una nueva colleccion con los elementos que devuelven true segun aBlock&quot;

otros: reject, inject, detect
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;Ejemplos:&lt;/p&gt;

&lt;div class=&quot;language-plaintext highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;|col arr sum|
col := OrderedCollection new.

col size.
	-&amp;gt; 0

col add: 4; add: 5.
col
	-&amp;gt; #(4 5)

sum := 0.
#(1 3 4) do: [:e | sum := sum + e].
sum.
	-&amp;gt; 8

#(1 2 3) collect: [:e | e + 10].
	-&amp;gt; #(11 12 13)
	
#(47 29 12 1 89 37845 12 94 58) select: [:e | e \\ 2 == 0].
	-&amp;gt; #(12 12 94 58)

arr := Array new: 5
arr at: 1 put: 23
arr
	-&amp;gt; #(23 nil nil nil nil)
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
</description>
        <pubDate>Sat, 05 Oct 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-10/apunteplp2</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-10/apunteplp2</guid>
        
        
        <category>facultad</category>
        
      </item>
    
      <item>
        <title>PLP - apunte para el primer parcial</title>
        <description>&lt;h2 id=&quot;paradigmas-de-lenguajes-de-programación-1c2024&quot;&gt;Paradigmas de Lenguajes de Programación 1C2024&lt;/h2&gt;

&lt;h2 id=&quot;resumen-para-el-primer-parcial&quot;&gt;Resumen para el primer parcial&lt;/h2&gt;

&lt;p&gt;Todo el contenido de este archivo es una recopilación/resumen del contenido de las teóricas/prácticas del campus de la materia, que fue transcrito en Latex por mi. Puede contener errores.&lt;/p&gt;

&lt;p&gt;&lt;a href=&quot;/assets/pdf/apunteplp1.pdf&quot;&gt;versión en pdf&lt;/a&gt;&lt;/p&gt;

&lt;h2 id=&quot;haskell&quot;&gt;Haskell&lt;/h2&gt;

&lt;h3 id=&quot;tipos-de-datos-algebraicos&quot;&gt;Tipos de datos algebraicos&lt;/h3&gt;

&lt;p&gt;En general, los tipos de datos algebraicos tienen la siguiente estructura:&lt;/p&gt;

&lt;p&gt;Los constructores base NO reciben parámetros de tipo T.&lt;/p&gt;

&lt;p&gt;Los constructores recursivos reciben al menos UN parámetro de tipo T.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Definición inductiva de T&lt;/strong&gt;: Los valores de tipo T solamente se pueden construir aplicando una cantidad finita de constructores base y/o recursivos del mismo tipo T.&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;casoBase1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoBase2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoBaseN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
						
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoRecursivo1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoRecursivo2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoRecursivoN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
				
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;recursión-estructural&quot;&gt;Recursión estructural&lt;/h3&gt;

&lt;p&gt;Dada una función &lt;strong&gt;&lt;em&gt;g : T → Y&lt;/em&gt;&lt;/strong&gt; definida por ecuaciones:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Cbase1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caso&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Cbase2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caso&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;base2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CbaseN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caso&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;baseN&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Crecursivo1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caso&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recursivo1&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Crecursivo2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caso&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recursivo2&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;g&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;CrecursivoN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;caso&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recursivoN&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;g&lt;/em&gt;&lt;/strong&gt; está dada por recursión estructural si cumple:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Cada caso base devuelve un valor fijo&lt;/li&gt;
  &lt;li&gt;Cada caso recursivo se escribe combinando:
    &lt;ol&gt;
      &lt;li&gt;Los parámetros del constructor que &lt;strong&gt;&lt;em&gt;NO&lt;/em&gt;&lt;/strong&gt; son de tipo T (sin usar los parámetros del constructor que son del tipo T).&lt;/li&gt;
      &lt;li&gt;El llamado recursivo sobre &lt;strong&gt;&lt;em&gt;cada&lt;/em&gt;&lt;/strong&gt; parámetro de tipo T (sin hacer otros llamados recursivos).&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Ejemplo de recursión estructural:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nil&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bin&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
							  
&lt;span class=&quot;c1&quot;&gt;-- Funcion que abstrae el esquema de recursion estructural en arboles binarios:&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cNil&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cBin&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nil&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cNil&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cNil&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cBin&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Bin&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;izq&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;der&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; 
	&lt;span class=&quot;n&quot;&gt;cBin&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cNil&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cBin&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;izq&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cNil&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;cBin&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;der&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	
&lt;span class=&quot;c1&quot;&gt;-- Ejemplo de uso: sumar todos los elementos del arbol &lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sumAB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;Num&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sumAB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;mi&quot;&gt;0&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recI&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recI&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;+&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;span class=&quot;n&quot;&gt;mapAB&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;mapAB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;fMap&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;foldAB&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nil&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;nf&quot;&gt;\&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;recI&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recD&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bin&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recI&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;fMap&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;r&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;recD&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;recursión-primitiva&quot;&gt;Recursión primitiva&lt;/h3&gt;

&lt;p&gt;Dada una función &lt;strong&gt;&lt;em&gt;g : T → Y&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;g&lt;/em&gt;&lt;/strong&gt; está dada por recursión primitiva si cumple:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Cada caso base devuelve un valor fijo&lt;/li&gt;
  &lt;li&gt;Cada caso recursivo se escribe combinando:
    &lt;ol&gt;
      &lt;li&gt;&lt;strong&gt;Todos&lt;/strong&gt; los parámetros del constructor del tipo T (incluyendo a los que son de tipo T)&lt;/li&gt;
      &lt;li&gt;El llamado recursivo sobre todos los constructores recursivos (sin hacer otros llamados recursivos)&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;recursión-iterativa&quot;&gt;Recursión iterativa&lt;/h3&gt;

&lt;p&gt;— TO-DO (en el parcial entra recursión estructural sobre tipos algebraicos)&lt;/p&gt;

&lt;h2 id=&quot;inducción-estructural&quot;&gt;Inducción estructural&lt;/h2&gt;

&lt;p&gt;Queremos &lt;strong&gt;demostrar que ciertas expresiones son equivalentes&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Para eso debemos asumir lo siguiente:&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Trabajamos con estructuras de datos finitas&lt;strong&gt;: tipos de datos inductivos&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;Trabajamos con &lt;strong&gt;funciones totales:&lt;/strong&gt;
    &lt;ol&gt;
      &lt;li&gt;Las ecuaciones deben cubrir &lt;strong&gt;todos&lt;/strong&gt; los casos.&lt;/li&gt;
      &lt;li&gt;La recursión &lt;strong&gt;siempre&lt;/strong&gt; debe terminar.&lt;/li&gt;
    &lt;/ol&gt;
  &lt;/li&gt;
  &lt;li&gt;El programa &lt;strong&gt;no&lt;/strong&gt; depende del orden de las ecuaciones.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;principio-de-reemplazo&quot;&gt;Principio de reemplazo&lt;/h3&gt;

&lt;p&gt;Sea &lt;strong&gt;&lt;em&gt;e1 = e2&lt;/em&gt;&lt;/strong&gt; una ecuación dentro del programa. Las siguientes operaciones preservan la &lt;strong&gt;igualdad de expresiones:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;Reemplazar cualquier instancia de e1 por e2&lt;/li&gt;
  &lt;li&gt;Reemplazar cualquier instancia de e2 por e1&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Si una igualdad se puede demostrar solo por principio de reemplazo, decimos que la igualdad &lt;strong&gt;vale por definición.&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;A veces conviene dar nombre a todas las ecuaciones del programa para saber cuál ecuación se utilizó para reemplazar una instancia por otra.&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;sucesor&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Int&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;-- tenemos una igualdad de la forma e1 = e2&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;sucesor&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;n&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;+&lt;/span&gt;&lt;span class=&quot;mi&quot;&gt;1&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;-- {SUC}&lt;/span&gt;

&lt;span class=&quot;c1&quot;&gt;-- sucesor (factorial 10) + 1&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;-- ((factorial 10) + 1) + 1        (por SUC. reemplazo e1 por e2)&lt;/span&gt;
&lt;span class=&quot;c1&quot;&gt;-- sucesor (factorial 10 + 1)      (por SUC. reemplazo e2 por e1)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;inducción-sobre-booleanos&quot;&gt;Inducción sobre booleanos&lt;/h3&gt;
&lt;p&gt;Si $P(True)\ \text y\ P(False)$ entonces: $∀x :: Bool.\enspace P(x)$&lt;/p&gt;

&lt;p&gt;Ejemplo:&lt;/p&gt;

\[\text{Para probar}\ \forall x::Bool.\text\ {not (not\ x) = x} \\\text{Basta con probar: }\\ \text{1. P(True): not(not True) = True}\\ \text{2.P(False): not(not False) = False}\]

&lt;p&gt;Ahora podemos usar principio de reemplazo usando las siguientes ecuaciones para probar 1 y 2:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;True&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;False&lt;/span&gt;   &lt;span class=&quot;c1&quot;&gt;-- {NT}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;not&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;False&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;True&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;-- {NF}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;inducción-sobre-pares&quot;&gt;Inducción sobre pares&lt;/h3&gt;

&lt;aside&gt;
&lt;img src=&quot;https://www.notion.so/icons/remove_gray.svg&quot; alt=&quot;https://www.notion.so/icons/remove_gray.svg&quot; width=&quot;40px&quot; /&gt;

Si $$ \ \forall x::a.\ \forall y::b. \ P((x,y))$  entonces $\ \forall p ::(a, b). \ P(p) $$

&lt;/aside&gt;

&lt;p&gt;Ejemplo:&lt;/p&gt;

\[\text{Para probar}\ \forall p::(a,b).\text{\ fst p = snd (swap p)} \\\text{Basta con probar: }\\ \forall x::a. \forall y::b.\ \text{fst (x,y) = snd (swap (x,y))}\]

&lt;p&gt;Y para probar esto podemos usar ppo. de reemplazo usando, por ejemplo, las siguientes ecuaciones dadas:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;fst&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;-- {FST}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;snd&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;-- {SND}&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;swap&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;,&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;-- {SWAP}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;inducción-sobre-naturales&quot;&gt;Inducción sobre naturales&lt;/h3&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;-- Usamos la siguiente representacion de numeros naturales&lt;/span&gt;
&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nat&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Zero&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Suc&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nat&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;aside&gt;
&lt;img src=&quot;https://www.notion.so/icons/remove_gray.svg&quot; alt=&quot;https://www.notion.so/icons/remove_gray.svg&quot; width=&quot;40px&quot; /&gt; Si $P(Zero)$ y $\ \forall n:: \text{Nat.}\ (P(n) \implies P(\text{Suc}\  n))$  entonces: $\forall n::\text{Nat.} \ P(n)$

&lt;/aside&gt;

&lt;h3 id=&quot;inducción-estructural-1&quot;&gt;Inducción estructural&lt;/h3&gt;

&lt;p&gt;Para probar una propiedad $P$ sobre &lt;strong&gt;todas&lt;/strong&gt; las instancias de tipo $T$, basta probar $P$ para cada uno de los constructores (asumiendo como H.I que se cumple para los constructores recursivos)&lt;/p&gt;

&lt;p&gt;Tenemos un tipo de datos inductivo de la forma:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;T&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;casoBase1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoBase2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
	&lt;span class=&quot;n&quot;&gt;casoBaseN&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
						
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoRecursivo1&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoRecursivo2&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;...&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;casoRecursivoM&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;&amp;lt;&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;parametros&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;aside&gt;
&lt;img src=&quot;https://www.notion.so/icons/remove_gray.svg&quot; alt=&quot;https://www.notion.so/icons/remove_gray.svg&quot; width=&quot;40px&quot; /&gt; Sea $P$ una propiedad acerca de las expresiones de tipo T tal que:
- $P$ vale sobre todos los constructores base de T.
- $P$ vale sobre todos los constructores recursivos de T, asumiendo como H.I. que vale para los parámetros de tipo T.
Entonces:
$\forall x::T. \; P(x)$

&lt;/aside&gt;

&lt;p&gt;Ejemplo: Inducción sobre árboles binarios&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nil&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bin&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;AB&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

\[\text{Sea} \ P \text{\ una propiedad sobre expresiones de tipo AB tal que:} \\- \ P(\text{Nil})\\ -\ \forall i::(AB \ \text{a}). \ \forall r:: \text{a}.\ \forall d:: (AB\ \text{a}). \\ (P(i) \land P(d)) \implies (P(\text{Bin} \ i  \ r \ d)) \\ \ \\ \text{Entonces} \ \forall x::AB\ a. \ P(x)\]

&lt;p&gt;Ejemplo: Inducción sobre listas&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;[]&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;[&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;a&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

\[\text{Sea} \ P \text{\ una propiedad sobre expresiones de tipo [a] tal que:} \\- \ P(\text{[ ]})\\ -\ \forall x::\text{a} . \ \forall xs:: \text{[a]}. \ (P(xs) \implies P(x:xs)) \\ \ \\ \text{Entonces} \ \forall xs:\text{[a]}. \ P(xs)\]

&lt;h2 id=&quot;extensionalidad&quot;&gt;Extensionalidad&lt;/h2&gt;

&lt;h3 id=&quot;extensionalidad-para-pares&quot;&gt;Extensionalidad para pares&lt;/h3&gt;

&lt;p&gt;(se prueba mediante ppo. de inducción estructural)&lt;/p&gt;

&lt;aside&gt;
&lt;img src=&quot;https://www.notion.so/icons/remove_gray.svg&quot; alt=&quot;https://www.notion.so/icons/remove_gray.svg&quot; width=&quot;40px&quot; /&gt; Si $\text{p :: (a,b)}$, entonces $\exists \text{x :: a.}\ \exists \text{y :: b.} \; \text{p = (x, y)}$

&lt;/aside&gt;

&lt;h3 id=&quot;extensionalidad-para-sumas&quot;&gt;Extensionalidad para sumas&lt;/h3&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;kr&quot;&gt;data&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Either&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Left&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;a&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Right&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;b&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;aside&gt;
&lt;img src=&quot;https://www.notion.so/icons/remove_gray.svg&quot; alt=&quot;https://www.notion.so/icons/remove_gray.svg&quot; width=&quot;40px&quot; /&gt; Si $\text{e :: Either a b}$, entonces:
- O bien $\exists \text{x :: a. \ e = Left x}$
- O bien $\exists \text{y :: b. \ e = Right y}$

&lt;/aside&gt;

&lt;h3 id=&quot;principio-de-extensionalidad-funcional&quot;&gt;Principio de extensionalidad funcional&lt;/h3&gt;

&lt;p&gt;Sea $\text{f, g :: \ a} \to \text{b}$&lt;/p&gt;

&lt;aside&gt;
&lt;img src=&quot;https://www.notion.so/icons/remove_gray.svg&quot; alt=&quot;https://www.notion.so/icons/remove_gray.svg&quot; width=&quot;40px&quot; /&gt; Si $\ (\forall \text{x :: a. \ f x = g x }) \implies \text{ f = g}$

&lt;/aside&gt;

&lt;p&gt;Para probar una igualdad de tipo $\text{f = g}$ basta con probar que vale $\text{f x = g x}$ para todo $\text{x}$ del dominio de las funciones $\text{f}$ y $\text{g}$. (Son iguales punto a punto)&lt;/p&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;calculo-lambda&quot;&gt;Calculo lambda&lt;/h2&gt;

&lt;h3 id=&quot;calculo-lambda-puro-sin-tipos-extendido-con-booleanos&quot;&gt;Calculo lambda puro (sin tipos) extendido con booleanos&lt;/h3&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;-- Sintaxis (términos)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;                     &lt;span class=&quot;c1&quot;&gt;-- Variables &lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;                 &lt;span class=&quot;c1&quot;&gt;-- Abstraccion&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;                  &lt;span class=&quot;c1&quot;&gt;-- Aplicacion&lt;/span&gt;
		
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;false&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;
		
&lt;span class=&quot;c1&quot;&gt;-- Semantica (reglas de reduccion)&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;Si&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;entonces&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;
	&lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;  &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt;
	&lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt;  &lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt;
	
	&lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt;
	
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h2 id=&quot;calculo-lambda-tipado-lambda-bn&quot;&gt;Calculo lambda tipado. $\lambda ^{BN}$&lt;/h2&gt;

&lt;p&gt;Se agregan los siguientes tipos:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Funciones&lt;/li&gt;
  &lt;li&gt;Booleanos&lt;/li&gt;
  &lt;li&gt;Naturales&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Es determinista: estrategia &lt;strong&gt;Call-by-value (e&lt;/strong&gt;valuar primero los argumentos antes de pasarlos a la función).&lt;/p&gt;

&lt;p&gt;$\lambda (x.M)\, V $  reduce solo cuando V está en &lt;strong&gt;forma normal&lt;/strong&gt; (no existe V’ tal que V → V’)&lt;/p&gt;

&lt;h3 id=&quot;sintaxis-del-cálculo-lambda-tipado-lambda-bn&quot;&gt;Sintaxis del cálculo lambda tipado $\lambda ^{BN}$&lt;/h3&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;-- Términos&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; 
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; 
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;false&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;zero&lt;/span&gt; 
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;suc&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		
&lt;span class=&quot;c1&quot;&gt;-- Tipos&lt;/span&gt;
&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;::=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Bool&lt;/span&gt;      &lt;span class=&quot;c1&quot;&gt;-- Booleanos&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;Nat&lt;/span&gt;       &lt;span class=&quot;c1&quot;&gt;-- Naturales&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;    &lt;span class=&quot;c1&quot;&gt;-- Funciones&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;reglas-de-tipado-de-lambda-bn&quot;&gt;Reglas de tipado de $\lambda ^{BN}$&lt;/h3&gt;

&lt;p&gt;Cada término tiene su propia regla de tipado.&lt;/p&gt;

\[\frac{}{\Gamma, x : \sigma \vdash x:\sigma}ax_v \\ \ \\
\frac{\Gamma, x:\sigma \vdash M:\tau}{\Gamma \vdash \lambda x:\sigma .M \ :\sigma \to \tau}\to_i \quad 
\frac{\Gamma \vdash M:\sigma \to \tau \quad \Gamma \vdash N:\sigma}{\Gamma \vdash MN : \tau}\to_e \\ \ \\
\frac{}{\Gamma \vdash \text{true} : Bool}ax_{true} \quad \frac{}{\Gamma \vdash \text{false}:Bool}ax_{false} \\ \ \\
\frac{\Gamma \vdash M:Bool \quad \Gamma \vdash P:\sigma \quad \Gamma \vdash Q:\sigma}{\Gamma \vdash \text{if M then P else Q : }\sigma}\text{if} \\ \ \\
\frac{}{\Gamma \vdash \text{Zero : Nat}}\text{zero} \quad \frac{\Gamma \vdash M : \text{Nat}}{\Gamma \vdash \text{isZero(M) : }Bool}\text{isZero} \\ \ \\
\frac{\Gamma \vdash \text{M : Nat}}{\Gamma \vdash \text{pred(M) : Nat}}\text{pred}\quad \frac{\Gamma \vdash \text{M : Nat}}{\Gamma \vdash \text{succ(M) : Nat}}\text{succ}\]

&lt;h3 id=&quot;semántica-del-cálculo-lambda-tipado-lambda-bn&quot;&gt;Semántica del cálculo lambda tipado $\lambda ^{BN}$&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Valores:&lt;/strong&gt; Son los términos M los cuales están en &lt;strong&gt;forma normal&lt;/strong&gt; y además &lt;strong&gt;FV(M) = ∅&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Semántica operacional (small-step):&lt;/p&gt;

&lt;p&gt;Las reglas de cómputo nos dan el significado de los términos al definir como operan.&lt;/p&gt;

&lt;p&gt;Las reglas de congruencia permiten reducir subtérminos. (Términos que están dentro de otros términos)&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;c1&quot;&gt;-- Valores&lt;/span&gt;
&lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;::=&lt;/span&gt;  &lt;span class=&quot;n&quot;&gt;true&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;false&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;zero&lt;/span&gt;
	&lt;span class=&quot;o&quot;&gt;|&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
		
&lt;span class=&quot;c1&quot;&gt;-- Semantica operacional:&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;-- Reglas de cómputo&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;β&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;             &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;if_t&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;if_f&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;false&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;pred_&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;          &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isZero0&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;zero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isZeroN&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;))&lt;/span&gt;        &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;false&lt;/span&gt; 

	&lt;span class=&quot;c1&quot;&gt;-- Reglas de congruencia&lt;/span&gt;
	&lt;span class=&quot;c1&quot;&gt;-- Si M -&amp;gt; M&apos; entonces:&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;u&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;v&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;       &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;V&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;ifC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;     &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;succC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;             &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;predC&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;   &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;             &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;-&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;           &lt;span class=&quot;o&quot;&gt;-&amp;gt;&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&apos;&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;h3 id=&quot;captura-de-variables-sustituciones&quot;&gt;Captura de variables (sustituciones)&lt;/h3&gt;

&lt;p&gt;$M{x:=N}$ significa &lt;strong&gt;sustitución sin captura de variables de las ocurrencias libres de x en M por N.&lt;/strong&gt;
Se define por inducción en M:&lt;/p&gt;

&lt;div class=&quot;language-haskell highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;        &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;        &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;                &lt;span class=&quot;c1&quot;&gt;-- No puedo sustituir x porque no está libre&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;          &lt;span class=&quot;c1&quot;&gt;-- Si y ∉ FV(N)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;err&quot;&gt;λ&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;:&lt;/span&gt;&lt;span class=&quot;err&quot;&gt;σ&lt;/span&gt;&lt;span class=&quot;o&quot;&gt;.&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;y&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;z&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;  &lt;span class=&quot;c1&quot;&gt;-- Si y ∈ FV(N), z ∉ FV(N)&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;    &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; 

&lt;span class=&quot;n&quot;&gt;true&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;                  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;true&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;false&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;                 &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;false&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;zero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;                  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;zero&lt;/span&gt;
&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;  &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kr&quot;&gt;if&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;then&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;O&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt; &lt;span class=&quot;kr&quot;&gt;else&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;P&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt; 
&lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;               &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;succ&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;               &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;pred&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;){&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;}&lt;/span&gt;             &lt;span class=&quot;o&quot;&gt;=&lt;/span&gt; &lt;span class=&quot;n&quot;&gt;isZero&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;(&lt;/span&gt;&lt;span class=&quot;kt&quot;&gt;M&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;{&lt;/span&gt;&lt;span class=&quot;n&quot;&gt;x&lt;/span&gt; &lt;span class=&quot;o&quot;&gt;:=&lt;/span&gt; &lt;span class=&quot;kt&quot;&gt;N&lt;/span&gt;&lt;span class=&quot;p&quot;&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;

&lt;hr /&gt;

&lt;h2 id=&quot;inferencia-de-tipos&quot;&gt;Inferencia de tipos&lt;/h2&gt;

&lt;p&gt;Un término $U$ sin anotaciones de tipo es &lt;strong&gt;Tipable&lt;/strong&gt; si y solo si existen:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Un contexto de tipado $\Gamma$&lt;/li&gt;
  &lt;li&gt;Un término con anotaciones de tipos $M$&lt;/li&gt;
  &lt;li&gt;Un tipo $\tau$&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Tales que &lt;strong&gt;erase(M) = U  y  $\ \Gamma \vdash M : \tau$&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Donde erase(M) es el término sin anotaciones de tipos que resulta de borrar las anotaciones de tipos de M.&lt;/p&gt;

&lt;h3 id=&quot;problema-de-inferencia-de-tipos&quot;&gt;Problema de inferencia de tipos&lt;/h3&gt;

&lt;ul&gt;
  &lt;li&gt;Dado un término $U$, determinar si este es tipable.&lt;/li&gt;
  &lt;li&gt;En caso de que $U$ sea tipable:
    &lt;ul&gt;
      &lt;li&gt;hallar un contexto $\Gamma$, un término $M$ y un tipo $\tau$ tales que &lt;strong&gt;erase(M) = U  y  $\ \Gamma \vdash M : \tau$&lt;/strong&gt;&lt;/li&gt;
    &lt;/ul&gt;
  &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Se resuelve con &lt;strong&gt;algoritmo $W$&lt;/strong&gt; de inferencia de tipos.&lt;/p&gt;

&lt;h3 id=&quot;algoritmo-de-unificación-de-martelli-montanari&quot;&gt;Algoritmo de unificación de Martelli-Montanari&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Unificación:&lt;/strong&gt; Problema de resolver sistemas de ecuaciones entre tipos con incógnitas.&lt;/p&gt;

&lt;p&gt;Definición:&lt;/p&gt;

&lt;p&gt;Dado un problema de &lt;strong&gt;unificación $E$:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Mientras $E \neq \varnothing$, se aplica sucesivamente alguna de las seis reglas de unificación&lt;/li&gt;
  &lt;li&gt;La regla puede resultar en una &lt;strong&gt;falla&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;De lo contrario, la regla es de la forma $E \to_S E’$
La resolución del problema E se reduce a resolver otro problema $E’$ aplicando la sustitución $S$.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Si $E = E_0 \to_{S_1} E_1 \to_{S_2} E_2 \to … \to_{Sn} E_n \to_{Sn+1} \text{falla}$
En tal caso, el problema de unificación $E$ &lt;strong&gt;no tiene solución&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Si $E = E_0 \to_{S_1} E_1 \to_{S_2} E_2 \to … \to_{Sn} E_n \to_{Sn+1} E_n = \varnothing$ 
En tal caso, el problema de unificación $E$ &lt;strong&gt;tiene solución&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Reglas:&lt;/strong&gt;&lt;/p&gt;

&lt;ol&gt;
  &lt;li&gt;&lt;strong&gt;Delete&lt;br /&gt;
$ {x\stackrel{?}{=}x } \ \cup E \to \quad E$&lt;/strong&gt;&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Decompose&lt;/strong&gt;&lt;br /&gt;
${C(\tau_1, …,\tau_n)\stackrel{?}{=}C(\sigma_1,…,\sigma_n)} \ \cup \ E \quad \to \quad { \tau_1 \stackrel{?}{=} \sigma_1,…, \tau_n \stackrel{?}{=}\sigma_n} \ \cup \ E$&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Swap&lt;br /&gt;
${\tau\stackrel{?}{=}\ {?n}} \ \cup E \to \quad {?n \stackrel{?}{=} \tau} \cup E$&lt;/strong&gt;            &lt;br /&gt;
                                                                               (Si $\tau$ no es una incógnita)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Elim&lt;br /&gt;
${?n\stackrel{?}{=}\tau} \ \cup E \to_{{?n\ := \ \tau}} \quad E’ = {{?n} := \tau }(E)$&lt;/strong&gt;
                                                                                            (Si ?n no ocurre en $\tau$)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Clash&lt;br /&gt;
${C(\tau_1, …,\tau_n)\stackrel{?}{=}C(\sigma_1,…,\sigma_n)} \ \cup \ E \phantom{lll}\to \quad \text{falla}$&lt;/strong&gt;      (Si $C \neq C’)$&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;Occurs-Check&lt;/strong&gt;&lt;br /&gt;
${?n\stackrel{?}{=}\tau} \ \cup E \to \quad \text{falla}$      (Si $?n \neq \tau \; \text{y} \; ?n$ ocurre en $\tau$)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;corrección-del-algoritmo-de-martelli-montanari&quot;&gt;Corrección del algoritmo de Martelli-Montanari&lt;/h3&gt;

&lt;ol&gt;
  &lt;li&gt;El algoritmo termina para cualquier $E$&lt;/li&gt;
  &lt;li&gt;Si $E$ no tiene solución, el algoritmo $\text{falla}$&lt;/li&gt;
  &lt;li&gt;Si $E$ tiene solución, el algoritmo llega a:
$\boxed{E = E_0 \to_{S_1} E_1 \to_{S_2} E_2 \to … \to_{Sn} E_n \to_{Sn+1} E_n = \varnothing }$
Y además: 
$\boxed{S = S_n\ \circ \ … \ \circ S_2 \ \circ S_1}$ 
Es el unificador más general posible (&lt;strong&gt;mgu&lt;/strong&gt;)&lt;/li&gt;
&lt;/ol&gt;

&lt;h3 id=&quot;algoritmo-w-de-inferencia-de-tipos&quot;&gt;Algoritmo W de inferencia de tipos&lt;/h3&gt;

&lt;p&gt;Recibe un término $U$ sin anotaciones de tipos.
Procede recursivamente sobre la estructura de $U$:&lt;/p&gt;

&lt;ul&gt;
  &lt;li&gt;Si falla, entonces $U$no es tipable.&lt;/li&gt;
  &lt;li&gt;Si tiene éxito:
Devuelve una tripla &lt;strong&gt;($\Gamma$, $M$, $\tau$)&lt;/strong&gt; tal que:
erase($M$) = $U$ y $\Gamma \vdash M : \tau$ es válido.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Escribimos $W(U) \rightsquigarrow \Gamma \vdash M : \tau$ para indicar que el algoritmo de inferencia tiene éxito cuando se le pasa U como entrada y devuelve una tripla $(\Gamma, M, \tau)$.&lt;/p&gt;

&lt;p&gt;Reglas:&lt;/p&gt;

\[\frac{}{W(\text{True}) \rightsquigarrow \varnothing \vdash \text{True : Bool}} \\ \ \\

\frac{}{W(\text{False}) \rightsquigarrow \varnothing \vdash \text{False : Bool}} \\ \ \\

\frac{?k \text{\ es una incógnita fresca}}{W(x) \rightsquigarrow x : \ ?k \vdash x: \ ?k} \\ \ \\

\frac{\begin{matrix}\Large\substack{W(U_1) \rightsquigarrow \Gamma_1 \  \vdash M_1 : \ \tau_1 \\ W(U_2) \rightsquigarrow \Gamma_2 \  \vdash M_2 : \ \tau_2 \\ W(U_3) \rightsquigarrow \Gamma_3 \  \vdash M_3 : \ \tau_3} &amp;amp; S= \text{mgu} \left(\Large{\substack{\{\tau_1 \stackrel{?}{=} \text{Bool}, \ \tau_2 \stackrel{?}{=} \tau_3\} \\ \{ \Gamma_{\text{i}}(x) \stackrel{?}{=}\Gamma_{\text{j}}(x) \  | \ i,j \ \in \{1,2,3\}, \ x \ \in \ \Gamma_{\text{i}} \cap\Gamma_{\text{j}} \}}}\right) \end{matrix}}{\Large{\substack{W(\text{if} \ U_1 \text{\ then}\ U_2 \text{\ else} \ U_3) \space \rightsquigarrow \space S(\Gamma_1) \ \cup \ S(\Gamma_2) \ \cup \  S(\Gamma_3) \ \vdash \\S(\text{if} \ M_1 \text{\ then}\ M_2 \text{\ else} \ M_3) \space : \space S(\tau_2)}}} \\ \ \\

\frac{\Large\substack{ W(U) \rightsquigarrow \Gamma_1 \ \vdash \ M : \tau \\ W(V) \rightsquigarrow \Gamma_2 \ \vdash \ N : \sigma \\ ?k \text{\ es una incógnita fresca} \\ S = \text{mgu} \{ \tau \; \stackrel{?}{=} \; \sigma \to ?k\} \ \cup \ \{\Gamma_1(x) \stackrel{?}{=} \Gamma_2(x) \; : \; x \; \in \; \Gamma_1 \cap \Gamma_2\}}}{W(UV) \rightsquigarrow S(\Gamma_1) \ \cup \ S(\Gamma_2) \ \space \vdash \space S(MN) \; : \; S(?k)} \\ \ \\

\frac{\begin{matrix} W(U) \rightsquigarrow \Gamma \ \vdash \ M : \tau &amp;amp; \sigma = \begin{cases} \Gamma(x) &amp;amp;\text{si x} \in \Gamma \\ \text{incógnita fresca} \ ?k &amp;amp;\text{si no}\end{cases} \end{matrix}}{W(\lambda x.\, U) \space \rightsquigarrow \space \Gamma /\{x\} \ \vdash \ (\lambda x : \sigma. M) : \sigma \to \tau}\]

&lt;p&gt;Algoritmo $W$ extendido para $\large\lambda^{BN}$&lt;/p&gt;

\[\frac{}{W(\text{zero}) \rightsquigarrow \varnothing \vdash \text{zero : Nat}} \\ \ \\

\frac{\begin{matrix} W(U) = \Gamma \vdash M : \sigma &amp;amp; \quad S = \text{mgu}(\sigma \stackrel{?}{=} \text{Nat})\end{matrix}}{W(\text{succ(}U)) \rightsquigarrow S(\Gamma) \vdash S(\text{succ(}M)) : \text{Nat}} \\ \ \\

\frac{\begin{matrix} W(U) = \Gamma \vdash M : \sigma &amp;amp; \quad S = \text{mgu}(\sigma \stackrel{?}{=} \text{Nat})\end{matrix}}{W(\text{pred(}U)) \rightsquigarrow S(\Gamma) \vdash S(\text{pred(}M)) : \text{Nat}} \\ \ \\

\frac{\begin{matrix} W(U) = \Gamma \vdash M : \sigma &amp;amp; \quad S = \text{mgu}(\sigma \stackrel{?}{=} \text{Nat})\end{matrix}}{W(\text{isZero(}U)) \rightsquigarrow S(\Gamma) \vdash S(\text{isZero(}M)) : \text{Bool}} \\ \ \\\]
</description>
        <pubDate>Sat, 05 Oct 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-10/apunteplp1</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-10/apunteplp1</guid>
        
        
        <category>facultad</category>
        
      </item>
    
      <item>
        <title>instalacion de termux y faq</title>
        <description>&lt;h2 id=&quot;que-es-termux&quot;&gt;Que es termux&lt;/h2&gt;
&lt;p&gt;Termux es un emulador de terminal para android, el principal uso que le doy es editar y ejecutar codigo, es útil para editar codigo “on-the-fly” de repositorios tanto en git como en syncthing.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/screenshot-termux.png&quot; alt=&quot;screenshot&quot; width=&quot;250&quot; /&gt;&lt;/p&gt;

&lt;h3 id=&quot;como-instalar-termux&quot;&gt;Como instalar termux&lt;/h3&gt;
&lt;p&gt;Está disponible en &lt;a href=&quot;https://f-droid.org/es/packages/com.termux/&quot;&gt;Fdroid&lt;/a&gt; en formato .apk o en &lt;a href=&quot;https://github.com/termux/termux-app#github&quot;&gt;Github&lt;/a&gt; (recomendado)&lt;/p&gt;

&lt;p&gt;Una vez instalado, Lo primero que hago es seleccionar un grupo de mirrors para mantener los repositorios&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;termux-change-repo
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Esto invoca una interfaz gráfica que permite seleccionar un mirror, seleccionemos &lt;strong&gt;mirror groups&lt;/strong&gt; y luego &lt;strong&gt;Mirrors in South America&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/scr-termux-change-repo.jpg&quot; alt=&quot;cambiar mirror-group&quot; /&gt;&lt;/p&gt;

&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;pkg update
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Ahora otorgamos acceso al almacenamiento del dispositivo para lectura/escritura de archivos.&lt;/p&gt;
&lt;div class=&quot;language-bash highlighter-rouge&quot;&gt;&lt;div class=&quot;highlight&quot;&gt;&lt;pre class=&quot;highlight&quot;&gt;&lt;code&gt;termux-setup-storage
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;&lt;/div&gt;
&lt;p&gt;Esto nos va a redirigir a la pantalla de configuracion del teléfono, activamos el slider para conceder acceso a todos los archivos:
&lt;img src=&quot;/assets/img/posts/termux-grant-access.jpg&quot; alt=&quot;termux-setup-storage&quot; /&gt;&lt;/p&gt;

&lt;p&gt;Ahora deberíamos tener acceso a todos los archivos del dispositivo.&lt;/p&gt;

&lt;p&gt;Listo! ya tenemos termux listo para editar y ejecutar código&lt;/p&gt;

&lt;hr /&gt;
&lt;p&gt;Algunas preguntas que me surgieron al utilizar termux son:&lt;/p&gt;

&lt;h3 id=&quot;que-es-un-emulador-de-terminal&quot;&gt;Que es un emulador de terminal?&lt;/h3&gt;
&lt;p&gt;Una &lt;a href=&quot;https://es.wikipedia.org/wiki/Terminal_(inform%C3%A1tica)&quot;&gt;terminal&lt;/a&gt; solía ser (es, supongo) un dispositivo físico (un monitor y un teclado) el cual se usaba para comunicarse directamente con una computadora, ver su información en lineas de texto y darle instrucciones mediante una interfaz de comandos.&lt;/p&gt;

&lt;p&gt;&lt;img src=&quot;/assets/img/posts/terminal.webp&quot; alt=&quot;terminal en fallout 4&quot; /&gt; ~&lt;em&gt;Una terminal en fallout 4&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Ahora las terminales son software, conocidas como emuladores de terminal. Imitan la misma funcionalidad pero sin necesitar hardware especializado.
Termux emula una terminal en Android aprovechando el kernel de linux y completandola con un entorno que contiene el software básico y los comandos que vienen con todas las distribuciones modernas de linux.&lt;/p&gt;

&lt;h3 id=&quot;termux-es-linux&quot;&gt;Termux es linux?&lt;/h3&gt;
&lt;blockquote&gt;
  &lt;p&gt;The environment setup in Termux is similar to that of a modern Linux distribution. However, running on Android implies several important differences.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Ver &lt;a href=&quot;https://wiki.termux.com/wiki/Differences_from_Linux&quot;&gt;Differences from Linux&lt;/a&gt; de la wiki de termux.&lt;/p&gt;

&lt;p&gt;Las limitaciones de Android hacen que termux no sea compatible con software nativo de linux, las diferencias mas importantes son que termux no usa el sistema de archivos de linux, y ademas usa Bionic libc: la libreria standard de C escrita por Google para Android. Lo que rompe la compatibilidad con el software escrito para linux.&lt;/p&gt;

&lt;p&gt;Mas contenido en la &lt;a href=&quot;/2024-09/termuxmenu&quot;&gt;guía principal&lt;/a&gt;&lt;/p&gt;
</description>
        <pubDate>Sun, 29 Sep 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-09/instalaciontermux</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-09/instalaciontermux</guid>
        
        
        <category>termux</category>
        
      </item>
    
      <item>
        <title>guía de termux</title>
        <description>&lt;h1 id=&quot;tutorial-para-termux&quot;&gt;tutorial para termux&lt;/h1&gt;
&lt;p&gt;Esto es una guía de cosas útiles para termux que escribí o tengo planeado escribir.&lt;/p&gt;

&lt;h3 id=&quot;contenido&quot;&gt;contenido:&lt;/h3&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;a href=&quot;/2024-09/instalaciontermux&quot;&gt;instalacion de termux y faq&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;&lt;a href=&quot;/2025-03/sshwindows&quot;&gt;conectarse por ssh desde windows&lt;/a&gt;&lt;/li&gt;
  &lt;li&gt;como editar código en termux&lt;/li&gt;
  &lt;li&gt;como ejecutar codigo en termux (python, C, C++, Haskell)&lt;/li&gt;
  &lt;li&gt;como editar la pantalla de inicio&lt;/li&gt;
  &lt;li&gt;que es y como editar archivo bash.rc&lt;/li&gt;
  &lt;li&gt;como configurar un servidor x11&lt;/li&gt;
  &lt;li&gt;como editar la barra de teclado&lt;/li&gt;
  &lt;li&gt;como instalar una distribucion de linux (ubuntu, arch, debian)&lt;/li&gt;
  &lt;li&gt;como establecer comandos personalizados&lt;/li&gt;
&lt;/ul&gt;

&lt;h3 id=&quot;comandos-utiles-para-termux&quot;&gt;comandos utiles para termux&lt;/h3&gt;
&lt;p&gt;Estos comandos son utiles también para linux&lt;/p&gt;
&lt;ul&gt;
  &lt;li&gt;&lt;strong&gt;nano&lt;/strong&gt; (editor de texto)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;mkdir&lt;/strong&gt; (crear carpeta)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;mv&lt;/strong&gt; (mover archivos/carpetas)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;fastfetch&lt;/strong&gt; (mostrar información del sistema)&lt;/li&gt;
  &lt;li&gt;&lt;strong&gt;unzip&lt;/strong&gt; (descomprimir archivos)&lt;/li&gt;
&lt;/ul&gt;

</description>
        <pubDate>Sat, 28 Sep 2024 00:00:00 +0000</pubDate>
        <link>http://valenrc.github.io/2024-09/termuxmenu</link>
        <guid isPermaLink="true">http://valenrc.github.io/2024-09/termuxmenu</guid>
        
        
        <category>termux</category>
        
      </item>
    
  </channel>
</rss>