import steps_widget18 AI: The AI predicts, you prove
A claim about what code does is a prediction to be verified.
This session repeats the same three-step routine, repeated on harder and harder expressions:
- You predict what an expression evaluates to, doing the substitution and reduction steps in your head or on paper.
- Then you ask the assistant what the expression evaluates to, and read its answer, including whatever reasoning it gives.
- Then you run the expression through the
%%stepswidget, which is the only one of the three that actually reduces the expression step by step,
When your prediction and the assistant’s answer agree, that is pleasant and proves nothing. When they disagree, and you need to figure out how the assistant or yourself was wrong, that is the session working as intended.
Every round below carries the AI: Explainer badge. You put something in front of the assistant that already exists and ask it to explain that thing. You do not ask it to create anything. You only ask it to explain and verify what you get back.
Warm-up
Straightforward operator precedence, to get the three-way move running smoothly before anything tricky shows up.
Exercise 18-1
4 + 6 * 2 - 3
%%steps
4 + 6 * 2 - 3 # PRINT STEPSExercise 18-2
2 ** 3 ** 2 (exponentiation groups right-to-left, decide what that means for this one before you predict)
Exercise 18-3
10 - 2 - 3 (subtraction groups left-to-right, same caution as above)
Exercise 18-4
(3 + 2) * (8 - 6) / 2
Exercise 18-5
7 % 3 + 2 * 5 // 2
Comparisons and boolean logic
Chained comparisons and not/and/or precedence are a place fluent-sounding wrong answers are common, because the rules read as obvious right up until you meet a case that breaks the obvious reading.
Exercise 18-6
1 < 2 < 3 (this is a chained comparison, not two separate comparisons combined by magic, predict what Python actually does with it before asking)
Exercise 18-7
1 < 2 > 3
Exercise 18-8
not 1 == 1 == 2
Exercise 18-9
True and False or True
Exercise 18-10
not True and not False
Short-circuit values, not just True/False
and and or do not return True or False; they return whichever operand decided the outcome. This is the single richest source of a plausible-but-wrong AI answer in this whole session, because “and/or return booleans” is a very natural, very common, very wrong simplification.
Exercise 18-11
'ATG' and 'GCC' (predict the actual value returned, not just whether it is “truthy”)
Exercise 18-12
'' or 'GCC'
Exercise 18-13
0 or '' or 'default'
Exercise 18-14
'ATG' and '' and 'GCC'
Exercise 18-15
Ask the assistant, before predicting or proving anything, to state in one sentence what and and or return in Python. Only after you have its claim in writing, run Exercises 11–14 through the widget and check its general claim against all four actual results. Does its one-sentence rule survive contact with all four?
Mixed types and strings
In Python some mathematical operators also work on strings in a way you may not anticipate. Very convenient, not knowing it would get you in trouble as you will see below.
Exercise 18-16
'AT' * 3 + 'G'
Exercise 18-17
'AT' * 2 == 'ATAT'
Exercise 18-18
bool('False') (a classic trap, predict carefully)
Exercise 18-19
3 == 3.0 and 3 is 3.0 (if your Python raises a SyntaxWarning on is with a literal, that is itself worth reading and predicting around)
Exercise 18-20
len('ATG') == 3 and 'G' in 'ATG'
Break the AI
Now you write the expressions. Working alone or with a partner, construct two expressions of your own, each combining precedence, comparison, and short-circuit logic, specifically designed to be the kind of case a fluent guesser would get wrong: something where the obvious-looking simplification (like “and/or return booleans”) fails. Trade your two expressions with another pair. For each expression you receive, do the full three-way move: predict, ask, prove.
Exercise 18-21
Before trading anything, write down in one sentence why each of your two expressions is designed to trip up a plausible-but-wrong guess. This is the harder half of the exercise: constructing a good trap requires understanding the rule well enough to know exactly where it is easy to misapply.
Exercise 18-22
Run the full three-way move on the two expressions you received from the other pair. Report back to them, in one sentence each, whether their trap actually caught the assistant, caught you, caught neither, or caught both.
Logbook
For your logbook this week, report your personal tally across the whole session: how many of the roughly twenty expressions the assistant got wrong, how many you got wrong, and whether the two of you tended to get the same ones wrong or different ones. That last question matters more than the raw count, it tells you whether your instincts and the assistant’s failure modes overlap, which is exactly the thing you need to know to check it well.