<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Spin Foam</title>
	<atom:link href="http://mchouza.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://mchouza.wordpress.com</link>
	<description>Just another WordPress.com weblog</description>
	<lastBuildDate>Sun, 03 Jan 2010 17:26:55 +0000</lastBuildDate>
	<generator>http://wordpress.com/</generator>
	<language>es</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<cloud domain='mchouza.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://www.gravatar.com/blavatar/92a14f4d3c822016a9feb9c5ce6b3301?s=96&#038;d=http://s.wordpress.com/i/buttonw-com.png</url>
		<title>Spin Foam</title>
		<link>http://mchouza.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://mchouza.wordpress.com/osd.xml" title="Spin Foam" />
		<item>
		<title>El poder del SAT</title>
		<link>http://mchouza.wordpress.com/2010/01/03/el-poder-del-sat/</link>
		<comments>http://mchouza.wordpress.com/2010/01/03/el-poder-del-sat/#comments</comments>
		<pubDate>Sun, 03 Jan 2010 17:26:55 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[informática]]></category>
		<category><![CDATA[javascript]]></category>
		<category><![CDATA[matemática]]></category>
		<category><![CDATA[python]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=893</guid>
		<description><![CDATA[Generalidades
SAT es el ejemplo canónico de problema NP-completo. Consiste en determinar, dada una fórmula booleana en forma de conjunción de disyunciones (donde cada disyunción se llama claúsula), si existe una asignación de valores a sus variables que hagan verdadera la fórmula (esto se denomina &#8220;satisfacer&#8221; la fórmula y de ahí viene el nombre SATisfiability asignado [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=893&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><h4>Generalidades</h4>
<p><a href="http://en.wikipedia.org/wiki/Boolean_satisfiability_problem">SAT</a> es <a href="http://pages.cs.wisc.edu/~shuchi/courses/787-F07/scribe-notes/lecture09.pdf">el ejemplo canónico</a> de <a href="http://en.wikipedia.org/wiki/NP-complete">problema NP-completo</a>. Consiste en determinar, dada una <a href="http://en.wikipedia.org/wiki/Conjunctive_normal_form">fórmula booleana en forma de conjunción de disyunciones</a> (donde cada disyunción se llama <a href="http://en.wikipedia.org/wiki/Clause_(logic)">claúsula</a>), si existe una asignación de valores a sus variables que hagan verdadera la fórmula (esto se denomina &#8220;satisfacer&#8221; la fórmula y de ahí viene el nombre <em>SATisfiability</em> asignado al problema). Por ejemplo,</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BSAT%7D%5Cleft%28+%28x_1+%5Cvee+x_2%29+%5Cwedge+%28%5Cneg+x_1+%5Cvee+%5Cneg+x_2%29+%5Cright%29+%3D+%5Ctop&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{SAT}\left( (x_1 \vee x_2) \wedge (\neg x_1 \vee \neg x_2) \right) = \top' title='\mathrm{SAT}\left( (x_1 \vee x_2) \wedge (\neg x_1 \vee \neg x_2) \right) = \top' class='latex' />,</p>
<p>ya que la asignación <img src='http://l.wordpress.com/latex.php?latex=x_1+%3D+%5Ctop%2C+x_2+%3D+%5Cbot&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='x_1 = \top, x_2 = \bot' title='x_1 = \top, x_2 = \bot' class='latex' /> hace verdadera a la expresión. Mientras que</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BSAT%7D%5Cleft%28+%28x_1+%5Cvee+x_2%29+%5Cwedge+%28%5Cneg+x_1+%5Cvee+%5Cneg+x_2%29+%5Cwedge+x_1+%5Cwedge+x_2%5Cright%29+%3D+%5Cbot&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{SAT}\left( (x_1 \vee x_2) \wedge (\neg x_1 \vee \neg x_2) \wedge x_1 \wedge x_2\right) = \bot' title='\mathrm{SAT}\left( (x_1 \vee x_2) \wedge (\neg x_1 \vee \neg x_2) \wedge x_1 \wedge x_2\right) = \bot' class='latex' />,</p>
<p>ya que no existe forma de asignarle valores de verdad a <img src='http://l.wordpress.com/latex.php?latex=x_1&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='x_1' title='x_1' class='latex' /> y <img src='http://l.wordpress.com/latex.php?latex=x_2&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='x_2' title='x_2' class='latex' /> sin hacer falsa a la fórmula.</p>
<p>Un algoritmo simple para resolverlo es probar distintas combinaciones de valores para las variables hasta encontrar alguna que haga verdadera a la fórmula o agotar las posibles combinaciones de valores. En el peor caso (cuando no se pueda encontrar una asignación), el algoritmo examinará <img src='http://l.wordpress.com/latex.php?latex=2%5En&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='2^n' title='2^n' class='latex' /> posibles asignaciones (siendo <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> el número de variables). Por lo tanto, este algoritmo tiene una complejidad temporal <img src='http://l.wordpress.com/latex.php?latex=%5CTheta%282%5En%29&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\Theta(2^n)' title='\Theta(2^n)' class='latex' />.</p>
<p>Pero, <a href="http://www.scottaaronson.com/thesis.html">aunque no</a> <a href="http://rjlipton.wordpress.com/2009/09/15/theory-has-bet-on-pnp/">se cree posible</a> encontrar un algoritmo de complejidad sub-exponencial para este problema, si se conocen <a href="http://rjlipton.wordpress.com/2009/07/13/sat-solvers-is-sat-hard-or-easy/">algoritmos que mejoran significativamente al algoritmo anteriormente descrito</a>. A continuación estudiaremos uno de los más simples, conocido como <a href="http://en.wikipedia.org/wiki/DPLL_algorithm">DPLL</a>.</p>
<h4>DPLL</h4>
<p>El algoritmo DPLL, llamado así por las iniciales de sus creadores, mejora al algoritmo anteriormente descrito mediante el uso de dos técnicas:</p>
<ul>
<li><strong>Backtracking:</strong> la asignación de variables para satisfacer la fórmula se construye variable por variable, volviéndose atrás apenas se detecta que la asignación de valor efectuada a una variable hace imposible satisfacer la fórmula.</li>
<li><strong>Unit propagation:</strong> cuando una de las cláusulas contiene una sola variable (negada o no), la conjunción obliga a que esta variable tome un valor específico. El proceso de <em>unit propagation</em> consiste en propagar el efecto de esta asignación de valor sobre el resto de las cláusulas.</li>
</ul>
<p>Si bien <a href="http://www.csd.uwo.ca/~eschost/Teaching/07-08/CS445a/p394-davis.pdf">la referencia original</a> utilizaba una técnica adicional de eliminación de literales puros, esta no proporciona ventajas significativas en performance por lo que la omitiremos del análisis.</p>
<h4>Implementación de DPLL en Javascript</h4>
<p>A continuación analizaremos <a href="http://js-games.googlecode.com/svn/trunk/dpll/test2.html">una implementación de este algoritmo</a> en <a href="http://www.ecmascript.org/docs.php">Javascript</a>. La <a href="http://js-games.googlecode.com/svn/trunk/dpll/test2.html">implementación enlazada</a> toma una claúsula por línea, utilizando <tt>-</tt> como operador de negación y sin requerir operadores explícitos para la disyunción y la conjunción. Por ejemplo, la fórmula <img src='http://l.wordpress.com/latex.php?latex=%28x_1+%5Cvee+x_2+%5Cvee+%5Cneg+x_3%29+%5Cwedge+%28%5Cneg+x_2++%5Cvee+x_3%29+%5Cwedge+%5Cneg+x_1&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='(x_1 \vee x_2 \vee \neg x_3) \wedge (\neg x_2  \vee x_3) \wedge \neg x_1' title='(x_1 \vee x_2 \vee \neg x_3) \wedge (\neg x_2  \vee x_3) \wedge \neg x_1' class='latex' /> se representaría como</p>
<p><code><br />
x1 x2 -x3<br />
-x2 x3<br />
-x1<br />
</code></p>
<p>Un <a href="http://code.google.com/p/js-games/source/browse/trunk/dpll/test2.html#11">script incluido en el archivo HTML</a> se encarga de transformar el problema a un formato canónico, en el que las variables son reemplazadas por números enteros mayores que uno y la negación lógica se transforma en una negaciór aritmética. Las cláusulas se convierten en <a href="https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Global_Objects/Array"><em>arrays</em> Javascript</a>, con lo que la fórmula anterior quedaría transformada en <code>[[1, 2, -3], [-2, 3], [-1]]</code>.</p>
<p>La primera función que analizaremos es <code>simplifyClause()</code>:</p>
<pre class="brush: jscript;">
function simplifyClause(c, a) {
	var nc, i;
	nc = [];
	for (i = 0; i &lt; c.length; i++) {
		if (c[i] in a) {
			return null;
		} else if (!(-c[i] in a)) {
			nc.push(c[i]);
		}
	}
	return nc;
}
</pre>
<p>Toma dos parámetros, <code>c</code> y <code>a</code>, que representan una claúsula dada como array de valores numéricos y una asignación de valores a las variables dada como un diccionario, respectivamente. El diccionario se utiliza como conjunto, empleando el número correspondiente a la variable como clave y <code>true</code> como valor; la clave <em>numérica</em> se niega para indicar la asignación de un valor falso a la variable. Por ejemplo, la asignación <img src='http://l.wordpress.com/latex.php?latex=x_1+%3D+%5Ctop&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='x_1 = \top' title='x_1 = \top' class='latex' /> y <img src='http://l.wordpress.com/latex.php?latex=x_2+%3D+%5Cbot&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='x_2 = \bot' title='x_2 = \bot' class='latex' /> se representaría con <code>{1: true, -2: true}</code>.</p>
<p>La función simplemente copia la claúsula <code>c</code> a una nueva cláusula <code>nc</code>, examinando las apariciones de variables a la luz de la asignación de valores que se utiliza en ese momento. Si encuentra una aparición de variable que se corresponda con una asignación incluida en <code>a</code>, significa que la cláusula es verdadera; por lo tanto devuelve <code>null</code> indicando la &#8220;desaparición&#8221; de la misma. Por el contrario, si encuentra la aparición <em>negada</em> en <code>a</code>, simplemente no la incluye en la nueva claúsula (ya que es falsa, el <a href="http://en.wikipedia.org/wiki/Identity_element">valor neutro</a> de la disyunción).</p>
<p>Continuando con las funciones, podemos examinar la función <code>applyAssignment()</code>:</p>
<pre class="brush: jscript;">
function applyAssignment(f, a) {
	var nf, i, nc;
	nf = [];
	for (i = 0; i &lt; f.length; i++) {
		nc = simplifyClause(f[i], a);
		if (nc !== null) {
			nf.push(nc);
		}
	}
	return nf;
}
</pre>
<p>Esta función hace lo mismo que la anteriormente descrita pero sobre toda una fórmula. Como la simplificación se efectúa cláusula por cláusula, el único procesamiento no delegado a <code>simplifyClause()</code> es la supresión de las claúsulas que son devueltas como <code>null</code> (que son las que <code>simplifyClause()</code> determinó como tautológicas dada la asignación <code>a</code>).</p>
<p>Dejando a un lado funciones auxiliares, como <code>cloneAssignment()</code>, solo resta analizar la función principal: <code>recDPLL()</code>.</p>
<pre class="brush: jscript;">
function recDPLL(f, a) {
	var i, na, v, ret;
	f = applyAssignment(f, a);
	if (f.length === 0) {
		return [true, a];
	}
	for (i = 0; i &lt; f.length; i++) {
		if (f[i].length === 0) {
			return [false, {}];
		} else if (f[i].length === 1) {
			na = cloneAssignment(a);
			na[f[i][0]] = true;
			return recDPLL(f, na);
		}
	}
	na = cloneAssignment(a);
	na[f[0][0]] = true;
	ret = recDPLL(f, na);
	if (ret[0]) {
		return ret;
	}
	delete na[f[0][0]];
	na[-f[0][0]] = true;
	return recDPLL(f, na);
}
</pre>
<p>En primer lugar la función simplifica la fórmula <code>f</code> con la asignación de valores <code>a</code>, empleando las técnicas anteriormente descritas. Si esta simplificación conduzca a una fórmula vacía, dado que una conjunción vacía es verdadera, devuelve <code>true</code> y la asignación de valores que llevó a este valor de verdad.</p>
<p>Si no se llegó a una fórmula vacía es obvio que restan cláusulas no tautológicas dentro de la misma (todo esto tomando como &#8220;dada&#8221; la asignación <code>a</code> de variables). Estas pueden ser de dos tipos: cláusulas contradictorias o contingencias. Como las cláusulas restantes no pueden contener variables con valores asignados, dado el anterior paso de simplificación, una cláusula contradictoria solo puede ser vacía.</p>
<p>El procesamiento restante de la fórmula consiste en recorrer las cláusulas buscando cláusulas vacías o con una sola aparición de variable. Si se encuentra un cláusula vacía, estaremos en presencia de una contradicción que imposibilita aumentar <code>a</code> hasta  convertirla en una asignación que satisfaga a la fórmula en cuestión. Por lo tanto se realiza <em>backtracking</em> devolviendo <code>[false, {}]</code>.</p>
<p>La aparición de una cláusula con una sola variable es más interesante, ya que puede verse como &#8220;forzando&#8221; una asignación. En este caso es cuando se realiza el proceso de <em>unit propagation</em>, que consiste simplemente en incorporar la única asignación compatible con la cláusula unitaria dentro de <code>a</code> y continuar la búsqueda recursiva. No es necesario simplificar la fórmula, ya que esto se realizará apenas comience la ejecución de la nueva instancia de <code>recDPLL()</code>.</p>
<p>Por último, si la fórmula no cae en ninguno de estos dos casos se realiza una exploración recursiva normal.</p>
<h4>Utilizando SAT para resolver otros problemas</h4>
<p>Para mostrar como SAT puede utilizarse para resolver problemas lógicos en general, veremos como aplicarlo a la resolución de un problema de lógica conocido como &#8220;el problema de Einstein&#8221; (aunque es bastante poco probable que Einstein efectivamente lo haya creado). <a href="http://www.davar.net/MATH/PROBLEMS/EINSTEIN.HTM">La formulación que utilizaremos</a> es la siguiente:</p>
<blockquote><p>
1. There are 5 houses (along the street) in 5 different colors: blue, green, red, white and yellow.<br />
2. In each house lives a person of a different nationality: Brit, Dane, German, Norwegian and Swede.<br />
3. These 5 owners drink a certain beverage: beer, coffee, milk, tea and water,<br />
   smoke a certain brand of cigar: Blue Master, Dunhill, Pall Mall, Prince and blend,<br />
   and keep a certain pet: cat, bird, dog, fish and horse.<br />
4. No owners have the same pet, smoke the same brand of cigar, or drink the same beverage.</p>
<p>Hints</p>
<p>1. The Brit lives in a red house.<br />
2. The Swede keeps dogs as pets.<br />
3. The Dane drinks tea.<br />
4. The green house is on the left of the white house (next to it).<br />
5. The green house owner drinks coffee.<br />
6. The person who smokes Pall Mall rears birds.<br />
7. The owner of the yellow house smokes Dunhill.<br />
8. The man living in the house right in the center drinks milk.<br />
9. The Norwegian lives in the first house.<br />
10. The man who smokes blend lives next to the one who keeps cats.<br />
11. The man who keeps horses lives next to the man who smokes Dunhill.<br />
12. The owner who smokes Blue Master drinks beer.<br />
13. The German smokes Prince.<br />
14. The Norwegian lives next to the blue house.<br />
15. The man who smokes blend has a neighbor who drinks water.</p>
<p>The question is: Who keeps fish?
</p></blockquote>
<p>(<a href="http://www.ite.educacion.es/w3/eos/MaterialesEducativos/mem2003/logica/logica/actividades/juegos/juegoeinstein.html">Puede verse también una formulación equivalente en español.</a>)</p>
<p>Si bien probablemente la técnica más simple de aplicar en este caso sea <a href="http://en.wikipedia.org/wiki/Constraint_programming"><em>constraint-based programming</em></a>, podemos aplicar SAT sin problemas. Para ello debemos decidir primero que variables utilizaremos, siendo una elección razonable numerar las casas, colores, nacionalidades, bebidas, cigarros y mascotas e introducir variables booleanas asociando las casas con los distintos atributos de la persona que vive en ellas. Eso nos da un total de <img src='http://l.wordpress.com/latex.php?latex=5%5E3+%3D+125&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='5^3 = 125' title='5^3 = 125' class='latex' /> variables.</p>
<p>La traducción de estas relaciones a cláusulas SAT puede ser algo tediosa, por lo que nos conviene emplear <a href="http://code.google.com/p/js-games/source/browse/trunk/dpll/einstein_problem.py">un script simple</a> para este proceso. En caso <a href="http://www.python.org/download/">de no disponer de Python</a>, puede consultarse la salida del script en <a href="http://code.google.com/p/js-games/source/browse/trunk/dpll/ep_sat.txt"><code>ep_sat.txt</code></a>. La nomenclatura de las variables es simple: <code>h<em>ijk</em></code>, donde <code><em>i</em></code> indica el núemro de casa, <code><em>j</em></code> indica el atributo en cuestión y <code><em>k</em></code> indica un posible valor de este atributo. <a href="http://code.google.com/p/js-games/source/browse/trunk/dpll/einstein_problem.py">En el código Python</a> pueden verse los detalles de como se traducen las implicaciones y restricciones a disyunciones.</p>
<p>Introduciendo las cláusulas SAT en <a href="http://js-games.googlecode.com/svn/trunk/dpll/test2.html">la página de prueba de DPLL</a>, podemos encontrar el siguiente resultado:</p>
<p><code><br />
SATISFIABLE h0c4 h1c0 h2c2 h3c1 h4c3 h0n3 h0b4 h0s1 h0p0 h1n1 h1b3 h1s4 h1p4 h2n0 h2b2 h2s2 h2p1 h3n2 h3b1 h3s3 h3p3 h4n4 h4b0 h4s0 h4p2 -h0c3 -h2b0 -h2b1 -h2b3 -h2b4 -h0b2 -h1b2 -h3b2 -h4b2 -h2n1 -h2c1 -h3c3 -h0n0 -h0n1 -h0n2 -h0n4 -h1n3 -h2n3 -h3n3 -h4n3 -h2s0 -h1c1 -h1c2 -h1c3 -h1c4 -h0c0 -h2c0 -h3c0 -h4c0 -h1n0 -h2c3 -h0c1 -h0c2 -h2c4 -h3c2 -h4c2 -h3c4 -h4c1 -h4c4 -h3n0 -h4n0 -h5c3 -h3b0 -h3b3 -h3b4 -h0b1 -h1b1 -h4b1 -h3n1 -h0s0 -h0s2 -h0s3 -h0s4 -h1s1 -h2s1 -h3s1 -h4s1 -h1p0 -h1p1 -h1p2 -h1p3 -h0p4 -h2p4 -h3p4 -h4p4 -h1n4 -h1s2 -h3s0 -h4s4 -h0b0 -h0b3 -h1b4 -h4b4 -h2s4 -h3s4 -h0p1 -h0p2 -h0p3 -h2p0 -h3p0 -h4p0 -h1n2 -h4n1 -h1b0 -h4b3 -h1s0 -h1s3 -h2n2 -h2n4 -h2s3 -h3s2 -h4s2 -h4s3 -h2p2 -h2p3 -h3p1 -h4p1 -h4n2 -h3n4 -h4p3 -h3p2<br />
</code></p>
<p>Como el pez sería la mascota número 3, buscamos apariciones de <code>p3</code> en una variable no negada y encontramos <code>h3p3</code>. Buscando la nacionalidad del habitante de la casa número 3 encontramos <code>h3n2</code>, por lo que podemos concluir que el alemán es quien tiene un pez como mascota (coincidiendo con <a href="http://www.davar.net/MATH/PROBLEMS/EINSTEIN.HTM">la solución dada a este problema</a>).</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/893/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/893/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/893/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=893&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2010/01/03/el-poder-del-sat/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
		<item>
		<title>Espirales sobre Noruega</title>
		<link>http://mchouza.wordpress.com/2009/12/23/espirales-sobre-noruega/</link>
		<comments>http://mchouza.wordpress.com/2009/12/23/espirales-sobre-noruega/#comments</comments>
		<pubDate>Wed, 23 Dec 2009 18:46:36 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[espacio]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=875</guid>
		<description><![CDATA[Hace una semana me mostraron una imagen tan espectacular que inmediatamente sospeché que era falsa:
Pero la explicación real resulta mucho más interesante:

Nota: ahora soy un nuevo miembro del extraño movimiento obsesionado en expresar algo con sentido usando solo 140 caracteres  
       <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=875&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Hace una semana me mostraron una imagen tan espectacular que inmediatamente sospeché que era falsa:</p>
<div class="wp-caption aligncenter" style="width: 505px"><a href="http://mchouza.files.wordpress.com/2009/12/norway_spiral.jpg"><img class="size-full wp-image-876" title="norway_spiral" src="http://mchouza.files.wordpress.com/2009/12/norway_spiral.jpg?w=495&#038;h=330" alt="" width="495" height="330" /></a><p class="wp-caption-text">Espiral observada sobre Noruega.</p></div>
<p>Pero <a href="http://blogs.discovermagazine.com/badastronomy/2009/12/09/awesomely-bizarre-light-show-freaks-out-norway/">la explicación real</a> resulta mucho más interesante:</p>
<p><span style="text-align:center; display: block;"><a href="http://mchouza.wordpress.com/2009/12/23/espirales-sobre-noruega/"><img src="http://img.youtube.com/vi/Zx8i5EfmYU4/2.jpg" alt="" /></a></span></p>
<p><strong>Nota:</strong> ahora soy <a href="http://twitter.com/mchouza">un nuevo miembro</a> del <a href="http://twitter.com/about#like">extraño movimiento</a> <a href="http://www.spinelessbooks.com/gadsby/01.html">obsesionado</a> en expresar algo con sentido usando solo 140 caracteres <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' /> </p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/875/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/875/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/875/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=875&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/12/23/espirales-sobre-noruega/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>

		<media:content url="http://mchouza.files.wordpress.com/2009/12/norway_spiral.jpg" medium="image">
			<media:title type="html">norway_spiral</media:title>
		</media:content>

		<media:content url="http://img.youtube.com/vi/Zx8i5EfmYU4/2.jpg" medium="image" />
	</item>
		<item>
		<title>Los orígenes del dialecto judicial y cosas varias</title>
		<link>http://mchouza.wordpress.com/2009/12/06/los-origenes-del-dialecto-judicial-y-cosas-varias/</link>
		<comments>http://mchouza.wordpress.com/2009/12/06/los-origenes-del-dialecto-judicial-y-cosas-varias/#comments</comments>
		<pubDate>Sun, 06 Dec 2009 21:16:18 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=871</guid>
		<description><![CDATA[Una interesante perspectiva &#8220;evolutiva&#8221; sobre el origen de la complejidad del dialecto utilizado (principalmente) por los abogados:

  Why is legal language so hard to understand?
     (a) A lawyer always tries to use clauses that
         have already been interpreted by the courts
  [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=871&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p><a href="http://people.csail.mit.edu/gregs/ll1-discuss-archive-html/msg02919.html">Una interesante perspectiva &#8220;evolutiva&#8221;</a> sobre el origen de la complejidad del dialecto utilizado (principalmente) por los abogados:</p>
<blockquote><p>
  Why is legal language so hard to understand?</p>
<p>     (a) A lawyer always tries to use clauses that<br />
         have already been interpreted by the courts<br />
         [as you noted].</p>
<p>     (b) A court interprets a clause only when it is<br />
         brought to its attention through litigation.</p>
<p>     (c) Litigation over the meaning of a clause<br />
         occurs only when there is some disagreement<br />
         over the meaning of a clause</p>
<p>     (d) Disagreement over the meaning of a clause<br />
         is most likely to occur when the clause is<br />
         ambiguous or hard to understand.</p>
<p>  Therefore, the system produces a kind of Darwinian<br />
  pressure: the legal language most likely to survive<br />
  is that which on its face is most ambiguous or<br />
  difficult to understand.
</p></blockquote>
<p>A continuación, debido a la falta de material adicional completo con la clásica lista de links:</p>
<ul>
<li><a href="http://www.freeskier.com/articles/article.php?article_id=3279">Como se observa una avalancha en primera persona</a>.</li>
<li><a href="http://www.dailyscript.com/scripts/jurassicpark_script_final_12_92.html">No todos</a> <a href="http://en.wikipedia.org/wiki/Hippopotamus">los herbívoros</a> <a href="http://scienceblogs.com/tetrapodzoology/2009/11/hippos_killing_crocodile.php">son</a> <a href="http://www.flickr.com/photos/johnbullas/2868730112/">inofensivos</a>.</li>
<li><a href="http://jwz.livejournal.com/1122877.html">Radiografías en tiempo real</a>.</li>
<li><a href="http://www.youtube.com/watch?v=IU_reTt7Hj4&amp;feature=player_embedded">Un interesante video <em>amateur</em></a> que combina elementos de los universos de <a href="http://es.wikipedia.org/wiki/Half-Life"><em>Half-Life</em></a> y <a href="http://es.wikipedia.org/wiki/Lost"><em>Lost</em></a>.</li>
</ul>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/871/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/871/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/871/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=871&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/12/06/los-origenes-del-dialecto-judicial-y-cosas-varias/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
		<item>
		<title>La caída de las lámparas&#8230; resuelta</title>
		<link>http://mchouza.wordpress.com/2009/11/24/la-caida-de-las-lamparas-resuelta/</link>
		<comments>http://mchouza.wordpress.com/2009/11/24/la-caida-de-las-lamparas-resuelta/#comments</comments>
		<pubDate>Tue, 24 Nov 2009 02:25:57 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[informática]]></category>
		<category><![CDATA[matemática]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=845</guid>
		<description><![CDATA[En un comentario del post anterior, Kardo mostraba una solución al problema en 19 intentos:
&#8230; Siguiendo este pensamiento, la idea es probar en los pisos múltiplos de N y, en el momento que la lámpara se rompe, probar en los anteriores N-1 pisos para buscar el piso mínimo. De esta forma, si buscamos el mínimo [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=845&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>En <a href="http://mchouza.wordpress.com/2009/11/02/la-caida-de-las-lamparas/#comment-41">un comentario</a> del <a href="http://mchouza.wordpress.com/2009/11/02/la-caida-de-las-lamparas/">post anterior</a>, <em>Kardo</em> mostraba una solución al problema en 19 intentos:</p>
<blockquote><p>&#8230; Siguiendo este pensamiento, la idea es probar en los pisos múltiplos de N y, en el momento que la lámpara se rompe, probar en los anteriores N-1 pisos para buscar el piso mínimo. De esta forma, si buscamos el mínimo de la función f(100/N+N-1) con 1&lt;N&lt;100, encontramos que ese valor es 19.</p></blockquote>
<p>Esa es la mejor solución &#8220;inteligible&#8221; al problema entre las que vi, pero no llega a ser óptima. </p>
<h5>El algoritmo</h5>
<p>Para buscar la solución óptima, definamos dos funciones: <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D%28n%2C+l%29&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}(n, l)' title='\mathrm{Cost}(n, l)' class='latex' /> y <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BFixedTryCost%7D%28t%2C+n%2C+l%29&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{FixedTryCost}(t, n, l)' title='\mathrm{FixedTryCost}(t, n, l)' class='latex' />, donde <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> es la cantidad de pisos que podrían ser el piso mínimo, <img src='http://l.wordpress.com/latex.php?latex=l&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='l' title='l' class='latex' /> es la cantidad de lámparas disponibles y <img src='http://l.wordpress.com/latex.php?latex=t&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' /> es un piso determinado desde donde la próxima lámpara será arrojada. La primera función <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}' title='\mathrm{Cost}' class='latex' /> nos indica la cantidad máxima de lanzamientos de lámparas requeridos según la estrategia óptima, mientras que <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BFixedTryCost%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{FixedTryCost}' title='\mathrm{FixedTryCost}' class='latex' /> nos indica esa misma cantidad con la restricción adicional del piso desde donde se arrojará la próxima lámpara.</p>
<p>Si hay un candidato solo restante no hace falta seguir realizando lanzamientos, por lo que</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D%281%2C+l%29+%3D+0&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}(1, l) = 0' title='\mathrm{Cost}(1, l) = 0' class='latex' />.</p>
<p>Por otro lado, si solo nos queda una lámpara no podemos arriesgarnos a que se rompa quedando pisos sin explorar y tendremos que ir probando piso por piso. Por consiguiente tendremos</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D%28n%2C+1%29+%3D+n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}(n, 1) = n' title='\mathrm{Cost}(n, 1) = n' class='latex' />.</p>
<p>En los otros casos habrá que efectuar un cierto número de lanzamientos para determinar el piso mínimo. No podemos saber <em>a priori</em> cual será el piso óptimo desde donde realizar el siguiente lanzamiento, pero sabemos que será uno de los <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> que son candidatos. Por lo tanto podemos decir que</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cdisplaystyle+%5Cmathrm%7BCost%7D%28n%2C+l%29+%3D+%5Cmin_%7B0+%5Cle+t+%3C+n%7D+%5Cmathrm%7BFixedTryCost%7D%28t%2C+n%2C+l%29&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\displaystyle \mathrm{Cost}(n, l) = \min_{0 \le t &lt; n} \mathrm{FixedTryCost}(t, n, l)' title='\displaystyle \mathrm{Cost}(n, l) = \min_{0 \le t &lt; n} \mathrm{FixedTryCost}(t, n, l)' class='latex' />,</p>
<p>ya que la estrategia óptima elegirá el piso desde donde lanzar de modo de minimizar el costo.</p>
<p>Pero cuando realizamos un lanzamiento desde el piso <img src='http://l.wordpress.com/latex.php?latex=t&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' /> solo podemos tener dos resultados: la lámpara puede romperse o no. En caso de que se rompa examinaremos los <img src='http://l.wordpress.com/latex.php?latex=t&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' /> candidatos menores que <img src='http://l.wordpress.com/latex.php?latex=t&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' />, mientras que en caso de que quede intacta haremos lo propio con los <img src='http://l.wordpress.com/latex.php?latex=n-t-1&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n-t-1' title='n-t-1' class='latex' /> candidatos menores que <img src='http://l.wordpress.com/latex.php?latex=t&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='t' title='t' class='latex' />. Como se realizó un lanzamiento, el costo será</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BFixedTryCost%7D%28t%2C+n%2C+l%29+%3D+1+%2B+%5Cmax%28%5Cmathrm%7BCost%7D%28t%2C+l-1%29%2C+%5Cmathrm%7BCost%7D%28n-t-1%2C+l%29%29&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{FixedTryCost}(t, n, l) = 1 + \max(\mathrm{Cost}(t, l-1), \mathrm{Cost}(n-t-1, l))' title='\mathrm{FixedTryCost}(t, n, l) = 1 + \max(\mathrm{Cost}(t, l-1), \mathrm{Cost}(n-t-1, l))' class='latex' />.</p>
<p>Con esto tenemos definidas casi por completo a las funciones <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}' title='\mathrm{Cost}' class='latex' /> y <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BFixedTryCost%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{FixedTryCost}' title='\mathrm{FixedTryCost}' class='latex' />, pero quedan pendientes <a href="http://en.wikipedia.org/wiki/Binary_search_algorithm#The_algorithm">algunas sutilezas</a> que suelen conducir a errores en las definiciones recursivas. En este caso particular, habrá llamadas a <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D%280%2C+l%29&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}(0, l)' title='\mathrm{Cost}(0, l)' class='latex' />, que nunca fue definida. Podemos resolver esto haciendo que</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D%280%2C+l%29+%3D+0&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}(0, l) = 0' title='\mathrm{Cost}(0, l) = 0' class='latex' />,</p>
<p>que es más simple que separar los casos en que es innecesario buscar.</p>
<h5>El algoritmo implementado</h5>
<p>La implementación, en este caso en Python, es directa a partir de las definiciones recursivas:</p>
<pre class="brush: python;">
def cost(n, l):
    if n in (0, 1):
        return 0
    elif l == 1:
        return n
    else:
        return min(fixed_try_cost(t, n, l) for t in xrange(0, n))

def fixed_try_cost(t, n, l):
    return 1 + max(cost(t, l-1), cost(n - t - 1, l))
</pre>
<p>Pero si intentamos ejecutar <code>cost(100, 2)</code>, observaremos que la ejecución no termina. Esto es debido a que, al igual que en caso del cálculo recursivo de los números de Fibonacci, se recalculan los mismos valores un gran número de veces. Incluso la ejecución de <code>cost(24, 2)</code> demora decenas de segundos.</p>
<h5>El algoritmo utilizando programación dinámica</h5>
<p>Una forma común para resolver este problema es aplicar la técnica conocida como <a href="http://en.wikipedia.org/wiki/Dynamic_programming">programación dinámica</a>, consistente esencialmente en almacenar los resultados previamente calculados de modo de no requerir calcularlos nuevamente. Una forma simple de implementar esto en Python es utilizar un diccionario para almacenar el costo correspondiente a cada valor de <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> y <img src='http://l.wordpress.com/latex.php?latex=l&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='l' title='l' class='latex' />:</p>
<pre class="brush: python;">
costs = {}

def m_fixed_try_cost(t, n, l):
    return 1 + max(m_cost(t, l-1), m_cost(n - t - 1, l))

def m_cost(n, l):
    if (n, l) in costs:
        return costs[(n, l)]
    if n in (0, 1):
        c = 0
    elif l == 1:
        c = n
    else:
        c = min(m_fixed_try_cost(t, n, l) for t in xrange(0, n))
    costs[(n, l)] = c
    return c
</pre>
<p>Se observa que las únicas diferencias (aparte del prefijo <code>m_</code>) son la consulta del diccionario al inicio de la función <code>m_cost</code> y el grabado del valor calculado antes de devolverlo.</p>
<p>Si se desea obtener mejor performance, puede utilizarse una tabla normal y llenarla mediante iteración en lugar de recursión. Por ejemplo, la misma función podría implementarse en C del siguiente modo:</p>
<pre class="brush: cpp;">
#define MAX_N 200
#define MAX_L 200

#define MAX(a, b) ((a) &gt; (b) ? (a) : (b))
#define MIN(a, b) ((a) &lt; (b) ? (a) : (b))

int cost(int n, int l)
{
	int costs[MAX_N][MAX_L];
	int i, j, k, c;
	for (i = 0; i &lt;= n; i++)
		costs[i][1] = i;
	for (j = 1; j &lt;= l; j++)
		costs[0][j] = costs[1][j] = 0;
	for (i = 2; i &lt;= n; i++)
	{
		for (j = 2; j &lt;= l; j++)
		{
			c = i;
			for (k = 0; k &lt; i; k++)
			{
				c = MIN(c, 1 + MAX(costs[k][j-1],
								   costs[i-k-1][j]));
			}
			costs[i][j] = c;
		}
	}
	return costs[n][l];
}
</pre>
<p>De todos modos, todas las versiones se ejecutan en forma esencialmente instantánea, dando como resultado <img src='http://l.wordpress.com/latex.php?latex=%5Cmathrm%7BCost%7D%28100%2C+2%29+%3D+14&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\mathrm{Cost}(100, 2) = 14' title='\mathrm{Cost}(100, 2) = 14' class='latex' />. Mediante una simple modificación podría devolverse la secuencia requerida en base a lo que sucede con las lámparas al ser arrojadas, obteniendo así un algoritmo para resolver el problema en la práctica.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/845/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/845/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/845/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=845&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/11/24/la-caida-de-las-lamparas-resuelta/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
		<item>
		<title>La caída de las lámparas</title>
		<link>http://mchouza.wordpress.com/2009/11/02/la-caida-de-las-lamparas/</link>
		<comments>http://mchouza.wordpress.com/2009/11/02/la-caida-de-las-lamparas/#comments</comments>
		<pubDate>Mon, 02 Nov 2009 16:46:50 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[informática]]></category>
		<category><![CDATA[matemática]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=838</guid>
		<description><![CDATA[We want to figure out how strong our new super-strong light bulbs
are. We know that they will be break when dropped from the top floor
of this building (the 101st). We want to know the exact minimum floor
from which a fall will cause the light bulb to break. You’ll be given
two light bulbs for this task [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=838&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><blockquote><p>We want to figure out how strong our new super-strong light bulbs<br />
are. We know that they will be break when dropped from the top floor<br />
of this building (the 101st). We want to know the exact minimum floor<br />
from which a fall will cause the light bulb to break. You’ll be given<br />
two light bulbs for this task and we want you to do it with the<br />
minimum number of trials.</p></blockquote>
<p>(<a href="http://lbrandy.com/blog/2008/09/here-be-the-code-monkeys/">Extraído</a> del <a href="http://lbrandy.com/blog/">blog de Louis Brandy</a>.)</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/838/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/838/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/838/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=838&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/11/02/la-caida-de-las-lamparas/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
		<item>
		<title>Respuestas pendientes</title>
		<link>http://mchouza.wordpress.com/2009/11/01/respuestas-pendientes/</link>
		<comments>http://mchouza.wordpress.com/2009/11/01/respuestas-pendientes/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 20:19:00 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[informática]]></category>
		<category><![CDATA[matemática]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=829</guid>
		<description><![CDATA[Un problema de sumas
El problema pedía encontrar un algoritmo subcuadrático para determinar si dos elementos en un vector de enteros con una suma dada. Si confiamos en el caracter O(1) de las tablas hash podemos obtener un algoritmo lineal aun más breve que el cuadrático mostrado anteriormente (y sin recurrir al code golfing   [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=829&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><h4>Un problema de sumas</h4>
<p><a href="http://mchouza.wordpress.com/2009/09/16/un-problema-de-sumas/">El problema</a> pedía encontrar un algoritmo subcuadrático para determinar si dos elementos en un vector de enteros con una suma dada. Si confiamos en el caracter O(1) de las tablas <em>hash </em>podemos obtener un algoritmo lineal aun más breve que el cuadrático mostrado anteriormente (y sin recurrir al <a href="http://codegolf.com/"><em>code golfing</em></a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  ):</p>
<pre class="brush: python;">
def sum1_n(s, v):
    d = {}
    for x in v:
        if s-x in d:
            return True
        d[x] = True
    return False
</pre>
<p>Si no confiamos en eso, puede hacerse en tiempo O(n log n) ordenando la secuencia y reemplazando las búsquedas en la tabla por búsquedas binarias (como sugirió Fer) o directamente escanear el vector ordenado con dos punteros desde los extremos (no es difícil determinar las reglas de avance).</p>
<p>Ahora pueden probar su suerte buscando algoritmos subcuadráticos para resolver <a href="http://en.wikipedia.org/wiki/3SUM">3SUM</a>; es solo un poquito más difícil&#8230; <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_razz.gif' alt=':-P' class='wp-smiley' /> </p>
<h4>Circuitos hamiltonianos</h4>
<p>Este otro problema pedía determinar si era posible encontrar circuitos hamiltonianos en grillas cuadradas con una cantidad impar de vértices. Para ver que esto no es posible, dividamos a los vértices de la grilla en dos clases de acuerdo al siguiente esquema:</p>
<div id="attachment_833" class="wp-caption aligncenter" style="width: 460px"><a href="http://mchouza.files.wordpress.com/2009/11/ham_cycle_parity.png"><img src="http://mchouza.files.wordpress.com/2009/11/ham_cycle_parity.png?w=450&#038;h=450" alt="ham_cycle_parity" title="ham_cycle_parity" width="450" height="450" class="size-full wp-image-833" /></a><p class="wp-caption-text">División de los nodos del grafo en dos clases, indicadas por el color utilizado para representarlos.</p></div>
<p>Si recorremos un circuito en el grafo no es difícil convencernos de que en cada paso cambiaremos de clase de vértice. Ahora, en un circuito hamiltoniano la cantidad de pasos será impar, dándonos para el último vértice una clase distinta que para el primero. Como esto es incompatible con el hecho de que se trata de un circuito, es imposible encontrar un circuito hamiltoniano en grillas con una cantidad impar de vértices (no solo cuadradas!).</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/829/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/829/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/829/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/829/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/829/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/829/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/829/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/829/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/829/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/829/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=829&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/11/01/respuestas-pendientes/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>

		<media:content url="http://mchouza.files.wordpress.com/2009/11/ham_cycle_parity.png" medium="image">
			<media:title type="html">ham_cycle_parity</media:title>
		</media:content>
	</item>
		<item>
		<title>Circuitos hamiltonianos</title>
		<link>http://mchouza.wordpress.com/2009/10/08/circuitos-hamiltonianos/</link>
		<comments>http://mchouza.wordpress.com/2009/10/08/circuitos-hamiltonianos/#comments</comments>
		<pubDate>Thu, 08 Oct 2009 17:54:46 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[matemática]]></category>
		<category><![CDATA[misc]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=808</guid>
		<description><![CDATA[Un circuito hamiltoniano es un recorrido cerrado de un grafo que pasa por todos sus vértices una única vez. Si nos limitamos a grafos en forma de grillas cuadradas, podemos encontrar fácilmente un circuito en las grillas con una cantidad par de vértices siguiendo este esquema:
Puede encontrarse un circuito de esta misma naturaleza en una [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=808&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Un circuito hamiltoniano es un recorrido <em>cerrado </em>de un grafo que pasa por todos sus vértices una única vez. Si nos limitamos a grafos en forma de grillas cuadradas, podemos encontrar fácilmente un circuito en las grillas con una cantidad par de vértices siguiendo este esquema:</p>
<div id="attachment_809" class="wp-caption aligncenter" style="width: 460px"><a href="http://mchouza.files.wordpress.com/2009/10/ham_cycle.png"><img class="size-full wp-image-809" title="ham_cycle" src="http://mchouza.files.wordpress.com/2009/10/ham_cycle.png?w=450&#038;h=450" alt="Circuito hamiltoniano en una grilla de 8x8 vértices." width="450" height="450" /></a><p class="wp-caption-text">Circuito hamiltoniano en una grilla de 8x8 vértices.</p></div>
<p>Puede encontrarse un circuito de esta misma naturaleza en una grilla cuadrada con una cantidad impar de vértices? Cambia esto si se permiten grillas rectangulares?</p>
<p>La respuesta a este problema (y al <a href="http://mchouza.wordpress.com/2009/09/16/un-problema-de-sumas/">anterior de sumas</a>) en el próximo post&#8230;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/808/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/808/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/808/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/808/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/808/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/808/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/808/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/808/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/808/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/808/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=808&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/10/08/circuitos-hamiltonianos/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>

		<media:content url="http://mchouza.files.wordpress.com/2009/10/ham_cycle.png" medium="image">
			<media:title type="html">ham_cycle</media:title>
		</media:content>
	</item>
		<item>
		<title>Números de Stirling de segunda especie</title>
		<link>http://mchouza.wordpress.com/2009/10/01/numeros-de-stirling-de-segunda-especie/</link>
		<comments>http://mchouza.wordpress.com/2009/10/01/numeros-de-stirling-de-segunda-especie/#comments</comments>
		<pubDate>Thu, 01 Oct 2009 16:46:13 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[matemática]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=776</guid>
		<description><![CDATA[Contar la cantidad de formas  en que pueden distribuirse  elementos en  cajas es bastante simple, una vez que descubrimos el truco de pensarlo como asignarle un número de caja a cada elemento. Claramente esto nos da  posibles formas. Si ignoramos el &#8220;etiquetado&#8221; de las cajas, claramente esto nos deja  formas.
Este [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=776&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Contar la cantidad de formas  en que pueden distribuirse <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> elementos en <img src='http://l.wordpress.com/latex.php?latex=k&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> cajas es bastante simple, una vez que descubrimos el truco de pensarlo como asignarle un número de caja a cada elemento. Claramente esto nos da <img src='http://l.wordpress.com/latex.php?latex=k%5En&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k^n' title='k^n' class='latex' /> posibles formas. Si ignoramos el &#8220;etiquetado&#8221; de las cajas, claramente esto nos deja <img src='http://l.wordpress.com/latex.php?latex=k%5En%2Fk%21&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k^n/k!' title='k^n/k!' class='latex' /> formas.</p>
<p>Este problema se hace más difícil si agregamos la restricción de que ninguna caja puede permanecer vacía y, de hecho, recuerdo haber esquivado resolver este problema en más de una ocasión (y <a href="http://cscs.umich.edu/~crshalizi/weblog/619.html">no soy el único</a> <img src='http://s.wordpress.com/wp-includes/images/smilies/icon_biggrin.gif' alt=':-D' class='wp-smiley' />  ). Pero <a href="http://en.wikipedia.org/wiki/Stirling_numbers_of_the_second_kind">en Wikipedia</a> encontré una solución elegante y, tal vez, lo suficientemente memorable para que la recuerde en caso de encontrarme nuevamente con este problema&#8230;</p>
<p>Denominemos</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D+n+%5C%5C+k+%5Cend%7Bmatrix%7D%5Cright%5C%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\left\{\begin{matrix} n \\ k \end{matrix}\right\}' title='\left\{\begin{matrix} n \\ k \end{matrix}\right\}' class='latex' /></p>
<p>al número de distintas formas en las que podemos distribuir <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> elementos en <img src='http://l.wordpress.com/latex.php?latex=k&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> cajas sin dejar ninguna vacía y sin distinguir entre cajas (o sea el número de distintas <a href="http://en.wikipedia.org/wiki/Partition_of_a_set">particiones</a> de <img src='http://l.wordpress.com/latex.php?latex=%5C%7B1%2C2%2C...%2Cn%5C%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\{1,2,...,n\}' title='\{1,2,...,n\}' class='latex' /> en <img src='http://l.wordpress.com/latex.php?latex=k&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> subconjuntos). Entonces podemos dividir las formas de efectuar esta distribución en dos clases: las que ponen al elemento <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> solo en una caja y las que no lo hacen.</p>
<p>Una vez situado el elemento <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> en una caja, las distribuciones serán equivalentes a <img src='http://l.wordpress.com/latex.php?latex=n-1&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n-1' title='n-1' class='latex' /> elementos en <img src='http://l.wordpress.com/latex.php?latex=k-1&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k-1' title='k-1' class='latex' /> cajas. Por lo tanto, habrá</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D+n-1+%5C%5C+k-1+%5Cend%7Bmatrix%7D%5Cright%5C%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\left\{\begin{matrix} n-1 \\ k-1 \end{matrix}\right\}' title='\left\{\begin{matrix} n-1 \\ k-1 \end{matrix}\right\}' class='latex' /></p>
<p>formas de efectuar la distribución dejando solo al elemento <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' />.</p>
<p>Por otro lado, si el elemento <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> no se encuentra solo, el problema es equivalente a distribuir <img src='http://l.wordpress.com/latex.php?latex=n-1&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n-1' title='n-1' class='latex' /> elementos en <img src='http://l.wordpress.com/latex.php?latex=k&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k' title='k' class='latex' /> cajas sin dejar ninguna vacía y luego insertar el elemento <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> en alguna de ellas (distinguibles por tener distintos subconjuntos de los elementos). En consecuencia habrá</p>
<p><img src='http://l.wordpress.com/latex.php?latex=k+%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D+n-1+%5C%5C+k+%5Cend%7Bmatrix%7D%5Cright%5C%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='k \left\{\begin{matrix} n-1 \\ k \end{matrix}\right\}' title='k \left\{\begin{matrix} n-1 \\ k \end{matrix}\right\}' class='latex' /></p>
<p>formas de efectuar la distribución sin dejar al elemento <img src='http://l.wordpress.com/latex.php?latex=n&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='n' title='n' class='latex' /> solo en una caja. </p>
<p>En conjunto eso nos deja la relación de recurrencia</p>
<p><img src='http://l.wordpress.com/latex.php?latex=%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D+n+%5C%5C+k+%5Cend%7Bmatrix%7D%5Cright%5C%7D+%3D+%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D+n-1+%5C%5C+k-1+%5Cend%7Bmatrix%7D%5Cright%5C%7D+%2B+k+%5Cleft%5C%7B%5Cbegin%7Bmatrix%7D+n-1+%5C%5C+k+%5Cend%7Bmatrix%7D%5Cright%5C%7D&#038;bg=eeeae8&#038;fg=000000&#038;s=0' alt='\left\{\begin{matrix} n \\ k \end{matrix}\right\} = \left\{\begin{matrix} n-1 \\ k-1 \end{matrix}\right\} + k \left\{\begin{matrix} n-1 \\ k \end{matrix}\right\}' title='\left\{\begin{matrix} n \\ k \end{matrix}\right\} = \left\{\begin{matrix} n-1 \\ k-1 \end{matrix}\right\} + k \left\{\begin{matrix} n-1 \\ k \end{matrix}\right\}' class='latex' /></p>
<p>para estas cantidades, denominadas <em>números de Stirling de segunda especie</em>.</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/776/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/776/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/776/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/776/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/776/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/776/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/776/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/776/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/776/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/776/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=776&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/10/01/numeros-de-stirling-de-segunda-especie/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
		<item>
		<title>Una historia interesante</title>
		<link>http://mchouza.wordpress.com/2009/09/25/una-historia-interesante/</link>
		<comments>http://mchouza.wordpress.com/2009/09/25/una-historia-interesante/#comments</comments>
		<pubDate>Fri, 25 Sep 2009 11:59:39 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[historia]]></category>
		<category><![CDATA[ww2]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=771</guid>
		<description><![CDATA[Via Steve Hsu, encontré una interesante entrevista a Daniel Kahneman. Me resultó particularmente interesante el siguiente fragmento (en aquel entonces vivía en una parte de Francia ocupada por los alemanes luego de 1940):

It must have been the fall of &#8216;41, when there was a curfew for Jews. We were also supposed to be wearing a [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=771&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Via <a href="http://infoproc.blogspot.com/">Steve Hsu</a>, encontré <a href="http://globetrotter.berkeley.edu/people7/Kahneman/kahneman-con1.html">una interesante entrevista</a> a <a href="http://en.wikipedia.org/wiki/Daniel_Kahneman">Daniel Kahneman</a>. Me resultó particularmente interesante el siguiente fragmento (en aquel entonces vivía en <a href="http://en.wikipedia.org/wiki/German_occupation_of_France_during_World_War_II">una parte de Francia</a> ocupada por los alemanes <a href="http://en.wikipedia.org/wiki/Fall_of_France">luego de 1940</a>):</p>
<blockquote><p>
It must have been the fall of &#8216;41, when there was a curfew for Jews. We were also supposed to be wearing a yellow star, and there was a curfew which I think was 6:00 PM. I was in first or second grade and I&#8217;d gone to play with a friend and I was going home and I missed the curfew, I was late. And so, I turned my sweater inside out and walked home, and as I was coming close I remember the street was deserted and there was this German soldier walking towards me. He was wearing the black uniform and I knew that was not good. That was the uniform of the SS. We were walking towards each other and as we were coming close he sort of beckoned me, and of course I went there, and he picked me up and hugged me. I remember being terrified that he would see the Star of David inside my sweater. Then he put me down and took out his wallet and showed me a picture of a boy and gave me some money. That&#8217;s a formative memory because of what it meant about the complexity of things. I remember being very fascinated at the time by this and by stories of Hitler liking flowers and kissing babies. The complexity of evil was much on my mind as a seven- or eight-year-old.
</p></blockquote>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/771/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/771/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/771/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=771&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/09/25/una-historia-interesante/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
		<item>
		<title>Un problema de sumas</title>
		<link>http://mchouza.wordpress.com/2009/09/16/un-problema-de-sumas/</link>
		<comments>http://mchouza.wordpress.com/2009/09/16/un-problema-de-sumas/#comments</comments>
		<pubDate>Wed, 16 Sep 2009 16:12:41 +0000</pubDate>
		<dc:creator>mchouza</dc:creator>
				<category><![CDATA[informática]]></category>

		<guid isPermaLink="false">http://mchouza.wordpress.com/?p=763</guid>
		<description><![CDATA[Sea v un vector formado por n enteros y sea s un número entero. El problema consiste en determinar de la forma más eficiente posible si existen dos elementos en v, vi y vj (i != j), tales que vi + vj = s.
Es simple hacerlo en tiempo cuadrático O(n2) mediante el algoritmo &#8220;de fuerza [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=763&subd=mchouza&ref=&feed=1" />]]></description>
			<content:encoded><![CDATA[<br /><p>Sea <em>v</em> un vector formado por <em>n</em> enteros y sea <em>s</em> un número entero. El problema consiste en determinar de la forma más eficiente posible si existen dos elementos en <em>v</em>, <em>v<sub>i</sub></em> y <em>v<sub>j</sub></em> (<em>i</em> != <em>j</em>), tales que <em>v<sub>i</sub></em> + <em>v<sub>j</sub></em> = <em>s</em>.</p>
<p>Es simple hacerlo en tiempo cuadrático <em>O(n<sup>2</sup>)</em> mediante el algoritmo &#8220;de fuerza bruta&#8221;:</p>
<pre class="brush: python;">
def sum1_nsq(s, v):
    for i in xrange(len(v)):
        for j in xrange(len(v)):
            if j &gt;= i:
                break
            if v[i] + v[j] == s:
                return True
    return False
</pre>
<p>pero lo interesante es ver si puede mejorarse este tiempo&#8230;</p>
  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/mchouza.wordpress.com/763/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/mchouza.wordpress.com/763/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/mchouza.wordpress.com/763/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/mchouza.wordpress.com/763/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/mchouza.wordpress.com/763/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/mchouza.wordpress.com/763/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/mchouza.wordpress.com/763/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/mchouza.wordpress.com/763/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/mchouza.wordpress.com/763/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/mchouza.wordpress.com/763/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=mchouza.wordpress.com&blog=6184898&post=763&subd=mchouza&ref=&feed=1" />]]></content:encoded>
			<wfw:commentRss>http://mchouza.wordpress.com/2009/09/16/un-problema-de-sumas/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
	
		<media:content url="http://1.gravatar.com/avatar/5277207dadc9ce68a228f38bf8d5f6a7?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">mchouza</media:title>
		</media:content>
	</item>
	</channel>
</rss>