Documentation

Archive.Examples.IfNormalization.Result

A solution to the if normalization challenge in Lean. #

See Statement.lean for background.

We add some local simp lemmas so we can unfold the definitions of the normalization condition.

Simp lemmas for eval. We don't want a simp lemma for (ite i t e).eval in general, only once we know the shape of i.

@[simp]
theorem IfExpr.eval_lit {b : Bool} {f : Bool} :
@[simp]
theorem IfExpr.eval_var {i : } {f : Bool} :
@[simp]
theorem IfExpr.eval_ite_lit {b : Bool} {t : IfExpr} {e : IfExpr} {f : Bool} :
IfExpr.eval f ((IfExpr.lit b).ite t e) = bif b then IfExpr.eval f t else IfExpr.eval f e
@[simp]
theorem IfExpr.eval_ite_var {i : } {t : IfExpr} {e : IfExpr} {f : Bool} :
IfExpr.eval f ((IfExpr.var i).ite t e) = bif f i then IfExpr.eval f t else IfExpr.eval f e
@[simp]
theorem IfExpr.eval_ite_ite {a : IfExpr} {b : IfExpr} {c : IfExpr} {d : IfExpr} {e : IfExpr} {f : Bool} :
IfExpr.eval f ((a.ite b c).ite d e) = IfExpr.eval f (a.ite (b.ite d e) (c.ite d e))

Custom size function for if-expressions, used for proving termination.

Equations
Instances For
    @[irreducible]
    def IfExpr.normalize (l : AList fun (x : ) => Bool) (e : IfExpr) :
    { e' : IfExpr // (∀ (f : Bool), IfExpr.eval f e' = IfExpr.eval (fun (w : ) => (AList.lookup w l).elim (f w) fun (b : Bool) => b) e) e'.normalized = true ve'.vars, AList.lookup v l = none }

    Normalizes the expression at the same time as assigning all variables in e to the literal booleans given by l

    Equations
    Instances For