# Shared context and competing toy rules

Run `python reproduce.py` with numpy and matplotlib. Standalone, wholly assigned teaching study: 101 mixture rows, two invented rule examples, original two-panel figure in PNG/SVG/PDF, recorded runtime versions, generator SHA256 and validation JSON. There are no biological observations, treatment effects, diagnosis or person scores.

## Model contract

`mixture(q)` takes a finite fraction q in [0,1]. A binary context Z is high with probability q. Within low context, A and B are independent Bernoulli variables each with probability0.2; within high context each has probability0.8. Conditional independence is an assumption of this constructed example, not a conclusion about real data.

Let p=0.2+0.6q. The four joint cells p11=P(A=1,B=1)=0.04+0.60q; p10=p01=0.16; p00=0.64-0.60q. Marginals P(A)=P(B)=p. Consequently P(B|A)=p11/p, P(B|not A)=0.16/(1-p), and Cov(A,B)=0.36q(1-q). Export q=0..1 by0.01. Joint cells are dimensionless probabilities; covariance refers to binary0/1 indicators.

At q=0.5, the mixed conditional probabilities are0.68 and0.32 and covariance0.09. At q=0 or1, mixed covariance is zero. Within either context P(B|A,Z)=P(B|not A,Z), equal to0.2 or0.8 respectively. At an endpoint the absent context's conditional distribution remains a specified part of the generative model; it is not an empirically estimable stratum there. No conditional denominator used by the mixed model is zero, since p remains between0.2 and0.8.

The figure illustrates how mixing two contexts creates association even though neither within-context distribution contains association. This does not identify a hidden context in a real study, prove the direction of causation, or estimate an intervention. Its practical use is to make alternative explanations visible before interpreting an association.

## Tiny invented rule exercise

Training string: `*red pushes blue`. Rule1 always selects the first symbol as agent; rule2 selects the star-marked symbol. Both select red. Held-out string: `blue pushes *red`. Rule1 selects blue and rule2 selects red. The answer red is deliberately assigned by the exercise designer. These two strings show how a discriminating new example separates two rules that fit one old example. They are not evidence for a natural language, a recovered translation, a general grammar or an accuracy rate.

## Independent verification

For each q, enumerate all eight (Z,A,B) possibilities using their product weights, marginalize and compare every joint cell, marginal, conditional and covariance with the closed forms. Check normalization, bounds, within-context independence, endpoints and midpoint. Four invalid inputs are rejected. The toy predictions are recomputed directly by token parsing. The reported errors are floating-point rounding, not sampling uncertainty. No random data or confidence interval is involved.
