Skip to content
Handbook navigation

Chapter 1 · Lab

Lab: The Dream of Thinking Machines

Run this lab

Edit and run the chapter code

Choose an available implementation, change the code, then run it here or continue in the dedicated Labs workspace.

Unlock execution

Output

Run the code to see output here.

Lab 1 - Build, Break and Bound Three Thinking Machines

Lab Brief

Difficulty: Beginner Estimated time: 75 minutes Lab ID: VOL1-SEC1-CH1-LAB1

Objective

Extend the chapter's program with a Turing machine, a threshold network and two ELIZA rules of your own, find the inputs that break each one, and finish with an evidence plan that says, for three components of a real workflow, whether you would enumerate or sample and how many runs you need.

Everything runs offline with examples/thinking_machines.py (standard-library Python) or java/ThinkingMachines.java (JDK 21). You can do Parts A to C with pencil and paper first and use the program to check.


Scenario

Your team is adding an AI assistant to the expense-claims process. Before anyone writes production code, your lead wants every engineer to be able to answer two questions in design reviews: "what exactly does this component compute?" and "what would convince you it never does the wrong thing?" This lab practises both on machines small enough to understand completely.


Tasks

Part A - A Turing machine that subtracts one

  1. Write a rule table, in the chapter's (state, symbol) → (write, move, next state) form, that subtracts one from a binary number greater than zero. Hint: walk right to the end as before, then borrow leftwards: a 0 becomes 1 and the borrow continues; a 1 becomes 0 and the machine stops.
  2. Trace your machine by hand on 1100 (twelve) and on 1000 (eight). Record the tape after every step.
  3. Derive a step-count formula like n + k + 2, where k now counts trailing zeros. Check it against your traces.
  4. Decide what your machine should do on input 0, then add the rules to the program as a second dictionary next to INCREMENT (in Java, a second map). run_machine reads INCREMENT directly, so give it the rule table as an extra argument first. Run all three inputs; the output for 1000 keeps its leading zero, 0111, which is still seven.

Part B - Threshold units and a two-layer network

  1. Find weights and a threshold for NOR (fires only on (0, 0)) and for "x1 AND NOT x2". Check each in Figure 1.5 and in the program's pattern function.
  2. Extend the exhaustive search to weights from −5 to 5, and the doubled threshold theta2 to −21 to 21 so that thresholds cover −10.5 to 10.5, and confirm that XOR and XNOR still never appear. Write down, in two or three sentences, why a wider search cannot help.
  3. Build XNOR (fires when both inputs are equal) from two layers of units and print its truth table.

Part C - Make ELIZA fail

  1. Add two rules to RULES: one for the keyword because (reassembly IS THAT THE REAL REASON) and one for mother or father (reassembly TELL ME MORE ABOUT YOUR FAMILY).
  2. Write three sentences that produce fluent but absurd replies, and one sentence where two rules compete and the rank decides which fires.
  3. Draft five questions you would ask any chatbot to separate fluency from knowledge. At least two must have answers you can check, and one must be unanswerable, so that the right response is to say so.

Part D - The evidence plan

The expense workflow has three new components:

  • a policy check that approves a claim only if a receipt is attached, the amount is under the category limit, and the claimant's manager is not the claimant (three yes/no facts);
  • a parser for an eight-digit cost-centre code;
  • an AI agent that reads receipts and proposes the category and amount for each claim.

For each component:

  1. State whether it can express arbitrary behaviour, and count its inputs (or say why they cannot be counted).
  2. Choose enumerate or sample, and justify the choice with the count.
  3. For the agent, compute the clean runs needed to rule out a wrong-proposal rate above 2% and above 0.5% at 95% confidence, using the formula in the chapter and Part 4 of the program. Then name one permission you would withhold so that the worst failure becomes impossible rather than merely rare.

Deliverables

  • Your subtract-one rule table, two hand traces and the step-count formula, plus the program output for all three inputs.
  • The NOR, "x1 AND NOT x2" and XNOR settings with their truth tables, and your explanation of why no single unit computes XOR.
  • The two new ELIZA rules, the four test sentences with the program's replies, and your five chatbot questions.
  • A one-page evidence plan for the three expense components, ending in the two-sentence answer you would give a risk committee.

Verification

  • Run the Python and the Java versions after your changes and diff their outputs; if you changed only one, the diff shows exactly what you added.
  • Every hand trace must match the program's step count, and every step-count formula must predict the traces you did not use to derive it.
  • Recompute each runs-needed figure with the calculator in Figure 1.6.

Success Criteria

  • Your Turing machine subtracts one correctly on every input greater than zero, and your document says what it does on 0 and why.
  • Your XOR explanation would convince a reader who has not seen the chapter, without relying on the search result alone.
  • At least one of your ELIZA test sentences produces a reply that a careless reader could mistake for understanding.
  • The evidence plan enumerates both finite components (8 and 100,000,000 inputs), samples the agent with correctly computed run counts (149 clean runs for 2% and 598 for 0.5% at 95% confidence), and removes at least one dangerous permission.
Lab — The Dream of Thinking Machines | KnowledgeOS