<?xml version="1.0" encoding="utf-8"?><feed xmlns="http://www.w3.org/2005/Atom" ><generator uri="https://jekyllrb.com/" version="3.10.0">Jekyll</generator><link href="https://thill.me/feed.xml" rel="self" type="application/atom+xml" /><link href="https://thill.me/" rel="alternate" type="text/html" /><updated>2026-09-11T22:52:00+00:00</updated><id>https://thill.me/feed.xml</id><title type="html">patrick’s blog</title><subtitle>Patrick Thill&apos;s blog.</subtitle><entry><title type="html">What I did at RC</title><link href="https://thill.me/2026/09/11/what-i-did-at-rc.html" rel="alternate" type="text/html" title="What I did at RC" /><published>2026-09-11T00:00:00+00:00</published><updated>2026-09-11T00:00:00+00:00</updated><id>https://thill.me/2026/09/11/what-i-did-at-rc</id><content type="html" xml:base="https://thill.me/2026/09/11/what-i-did-at-rc.html"><![CDATA[<p>I spent the summer at <a href="https://www.recurse.com/">Recurse Center</a>, a programming retreat in Brooklyn, at the recommendation of my friend Cory. These are some things I did there.</p>

<h4 id="participated-in-study-groups">Participated in study groups</h4>

<p>RC has regular study groups that anyone can organize and schedule. For example, people would get together every Friday to work through old Advent of Code challenges together. I did Agentic Adventures, Practical Deep Learning, Math Monday, and a short series investigating an open source board game AI.</p>

<h4 id="agentic-adventures">Agentic Adventures</h4>

<p>Agentic Adventures is a discussion group for people interested in modern LLMs and agents; we did different things every week. Some highlights:</p>

<ul>
  <li>Amanda and I built a remote sandbox for a vibecoding agent that we could run with dangerously-skip-permissions.</li>
  <li>In the same vein, Michelle taught us how to set up a sandboxed environment for local agents using ollama and docker.</li>
  <li>This was what we built the <a href="https://thill.me/just-one-bot/">“Just One” game</a> for, to investigate how agents can cooperate.</li>
  <li>We played around with minGPT together, building a small text predictor model trained on Romeo and Juliet to talk like Shakespeare.</li>
  <li>We did a basic LoRA to train a small model to talk more conversationally.</li>
</ul>

<h4 id="practical-deep-learning">Practical Deep Learning</h4>

<p>This was a study group working through the (first half of the) book <a href="https://github.com/fastai/fastbook">Practical Deep Learning</a> by Jeremy Howard and Sylvain Gugger; we worked our way up through classical machine learning approaches, used or adapted prebuilt models, and then learned how to build up actual neural network models. The book gave a high level practitioner’s introduction, which was good for building intuition and having a sense for how they work, as well as what can be built with them. Since I’m not interested in research myself, this was the level of understanding I wanted.</p>

<h4 id="math-monday">Math Monday</h4>

<p>In a coffee chat, Sophia and I discovered we shared a passion for math and decided to start a discussion group for mathematical topics. This was meant to be a fun distraction and chance to learn and explore, so we would spend maybe the first half of each meeting on learning and then split into pairs to build things based on what we learned. Some fun things we worked on were:</p>

<ul>
  <li>Working through <a href="https://projecteuler.net/">project euler</a> problems together.</li>
  <li>Thinking our way through some problems from Peter Winkler’s book <a href="https://math.dartmouth.edu/news-resources/electronic/puzzlebook/book/book.pdf">Mathematical Puzzles</a>.</li>
  <li>Drawing fractals and other generative art.</li>
  <li>Building programs using Voronoi diagrams, such as <a href="https://thill.me/voronoi-game/">this game</a>.</li>
  <li>Ben gave us an introduction to the Rocq proof assistant, and we worked our way through some boolean identities.</li>
  <li>We wrote a program to generate Hilbert curves for drawing with the pen plotter.</li>
  <li>Kenji and I built some fun extensions of the <a href="https://en.wikipedia.org/wiki/Chaos_game">chaos game</a> in Desmos:</li>
</ul>

<p><img src="/assets/images/what-i-did-at-rc/desmos-chaos.jpg" alt="Some photogenic fractals we built in Desmos." width="700" /></p>

<h4 id="reverse-engineering-a-board-game-ai">Reverse engineering a board game AI</h4>

<p>Tony started a short sequence to dig into the code of the <a href="http://keldon.net/rftg/">Keldon</a> AI for playing the board game <a href="https://en.wikipedia.org/wiki/Race_for_the_Galaxy">Race for the Galaxy</a>. We spent the first session just learning the rules and playing the AI, then dug into the code - an old school two-layer neural network with curated features. Claude was pretty good at interpreting the weights of the neural network and explaining what it reacted to; we spent some time trying to understand what the Keldon AI had learned about strategy. Takeaway was that econ strategies are much stronger than military in the base game (coinciding with player sentiment). One of the things that stood out to me was how many of the strongest weighted nodes corresponded to the presence of individual cards.</p>

<h4 id="finished-up-dodo">Finished up dodo</h4>

<p>I wrapped up the mini language, <a href="https://thill.me/2026/06/02/dodo.html">dodo</a>, that I had made as part of my application to RC. This included what was probably the most interesting part, writing the tricky recursive code to implement the match statement. This was an interesting balance with LLMs - I didn’t let them write any of the code for me, but it was nice to have someone writing up a nice spec and writing test cases and example programs. LLMs also made it easy to share what I did - try it out in a vibe-coded online REPL <a href="https://thill.me/dodo/repl.html">here</a>!</p>

<h4 id="implemented-deflate">Implemented DEFLATE</h4>

<p>RC hosts a lot of talks by people discussing their projects. One I attended early in batch was by Josh on the ZIP file format, and his investigations about inconsistencies between implementations. It dove deep into details that I’d never thought about before. For example, if the unzipper that your virus scanner uses handles edge cases slightly differently than the unzipper that you use, it might see a file with malware in it as innocent, because it doesn’t unzip the virus. This is a security vulnerability!</p>

<p>One part of the talk that caught my attention was the digression on the compression algorithm that zip uses, called DEFLATE. Kevan and I thought that reimplementing it sounded like a fun exercise, so we paired on it in a few sessions over the next few weeks.</p>

<p>DEFLATE is basically LZ77 (generalized run length encoding) + Huffman codes. It compresses text (or actually any sequence of bytes, but here we consider it as text) in two ways: (1) replacing repeated sequences with backreferences, e.g. “to be or not to be” could become “to be or not (13, 5)” where the part in parentheses means “go back 13 bytes, then copy 5 bytes from there”, and (2) Huffman encoding, where we assign shorter sequences of bits to represent common bytes, and longer sequences for rare bytes - e.g., instead of 01100101 for ‘e’ and 00000111 for the bell character, you might use only 4 or 5 bits for the very common ‘e’, and 16 bits (or no representation) for the bell which never occurs in English text.</p>

<p>We wrote a <a href="https://github.com/kpthill/deflate-rust">decompressor</a>, working straight from the <a href="https://www.rfc-editor.org/rfc/rfc1951.txt">spec</a>, in Rust. It was my first time using the language but I found it to be quite nice. (Although I just gave up on understanding some of the data lifetime rules.) Most of the time, it just felt like what I wanted C to be. Still, it didn’t eliminate any of the conceptual difficulties involved with bit packing - in debugging, we would frequently have to stop and write down the bit sequences we expected to compare them to what we got. No project made me feel more like a true hacker than that one.</p>

<h4 id="paired-a-lot">Paired a lot</h4>

<p>RC emphasizes the value of pairing - working on problems with other people. I’m a bit introverted even by RC standards, but I still did a bunch of that. Implementing DEFLATE with Kevan was the biggest example of pairing, but I did some other stuff as well. So with <a href="https://github.com/zmughal">Zaki</a> and <a href="https://tommymaranges.com">Tommy</a> we <a href="https://thill.me/2026/07/16/corn-puzzle-sat-solver.html">used SAT solvers to solve sudoku</a> - bringing heavyweight tools to a relatively straightforward problem. I implemented the game of life with Seyoung, and we learned how to use the shell cursor to have it redraw itself neatly with each generation (or not neatly, if you get the command wrong). With William we implemented the game mastermind. With Bill we tried to make a new view for magit in emacs, which was honestly way too ambitious considering neither of us had written anything serious in emacs lisp before. But he did convince me to give doom emacs a try, and I’ve been enjoying it!</p>

<h4 id="vibecoded-a-bunch-of-mini-projects">Vibecoded a bunch of mini projects</h4>

<p>My goal coming into RC was to get the hang of them newfangled LLM things that all the kids are raving about. That’s obviously part of the motivation for my participation in Agentic Adventures and Practical Deep Learning, but I also spent a bunch of time just vibecoding random things and trying to push the limits of what I could tackle.</p>

<p>One of them was a <a href="https://thill.me/rhythm-game/">rhythm game</a> for the <a href="https://rcade.dev/">rcade</a>; this was the first one where I really leveraged LLM capabilities, since I had it make ten different prototypes and chose the one I liked the best.</p>

<p><img src="/assets/images/what-i-did-at-rc/rhythm-game.png" alt="The opening of a song in the rhythm game." width="500" /></p>

<p>Amanda and I experimented with how large of tasks we could leave an agent to do on its own; the result of that was a <a href="https://thill.me/live-dangerously/">fantasy map generator</a> implementing climate modeling based on an academic <a href="https://doi.org/10.1007/s00371-020-01920-7">paper</a>.</p>

<p><img src="/assets/images/what-i-did-at-rc/autobiomes-earth.png" alt="A pixellated map of the earth showing climate zones in different colors." width="700" /></p>

<p>I also experimented with games that include agents as part of them. In one, we asked agents to play a word guessing game, Just One:</p>

<p><img src="/assets/images/what-i-did-at-rc/just-one.png" alt="Several Claude Sonnet instances try to give hints to the word 'crocodile'." width="700" /></p>

<p>The goal of the game is to give hints to a secret word without giving the same hint as another player; it was shocking how often all the agents playing would give the same hint, even at temperature 1. We resolved this by giving them all “personalities” which were really just topics; for example we’d be telling one agent to think about things in the context of sports, so their clue for “shell” might be “defense” or something, whereas the agent told to be a hippie might say “cancer” for the zodiac’s crab.</p>

<p>In the same vein, I tried building a <a href="https://thill.me/llm-game/">diplomacy game</a> where you can interact with agents as the main gameplay mechanic; unfortunately the main learning was that telling agents to “hold out on helping the player until they give you what you want” means that you get really stiff and combative characters. There’s probably some secrets of character building and prompting that could have made this work, but I didn’t find them.</p>

<p>Since both of these are browser games and I didn’t want to spend my own tokens when people try them out, I also vibecoded a component that would let people use their own access keys or their own GPU (through WebLLM), which is what made those shareable!</p>

<p>At risk of falling into the classic yak shaving trap, I made an emacs mode for listing active vibecoding sessions:</p>

<p><img src="/assets/images/what-i-did-at-rc/llm-supervisor.png" alt="A view of some of my current sessions." width="700" /></p>

<p>Likewise, I had Claude build a bunch of improvements to this site and set things up so I could write this for you.</p>

<p>Later in the summer I got interested in trying to use these tools in a domain I was unfamiliar with, to answer questions I wasn’t sure I could answer within my skill set. I was curious about how much overlap there could be between different languages’ words, and vibecoded a tree search to find sequences of words in two languages which had the same (or very similar) pronunciations. This turns out to be very hard even for languages with similar phonologies (we used Indonesian and Farsi, based on their similar sound inventories according to PHOIBLE) but we did end up with a very mediocre poem, which you can see <a href="https://thill.me/build-ten-thousand-things/poem.html">here</a>.</p>

<p>Building on what I learned there, I then tried to vibecode a new constructed language. This was inspired by conlang critic’s <a href="https://www.youtube.com/watch?v=Sao9mCLy3Xo">video on Esperanto</a>. Esperanto isn’t as simple as you might prefer an international auxiliary language to be, and its vocabulary is notably eurocentric - which Zamenhof can hardly be blamed for, since he was making one of the first ones, but nevertheless I wondered if we could do better given all the information on the internet that we have available.</p>

<p>I probably owe a full post on this at some point (though if I start a new job, good luck on ever seeing that) but I’ll give the nutshell version here: First, we used PHOIBLE data to put together a set of sounds that are common across languages, including recommended allophones to ensure that words remain producible and distinguishable for people with all sorts of native languages. Then we built a grammar piece by piece, loosely following a guide that real linguists use when describing the grammar of natural languages (the <a href="https://www.eva.mpg.de/lingua/tools-at-lingboard/questionnaire/lingua-descriptive_description.php">Lingua Descriptive Studies questionnaire</a> by Bernard Comrie and Norval Smith). One cool trick there was that we made decisions based on the evidence of existing creole and (especially) pidgin languages described in <a href="https://apics-online.info/">APiCS</a> (the Atlas of Pidgin and Creole Language Structures). Those languages were a good guide to what people who were used to different grammar systems actually converged on when they had to collaborate, so it was likely that many people around the world would find it intuitive or at least understandable. (Bonus fun fact - when you do this, you kind of naturally end up with a grammar that looks a lot like Chinese or Vietnamese - analytic languages using function words rather than declension to convey grammatical information.) Finally we built the lexicon from a collection of dictionaries for various world languages. Root words that came from an international canon - ones already borrowed into a bunch of languages - simply got borrowed and transliterated. (e.g. words like “phonology” or “coffee” became “fonologia” and “kafe”.) For other words, we wrote an optimizer to select words that are both widely recognizable (favoring widely spoken languages like English or Chinese) and words that are representative of many different language families, to avoid Eurocentrism. Full disclosure - this part didn’t really work right and I had Claude fake it just enough to get a sample script for my presentation. If I ever do make the full post, fixing that will be the first step.</p>

<p>At the end of the summer, I gave a talk about these projects, the slides for which are <a href="https://thill.me/build-ten-thousand-things/">here</a>. The slides were, of course, made by Claude.</p>

<h4 id="blogged-a-little">Blogged a little?</h4>

<p>I was more interested in doing than writing, but what little I did write you can see at the blog index. And I kept up an internally public series of checkins, which is what I’m referencing to write this post. If you ever do RC, I highly recommend following through on checkins, even if they’re annoying at the time!</p>

<h4 id="played-around">Played around</h4>

<p>There’s also just a lot of fun random tools and things to try at RC. For example, I made my first 3D print - a candle holder for a friend’s 36th, and my 38th, birthdays:</p>

<p><img src="/assets/images/what-i-did-at-rc/candle-trio.jpg" alt="Some views of the candle holder, showing how it shows different numbers when viewed from different sides." width="700" /></p>

<p>The hub (RC’s physical space in Brooklyn) also has an HP 7440A pen plotter that we like to mess around with. I drew a snapshot from a famous Go game and, with Jess, wrote a program to generate a Hilbert curve:</p>

<p><img src="/assets/images/what-i-did-at-rc/plotter-pair.jpg" alt="A snapshot of the broken ladder game and a Hilbert curve, printed with the pen plotter." width="700" /></p>

<p>We had weekly board game nights, and Dan and I led a few teaching sessions for the board game Go, as well as a trip to visit the Gowanus Go club.</p>

<h4 id="ooohed-and-aaaahed-at-other-peoples-projects">Ooohed and aaaahed at other people’s projects</h4>

<p>Everyone at RC has their own cool projects going and part of the joy of it is getting to see what they’re working on. I want to keep this section short, so I’m just going to list a fraction of the projects which have cool pictures attached:</p>

<p>Teresa made a photo studio setup that would give your picture a cool aura based on biometrics like your skin temperature:</p>

<p><img src="/assets/images/what-i-did-at-rc/aura.jpg" alt="This unc got aura." width="400" /></p>

<p>There were a bunch of cool drawings to see that people had made with the pen plotter:</p>

<p><img src="/assets/images/what-i-did-at-rc/plot-wall.jpg" alt="A picture of the pen plotter wall." width="700" /></p>

<p>Jagi made an awesome active decoration that would react and change its pattern based on the noise around it.</p>

<p><img src="/assets/images/what-i-did-at-rc/jagi-decoration.gif" alt="Jagi's LED wheel." width="360" /></p>

<p>Sarah and others made a “nintonio game mother” from an old e-ink screen:</p>

<p><img src="/assets/images/what-i-did-at-rc/game-mother.jpg" alt="The nintonio game mother, playing pokemon." width="400" /></p>

<p>Tony made an <a href="https://en.wikipedia.org/wiki/Exquisite_corpse">exquisite corpse</a> game using the receipt printer.</p>

<video src="/assets/images/what-i-did-at-rc/exquisite-corpse.mp4" width="340" autoplay="" loop="" muted="" playsinline="" style="display:block;margin:1.5em auto"></video>

<p>You could play games other Recursers had built on the RCade cabinet:</p>

<p><img src="/assets/images/what-i-did-at-rc/rcade-cabinet.jpg" alt="The RCade." width="400" /></p>

<h4 id="wrote-a-return-statement">Wrote a “Return Statement”</h4>

<p>RC alumni are encouraged to write a “return statement” - a brief reflection on their time at RC. That’s this post!</p>

<p>If you were intrigued by it, consider <a href="https://www.recurse.com/apply">applying to a future batch</a>!</p>]]></content><author><name></name></author><category term="RC" /><category term="projects" /><summary type="html"><![CDATA[I spent the summer at Recurse Center, a programming retreat in Brooklyn, at the recommendation of my friend Cory. These are some things I did there.]]></summary></entry><entry><title type="html">Solving a corn puzzle with CP-SAT</title><link href="https://thill.me/2026/07/16/corn-puzzle-sat-solver.html" rel="alternate" type="text/html" title="Solving a corn puzzle with CP-SAT" /><published>2026-07-16T00:00:00+00:00</published><updated>2026-07-16T00:00:00+00:00</updated><id>https://thill.me/2026/07/16/corn-puzzle-sat-solver</id><content type="html" xml:base="https://thill.me/2026/07/16/corn-puzzle-sat-solver.html"><![CDATA[<p>One random Friday at <a href="recurse.com">RC</a>, I was bored and playing around with a
puzzle someone had 3d printed:</p>

<p><img src="/assets/images/corn-puzzle/corn-4.jpg" alt="corn puzzle" width="400" /></p>

<p>It’s a physical puzzle consisting of a white “cob” with grooves in it and a
bunch of “corn” pieces, each made of 3-10 kernels stuck together in a particular
shape, that can slide into the grooves. The goal is to slide them on so that
they fit together exactly, with no overlaps and no gaps.</p>

<p>Like all software engineers in the year of our lord 2026, I quickly got tired of
solving the puzzle myself and asked Claude to do it for me:</p>

<p><img src="/assets/images/corn-puzzle/claude-prompt.png" alt="my prompt to Claude" width="600" /></p>

<p>After a little bit of wrangling - it turns out computer vision isn’t <em>quite</em>
that good yet, so I had to clarify some of the piece shapes - Claude wrote a
script in python that gave a solution.</p>

<p>It was much better than I would have written myself, and I ended up learning
from it.</p>

<p><img src="/assets/images/corn-puzzle/corn-9.jpg" alt="corn puzzle" width="400" /></p>

<h3 id="what-i-expected">What I expected</h3>

<p>If I was solving this problem myself, I would naively reach for recursive
backtracking. If you’re a programmer, you’ve probably seen this algorithm in an
intro CS class.</p>

<p>Basically, it’s the brute force approach - try something at random, then try
something else, keep going until the puzzle is solved. If you ever get stuck and
there are no legal moves left, undo your last move and try again from there. If
all moves from that point fail, undo another move, and so on.</p>

<p>This is just an organized way of trying all the options, and it does admit some
nice optimizations based on the structure of the problem. For example, you can
take into account the symmetry that rotating the cob doesn’t change the solution
in any way, or fail early if you ever isolate a single kernel space on its own
(so that no piece can cover it). So a well thought-out approach to backtracking
would likely work.</p>

<p>However, when I looked at Claude’s script I realized from the first line that I
was being dumb:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kn">from</span> <span class="nn">ortools.sat.python</span> <span class="kn">import</span> <span class="n">cp_model</span>
</code></pre></div></div>

<h3 id="this-wheel-has-already-been-invented">This wheel has already been invented</h3>

<p>Instead of backtracking, Claude just imported an industrial-strength library
made to solve these sorts of problems. <a href="https://developers.google.com/optimization/cp/cp_solver">OR-Tools
CP-SAT</a> is put out by
Google and is made for solving constrained optimization problems, as well as
satisfiability problems like this one.</p>

<p>The idea here is to model any such problem as a set of variables - classically
binary - and a set of constraints or assertions about those variables that all
have to be simultaneously satisfied. (As well as an objective function, for
optimization problems.) Then the library draws on many decades of research to
efficiently find a setting for those variables that meets all of the
constraints.</p>

<p>The corn problem is a variant of the <a href="https://en.wikipedia.org/wiki/Exact_cover">Exact
Cover</a> problem, so those in the know
can probably already see how it would be represented, but I’ll go through it as
it was new to me.</p>

<p>The variables in this problem are binary - true or false - and each one
represents the idea “X piece is placed in a particular way”. So for each of
$N_i$ ways that piece $i$ could be placed, we have one variable $V_{i,n}$, which
is true ($1$) if the piece is placed there, false ($0$) if it isn’t.</p>

<p><strong>Constraint class 1: All pieces are placed exactly once</strong></p>

<p>This part is easy - for each piece $i$, we have</p>

<p>$ \sum_{n=1}^{N_i} V_{i,n} = 1 $</p>

<p>This enforces that exactly one of the \(V_{i, n}\) variables is $1$, and the
rest are $0$.</p>

<p><strong>Constraint class 2: Each spot is covered exactly once</strong></p>

<p>This is a little harder, but just tedious, not confusing. For each piece
placement we have to go through all of the spaces on the cob that it covers and
add it to the set of covering pieces $C_s$. Then for all spaces $s$ on the cob,
we have a very similar looking constraint:</p>

<p>$ \sum_{V_{i,n} \in C_s} V_{i,n} = 1 $</p>

<p>So every piece is used once, and every spot is covered once. If we assume that
this is a well constructed puzzle - so the total number of kernels in the pieces
is equal to the number of spaces on the cob - this is all the constraints we
need!</p>

<p>Claude’s python script to solve this was pretty complicated because it had to
actually enumerate all the possible positions of all the pieces, but actually
invoking the solver was very straightforward:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>    <span class="k">for</span> <span class="n">plist</span> <span class="ow">in</span> <span class="n">by_piece</span><span class="p">:</span>
        <span class="n">m</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">v</span> <span class="k">for</span> <span class="n">v</span><span class="p">,</span> <span class="n">_</span> <span class="ow">in</span> <span class="n">plist</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
    <span class="k">for</span> <span class="n">clist</span> <span class="ow">in</span> <span class="n">by_cell</span><span class="p">:</span>
        <span class="n">m</span><span class="p">.</span><span class="n">Add</span><span class="p">(</span><span class="nb">sum</span><span class="p">(</span><span class="n">clist</span><span class="p">)</span> <span class="o">==</span> <span class="mi">1</span><span class="p">)</span>
 
    <span class="c1"># ...
</span>    
    <span class="n">s</span><span class="p">.</span><span class="n">solve</span><span class="p">(</span><span class="n">m</span><span class="p">)</span>
</code></pre></div></div>

<h3 id="an-artisanal-hand-crafted-cp-sat-invocation">An artisanal hand-crafted CP-SAT invocation</h3>

<p>To learn more about this and try to lock in the lesson not to reinvent the
wheel, I got together with <a href="https://github.com/zmughal">Zaki</a> and
<a href="https://tommymaranges.com">Tommy</a> at recurse to do what is probably the most classic
application of cp-sat to a puzzle, Sudoku.</p>

<p>This is a classic beginner application of the tool and easier to apply than for
the corn puzzle; we simply have one variable per cell, with a value 1-9, and our
constraint classes are that every row, column, and box has to have one of each.
We don’t need to have utility methods for setting this up, as the corn puzzle
did for rotating pieces:</p>

<div class="language-python highlighter-rouge"><div class="highlight"><pre class="highlight"><code>  <span class="n">model_vars</span> <span class="o">=</span> <span class="p">[</span> <span class="p">[</span> <span class="bp">None</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span> <span class="p">]</span> <span class="k">for</span> <span class="n">_</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span> <span class="p">]</span>
  <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">j</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">):</span>
      <span class="n">board_var_name</span> <span class="o">=</span> <span class="sa">f</span><span class="s">"s[</span><span class="si">{</span><span class="n">i</span><span class="si">}</span><span class="s">,</span><span class="si">{</span><span class="n">j</span><span class="si">}</span><span class="s">]"</span>
      <span class="k">if</span> <span class="n">board</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">==</span> <span class="o">-</span><span class="mi">1</span><span class="p">:</span>
        <span class="n">model_vars</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</span><span class="p">.</span><span class="n">new_int_var</span><span class="p">(</span><span class="mi">1</span><span class="p">,</span> <span class="mi">9</span><span class="p">,</span> <span class="n">board_var_name</span><span class="p">)</span>
      <span class="k">else</span><span class="p">:</span>
        <span class="c1"># for given values, there's only one legal value for the variable
</span>        <span class="n">model_vars</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">]</span> <span class="o">=</span> <span class="n">model</span><span class="p">.</span><span class="n">new_int_var</span><span class="p">(</span><span class="n">board</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">board</span><span class="p">[</span><span class="n">i</span><span class="p">][</span><span class="n">j</span><span class="p">],</span> <span class="n">board_var_name</span><span class="p">)</span>

  <span class="c1"># rows
</span>  <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">):</span>
    <span class="n">model</span><span class="p">.</span><span class="n">add_all_different</span><span class="p">(</span> <span class="p">[</span> <span class="n">model_vars</span><span class="p">[</span><span class="n">r</span><span class="p">][</span><span class="n">c</span><span class="p">]</span> <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span> <span class="p">]</span> <span class="p">)</span>

  <span class="c1"># columns
</span>  <span class="k">for</span> <span class="n">c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">):</span>
    <span class="n">model</span><span class="p">.</span><span class="n">add_all_different</span><span class="p">(</span> <span class="p">[</span> <span class="n">model_vars</span><span class="p">[</span><span class="n">r</span><span class="p">][</span><span class="n">c</span><span class="p">]</span> <span class="k">for</span> <span class="n">r</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span> <span class="p">]</span> <span class="p">)</span>

  <span class="c1"># boxes
</span>  <span class="k">for</span> <span class="n">off_r</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
    <span class="k">for</span> <span class="n">off_c</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">3</span><span class="p">):</span>
      <span class="n">model</span><span class="p">.</span><span class="n">add_all_different</span><span class="p">(</span> <span class="p">[</span>
          <span class="n">model_vars</span><span class="p">[</span><span class="mi">3</span><span class="o">*</span><span class="n">off_r</span> <span class="o">+</span> <span class="n">numpad</span> <span class="o">%</span> <span class="mi">3</span><span class="p">][</span><span class="mi">3</span><span class="o">*</span><span class="n">off_c</span> <span class="o">+</span> <span class="n">numpad</span> <span class="o">//</span> <span class="mi">3</span><span class="p">]</span>
            <span class="k">for</span> <span class="n">numpad</span> <span class="ow">in</span> <span class="nb">range</span><span class="p">(</span><span class="mi">9</span><span class="p">)</span> <span class="p">]</span> <span class="p">)</span>
</code></pre></div></div>

<p>This indeed solved a reference sudoku we gave it, quickly.</p>

<p>There’s a lot more left to learn about these, but we’ve now learned the most
important thing - when I get another cp-sat shaped problem in the future, I’ll
know to try a solver and read the docs for whatever else I need, rather than
roll my own.</p>

<h4 id="links">Links</h4>

<p><a href="https://claude.ai/share/37b27e39-f11b-4a9a-98b0-04b98fa84662">The conversation with claude about solving the corn puzzle (with claude’s python script)</a></p>

<p><a href="https://github.com/kpthill/cp-sudoku">Our sudoku solver</a></p>

<p><a href="https://docs.google.com/presentation/d/17L0fYkLVCgGt8L1rCSSJ3ymXYsKTvNMIRRTmK69V5A8/edit?usp=sharing">Slides from a short talk I gave about this at RC</a></p>]]></content><author><name></name></author><summary type="html"><![CDATA[One random Friday at RC, I was bored and playing around with a puzzle someone had 3d printed:]]></summary></entry><entry><title type="html">Making a toy programming language</title><link href="https://thill.me/2026/06/02/dodo.html" rel="alternate" type="text/html" title="Making a toy programming language" /><published>2026-06-02T00:00:00+00:00</published><updated>2026-06-02T00:00:00+00:00</updated><id>https://thill.me/2026/06/02/dodo</id><content type="html" xml:base="https://thill.me/2026/06/02/dodo.html"><![CDATA[<p>I made a programming language! It’s called dodo. There’s basically nothing special about it — it’s a Lisp, chosen to be easy to implement, and it’s interpreted in JavaScript. You can try it <a href="/dodo/repl.html">here</a> and read the spec <a href="/dodo/spec.html">here</a>.</p>

<h2 id="the-language">The language</h2>

<p>Dodo is a Lisp. Function calls are made by putting the function and its arguments in parentheses, and can be arbitrarily nested:</p>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nb">+</span> <span class="mi">1</span> <span class="mi">1</span><span class="p">)</span> <span class="c1">;; =&gt; 2</span>
</code></pre></div></div>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">str-join</span>
    <span class="p">(</span><span class="nv">str-split</span> <span class="s">"john paul ringo george"</span> <span class="s">" "</span><span class="p">)</span>
    <span class="s">","</span><span class="p">)</span> <span class="c1">;; =&gt; "john,paul,ringo,george"</span>
</code></pre></div></div>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">defn</span> <span class="nv">square</span> <span class="p">(</span><span class="nv">x</span><span class="p">)</span> <span class="p">(</span><span class="nb">*</span> <span class="nv">x</span> <span class="nv">x</span><span class="p">))</span>
<span class="p">(</span><span class="nv">defn</span> <span class="nv">pythag</span> <span class="p">(</span><span class="nv">a</span> <span class="nv">b</span><span class="p">)</span> <span class="p">(</span><span class="nb">+</span> <span class="p">(</span><span class="nv">square</span> <span class="nv">a</span><span class="p">)</span> <span class="p">(</span><span class="nv">square</span> <span class="nv">b</span><span class="p">)))</span>
<span class="p">(</span><span class="nv">pythag</span> <span class="mi">3</span> <span class="mi">4</span><span class="p">)</span> <span class="c1">;; =&gt; 25</span>
</code></pre></div></div>

<p>List and map literals use JavaScript-style syntax, rather than Lisp-style quoting:</p>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">head</span> <span class="nv">[1</span> <span class="mi">2</span> <span class="nv">3]</span><span class="p">)</span> <span class="c1">;; =&gt; 1</span>
<span class="p">(</span><span class="nb">get</span> <span class="nv">{</span> <span class="s">"hi"</span><span class="err">:</span> <span class="s">"hola"</span><span class="o">,</span> <span class="s">"bye"</span><span class="err">:</span> <span class="s">"adios"</span> <span class="nv">}</span> <span class="s">"bye"</span><span class="p">)</span> <span class="c1">;; =&gt; "adios"</span>
</code></pre></div></div>

<p>The most interesting thing (currently still a little broken) is the match functionality. You can match arbitrary objects against literals as a control flow construct (in fact, the only control flow construct), with <code class="language-plaintext highlighter-rouge">_</code> as a wildcard:</p>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">match</span> <span class="mi">5</span>
    <span class="p">(</span><span class="mi">1</span> <span class="s">"one"</span><span class="p">)</span>
    <span class="p">(</span><span class="mi">2</span> <span class="s">"two"</span><span class="p">)</span>
    <span class="p">(</span><span class="nv">_</span> <span class="s">"many"</span><span class="p">))</span> <span class="c1">;; =&gt; "many"</span>
</code></pre></div></div>

<p>You can also recursively match on data structures:</p>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">match</span> <span class="nv">band</span>
    <span class="p">(</span><span class="nv">[{</span><span class="s">"name"</span><span class="err">:</span> <span class="s">"Annie"</span><span class="nv">},</span> <span class="nv">{</span><span class="s">"name"</span><span class="err">:</span> <span class="s">"Dave"</span><span class="nv">}]</span> <span class="s">"The Eurhythmics"</span><span class="p">)</span>
    <span class="p">(</span><span class="nv">[{</span><span class="s">"name"</span><span class="err">:</span> <span class="s">"Richard"</span><span class="nv">},</span> <span class="nv">{</span><span class="s">"name"</span><span class="err">:</span> <span class="s">"Karen"</span><span class="nv">}]</span> <span class="s">"The Carpenters"</span><span class="p">))</span>
</code></pre></div></div>

<p>You can bind destructured values to variables in the local scope:</p>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">match</span> <span class="nv">points</span>
    <span class="p">(</span><span class="nv">[[x1,</span> <span class="nv">y1],[x2,</span> <span class="nv">y2]]</span> <span class="p">(</span><span class="nv">js</span> <span class="s">"Math.sqrt"</span> <span class="p">(</span><span class="nb">+</span> <span class="p">(</span><span class="nv">square</span> <span class="p">(</span><span class="nb">-</span> <span class="nv">x2</span> <span class="nv">x1</span><span class="p">))</span> <span class="p">(</span><span class="nv">square</span> <span class="p">(</span><span class="nb">-</span> <span class="nv">y2</span> <span class="nv">y1</span><span class="p">))))))</span>
</code></pre></div></div>

<p>You can also use a <code class="language-plaintext highlighter-rouge">when</code> clause to filter based on bound variables or anything else:</p>

<div class="language-lisp highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="p">(</span><span class="nv">match</span> <span class="nv">n</span>
    <span class="p">(</span><span class="nv">x</span> <span class="nb">when</span> <span class="p">(</span><span class="nb">&gt;</span> <span class="nv">x</span> <span class="mi">0</span><span class="p">)</span> <span class="s">"positive"</span><span class="p">)</span>
    <span class="p">(</span><span class="nv">x</span> <span class="nb">when</span> <span class="p">(</span><span class="nb">&lt;</span> <span class="nv">x</span> <span class="mi">0</span><span class="p">)</span> <span class="s">"negative"</span><span class="p">)</span>
    <span class="p">(</span><span class="nv">_</span> <span class="s">"zero"</span><span class="p">))</span>
</code></pre></div></div>

<h2 id="implementation-notes">Implementation Notes</h2>

<h3 id="parser-combinators">Parser Combinators</h3>

<p>I wrote the lexer / parser together as a handrolled parser combinator library. This would be a very silly thing to do for a real project - both production grade lexers and parsers, as well as good parser combinator libraries, already exist. But it was fun, and I learned a lot from it.</p>

<p>A parser combinator takes parsers - functions from strings to some data structure - and combines them into new parsers. For example, the <code class="language-plaintext highlighter-rouge">lit()</code> function creates a parser that matches some string exactly:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="k">export</span> <span class="kd">function</span> <span class="nx">lit</span><span class="p">(</span><span class="nx">str</span><span class="p">)</span> <span class="p">{</span>
  <span class="kd">const</span> <span class="nx">len</span> <span class="o">=</span> <span class="nx">str</span><span class="p">.</span><span class="nx">length</span><span class="p">;</span>
  <span class="k">return</span> <span class="p">(</span><span class="nx">input</span><span class="p">)</span> <span class="o">=&gt;</span> <span class="p">{</span>
    <span class="k">return</span> <span class="p">(</span>
      <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="mi">0</span><span class="p">,</span> <span class="nx">len</span><span class="p">)</span> <span class="o">===</span> <span class="nx">str</span>
        <span class="p">?</span> <span class="p">{</span>
          <span class="na">result</span><span class="p">:</span> <span class="nx">str</span><span class="p">,</span>
          <span class="na">rest</span><span class="p">:</span> <span class="nx">input</span><span class="p">.</span><span class="nx">slice</span><span class="p">(</span><span class="nx">len</span><span class="p">)</span>
        <span class="p">}</span> <span class="p">:</span> <span class="kc">null</span>
    <span class="p">);</span>
  <span class="p">}</span>
<span class="p">}</span>
</code></pre></div></div>

<p>(The <code class="language-plaintext highlighter-rouge">rest</code> part of the return value is the remainder of the string that was unused). Then an example of a combinator would be <code class="language-plaintext highlighter-rouge">seq</code>, as in the grammar definition of <code class="language-plaintext highlighter-rouge">fn</code>:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="nx">fn</span> <span class="o">=</span> <span class="p">{...}</span> <span class="nx">seq</span><span class="p">(</span><span class="nx">tok</span><span class="p">(</span><span class="dl">'</span><span class="s1">fn</span><span class="dl">'</span><span class="p">),</span> <span class="nx">lit</span><span class="p">(</span><span class="dl">'</span><span class="s1">(</span><span class="dl">'</span><span class="p">),</span> <span class="nx">many</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">identifier</span><span class="p">),</span> <span class="nx">lit</span><span class="p">(</span><span class="dl">'</span><span class="s1">)</span><span class="dl">'</span><span class="p">),</span> <span class="nx">g</span><span class="p">.</span><span class="nx">expr</span><span class="p">)</span> <span class="p">{...};</span>
</code></pre></div></div>

<p>This is saying that an anonymous function definition consists of the keyword <code class="language-plaintext highlighter-rouge">fn</code>, followed by a list of variable names in parentheses, followed by an expression. Each of those is represented by a parser that identifies its own part of the input, and the <code class="language-plaintext highlighter-rouge">seq</code> parser combinator tries each of them in order, passing the <code class="language-plaintext highlighter-rouge">rest</code> from one parser into the next one. Note that <code class="language-plaintext highlighter-rouge">many</code> is itself a parser combinator, so we’re nesting them here.</p>

<p>This technique is remarkably powerful and remarkably general - the full list of parsing utilities I had to define for this project is:</p>
<ul>
  <li>parsers:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">lit</code>: creates a parser to recognize literal strings</li>
      <li><code class="language-plaintext highlighter-rouge">tok</code>: like <code class="language-plaintext highlighter-rouge">lit</code>, with a fix to keep it from recognizing prefixes of other tokens (e.g., it won’t recognize the first character of <code class="language-plaintext highlighter-rouge">if (condition)</code> as the variable <code class="language-plaintext highlighter-rouge">i</code>)</li>
      <li><code class="language-plaintext highlighter-rouge">regex</code>: parser to recognize any string that matches a regular expression</li>
    </ul>
  </li>
  <li>combinators:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">seq</code>: applies parsers one after another</li>
      <li><code class="language-plaintext highlighter-rouge">or</code>: tries one parser; if it does not match, tries the next</li>
      <li><code class="language-plaintext highlighter-rouge">many</code>: like BNF <code class="language-plaintext highlighter-rouge">*</code>, keeps applying a parser until it fails to match</li>
    </ul>
  </li>
  <li>utilities:
    <ul>
      <li><code class="language-plaintext highlighter-rouge">oneOrMore</code>: <code class="language-plaintext highlighter-rouge">many</code>, but must match at least once</li>
      <li><code class="language-plaintext highlighter-rouge">barring</code>: removes some strings from those a parser would match (for reserved words)</li>
      <li><code class="language-plaintext highlighter-rouge">opt</code>: makes a parser optional - if it doesn’t match, <code class="language-plaintext highlighter-rouge">opt(parser)</code> matches with no return value and consuming none of the input</li>
    </ul>
  </li>
</ul>

<p>This was enough to already be able to write a grammar for dodo that is basically a mechanical transformation of the grammar in the spec!</p>

<p>There were a few hacks that I did to get things working, that would have been done better by a real library. For example, with no lexing step, it’s a bit hard to recognize token boundaries, and to consume whitespace properly - you need to ignore spaces, newlines, and commas, but can’t rely on them to delimit tokens because open / close parens might bump up against the identifiers directly. I ended up just doing greedy regex matching for most identifiers and having <code class="language-plaintext highlighter-rouge">seq</code> consume whitespace as it goes along, but this is tailored specifically for dodo.</p>

<p>As I look now though it looks like more production grade uses of parser combinators don’t have a great trick for getting around this - <a href="https://github.com/jneen/parsimmon/blob/master/examples/lisp.js">this</a> lisp grammar using <a href="https://github.com/jneen/parsimmon">Parsimmon</a> just calls <code class="language-plaintext highlighter-rouge">.trim(P.optWhitespace)</code> a bunch. Probably better to be explicit like that than to silently eat it like I do though.</p>

<p>Another thing to note is that grammars are hard to define in a naive way because of evaluation order in javascript. For example, we might want to write:</p>

<div class="language-js highlighter-rouge"><div class="highlight"><pre class="highlight"><code><span class="kd">const</span> <span class="nx">expr</span> <span class="o">=</span> <span class="nx">or</span><span class="p">(</span><span class="nx">literal</span><span class="p">,</span> <span class="nx">identifier</span><span class="p">,</span> <span class="nx">fnCall</span><span class="p">,</span> <span class="p">{...</span><span class="nx">etc</span><span class="p">});</span>

<span class="kd">const</span> <span class="nx">fnCall</span> <span class="o">=</span> <span class="nx">seq</span><span class="p">(</span><span class="nx">lit</span><span class="p">(</span><span class="dl">'</span><span class="s1">(</span><span class="dl">'</span><span class="p">),</span> <span class="nx">oneOrMore</span><span class="p">(</span><span class="nx">g</span><span class="p">.</span><span class="nx">expr</span><span class="p">),</span> <span class="nx">lit</span><span class="p">(</span><span class="dl">'</span><span class="s1">)</span><span class="dl">'</span><span class="p">));</span>
</code></pre></div></div>

<h2 id="takeaways">Takeaways</h2>

<p>You can just write a programming language. Lexer, parser, grammar, interpreter, compiler — do whatever you find interesting and most of the rest is optional or has a library. Learn from the experience and start seeing the skeleton underneath the tools you use every day.</p>]]></content><author><name></name></author><category term="programming-languages" /><summary type="html"><![CDATA[I made a programming language! It’s called dodo. There’s basically nothing special about it — it’s a Lisp, chosen to be easy to implement, and it’s interpreted in JavaScript. You can try it here and read the spec here.]]></summary></entry><entry><title type="html">Proof Tips from my Old CS Theory Class</title><link href="https://thill.me/2020/07/11/proof-tips-from-my-old-cs-theory-class.html" rel="alternate" type="text/html" title="Proof Tips from my Old CS Theory Class" /><published>2020-07-11T00:00:00+00:00</published><updated>2020-07-11T00:00:00+00:00</updated><id>https://thill.me/2020/07/11/proof-tips-from-my-old-cs-theory-class</id><content type="html" xml:base="https://thill.me/2020/07/11/proof-tips-from-my-old-cs-theory-class.html"><![CDATA[<p>Back in the early 20-teens I was a TA for CS103, Stanford’s introduction to CS theory. For many of the students it was their first introduction to proof-based mathematics. We started off with an introduction to propositional logic, with two-column proofs and very explicit rules about how everything was supposed to work.</p>

<p>The students took to this pretty quickly, and unsurprisingly so - the rigid formalism of propositional logic maps pretty closely onto the rigid formalism of programming languages that they were already familiar with. However, a little less than halfway through the quarter, we switched to expecting normal paragraph-style proofs such as you might see in published papers, and the students started having a ton of trouble.</p>

<p>They would leave out essential justifications, or include extraneous ones. They would meander around the point without ever reaching it. They would appeal to vague concepts, like the “arrow from x values to y values” definition of functions, rather than engaging with the concrete definitions. They would claim things “by definition” that had no relation to the definitions given in the book.</p>

<p>I wrote the following handout to help them understand how to write cleaner, more rigorous proofs. It never actually got used - they figured out what they were doing well before I figured out what I wanted to say - but I include it here in hopes that you might find it interesting.</p>

<h2 id="cs103-proof-tips">CS103 Proof Tips</h2>

<p>Every proof in this class should be an informal, “paragraph style” proof from here on out unless the problem says otherwise.  We’ve had a lot of experience with formal proofs up till now, but informal proofs have their own style and their own requirements.  Paragraph style proofs are what will be expected in every theory or math class that you might take, and are how proofs are written in the literature, so it is worth getting familiar with the way that they are written.</p>

<p>Informal proofs should all be in one or more paragraphs.  The lines should not be separated or numbered, and justifications of boolean logic or simple arithmetic may be skipped. Because of this, informal proofs look very different from formal proofs.  However, they are very closely related.  A mathematically competent reader should be able to construct a formal proof from an informal proof, more or less mechanically - without having to have any deep thoughts or creative insights.  As a result, even in an informal proof you have to do more than just convey the intuitions behind a problem - you have to actually address the definitions that govern the thing you are trying to prove.</p>

<p>In particular, if the definition of something that you are trying to prove includes a (universal or existential) quantifier, you do actually need to instantiate that quantifier - even in an informal proof!  This means that you should be talking about a specific object, with a name.  An “x” or an “a” or a “p”, but not just “that element”.  This will make it much easier on the readers of your proof, and much easier for you to keep track of what is going on when you construct it.</p>

<h3 id="instantiation-and-generalization">Instantiation and Generalization</h3>

<p>Remember from when we were doing propositional logic with quantifiers and we had to make a distinction between “universal” and “existential” quantifiers?  This distinction made a big difference in what we were allowed to do in a formal proof; even now that we are doing informal proofs, this distinction is still very important!  For example, let’s try proving a very simple theorem:</p>

<p><em>Theorem 1</em> There is some positive number which divides every positive number.</p>

<p>By writing this in the language of formal logic, we can get a sense of how our proof should look:</p>

<p><em>Theorem 1</em> \(\exists x \in \mathbb{N} s.t. \forall y \in \mathbb{N}, x \vert y\)</p>

<p>“There exists a natural number x such that for every natural number y, x divides y.”</p>

<p>Aha! From the first week of the course, we know how to write a formal proof of this - first we have to pick some x, then pick an arbitrary y, then prove that x divides y, then use universal generalization to conclude that for all y, x divides y, and then use existential generalization to say that, because this x works, there is some x that works.  Similarly for an informal proof, we may not know how to prove this, but we at least know how the proof will look:</p>

<p><em>Proof (template)</em></p>

<p>Pick \(x = \_\_\_\_\). Then \(x \in \mathbb{N}\) because ____. Let \(y \in \mathbb{N}\).</p>

<p>{Now, prove x divides y.}</p>

<p>Therefore, x divides y, and we are done.</p>

<p>Notice how we haven’t even <em>done anything</em> yet.  This proof structure follows immediately from the structure of the theorem - to show that there exists an x, we can pick any x we want, as long as it is a natural number, and then to show something is true for every y, we have to let y be arbitrary, and then we need to prove that x divides y.  Once we do this, because of the way we set up the proof, we have shown the theorem - we can skip the generalization steps at the end, because they are fixed by what we did at the beginning (which means you have to be very careful with the set up!).  The other thing to note is that the order is important - \(\exists x \forall y\) does not mean the same thing as \(\forall y \exists x\), and so we need to be certain that we pick x before we let y, or we will have proved something completely different!</p>

<p>How do you prove that x divides y?  Well, let’s just look at the definition:</p>

<p><em>Definition</em> We say that “x divides y” or \(x \vert y\) if and only if there exists some natural number n such that \(y = n x\). That is, \(x \vert y \iff \exists n \! \in \! \mathbb{N} \, s.t. \, y = n x\).</p>

<p>Well, we still may not know why the theorem is true, but now we can see another step that the eventual proof is going to have to have, within the {prove x divides y} section:</p>

<p>Pick \(n = \_\_\_\_\).  Then \(n \in \mathbb{N}\) because ____.</p>

<p>{ Prove \(y=n x\). }</p>

<p>Therefore x divides y.</p>

<p>Now we still haven’t done anything interesting - we are just chasing definitions.  But looking over the proof skeleton, it is pretty easy to guess that \(x = 1\) and \(n = y\), so we can fill in the blanks:</p>

<p><em>Proof</em></p>

<p>Pick \(x=1\), so \(x \in \mathbb{N}\).  Let \(y \in \mathbb{N}\). Pick \(n = y\), and hence \(n \in \mathbb{N}\) as well.  Then</p>

<p>\(n*x=y*1=y\),</p>

<p>so x divides y, as desired.</p>

<p>That’s a good proof!  Even though we had 2 existential generalizations and 1 universal generalization to do, and a lot of things to prove, the result came out very concise because we focused on the things that are central to the proof - letting and picking variables and showing that the values we chose satisfy the definition.</p>

<p>In trying to find your own proofs, the strategy above is something that you can do on any problem - first break down the definitions and figure out what sort of variables the definitions are forcing you to adopt, and then try to fill in that proof skeleton.  Often, just spelling out the definitions this way will make it obvious what you have to do to prove it!</p>

<p>So, we’ve seen that to prove a theorem we get to pick a variable whenever we see an existential quantifier, and we have to let an arbitrary variable whenever we see a universal quantifier.  What about when we want to use a theorem?  Let’s use theorem 1 to prove that:</p>

<p><em>Thm 2</em> Every natural number has at least one natural-number factor.</p>

<p>(Yes, this is a very easy theorem, and we don’t need theorem 1 to show this.  Bear with me).  If we recall that x is a factor of y if and only if x divides y, and we try to write out a proof skeleton, we get something that looks like:</p>

<p>Let \(n \in \mathbb{N}\). Pick \(f = \_\_\_\_\), and \(f \in \mathbb{N}\) because ____.</p>

<p>{ Show that f divides n. }</p>

<p>Hence, f is a factor of n, so we are done.</p>

<p>Now we think that we might want to use theorem 1 to find f.  Well, when you want to use a theorem, the rule is opposite - wherever the theorem says “for all”, you can choose any value you want, but when the theorem says “there exists”, you have to just take whatever value it gives you.  Let’s do this to finish our proof:</p>

<p><em>Proof</em>
Let \(n \in \mathbb{N}\).
By thm 1, there is some \(x \in \mathbb{N}\) such that, for all \(y \in \mathbb{N}\), x divides y.
Pick \(f = x\), and \(f \in \mathbb{N}\) because \(x \in \mathbb{N}\).
Pick \(y = n\).</p>

<p>Then x divides y by the theorem, so f divides n. Hence, f is a factor of n, so we are done.</p>

<p>In practice, this is still too verbose, so when we get something from a theorem and then use it immediately, we will collapse the picks and lets.  This is how we might write a final version of our proof:</p>

<p><em>Proof</em>
Let \(n \in \mathbb{N}\).  By theorem 1, there is some \(x \in \mathbb{N}\) which divides every other natural number y, so in particular, x divides n.  Because x divides n, x is a factor of n, and we are done.</p>

<p>Nice!  You can use this trick with almost any problem to get an idea of what variables you need to use.  Just remember that to prove a theorem, for every “\(\exists\)” you get to pick a variable, and for every “\(\forall\)” you have to let an arbitrary variable, but when you are using a theorem it is the other way around.</p>

<h3 id="leaving-things-out">Leaving things out</h3>

<p>Paragraph style informal proofs are focused on getting an idea across rigorously, but also concisely.  The idea is that there should be enough information in the proof that anyone can take it and turn it into a formal proof if they want to, but to leave out the technical details that aren’t relevant to the main idea of the proof.</p>

<p>Look back at our proof of theorem 1.  We already mentioned that we left out the generalization steps at the end.  We also glossed over the things that weren’t central to the idea of the proof, and would have merely clouded up the central ideas - these things include not only the existential and universal generalizations at the end, which were already implied by the way that we chose our variables at the start, but also the justifications that \(1 \in \mathbb{N}\) and that \(1*y=y\), which are not interesting in the context of the theorem, and the boolean logic that we would have to do to show that this actually satisfies the definition.</p>

<p>At this stage of the class, you can and should omit justifications for arithmetic and algebra, set theoretic identities, and boolean manipulations, unless that is specifically the subject matter of the problem.  Of course, you should only omit justifications if you can see at a glance what they would be - omissions are not a way of ignoring things that you do not understand, but a way of sparing the reader an obvious and tedious subproof.</p>

<p>For example, on the midterm and problem set 3, many people wrote things like “If AB then A by the definition of intersection.”  That is not what the definition of intersection says.  What is happening when you write that is that you come up with an identity that is obviously true, but that hasn’t been presented in the course.  This is fine; you don’t have to spell all of these things out if they are not central to the proof and they are simple enough that anyone in this class would see immediately that they are true.  However, then you aren’t going to be able to come up with a valid justification, so just don’t put one.</p>

<p>Another thing that you should omit from your proofs are anything that is actually unnecessary to the proof.  If there is something that you observe but do not use, take it out.  (When you are doing an exposition, trying to explain the topic to someone, these can be very important, but for the proofs we will ask you to do it’s better to be concise.  If you end up stating something that is not only unnecessary but also wrong, you will lose points).</p>

<p>There is a lot of stuff then that you can leave out of a proof, and they tend to be the small details and technicalities that most people would never consider.  (One of the reasons that we covered formal proofs and formal logic is so that you would know that those were there, hiding underneath.)  So what should you include?  There are few hard and fast rules, but some good rules of thumb would be to include all of the conditions and antecedents for definitions that you use explicitly, any theorems from class or the book that you invoke, the definitions of every variable you use, and everything that you personally found interesting or surprising.</p>

<p>There is also one rule that is universal: if there are a set of assumptions or conditions mentioned in the problem, you can bet that you will need to use them.  Your proof should be explicit when you invoke them (say “by assumption (i),” or something similar); if you don’t use one of the hypotheses, this is definitely noteworthy and you should point out explicitly why it was not necessary.  It is sometimes unclear what you need to spell out and what you can elide, but the conditions / hypotheses / antecedents mentioned in the problem statement should never be left out!</p>

<h3 id="more-tips">More Tips</h3>

<p>Don’t repeat yourself!  If you make some claim, and then decide that it requires justification, go back and replace that claim with the reasoning - if you leave it there, even with logic to back it up later, it will look to the reader like you are just pulling something totally out of the blue.</p>

<p>Informal definitions and ideas like the “arrow” description of functions are appropriate for motivations and for explaining the ideas to a casual observer, but not for proofs.  In a paragraph proof, you should not say, “because f is onto, everything has an arrow pointing into it,” but instead, “because \(f\) is onto, for every element \(y\) in its codomain, there is an \(x\) in its domain such that \(f(x)=y\)”.  Proofs are for more than just getting the idea across - your proof should force the reader to admit that you are right, even if they believe otherwise.  To this end you must be precise.</p>

<p>Negations in the problem statement can make it more confusing whether you should pick or let a variable, because of DeMorgan’s laws for quantifiers.  Since \(\neg \exists x \, s.t. P(x)\) is the same as \(\forall x \, \neg P(x)\), should you pick a specific x, or let x be arbitrary?  Fortunately, there is a hard and fast rule for this one - always move the negation all the way into the problem statement before picking or letting.  In the example, this means that you would let x, because there is a “for all” in the front when the negation has been moved in.</p>]]></content><author><name></name></author><category term="math" /><summary type="html"><![CDATA[Back in the early 20-teens I was a TA for CS103, Stanford’s introduction to CS theory. For many of the students it was their first introduction to proof-based mathematics. We started off with an introduction to propositional logic, with two-column proofs and very explicit rules about how everything was supposed to work.]]></summary></entry></feed>