@@ -7,6 +7,7 @@ import Batteries.Tactic.Exact
77import Batteries.Tactic.Init
88import Mathlib.Logic.Basic
99import Mathlib.Util.AtomM
10+ import Std.Data.TreeMap
1011import Qq
1112
1213/-!
@@ -80,6 +81,8 @@ propositional logic, intuitionistic logic, decision procedure
8081-/
8182
8283
84+ open Std (TreeMap TreeSet)
85+
8386namespace Mathlib.Tactic.ITauto
8487
8588/-- Different propositional constructors that are variants of "and" for the purposes of the
@@ -338,11 +341,11 @@ def Proof.check : Lean.NameMap IProp → Proof → Option IProp
338341@[inline] def freshName : StateM Nat Name := fun n => (Name.mkSimple s! "h{ n} " , n + 1 )
339342
340343/-- The context during proof search is a map from propositions to proof values. -/
341- def Context := Lean.RBMap IProp Proof IProp.cmp
344+ abbrev Context := TreeMap IProp Proof IProp.cmp
342345
343346/-- Debug printer for the context. -/
344347def Context.format (Γ : Context) : Std.Format :=
345- Γ.fold (init := "" ) fun f P p => P.format ++ " := " ++ p.format ++ ",\n " ++ f
348+ Γ.foldl (init := "" ) fun f P p => P.format ++ " := " ++ p.format ++ ",\n " ++ f
346349
347350instance : Std.ToFormat Context := ⟨Context.format⟩
348351
@@ -406,12 +409,12 @@ prove `A₁ → A₂`, which can be written `A₂ → C, A₁ ⊢ A₂` (where w
406409potentially many implications to split like this, and we have to try all of them if we want to be
407410complete. -/
408411partial def search (Γ : Context) (B : IProp) : StateM Nat (Bool × Proof) := do
409- if let some p := Γ.find? B then return (true , p)
412+ if let some p := Γ[B]? then return (true , p)
410413 fun n =>
411- let search₁ := Γ.fold (init := none) fun r A p => do
414+ let search₁ := Γ.foldl (init := none) fun r A p => do
412415 if let some r := r then return r
413416 let .imp A' C := A | none
414- if let some q := Γ.find? A' then
417+ if let some q := Γ[A']? then
415418 isOk <| Context.withAdd (Γ.erase A) C (p.app q) B prove n
416419 else
417420 let .imp A₁ A₂ := A' | none
@@ -454,7 +457,7 @@ partial def prove (Γ : Context) (B : IProp) : StateM Nat (Bool × Proof) :=
454457 let (ok, p) ← prove Γ A
455458 mapProof (p.andIntro ak) <$> whenOk ok B (prove Γ B)
456459 | B =>
457- Γ.fold
460+ Γ.foldl
458461 (init := fun found Γ => bif found then prove Γ B else search Γ B)
459462 (f := fun IH A p found Γ => do
460463 if let .or A₁ A₂ := A then
@@ -639,11 +642,11 @@ partial def applyProof (g : MVarId) (Γ : NameMap Expr) (p : Proof) : MetaM Unit
639642def itautoCore (g : MVarId)
640643 (useDec useClassical : Bool) (extraDec : Array Expr) : MetaM Unit := do
641644 AtomM.run (← getTransparency) do
642- let mut hs := mkRBMap ..
645+ let mut hs := mkNameMap Expr
643646 let t ← g.getType
644647 let (g, t) ← if ← isProp t then pure (g, ← reify t) else pure (← g.exfalso, .false )
645- let mut Γ : Except (IProp → Proof) ITauto.Context := .ok (mkRBMap ..)
646- let mut decs := mkRBMap ..
648+ let mut Γ : Except (IProp → Proof) ITauto.Context := .ok TreeMap.empty
649+ let mut decs := TreeMap.empty
647650 for ldecl in ← getLCtx do
648651 if !ldecl.isImplementationDetail then
649652 let e := ldecl.type
@@ -658,7 +661,7 @@ def itautoCore (g : MVarId)
658661 if useDec then
659662 let A ← reify p
660663 decs := decs.insert A (false , Expr.fvar ldecl.fvarId)
661- let addDec (force : Bool) (decs : RBMap IProp (Bool × Expr) IProp.cmp) (e : Q(Prop )) := do
664+ let addDec (force : Bool) (decs : TreeMap IProp (Bool × Expr) IProp.cmp) (e : Q(Prop )) := do
662665 let A ← reify e
663666 let dec_e := q(Decidable $e)
664667 let res ← trySynthInstance q(Decidable $e)
@@ -669,9 +672,9 @@ def itautoCore (g : MVarId)
669672 pure (decs.insert A (match res with | .some e => (false , e) | _ => (true , e)))
670673 decs ← extraDec.foldlM (addDec true ) decs
671674 if useDec then
672- let mut decided := mkRBTree Nat compare
675+ let mut decided := TreeSet.empty (cmp := compare)
673676 if let .ok Γ' := Γ then
674- decided := Γ'.fold (init := decided) fun m p _ =>
677+ decided := Γ'.foldl (init := decided) fun m p _ =>
675678 match p with
676679 | .var i => m.insert i
677680 | .not (.var i) => m.insert i
0 commit comments