RSA Bottom-Up RExpr Builder #
Constructs RExpr trees for RSA expressions bottom-up from evaluated leaf values,
completely bypassing the generic reifier's top-down unfoldDefinition? chain.
The generic reifier discovers expression structure by unfolding definitions one
at a time (~31K unfoldDefinition? calls for the first cross-utterance theorem).
The builder knows the RSA layered structure and constructs RExpr trees directly:
- Leaf evaluation: Evaluate meaning Bool values natively, reify priors/costs via the generic reifier (small expressions, ~0.1ms each).
- Layer composition: Build L0 → S1 → L1 RExpr trees by direct construction.
- Direct return: Return the full RExpr to the caller, bypassing
reifyToRExpr.
The kernel verifies denote(rexpr) ≡ original_expr by reducing both sides.
The builder's RExpr matches because:
- Left-fold sums match
Finset.sumreduction (via0 + x ≡ xfor ℝ) - iteZero matches
if totalScore = 0 then 0 else score / totalScore - expMulLogSub matches
exp(α * (log x - c)) - Leaf values are reified by the generic reifier (denote matches by construction)
Module-scope cache for RSA build results. Keyed by config expression hash. Avoids rebuilding the full layer stack (L0→S1→L1) when the same RSAConfig is used across multiple theorems in the same file.
Scan an expression tree for RSA.RSAConfig.L1agent applied to a cfg argument. Returns the cfg Expr if found.
Try to build RExpr trees for an RSA comparison, bypassing the generic reifier.
Returns (lhsRExpr, lhsBounds, rhsRExpr, rhsBounds) on success.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build L1 and L1_latent RExprs for an RSAConfig by:
- Instantiating the s1Score lambda body directly (bypassing S1→S1agent→policy chain)
- Reifying each instantiated body via the generic reifier
- Assembling S1→L1 layers algebraically
This avoids the expensive whnf chain through cfg.S1 l w u → (S1agent l).policy w u → RationalAction.policy → iteZero → Finset.sum.
Instead, we substitute concrete L0 policy function + args into the s1Score body
and reify the resulting simple arithmetic expression (ite/exp/log/Finset.sum).
Seeds the reification cache with L1/L1_latent values so the generic reifier finds them immediately when processing S2Utility or similar composite expressions.
Recursively detects nested RSA configs in worldPrior/meaning (e.g.,
seqAdjCfg's worldPrior is (evalCfg mu).L1) and builds them first.
Pre-seed the reification cache with L1/L1_latent values for RSAConfig references found in the expression. Call before reifyToRExpr to avoid expensive whnf of nested L1 computations (e.g., in S2Utility).
Equations
- One or more equations did not get rendered due to their size.