The code and the explanation can disagree even when they arrive in the same model response. A green program test does not reach backward and validate every sentence above the program.
Jakob Frick’s new Malama training write-up includes a published generation for mean absolute deviation. The prose gives the mean of [0, 0, 1] as 0.5; its final function calculates the mean from the values. [1] That makes a small, checkable example of two different evaluation targets.
I checked the published function and the arithmetic. This is an inspection of a saved example, not a new Malama response or an estimate of how often it makes this mistake.
Follow the numbers before the verdict
The sum is one and the list has three elements. Its mean is 1/3. The absolute distances from that mean are 1/3, 1/3, 2/3. Their average is 4/9, about 0.444444444444.
The final function in the source returns that floating-point result on this input. Its accompanying trace’s mean is still wrong. A function can implement the right formula while the surrounding explanation contains a false worked example.
Original arithmetic illustration of the published example. Image by Shivam Dwivedi.
There is no need to guess what the model “really thought” to check this. The claim is an observable piece of text, and ordinary arithmetic supplies a counterexample. The trace is not a direct instrument reading of an internal reasoning process.
Give the program an independent arithmetic oracle
Here is my own small checker. Save it as check_deviation.py and run python3 check_deviation.py. It requires no model, account or external package.
The floating implementation uses fsum. The exact reference rearranges the formula for integer inputs: with n values and total s, the deviation is sum(abs(n*x - s)) / n². That avoids representing a repeating mean as a float. Python’s Fraction keeps the result rational. [2][3]
from fractions import Fraction as F from itertools import product from math import fsum, isclose def deviation(values): if not values: raise ValueError('a mean needs data') mean = fsum(values) / len(values) return fsum(abs(x - mean) for x in values) / len(values) def exact(values): n, total = len(values), sum(values) if not n: raise ValueError('a mean needs data') return F(sum(abs(n*x - total) for x in values), n*n) values = [0, 0, 1] print('mean:', F(sum(values), len(values))) print('exact deviation:', exact(values)) print('floating result:', f'{deviation(values):.12f}') checked = 0 for n in range(1, 5): for xs in product((-1, 0, 1), repeat=n): assert isclose(deviation(xs), float(exact(xs)), abs_tol=1e-12) checked += 1 assert exact(values) == F(4, 9) assert exact([5, 5, 5]) == 0 try: deviation([]) except ValueError: pass else: raise AssertionError('empty input accepted') print('bounded cases:', checked) mean: 1/3 exact deviation: 4/9 floating result: 0.444444444444 bounded cases: 120 The bounded enumeration checks every vector of lengths one through four over the alphabet -1, 0, 1: 3 + 9 + 27 + 81 = 120 inputs. It includes repeated values, negative values and constant lists. The empty-input check is separate because an empty list has no arithmetic mean.
This checker deliberately raises an exception for empty input. The published function returns zero there. I am choosing a contract for this example, rather than claiming that my exception reproduces the benchmark’s requirements. Decide that boundary before grading an implementation.
Keep the verdicts attached to their evidence
A program test asks whether executable behavior meets its specified cases. An explanation check asks whether the stated calculations or inferences are true. Store those verdicts separately; one does not certify the other.
For a concrete arithmetic assertion, I would retain the input, claimed intermediate value, independent expected value and comparison result. Free-form explanations may contain ambiguity that requires human judgment. Do not turn every sentence into a brittle string match, or let another model’s confident approval stand in for the arithmetic available here.
There is also a causal boundary. Finding a wrong sentence alongside correct code does not show whether the sentence helped, hurt or had no effect on generation. That would require a different investigation. It does show why selecting successful code samples does not, by itself, select correct explanations.
The source offers this as a passing generation. I have not rerun its full benchmark or measured Malama’s overall coding quality. The useful result here is narrower: on a published, nonempty input, the final function and an exact calculation agree while a specific prose claim does not. Keep the passing code. Keep the failed explanation check too.
References
Jakob Frick, Training my own LLM from scratch, appendix example for mean absolute deviation.
Python documentation, rational arithmetic with fractions.
Python documentation, math.fsum and math.isclose.
Asset credits
Original figure and checker, CC BY 4.0. Credit: Shivam Dwivedi. No third-party images or generated trace text reproduced.
AI disclosure
AI was used to draft the article.
