<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:media="http://search.yahoo.com/mrss/">
<channel>
<title><![CDATA[Ensaios - Rafael Quintanilha]]></title>
<description><![CDATA[Essays about software engineering, web development, artificial intelligence, quantitative analysis, financial markets, books and tradition.]]></description>
<link>https://rafaelquintanilha.com/ensaios/</link>
<image><url>https://rafaelquintanilha.com/content/images/2022/12/Logo-Design--2-.png</url><title>Ensaios - Rafael Quintanilha</title><link>https://rafaelquintanilha.com/ensaios/</link></image>
<lastBuildDate>Mon, 14 Oct 2024 22:52:49 GMT</lastBuildDate>
<atom:link href="https://rafaelquintanilha.com/ensaios/rss/" rel="self" type="application/rss+xml"/>
<ttl>60</ttl>
<item>
<title><![CDATA[Personalizando o ChatGPT para Obter Melhores Respostas]]></title>
<description><![CDATA[Ou: treinando o ChatGPT para responder com base em vídeos do YouTube.]]></description>
<link>https://rafaelquintanilha.com/ensaios/personalizando-o-chatgpt-para-obter-melhores-respostas/</link>
<guid isPermaLink="false">6429e2181f864a003dddf2c0</guid>
<category><![CDATA[Artificial Intelligence]]></category>
<dc:creator><![CDATA[Rafael Quintanilha]]></dc:creator>
<pubDate>Sun, 02 Apr 2023 22:23:43 GMT</pubDate>
<media:content url="https://rafaelquintanilha.com/content/images/2023/04/robot-reading.jpg" medium="image"/>
<content:encoded><![CDATA[<p>Desde seu lançamento o ChatGPT tem dividido opiniões: há o espectro que acredita que ele irá dominar o mundo, destruir todos os empregos e subjugar a raça humana, e os que o desprezam simplesmente pelo fato de não conseguir <em>fazer tudo.</em></p>
<p>Naturalmente, como Engenheiro de Software, essa tecnologia chamou bastante minha atenção e minha percepção é mais balanceada – acredito que irá ser essencial como assistente, da mesma forma que o Google é "essencial" para quem quiser buscar alta produtividade.</p>
<p>No entanto, o potencial socialmente disruptivo dessa tecnologia trouxe a discussão sobre Inteligência Artificial para os jornais, o que infelizmente significa que todo jornalista tem que expor sua opinião. Longe de mim clamar exclusividade sobre a discussão desse assunto, mas é particularmente cansativo ver pessoas se posicionando sem o completo entendimento da tecnologia, o que inevitavelmente joga o holofote dos políticos e burocratas sobre o assunto (<a href="https://exame.com/tecnologia/chatgpt-foi-banido-na-italia-e-sera-investigado-por-autoridades-do-pais/" rel="noopener noreferrer" target="_blank">o que já aconteceu na Itália</a>).</p>
<p>Mesmo dentro da "direita" e dos supostos "liberais" houve um choro e ranger de dentes coletivo por conta do viés "esquerdista" do ChatGPT. Seria ele uma ferramenta de domínio comunista? Explorei esse assunto nos seguintes tweets:</p>
<figure class="embed embed-twitter" data-url="https://x.com/rafaquint/status/1632845387487752193">
<blockquote class="twitter-tweet"><p lang="pt" dir="ltr">O CHATGPT É COMUNISTA, E AGORA?<br><br>Todo mundo decidiu falar ao mesmo tempo que o ChatGPT é de "esquerda", ou tem "viés ideológico".<br><br>Esse assunto cansa um pouco, então vou tentar explicar na thread se isso é um problema.<br><br>🧵1/11 <a href="https://t.co/CgsFytrGxM" rel="noopener noreferrer" target="_blank">pic.twitter.com/CgsFytrGxM</a></p>— Rafael Quintanilha (@rafaquint) <a href="https://twitter.com/rafaquint/status/1632845387487752193" rel="noopener noreferrer" target="_blank">March 6, 2023</a></blockquote>
</figure>
<p>Em suma, o que temos aqui é a falta de entendimento da tecnologia e a pressa típica de olhar qualquer novidade sob a ótica da política. O ChatGPT é uma <em>aplicação</em> que utiliza um <em>LLM</em>, ou Large Language Model, para responder perguntas baseado num corpo de documentos onde ele foi <em>treinado</em>.</p>
<p>Ora, se espantar que o ChatGPT tem um viés progressista é o mesmo que se espantar que um aluno da Ivy League tem o viés progressista! Afinal de contas, o ChatGPT, como seu típico aluno de Harvard, "aprende" e "reproduz" o que lhe ensinam.</p>
<p>Isso significa então que o ChatGPT é inútil a menos que ele se alinhe com seu espectro político? Claro que não. Diferentemente do aluno de Harvard (cuja lavagem cerebral é provavelmente irreversível) o ChatGPT não tem apego aos seus criadores e pode ser facilmente "domesticado".</p>
<p>Nesse momento, preciso fazer uma importante distinção: como disse, o ChatGPT é uma <em>aplicação</em>, o que significa que ele é uma instância de uma tecnologia desenvolvido com propósito em particular. Exemplo: o fato de que existem TVs ruins não significa que a tecnologia por trás da TV seja necessariamente ruim. No caso, o ChatGPT é um LLM do <em>tipo</em> GPT-3 (ou GPT-4, mais recentemente). É como dizer que uma TV Samsung pode ser do <em>tipo</em> Ultra HD, ou 4K.</p>
<p>Por que estou fazendo essa distinção? Porque entender que a disrupção está na <em>tecnologia</em>, não no <em>software</em>, é fundamental. Pois a tecnologia está disponível pra todos, ainda que o software seja proprietário de uma empresa.</p>
<p>De modo a ilustrar essa diferença eu me propus a fazer o seguinte projeto: utilizar o <a href="https://www.youtube.com/@guilhermefclfreire" rel="noopener noreferrer" target="_blank">excelente canal no YouTube do professor Guilherme Freire</a> como fonte de dados para um "treinamento exclusivo" do ChatGPT.</p>
<p>Guilherme Freira é professor de filosofia, tendo suas visões de mundo bem diferentes daquela que você imaginaria encontrar na <em>high society</em> democrata. Ele se embrenha em temas espinhentos como <a href="https://www.youtube.com/watch?v=rm2palF2RHI" rel="noopener noreferrer" target="_blank">Os Mitos sobre a Inquisição</a>, <a href="https://www.youtube.com/watch?v=fQ7h6hw7wfQ" rel="noopener noreferrer" target="_blank">Existe Moral sem religião?</a> e <a href="https://www.youtube.com/watch?v=kPQkFXQ898s" rel="noopener noreferrer" target="_blank">Como a Proclamação da República estragou o Brasil</a>.</p>
<p>O objetivo do projeto então foi personalizar o ChatGPT para responder de acordo com os ensinamentos das aulas do professor (disponíveis em seu <a href="https://www.youtube.com/@guilhermefclfreire" rel="noopener noreferrer" target="_blank">canal do YouTube</a>), ainda que muitos dos temas sejam completamente ortogonais ao que você esperaria do progressista típico.</p>
<p>Isso é possível pois o GPT-4, sendo um modelo de linguagem natural, é capaz de receber instruções que o induzem a responder de uma certa forma ou utilizando certo material. Esse trabalho é chamado de <em>prompt engineering</em>, ou seja, a "arte" de induzir o modelo a responder como você quer.</p>
<p>Voltando ao exemplo do progressista de Harvard, esse processo é análogo a tirar esse jovem da universidade americana e jogá-lo no meio de uma fazenda de cana-de-açúcar no Paraná. Ele pode ter todo o conhecimento do mundo incutido em sua mente, mas pra trabalhar no campo vai ter que agir de acordo com um rígido manual de conduta (ainda que ocasionalmente ele possa deixar seu viés aflorar, afinal, ninguém é perfeito).</p>
<p>Pois bem – embora esse post não seja completamente técnico (a despeito do que tipicamente publico em meu <a href="https://rafaelquintanilha.com/">blog</a>), vou explicar em linhas gerais o processo, de modo que os curiosos possam replicá-lo para os seus assuntos de interesse.</p>
<h3 id="gerando-os-documentos-relevantes">Gerando os documentos relevantes</h3>
<p>Um LLM basicamente é treinado sobre um corpo de texto, e responde com outro texto. Exemplo: você pode alimentá-lo com o capítulo de um livro e pedir para o modelo resumi-lo em 3 pontos principais.</p>
<p>Sendo assim, o primeiro passo é conseguir os documentos que serão utilizados como fonte para o modelo, de modo que ele não precise buscar no seu conhecimento "original". No meu caso, o primeiro passo foi baixar os vídeos do YouTube e transcrevê-los utilizando a biblioteca <a href="https://openai.com/research/whisper" rel="noopener noreferrer" target="_blank">Whisper</a>, também do <a href="https://openai.com/" rel="noopener noreferrer" target="_blank">OpenAI</a> (a empresa pro trás do ChatGPT).</p>
<p>O Whisper é uma ferramenta do tipo <em>speech-to-text</em> que, embora otimizada para o inglês, vai bem o suficiente em português. Existem diversos tipos de modelo, variando do <em>tiny</em> ao <em>large,</em> que resultam em melhores transcrições. Para esse caso, utilizei o <em>tiny</em> na maior parte dos vídeos, embora meus testes com o modelo <em>small</em> foram significativamente melhores (modelos maiores fritaram o meu computador).</p>
<p>Bem, ao final desse (longo) processo eu gerei 20 <em>transcripts</em>, ou o equivalente a 20 horas de aula do professor no YouTube. Vale mencionar que qualquer tipo de texto poderia ser utilizado: <em>docs</em>, <em>pdfs</em>, <em>ebooks</em>, tweets, chats do WhatsApp, enfim, vai da sua aplicação.</p>
<h3 id="gerando-os-vetores-embeddings">Gerando os vetores (embeddings)</h3>
<p>Simplificadamente, o processo de busca funciona assim: os textos utilizados como fonte são particionados e transformados em vetores. É como se cada página de um livro fosse arrancada e "codificada". Esse "código" é uma representação vetorial daquele texto. A esses vetores damos o nome de <em>embeddings</em>.</p>
<p>A vantagem de trabalhar com vetores é que podemos utilizar diversos métodos para calcular a <em>proximidade</em> entre eles. Uma das formas mais conhecidas é a distância euclidiana: quanto menor a distância de um vetor a outro, <em>mais próximos</em> eles estão.</p>
<p>Ou seja: quando fazemos uma pergunta para o modelo, primeiro transformamos essa pergunta em um vetor e depois buscamos no nosso banco de dados de vetores (tecnicamente chamado de <em>vectorstore</em>) aqueles que são mais próximos (por exemplo, utilizando a distância euclidiana).</p>
<p>Nós então alimentamos o modelo com os <em>n</em> "pedaços de texto" (ou <em>chunks</em>) mais próximos da pergunta, e instruímo-no a responder baseado nesses <em>chunks</em>. Assim, garantimos que a resposta <strong>tem</strong> que ser derivada desses documentos.</p>
<h3 id="instruindo-o-modelo-prompt-engineering">Instruindo o modelo (prompt engineering)</h3>
<p>Talvez uma das partes mais variáveis do processo seja a melhor forma de induzir o modelo a responder de acordo com seu desejo. É o equivalente a um chefe dando instruções para um empregado – seja educado, responda formalmente, responda em inglês, etc.</p>
<p>Para fins de registro, esse foi o <em>prompt</em> que utilizei com o modelo:</p>
<figure class="code"><figcaption>python</figcaption><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="python"><code><span class="line"><span style="color:#ECEBE8">prompt_template </span><span style="color:#A1C1E4">=</span><span style="color:#97CCAE"> """You are an assistant that should answer based on the transcripts from several lessons.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#97CCAE">The name of the professor is Guilherme Freire. The transcripts are in Portuguese. He is a catholic philosopher.</span></span>
<span class="line"><span style="color:#97CCAE">The opinion of other people is not relevant. Only the professor's opinion is relevant.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#97CCAE">Here are relevant parts of the transcripts:</span></span>
<span class="line"></span>
<span class="line"><span style="color:#97CCAE">{context}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#97CCAE">Question in Portuguese: {question}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#97CCAE">Do not answer anything that is not relevant to the question.</span></span>
<span class="line"><span style="color:#97CCAE">Use only knowledge from the transcripts.</span></span>
<span class="line"></span>
<span class="line"><span style="color:#97CCAE">How would the professor answer the question? Answer in Portuguese:"""</span></span></code></pre></figure>
<p>Notem algumas instruções:</p>
<ul>
<li>O modelo foi instruído a explicitamente responder baseado nos <em>transcripts</em>;</li>
<li>Um background do professor foi passado (o fato que ele é católico, por exemplo);</li>
<li>Nenhuma outra opinião é relevante, no sentido de que o modelo não deve contrapor as ideias apresentadas nos textos;</li>
<li>O modelo deve responder em Português.</li>
</ul>
<h3 id="resultados">Resultados</h3>
<p>Com tudo isso dito, vamos agora comparar o resultado de algumas perguntas enviadas para o modelo treinado (batizado de <em>FreireGPT</em>) e para o ChatGPT regular. Em ambos os casos foi utilizado o GPT-4 como modelo.</p>
<figure class="image"><img alt="FreireGPT sobre as cruzadas" loading="lazy" decoding="async" width="954" height="209" src="https://rafaelquintanilha.com/_astro/Screenshot-from-2023-04-02-18-50-08.DVKD2C5u_1FUNJt.webp"><figcaption>FreireGPT sobre as cruzadas</figcaption></figure>
<p>Nesse primeiro exemplo, veja como um tema complexo e politicamente incorreto como as cruzadas foi respondido sem problemas, inclusive refutando a ideia geral de vilanização dos cristãos e pacifismo dos muçulmanos.</p>
<figure class="image"><img alt="ChatGPT sobre as cruzadas" loading="lazy" decoding="async" width="828" height="589" src="https://rafaelquintanilha.com/_astro/Screenshot-20230402182215-828x589.BgNxSb4S_Zed9oE.webp"><figcaption>ChatGPT sobre as cruzadas</figcaption></figure>
<p>A resposta do ChatGPT é equilibrada, porém politicamente correta demais, embora ambos os modelos entendam a natureza complexa desse empreendimento.</p>
<p>Vamos ser mais polêmicos e perguntar por que o progressismo é ruim:</p>
<figure class="image"><img alt="FreireGPT sobre progressismo" loading="lazy" decoding="async" width="914" height="221" src="https://rafaelquintanilha.com/_astro/Screenshot-20230402182746-914x221.ilXJNLz7_ZA5XLK.webp"><figcaption>FreireGPT sobre progressismo</figcaption></figure>
<p>Aqui vemos a opinião contudente do professor, que pode ser vista em vídeos como <a href="https://www.youtube.com/watch?v=0n4p9oerAR0" rel="noopener noreferrer" target="_blank">O que é Progressismo?</a> Além de evitar ficar em cima do muro, o modelo recupera visões e exemplos específicos dados em aulas, como por exemplo o caso do aumento de estupros na Suécia.</p>
<figure class="image"><img alt="ChatGPT sobre progressismo" loading="lazy" decoding="async" width="794" height="887" src="https://rafaelquintanilha.com/_astro/Screenshot-20230402182948-794x887.BRMXrifu_ZIQtaH.webp"><figcaption>ChatGPT sobre progressismo</figcaption></figure>
<p>Já o ChatGPT faz seu disclaimer e responde críticas genéricas sobre o progressismo. Note que, por ser um modelo treinado de forma muito diversa, ele dificilmente entrará com profundidade em assuntos dessa natureza.</p>
<h3 id="utilizando-a-inteligência-artificial-ao-seu-favor">Utilizando a Inteligência Artificial ao seu favor</h3>
<p>Por fim, é importante não ficarmos presos apenas à camada de que a IA tem viés de esquerda ou de direita. Existem aplicabilidades muito mais edificantes.</p>
<p>Por exemplo, ao longo de suas aulas o professor cita diversos livros. Podemos usar nosso modelo para recuperar aqueles que foram mais citados:</p>
<figure class="image"><img alt="5 livros mais citados" loading="lazy" decoding="async" width="924" height="382" src="https://rafaelquintanilha.com/_astro/Screenshot-20230402183309-924x382.xb3yHIpY_ZV5qnh.webp"><figcaption>5 livros mais citados</figcaption></figure>
<p>Apesar do erro de transcrição que fez com que o modelo cometesse a gafe de chamar o <a href="https://pt.wikipedia.org/wiki/Antonin-Gilbert_Sertillanges" rel="noopener noreferrer" target="_blank">Padre Sertillanges</a> de "Padre Certe de Langes", ele recupera livros frequentemente citados nas aulas, como <a href="https://www.googleadservices.com/pagead/aclk?sa=L&#x26;ai=DChcSEwjYi_H1k4z-AhVFFdQBHc_MCL4YABAGGgJvYQ&#x26;ohost=www.google.com&#x26;cid=CAESauD2fA1hftl5HSthpHF17zmYRUY_3Z17qxfXp8MsBQfvUhrWNTW94FY9DeKlMdvtVVkTTJl1kteeJzfdhRwSpfUqC9xNbQeEgI3dZ0iFVXtqoiHkrT0pW8vPw9C-5sEkeILL0YOswHZPCak&#x26;sig=AOD64_006emcRORMknL3O9Wr-XIyckbXHg&#x26;ctype=5&#x26;q=&#x26;ved=2ahUKEwi22uT1k4z-AhUCppUCHXpXAbEQww8oAnoECAEQCg&#x26;adurl=" rel="noopener noreferrer" target="_blank">Ideias tem Consequências</a> e <a href="https://www.amazon.com.br/%C3%BAltima-supersti%C3%A7%C3%A3o-Uma-refuta%C3%A7%C3%A3o-neoate%C3%ADsmo-ebook/dp/B078XQKFKB" rel="noopener noreferrer" target="_blank">Refutando o Neoateísmo</a>.</p>
<figure class="image"><img alt="FreireGPT sobre Chesterton" loading="lazy" decoding="async" width="927" height="229" src="https://rafaelquintanilha.com/_astro/Screenshot-from-2023-04-02-18-39-15.CFx7vjJ1_1s0sA.webp"><figcaption>FreireGPT sobre Chesterton</figcaption></figure>
<p>Ao perguntar explicitamente sobre o grande <a href="https://pt.wikipedia.org/wiki/G._K._Chesterton" rel="noopener noreferrer" target="_blank">Chesterton</a>, recebemos recomendações que de fato podem ser observadas na live <a href="https://www.youtube.com/watch?v=Y37_qqVcr9c" rel="noopener noreferrer" target="_blank">Por que você deve ler G. K. Chesterton?</a></p>
<hr>
<p>O objetivo desse artigo não é limitar a conversa sobre Inteligência Artifical aos técnicos – ao contrário, é um chamado ao uso <em>consciente</em> da tecnologia, afinal, o que é a tecnologia se não um meio para um fim?</p>
<p>Perde-se muito tempo discutindo-se os meios, enquanto o que realmente importa é o <em>uso que você faz dele</em>. Foi justamente isso que me atraiu para a Engenharia de Software – a possibilidade de usar a tecnologia como ferramenta para algo palpável, real.</p>
<p>Em vez de reclamar que o programa de computador feito por progressistas na Califórnia não faz exatamente o que você quer, por que não utilizar-se das mesmas ferramentas, mas ao seu favor? Os exemplos desse texto se basearam em algumas poucas aulas, mas o que não conseguiríamos fazer se alimentássemos o modelo com nossos autores favoritos, os filósofos mais importantes, e os escritores mais influentes?</p>
<p>A tecnologia está aí. Usem-na.</p>]]></content:encoded>
</item>
<item>
<title><![CDATA[The Drunken Sailor and The Lindy Effect]]></title>
<description><![CDATA[Understand the Lindy Effect mathematically by applying it to the well-known Drunken Sailor problem.]]></description>
<link>https://rafaelquintanilha.com/ensaios/the-drunken-sailor-and-the-lindy-effect/</link>
<guid isPermaLink="false">638bcd8f24336d003d59fc0d</guid>
<category><![CDATA[Lindy Effect]]></category><category><![CDATA[Math]]></category>
<dc:creator><![CDATA[Rafael Quintanilha]]></dc:creator>
<pubDate>Wed, 27 Mar 2019 03:00:00 GMT</pubDate>

<content:encoded><![CDATA[<p>I was scrolling through my Twitter feed on a boring Saturday afternoon when I stumbled upon this tweet:</p>
<figure class="embed embed-twitter" data-url="https://twitter.com/bilayerguy/status/1098926919402311680">
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">Dear <a href="https://twitter.com/nntaleb" rel="noopener noreferrer" target="_blank">@nntaleb</a> , will you post this puzzle in memory of <a href="https://twitter.com/CutTheKnotMath" rel="noopener noreferrer" target="_blank">@CutTheKnotMath</a>? I had it in an exam 21 years ago and still do not know the solution. I am sure your followers or you will do it and I will learn something useful. Thank you! <a href="https://t.co/e9HXQZwo9K" rel="noopener noreferrer" target="_blank">pic.twitter.com/e9HXQZwo9K</a></p>— Adrian Mureșan (@bilayerguy) <a href="https://twitter.com/bilayerguy/status/1098926919402311680" rel="noopener noreferrer" target="_blank">February 22, 2019</a></blockquote>
</figure>
<p>I was immediately thrilled - finally something interesting to do!</p>
<p>Here’s the problem in full:</p>
<blockquote>
<p>A drunken sailor stands near the edge of an abyss and takes random steps either towards or away from the edge. A step towards the edge has a probability of p<em>p</em> and a step away from the edge has a probability of (1 - p)(1−<em>p</em>). If the sailor starts n<em>n</em> steps from the edge, what is his chance of survival? What is the minimum value of p<em>p</em> for which there is no chance of survival?</p>
</blockquote>
<p>Turns out the solution for this problem is not beautiful only mathematically, but also provides great insights into our daily life.</p>
<p>Let’s solve it first.</p>
<h2 id="solving-computationally"><strong>Solving Computationally</strong></h2>
<p>Before jumping into the maths, let’s try to get some intuition from code. Here’s a simple simulator for our problem:</p>
<iframe src="https://codesandbox.io/embed/angry-jerry-q3w4l9?fontsize=14&#x26;hidenavigation=1&#x26;theme=dark" style="width:100%; height:500px; border:0; border-radius: 4px; overflow:hidden;" title="drunken-sailor" allow="accelerometer; ambient-light-sensor; camera; encrypted-media; geolocation; gyroscope; hid; microphone; midi; payment; usb; vr; xr-spatial-tracking" sandbox="allow-forms allow-modals allow-popups allow-presentation allow-same-origin allow-scripts" loading="lazy"></iframe>
<p>The complete code is on <a href="https://codesandbox.io/s/drunken-sailor-q3w4l9" rel="noopener noreferrer" target="_blank">CodeSandbox</a> but the algorithm is pretty straightforward.</p>
<figure class="code"><figcaption>jsx</figcaption><pre class="astro-code linha" style="background-color:#1b1814;color:#ecebe8; overflow-x: auto;" tabindex="0" data-language="jsx"><code><span class="line"><span style="color:#A1C1E4">const</span><span style="color:#ECEBE8"> MAX_ITERATIONS </span><span style="color:#A1C1E4">=</span><span style="color:#97CCAE"> 10000</span><span style="color:#ECEBE8">;</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A1C1E4">const</span><span style="color:#EDCC95"> updatePosition</span><span style="color:#A1C1E4"> =</span><span style="color:#ECEBE8"> (currentPosition, p) </span><span style="color:#A1C1E4">=></span><span style="color:#ECEBE8"> {</span></span>
<span class="line"><span style="color:#A1C1E4">  const</span><span style="color:#ECEBE8"> randomVariable </span><span style="color:#A1C1E4">=</span><span style="color:#EDCC95"> Math.random</span><span style="color:#ECEBE8">();</span></span>
<span class="line"><span style="color:#A1C1E4">  if</span><span style="color:#ECEBE8"> ( randomVariable </span><span style="color:#A1C1E4">&#x3C;</span><span style="color:#ECEBE8"> p ) </span><span style="color:#A1C1E4">return</span><span style="color:#ECEBE8"> currentPosition </span><span style="color:#A1C1E4">-</span><span style="color:#97CCAE"> 1</span><span style="color:#ECEBE8">;</span></span>
<span class="line"><span style="color:#A1C1E4">  else</span><span style="color:#A1C1E4"> return</span><span style="color:#ECEBE8"> currentPosition </span><span style="color:#A1C1E4">+</span><span style="color:#97CCAE"> 1</span><span style="color:#ECEBE8">;</span></span>
<span class="line"><span style="color:#ECEBE8">}</span></span>
<span class="line"></span>
<span class="line"><span style="color:#A1C1E4">const</span><span style="color:#EDCC95"> simulation</span><span style="color:#A1C1E4"> =</span><span style="color:#ECEBE8"> (initialPosition, p) </span><span style="color:#A1C1E4">=></span><span style="color:#ECEBE8"> {</span></span>
<span class="line"><span style="color:#A1C1E4">  let</span><span style="color:#ECEBE8"> iterations </span><span style="color:#A1C1E4">=</span><span style="color:#97CCAE"> 0</span><span style="color:#ECEBE8">;</span></span>
<span class="line"><span style="color:#A1C1E4">  let</span><span style="color:#ECEBE8"> currentPosition </span><span style="color:#A1C1E4">=</span><span style="color:#ECEBE8"> initialPosition;</span></span>
<span class="line"><span style="color:#A1C1E4">  while</span><span style="color:#ECEBE8"> ( currentPosition </span><span style="color:#A1C1E4">></span><span style="color:#97CCAE"> 0</span><span style="color:#A1C1E4"> &#x26;&#x26;</span><span style="color:#ECEBE8"> iterations </span><span style="color:#A1C1E4">&#x3C;=</span><span style="color:#ECEBE8"> MAX_ITERATIONS ) {</span></span>
<span class="line"><span style="color:#ECEBE8">    currentPosition </span><span style="color:#A1C1E4">=</span><span style="color:#EDCC95"> updatePosition</span><span style="color:#ECEBE8">(currentPosition, p);</span></span>
<span class="line"><span style="color:#ECEBE8">    iterations</span><span style="color:#A1C1E4">++</span><span style="color:#ECEBE8">;</span></span>
<span class="line"><span style="color:#ECEBE8">  }</span></span>
<span class="line"><span style="color:#A1C1E4">  return</span><span style="color:#ECEBE8"> [currentPosition, iterations];</span></span>
<span class="line"><span style="color:#ECEBE8">}</span></span></code></pre></figure>
<p>The trick is to think of the sailor’s position as a point in the x-axis. We update the position until he dies (<code>currentPosition === 0</code>) or the maximum number of iterations is reached. In every round, we compare a random variable between 0 and 1 (yielded by <code>Math.random</code>) with p<em>p</em> and move the sailor left or right accordingly.</p>
<p>I encourage you to play a little bit with the simulator and check how’s your intuition going. In any case, here’s a table with the % of deaths for some combinations of <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span></span> and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span></span>:</p>
<table>
<thead>
<tr>
<th>p</th>
<th>Deaths (n = 5n=5) (%)</th>
<th>Deaths (n = 15n=15) (%)</th>
<th>Deaths (n = 50n=50) (%)</th>
</tr>
</thead>
<tbody>
<tr>
<td>0.1</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0.2</td>
<td>0</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0.3</td>
<td>1.7</td>
<td>0</td>
<td>0</td>
</tr>
<tr>
<td>0.4</td>
<td>13.2</td>
<td>0.3</td>
<td>0</td>
</tr>
<tr>
<td>0.5</td>
<td>96.1</td>
<td>86.8</td>
<td>61.8</td>
</tr>
<tr>
<td>0.6</td>
<td>100</td>
<td>100</td>
<td>100</td>
</tr>
<tr>
<td>0.7</td>
<td>100</td>
<td>100</td>
<td>100</td>
</tr>
<tr>
<td>0.8</td>
<td>100</td>
<td>100</td>
<td>100</td>
</tr>
<tr>
<td>0.9</td>
<td>100</td>
<td>100</td>
<td>100</td>
</tr>
</tbody>
</table>
<p>As one could imagine, the % of deaths increases with <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span></span> and somehow decreases with <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span></span>… but only for values around <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>0.50</mn></mrow><annotation encoding="application/x-tex">0.50</annotation></semantics></math></span></span>. It seems that the fate of our beloved sailor is settled for <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>></mo><mn>0.5</mn></mrow><annotation encoding="application/x-tex">p > 0.5</annotation></semantics></math></span></span> and therefore this should be the answer to the second question of the problem.</p>
<p>Let us now find the exact probability of survival.</p>
<h2 id="solving-mathematically"><strong>Solving Mathematically</strong></h2>
<p>There are many solutions for this problem but the one I liked most was written in <a href="https://medium.com/i-math/the-drunkards-walk-explained-48a0205d304" rel="noopener noreferrer" target="_blank">this post by Brett Berry</a>. Here’s a summary:</p>
<p>Recall that in order to solve through code we abstracted the sailor’s position into a point in the x-axis. Let <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(n)</annotation></semantics></math></span></span> be the probability that the sailor dies when <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span></span> steps away from the edge.</p>
<figure class="image"><img alt="Credits: Brett Berry" loading="lazy" decoding="async" width="609" height="219" src="https://rafaelquintanilha.com/_astro/drunken-sailor.CNWIupFz_1ENKr0.webp"><figcaption>Credits: Brett Berry</figcaption></figure>
<p>Then:</p>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mi>p</mi><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><mo stretchy="false">)</mo><mi>P</mi><mo stretchy="false">(</mo><mn>2</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(1)=p+(1−p)P(2)</annotation></semantics></math></span></span></span>
<p>The sailor surely dies if he goes to the left (with probability <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi></mrow><annotation encoding="application/x-tex">p</annotation></semantics></math></span></span>). But if he manages to move right, we now have him in <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">n = 2</annotation></semantics></math></span></span> and therefore the probability that he dies is what we call <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>2</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(2)</annotation></semantics></math></span></span>.</p>
<p>Well, in order to die he <strong>necessarily</strong> needs to move to the left (i.e. go from <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>2</mn></mrow><annotation encoding="application/x-tex">n = 2</annotation></semantics></math></span></span> to <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">n = 1</annotation></semantics></math></span></span>). But what is <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(1)</annotation></semantics></math></span></span> if not the probability that the sailor moves one unit left? Therefore, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(2) = P(1)</annotation></semantics></math></span></span> <em>times the probability of going from</em> <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">n = 1</annotation></semantics></math></span></span> to <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">n = 0</annotation></semantics></math></span></span>, or, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(1)</annotation></semantics></math></span></span>.</p>
<p>Hence:</p>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mi>p</mi><mo>+</mo><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><mo stretchy="false">)</mo><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">P(1) = p + (1−p)P(1)^2</annotation></semantics></math></span></span></span>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mo stretchy="false">(</mo><mn>1</mn><mo>−</mo><mi>p</mi><mo stretchy="false">)</mo><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><msup><mo stretchy="false">)</mo><mn>2</mn></msup><mo>−</mo><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>+</mo><mi>p</mi><mo>=</mo><mn>0</mn></mrow><annotation encoding="application/x-tex">(1 - p) P(1)^2 - P(1) + p = 0</annotation></semantics></math></span></span></span>
<p>Which yields <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">P(1) = 1</annotation></semantics></math></span></span> or <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mfrac><mi>p</mi><mrow><mn>1</mn><mo>−</mo><mi>p</mi></mrow></mfrac></mrow><annotation encoding="application/x-tex">P(1) = \frac{p}{1 - p}</annotation></semantics></math></span></span>.
Now, notice that <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo></mrow><annotation encoding="application/x-tex">P(1)</annotation></semantics></math></span></span> is a probability and therefore must be in the <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mo stretchy="false">[</mo><mn>0</mn><mo separator="true">,</mo><mn>1</mn><mo stretchy="false">]</mo></mrow><annotation encoding="application/x-tex">[0, 1]</annotation></semantics></math></span></span> range. Follows that <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mi>p</mi><mrow><mn>1</mn><mo>−</mo><mi>p</mi></mrow></mfrac><mo>≤</mo><mn>1</mn></mrow><annotation encoding="application/x-tex">\frac{p}{1 - p} \leq 1</annotation></semantics></math></span></span> and then <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>≤</mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow><annotation encoding="application/x-tex">p \leq \frac{1}{2}</annotation></semantics></math></span></span>.</p>
<p>Finally, we can write:</p>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><mo stretchy="false">)</mo><mo>=</mo><mrow><mo fence="true">{</mo><mtable rowspacing="0.36em" columnalign="left left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi>p</mi><mo>></mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mfrac><mi>p</mi><mrow><mn>1</mn><mo>−</mo><mi>p</mi></mrow></mfrac></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi>p</mi><mo>≤</mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr></mtable></mrow></mrow><annotation encoding="application/x-tex">P(1) = \begin{cases} 1 &#x26;\text{if } p \gt \frac{1}{2} \\ \frac{p}{1 - p} &#x26;\text{if } p \leq \frac{1}{2} \end{cases}</annotation></semantics></math></span></span></span>
<p>Once <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>2</mn><mo stretchy="false">)</mo><mo>=</mo><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><msup><mo stretchy="false">)</mo><mn>2</mn></msup></mrow><annotation encoding="application/x-tex">P(2) = P(1)^2</annotation></semantics></math></span></span>, it follows that:</p>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mrow><mo fence="true">{</mo><mtable rowspacing="0.36em" columnalign="left left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi>p</mi><mo>></mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo stretchy="false">(</mo><mfrac><mi>p</mi><mrow><mn>1</mn><mo>−</mo><mi>p</mi></mrow></mfrac><msup><mo stretchy="false">)</mo><mi>n</mi></msup></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi>p</mi><mo>≤</mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr></mtable></mrow></mrow><annotation encoding="application/x-tex">P(n) = \begin{cases} 1 &#x26;\text{if } p \gt \frac{1}{2} \\ (\frac{p}{1 - p})^n &#x26;\text{if } p \leq \frac{1}{2} \end{cases}</annotation></semantics></math></span></span></span>
<p>By the same reasoning presented above, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mn>3</mn><mo stretchy="false">)</mo><mo>=</mo><mi>P</mi><mo stretchy="false">(</mo><mn>1</mn><msup><mo stretchy="false">)</mo><mn>3</mn></msup></mrow><annotation encoding="application/x-tex">P(3) = P(1)^3</annotation></semantics></math></span></span>. It follows that, for a given <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi></mrow><annotation encoding="application/x-tex">n</annotation></semantics></math></span></span>:</p>
<span class="katex-display"><span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML" display="block"><semantics><mrow><mi>P</mi><mo stretchy="false">(</mo><mi>n</mi><mo stretchy="false">)</mo><mo>=</mo><mrow><mo fence="true">{</mo><mtable rowspacing="0.36em" columnalign="left left" columnspacing="1em"><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mn>1</mn></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi>p</mi><mo>></mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr><mtr><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mo stretchy="false">(</mo><mfrac><mi>p</mi><mrow><mn>1</mn><mo>−</mo><mi>p</mi></mrow></mfrac><msup><mo stretchy="false">)</mo><mi>n</mi></msup></mrow></mstyle></mtd><mtd><mstyle scriptlevel="0" displaystyle="false"><mrow><mtext>if </mtext><mi>p</mi><mo>≤</mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow></mstyle></mtd></mtr></mtable></mrow></mrow><annotation encoding="application/x-tex">P(n) = \begin{cases} 1 &#x26;\text{if } p \gt \frac{1}{2} \\ (\frac{p}{1 - p})^n &#x26;\text{if } p \leq \frac{1}{2} \end{cases}</annotation></semantics></math></span></span></span>
<p>Which completes our answer and matches the results found in the simulations.</p>
<h2 id="intepreting-the-result"><strong>Intepreting the Result</strong></h2>
<p>The answer to this problem is quite interesting because it reveals a big asymmetry: for any value <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>></mo><mfrac><mn>1</mn><mn>2</mn></mfrac></mrow><annotation encoding="application/x-tex">p > \frac{1}{2}</annotation></semantics></math></span></span>, the sailor will eventually die. Certainly, for any number sufficiently big of iterations (we are using a relatively small number of 10000 iterations per simulation), the sailor dies anyway. <em>But real life often has an upper limit</em> and therefore I'm not interested in <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>→</mo><mi mathvariant="normal">∞</mi></mrow><annotation encoding="application/x-tex">n \to \infty</annotation></semantics></math></span></span>.</p>
<p>But once life is finite and the sailor can't take random steps forever, how resilient he is? In other words, <strong>what's the probability of survival given that the sailor has been surviving for a while?</strong></p>
<h2 id="the-lindy-effect"><strong>The Lindy Effect</strong></h2>
<p>The Lindy Effect is a theory for our very intuition. From <a href="https://en.wikipedia.org/wiki/Lindy_effect" rel="noopener noreferrer" target="_blank">Wikipedia</a>:</p>
<blockquote>
<p>The Lindy effect is a theory that the future life expectancy of some non-perishable things like a technology or an idea is proportional to their current age, so that every additional period of survival implies a longer remaining life expectancy.</p>
</blockquote>
<p>In simple words, the longer <em>something</em> lives, the longer it is expected to live. We are used to perceive this as the “test of time”. If you give enough time for an idea to be tested and it survives (i.e. people keep adopting it), chances are it will survive for a while.</p>
<p>How does this apply to the Drunken Sailor problem?</p>
<p>Let us try to observe the outcome of his random walk after an arbitrary number of rounds (iterations). For example, given that the sailor survived 100 rounds, how many times does he end up alive? And for 1000? 5000?</p>
<p>Consider the following table for <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>p</mi><mo>=</mo><mn>0.5</mn></mrow><annotation encoding="application/x-tex">p = 0.5</annotation></semantics></math></span></span>, <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>n</mi><mo>=</mo><mn>10</mn></mrow><annotation encoding="application/x-tex">n = 10</annotation></semantics></math></span></span> and <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mn>10</mn><mo separator="true">,</mo><mn>000</mn></mrow><annotation encoding="application/x-tex">10,000</annotation></semantics></math></span></span> simulations, where <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mi>i</mi></mrow><annotation encoding="application/x-tex">i</annotation></semantics></math></span></span> is the min number of iterations for a surviving sailor:</p>
<table>
<thead>
<tr>
<th>ii</th>
<th>Survived at this point</th>
<th>Died in the end</th>
<th>Survival rate (%)</th>
</tr>
</thead>
<tbody>
<tr>
<td>10</td>
<td>10,000</td>
<td>9,230</td>
<td>7.70</td>
</tr>
<tr>
<td>100</td>
<td>6,793</td>
<td>6,023</td>
<td>11.34</td>
</tr>
<tr>
<td>1000</td>
<td>2,527</td>
<td>1,757</td>
<td>30.47</td>
</tr>
<tr>
<td>5000</td>
<td>1,129</td>
<td>359</td>
<td>68.20</td>
</tr>
</tbody>
</table>
<p>The table is very informative -- if a sailor manages to survive until the 1000th iteration (which is only <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mn>10</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{1}{10}</annotation></semantics></math></span></span> of the number of rounds), <em>he increases his chance of survival by a factor of 4</em>. If he survives until half of the iterations, <em>his survival rate increases 800%!</em></p>
<p>The sailor is, therefore, Lindy. The longer he lives, the longer he is expected to live.</p>
<h2 id="wrapping-up"><strong>Wrapping Up</strong></h2>
<p>The Drunken Sailor Problem and the Lindy Effect help us understand the <em>test of time.</em></p>
<p>Lindy enhances <em>evolution</em>. What survives tend to have offsprings that are alike. Things that change very quickly don’t allow evolution to do its job.</p>
<p><strong>That doesn't mean that we should wait forever</strong> -- recall that even dying <span class="katex"><span class="katex-mathml"><math xmlns="http://www.w3.org/1998/Math/MathML"><semantics><mrow><mfrac><mn>1</mn><mn>3</mn></mfrac></mrow><annotation encoding="application/x-tex">\frac{1}{3}</annotation></semantics></math></span></span> less when they hit the 5,000 mark compared to when they start to walk, <em>31% of the sailors still die</em>. But we should be respectful of things that have survived for a considerable amount of time.</p>
<p>For what is new might be fragile for events that are hard to anticipate. And drunken sailors might avoid falling off a cliff.</p>]]></content:encoded>
</item>
<item>
<title><![CDATA[Quando os Fatos Não Se Encaixam na Agenda]]></title>
<description><![CDATA[Ou "porquê virtue-signalling eventualmente revelará sua hipocrisia".]]></description>
<link>https://rafaelquintanilha.com/ensaios/quando-os-fatos-nao-se-encaixam-na-agenda/</link>
<guid isPermaLink="false">638ce70824336d003d59fc6b</guid>

<dc:creator><![CDATA[Rafael Quintanilha]]></dc:creator>
<pubDate>Fri, 02 Nov 2018 03:00:00 GMT</pubDate>

<content:encoded><![CDATA[<figure class="image"><img alt="Identity Politics cartoon" loading="lazy" decoding="async" width="590" height="332" src="https://rafaelquintanilha.com/_astro/identity-politics.BnnZUi-H_Z1yVXNg.webp"><figcaption>Identity Politics cartoon</figcaption></figure>
<p>Na manhã do dia 27 de Outubro de 2018, Robert Bowers, morador de Pittsburgh, USA, tomou uma decisão: após desabafar nas redes sociais, invadiu uma sinagoga e abriu fogo contras os judeus lá presentes. No total, 11 pessoas foram mortas.</p>
<p>Bowers será indiciado por “crime de ódio” e, caso condenado, deverá enfrentar a pena de morte.</p>
<p>O atentado é tido como o ataque mais mortal aos judeus na história dos Estados Unidos de acordo com a Anti-Defamation League.</p>
<p>A imprensa logo correu para acusar Bowers de alt-right. De fato, supremacistas brancos têm histórico anti-semita e a associação é natural. No entanto, popularizou-se nos Estados Unidos recentemente a ideia de que tais extremistas são associados ao presidente Trump. Não é o caso de Bowers. Na mesma rede social onde declarou estar indo ao ataque, ele destilou críticas a Trump e afirmou que o atual presidente não recebeu o seu voto.</p>
<blockquote>
<p>“I can’t sit by and watch my people get slaughtered. Screw your optics, I’m going in.” — Bowers na rede social Gab</p>
</blockquote>
<figure class="image"><img alt="Bowers" loading="lazy" decoding="async" width="590" height="393" src="https://rafaelquintanilha.com/_astro/bowers.B8hO8v8y_Ocx30.webp"><figcaption>Bowers</figcaption></figure>
<p>O ocorrido é lamentável e pode ter pego muita gente de surpresa, mas o fato é que os casos anti-semitas tem aumentado nos Estados Unidos. De forma até surpreendente, o New York Times publicou essa semana uma matéria com um título reflexivo: <a href="https://www.nytimes.com/2018/10/31/nyregion/jewish-bias-safety-nyc.html" rel="noopener noreferrer" target="_blank">é seguro ser judeu em Nova Iorque?</a></p>
<p>Ao contrário do que popularmente acreditado, <strong>metade dos crimes de ódio em Nova Iorque tem judeus como alvos</strong>. Comparativamente, são <strong>4x mais do que contra negros e 20x mais do que contra transgêneros</strong>.</p>
<p>Os números são impressionantes, não porque outros grupos são menos importantes — crimes de ódio são abomináveis e deve ser punidos como tal. No entanto, a cultura popular e a cobertura da mídia tem sido absolutamente desproporcional — e não em favor da comunidade judaica.</p>
<p>Se os números são tão desproporcionais, por que eles não fazem parte do noticiário?</p>
<p>A resposta para essa pergunta é o título desse texto: <strong>pois os fatos não se encaixam na agenda.</strong></p>
<figure class="embed embed-twitter" data-url="https://twitter.com/RubinReport/status/1058095862163881984">
<blockquote class="twitter-tweet"><p lang="en" dir="ltr">I’m actually shocked that the NY Times ran the piece. It’s (probably unintentionally) the best destruction of Intersectionality and Identity Politics that has ever appeared in the paper. <a href="https://t.co/tKGYSCsGAN" rel="noopener noreferrer" target="_blank">https://t.co/tKGYSCsGAN</a></p>— Dave Rubin (@RubinReport) <a href="https://twitter.com/RubinReport/status/1058095862163881984" rel="noopener noreferrer" target="_blank">November 1, 2018</a></blockquote>
</figure>
<p>Dave Rubin, assim como muitos, se surpreenderam com a exposição clara da hipocrisia da esquerda neste caso em particular. Segundo o NYT:</p>
<blockquote>
<p>During the past 22 months, not one person caught or identified as the aggressor in an anti-Semitic hate crime has been associated with a far right-wing group, Mark Molinari, commanding officer of the police department’s <a href="https://www.ny.gov/programs/hate-crimes-task-force" rel="noopener noreferrer" target="_blank">Hate Crimes Task Force</a>, told me.</p>
</blockquote>
<p>E em outra passagem:</p>
<blockquote>
<p>In fact, it is the varied backgrounds of people who commit hate crimes in the city that make combating and talking about anti-Semitism in New York much harder (…)</p>
</blockquote>
<p>O que nos faz concluir (e o que me deu a inspiração para esse texto):</p>
<blockquote>
<p>That anti-Semitism would go unchallenged (and the fight against it unchampioned) just because it didn’t fit a particular narrative, is disgusting. — <a href="https://twitter.com/BradThor/" rel="noopener noreferrer" target="_blank">Brad Thor</a></p>
</blockquote>
<p>Anti-Semitismo não se encaixa na narrativa da esquerda. Não existe um grupo opressor bem definido na outra ponta. Os agressores, podem apoiar Trump ou odiá-lo — como Robert Bowers demonstrou. Não é fácil apontar dedos. Não existe um grupo específico a se atacar. Resultado? Melhor fingir que não ocorre.</p>
<p>Em outros atentados famosos, como na <a href="https://en.wikipedia.org/wiki/Pulse_nightclub" rel="noopener noreferrer" target="_blank">boate Pulse em 2016</a> e <a href="https://www.nytimes.com/2018/05/18/us/school-shooting-santa-fe-texas.html" rel="noopener noreferrer" target="_blank">numa escola do Texas</a> no início desse ano, o call to action foi muito maior. Novamente, <em>não é meu objetivo relativizar tragédias nem desmerecer a dor e o sofrimento das vítimas e seus familiares afetados</em>. Mas sim, entender que quando uma determinada agenda política está envolvida, o melhor a se fazer é analisar a situação friamente.</p>
<p>Na tragédia da boate Pulse, além do resultado lamentavelmente maior (foram 49 mortos no total), o fato de ser um <em>gay nightclub</em> expôs a intolerância ao mundo inteiro. Já em Santa Fé, onde um adolescente de 17 anos abriu fogo em sua escola e deixou 10 mortos, a retórica contra o desarmamento populou os noticiários por meses (convenientemente ignorando que possuir uma arma nessa idade e carregá-la até uma escola são infrações legais).</p>
<figure class="image"><img alt="Santa Fé" loading="lazy" decoding="async" width="540" height="360" src="https://rafaelquintanilha.com/_astro/santafe.Dhv3o1B3_ZtxQQS.webp"><figcaption>Santa Fé</figcaption></figure>
<p>Porém, na tragédia de Pittsburgh, não há ganho político claro em debatê-lo. A direita sai enfraquecida? Certamente não da mesma forma como seria se o massacre tivesse sido direcionado a transsexuais.</p>
<p>Se não há ganho claro, só nos resta lamentar pela comunidade judaica, os reais perdedores do episódio. E entender que <em>identity politics</em>, um jogo bastante jogado no mundo ocidental atual, não se interessa pela realidade quando os fatos não se encaixam na agenda.</p>]]></content:encoded>
</item>
</channel>
</rss>
