@@ -86,7 +86,7 @@ def mkCoordinateEvalAtomsEq (e : Expr) (n : Nat) : OmegaM Expr := do
8686 mkEqTrans eq (← mkEqSymm (mkApp2 (.const ``LinearCombo.coordinate_eval []) n atoms))
8787
8888/-- Construct the linear combination (and its associated proof and new facts) for an atom. -/
89- def mkAtomLinearCombo (e : Expr) : OmegaM (LinearCombo × OmegaM Expr × Std.HashSet Expr) := do
89+ def mkAtomLinearCombo (e : Expr) : OmegaM (LinearCombo × OmegaM Expr × List Expr) := do
9090 let (n, facts) ← lookup e
9191 return ⟨LinearCombo.coordinate n, mkCoordinateEvalAtomsEq e n, facts.getD ∅⟩
9292
@@ -100,7 +100,7 @@ Gives a small (10%) speedup in testing.
100100I tried using a pointer based cache,
101101but there was never enough subexpression sharing to make it effective.
102102-/
103- partial def asLinearCombo (e : Expr) : OmegaM (LinearCombo × OmegaM Expr × Std.HashSet Expr) := do
103+ partial def asLinearCombo (e : Expr) : OmegaM (LinearCombo × OmegaM Expr × List Expr) := do
104104 let cache ← get
105105 match cache.get? e with
106106 | some (lc, prf) =>
@@ -126,7 +126,7 @@ We also transform the expression as we descend into it:
126126* pushing coercions: `↑(x + y)`, `↑(x * y)`, `↑(x / k)`, `↑(x % k)`, `↑k`
127127* unfolding `emod`: `x % k` → `x - x / k`
128128 -/
129- partial def asLinearComboImpl (e : Expr) : OmegaM (LinearCombo × OmegaM Expr × Std.HashSet Expr) := do
129+ partial def asLinearComboImpl (e : Expr) : OmegaM (LinearCombo × OmegaM Expr × List Expr) := do
130130 trace[omega] "processing { e} "
131131 match groundInt? e with
132132 | some i =>
@@ -148,7 +148,7 @@ partial def asLinearComboImpl (e : Expr) : OmegaM (LinearCombo × OmegaM Expr ×
148148 mkEqTrans
149149 (← mkAppM ``Int.add_congr #[← prf₁, ← prf₂])
150150 (← mkEqSymm add_eval)
151- pure (l₁ + l₂, prf, facts₁.union facts₂)
151+ pure (l₁ + l₂, prf, facts₁ ++ facts₂)
152152 | (``HSub.hSub, #[_, _, _, _, e₁, e₂]) => do
153153 let (l₁, prf₁, facts₁) ← asLinearCombo e₁
154154 let (l₂, prf₂, facts₂) ← asLinearCombo e₂
@@ -158,7 +158,7 @@ partial def asLinearComboImpl (e : Expr) : OmegaM (LinearCombo × OmegaM Expr ×
158158 mkEqTrans
159159 (← mkAppM ``Int.sub_congr #[← prf₁, ← prf₂])
160160 (← mkEqSymm sub_eval)
161- pure (l₁ - l₂, prf, facts₁.union facts₂)
161+ pure (l₁ - l₂, prf, facts₁ ++ facts₂)
162162 | (``Neg.neg, #[_, _, e']) => do
163163 let (l, prf, facts) ← asLinearCombo e'
164164 let prf' : OmegaM Expr := do
@@ -184,7 +184,7 @@ partial def asLinearComboImpl (e : Expr) : OmegaM (LinearCombo × OmegaM Expr ×
184184 mkEqTrans
185185 (← mkAppM ``Int.mul_congr #[← xprf, ← yprf])
186186 (← mkEqSymm mul_eval)
187- pure (some (LinearCombo.mul xl yl, prf, xfacts.union yfacts), true )
187+ pure (some (LinearCombo.mul xl yl, prf, xfacts ++ yfacts), true )
188188 else
189189 pure (none, false )
190190 match r? with
@@ -242,15 +242,15 @@ where
242242 Apply a rewrite rule to an expression, and interpret the result as a `LinearCombo`.
243243 (We're not rewriting any subexpressions here, just the top level, for efficiency.)
244244 -/
245- rewrite (lhs rw : Expr) : OmegaM (LinearCombo × OmegaM Expr × Std.HashSet Expr) := do
245+ rewrite (lhs rw : Expr) : OmegaM (LinearCombo × OmegaM Expr × List Expr) := do
246246 trace[omega] "rewriting { lhs} via { rw} : { ← inferType rw} "
247247 match (← inferType rw).eq? with
248248 | some (_, _lhs', rhs) =>
249249 let (lc, prf, facts) ← asLinearCombo rhs
250250 let prf' : OmegaM Expr := do mkEqTrans rw (← prf)
251251 pure (lc, prf', facts)
252252 | none => panic! "Invalid rewrite rule in 'asLinearCombo'"
253- handleNatCast (e i n : Expr) : OmegaM (LinearCombo × OmegaM Expr × Std.HashSet Expr) := do
253+ handleNatCast (e i n : Expr) : OmegaM (LinearCombo × OmegaM Expr × List Expr) := do
254254 match n with
255255 | .fvar h =>
256256 if let some v ← h.getValue? then
@@ -297,7 +297,7 @@ where
297297 | (``Fin.val, #[n, x]) =>
298298 handleFinVal e i n x
299299 | _ => mkAtomLinearCombo e
300- handleFinVal (e i n x : Expr) : OmegaM (LinearCombo × OmegaM Expr × Std.HashSet Expr) := do
300+ handleFinVal (e i n x : Expr) : OmegaM (LinearCombo × OmegaM Expr × List Expr) := do
301301 match x with
302302 | .fvar h =>
303303 if let some v ← h.getValue? then
@@ -343,12 +343,11 @@ We solve equalities as they are discovered, as this often results in an earlier
343343-/
344344def addIntEquality (p : MetaProblem) (h x : Expr) : OmegaM MetaProblem := do
345345 let (lc, prf, facts) ← asLinearCombo x
346- let newFacts : Std.HashSet Expr := facts.fold (init := ∅) fun s e =>
347- if p.processedFacts.contains e then s else s.insert e
346+ let newFacts : List Expr := facts.filter (p.processedFacts.contains · = false )
348347 trace[omega] "Adding proof of { lc} = 0"
349348 pure <|
350349 { p with
351- facts := newFacts.toList ++ p.facts
350+ facts := newFacts ++ p.facts
352351 problem := ← (p.problem.addEquality lc.const lc.coeffs
353352 (some do mkEqTrans (← mkEqSymm (← prf)) h)) |>.solveEqualities }
354353
@@ -359,12 +358,11 @@ We solve equalities as they are discovered, as this often results in an earlier
359358-/
360359def addIntInequality (p : MetaProblem) (h y : Expr) : OmegaM MetaProblem := do
361360 let (lc, prf, facts) ← asLinearCombo y
362- let newFacts : Std.HashSet Expr := facts.fold (init := ∅) fun s e =>
363- if p.processedFacts.contains e then s else s.insert e
361+ let newFacts : List Expr := facts.filter (p.processedFacts.contains · = false )
364362 trace[omega] "Adding proof of { lc} ≥ 0"
365363 pure <|
366364 { p with
367- facts := newFacts.toList ++ p.facts
365+ facts := newFacts ++ p.facts
368366 problem := ← (p.problem.addInequality lc.const lc.coeffs
369367 (some do mkAppM ``le_of_le_of_eq #[h, (← prf)])) |>.solveEqualities }
370368
0 commit comments