RSAPredict Auto-Detection (Tier 2) #
Structural auto-detection of S1 score patterns from raw RSAConfig.
When cfg is NOT built via RSAConfigData.toRSAConfig (Tier 1 fails),
this module classifies the s1Score lambda into a known S1ScoreSpec
variant by pattern-matching on the normalized AST, then builds an
RSAConfigData whose .toRSAConfig is definitionally equal to the
user's config.
Pipeline #
- Normalize: Unfold
cfg.s1Score, whnf to expose the lambda body. - Detect: Pattern-match outermost structure (rpow, ite, exp) to classify.
- Extract: Evaluate meaning/priors/cost pointwise over finite types → ℚ arrays.
- Build: Construct an
RSAConfigDataExpr with ite-chain functions + sorryAx proofs. - Bridge:
native_decideoncheckL1ScoreGt d..., thenisDefEqto the goal.
If any step fails, returns false — CProof (Tier 3) handles it.
Detected S1 score pattern. Each variant corresponds to an S1ScoreSpec constructor.
QUD projection is handled orthogonally via RSAConfigData.qudProject.
- beliefBased : DetectedPattern
- beliefAction : DetectedPattern
- weightedBeliefAction : DetectedPattern
- actionBased : DetectedPattern
- beliefWeighted : DetectedPattern
- combinedUtility : DetectedPattern
Instances For
Walk an expression tree checking if it contains a specific constant name.
Detect the S1ScoreSpec variant by inspecting the reduced s1Score expression.
Strategy: reduce cfg.s1Score to whnf and look for signature constants:
Real.rpow→ beliefBased (QUD projection is orthogonal, viaqudProject)Real.exp+Real.log→ beliefAction (filter from QUD is handled separately)Real.expwithoutReal.log→ actionBasedFinset.suminsideReal.expargument (weighted sum) → beliefWeighted
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract meaning values: meaning(l, u, w) as ℚ for all (l,u,w) triples. Returns array indexed as [lIdx * nU * nW + uIdx * nW + wIdx].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract world prior values as ℚ.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract latent prior values as ℚ. Indexed as [wIdx * nL + lIdx].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Peel 5 lambdas from a reduced s1Score expression to expose the body. Returns (body, fvars) where fvars = [l0, α, l, w, u].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Extract belief and quality values from a beliefWeighted s1Score.
The expected pattern is:
if quality(l, u) then exp(α * Σ_s belief(l,s) * log(l0 u s)) else 0
Also handles the KL divergence form where the sum body includes
- Σ_s belief(l,s) * log(belief(l,s)) (constant w.r.t. u, so stripped).
Uses withLocalDecl for lambda peeling so fvars are properly registered
in the local context (required for whnf/isDefEq to work).
Returns (beliefVals, qualityVals) where:
beliefValsis indexed as[lIdx * nW + wIdx]qualityValsis indexed as[lIdx * nU + uIdx]
Equations
- One or more equations did not get rendered due to their size.
Instances For
Find a sub-expression that looks like a cost term:
- Appears as the RHS of a subtraction (... - cost)
- Does NOT mention wFvar (cost depends on utterance, not world)
- May or may not mention uFvar (constant cost like 0 is valid)
Extract cost values by structurally finding the cost sub-expression in the s1Score body. For beliefAction: s1Score l0 α l w u = if l0(u,w) = 0 then 0 else exp(α*(log(l0(u,w)) - cost(u))) For actionBased: s1Score l0 α l w u = exp(α*(l0(u,w) - cost(u)))
Uses withLocalDecl for lambda peeling (matching extractBeliefAndQuality)
so that fvars have proper types in the local context. This ensures whnf
can fully reduce match expressions in the body (e.g., beliefGoalScore/
actionGoalScore pattern matches). Without registered fvars, the match
doesn't evaluate and findCostSubExpr fails to find the subtraction.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build fun (x₁ : T₁) (x₂ : T₂) => <ite chain> returning Bool.
values indexed as [i * n₂ + j].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build fun (l : L) (u : U) (w : W) => <ite chain>.
values indexed as [li * nU * nW + ui * nW + wi].
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build a sorryAx proof of type ty : Prop.
Equations
- Linglib.Tactics.RSAPredict.mkSorryProof ty = Lean.mkApp2 (Lean.mkConst `sorryAx [Lean.Level.zero]) ty (Lean.mkConst `Bool.true)
Instances For
Build ∀ (l : L) (u : U) (w : W), 0 ≤ meaningFn l u w and its sorry proof.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build 0 < α and its sorry proof (α : ℚ).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build ∀ (w : W), 0 ≤ wpFn w and its sorry proof.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build ∀ (w : W) (l : L), 0 ≤ lpFn w l and its sorry proof.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Build an RSAConfigData Expr from detected pattern and extracted ℚ values.
The result d has the property that d.toRSAConfig is definitionally
equal to the user's cfg (verified by isDefEq at the bridge step).
Proof obligations are closed with sorryAx (erased at runtime,
so native_decide works).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Full Tier 2 pipeline for L1 comparison: detect → extract → build → native_decide → bridge.
Returns true if successful, false to fall back to CProof (Tier 3).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Tier 2 pipeline for ¬(L1 gt).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Tier 2 pipeline for S1 comparison.
Equations
- One or more equations did not get rendered due to their size.
Instances For
Tier 2 pipeline for ¬(S1 gt).
Equations
- One or more equations did not get rendered due to their size.
Instances For
Tier 2 pipeline for L1 score gt (cross-utterance).
Equations
- One or more equations did not get rendered due to their size.