11import Lean
2- import Smt
3- import Smt.Real
4- import Lean.Meta.Tactic.Congr
52
3+ import Smt.Preprocess.Basic
64import Smt.Preprocess.BoolAsProp
75import Smt.Preprocess.NatAsInt
86import Smt.Preprocess.RatAsReal
97
10- namespace Smt.Preprocess.SmtTranslate
8+ namespace Smt.Preprocess
119
1210open Lean Meta
1311
@@ -334,7 +332,7 @@ def addNonNegToHypotheses (mv : MVarId) (sortedNatDomainVars : Array Expr) : Met
334332 `Int.toNat_of_nonneg` normalization, generalize away Bool/Rat/Nat locals,
335333 then re-introduce hypotheses and clear the original variables.
336334 -/
337- def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruct.smt_translate traceSmtTranslate do
335+ def smtTranslateCore (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruct.smtTranslate traceSmtTranslate do
338336 trace[debug] m! "initial goal: { mv'} "
339337
340338 let mut mv := mv'
@@ -397,7 +395,7 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
397395 -- For each `x : Rat`, assert a witness equation `x = a / b` with `a b : Int`
398396 for ratVar in sortedRatVars do
399397 let varName ← ratVar.fvarId!.getUserName
400- let divProof ← mkAppOptM `` Rat.cast_eq_div_int #[ratVar]
398+ let divProof ← mkAppOptM `Rat.cast_eq_div_int #[ratVar]
401399 let divType ← inferType divProof
402400 mv ← mv.assert (varName.appendAfter "_rat" ) divType divProof
403401 let (fVarId, mv') ← mv.intro (varName.appendAfter "_rat" )
@@ -669,7 +667,7 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
669667 let ns := [
670668 ``Bool.and_eq_true, ``Bool.or_eq_true, ``Bool.not_eq_true2, ``Bool.iff_eq_true, ``Bool.xor_eq_true, ``Bool.eq_eq_true, ``Bool.eq_self, ``Bool.true_eq_false, ``Bool.false_eq_true, ``Prop .eq_true, ``Prop .eq_false,
671669
672- ``Int.natCast_add, ``Int.natCast_sub2, ``Int.natCast_mul, ``Int.natCast_ediv, ``Int.natCast_emod, ``Int.ofNat_eq, ``Int.ofNat_le2, ``Int.ofNat_lt2, ``Int.ofNat_ge, ``Int.ofNat_gt, ``Int.ofNat_ne, ``Nat.cast_zero, ``Nat.cast_one , ``Nat.cast_ofNat, `` Int.natSub.eq_1 , ``Int.toNat_of_nonneg , ``Int.ofNat_eq_coe ,
670+ ``Int.natCast_add, ``Int.natCast_sub2, ``Int.natCast_mul, ``Int.natCast_ediv, ``Int.natCast_emod, ``Int.ofNat_eq, ``Int.ofNat_le2, ``Int.ofNat_lt2, ``Int.ofNat_ge, ``Int.ofNat_gt, ``Int.ofNat_ne, ``Int.natSub.eq_1 , ``Int.toNat_of_nonneg , ``Int.ofNat_eq_coe , ``Int.cast_ofNat_Int ,
673671
674672 ``Rat.cast_add, ``Rat.cast_sub, ``Rat.cast_mul, ``Rat.cast_div, ``Rat.cast_neg, ``Rat.cast_inv, ``Rat.cast_eq, ``Rat.cast_le, ``Rat.cast_lt, ``Rat.cast_ge, ``Rat.cast_gt, ``Rat.cast_ne, ``Rat.cast_zero, ``Rat.cast_one, ``Rat.cast_ofNat,
675673 ]
@@ -729,7 +727,7 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
729727
730728 for ratVar in sortedRatVars do
731729 let varName ← ratVar.fvarId!.getUserName
732- let castExpr ← mkAppOptM `` Rat.cast #[mkConst ` `Real, none, ratVar]
730+ let castExpr ← mkAppOptM `Rat.cast #[mkConst `Real, none, ratVar]
733731 (_, mv) ← mv.generalize #[{ expr := castExpr, xName? := varName }]
734732
735733 for natVar in sortedNatVars do
@@ -751,14 +749,10 @@ def smt_translate (mv' : MVarId) : MetaM MVarId := withTraceNode `smt.reconstruc
751749
752750 return mv
753751
754- namespace Tactic
752+ def smtTranslate (mv : MVarId) : MetaM Result := do
753+ let mv ← smtTranslateCore mv
754+ trace[smt.preprocess] m! "final translated goal: { mv} "
755+ let hs ← mv.withContext (return (← getPropHyps).map Expr.fvar)
756+ return { map := {}, hs, mv }
755757
756- syntax (name := smt_translate) "smt_translate" : tactic
757-
758- open Lean.Elab Tactic in
759- @ [tactic smt_translate] def evalSmtTranslate : Tactic := fun _ => withMainContext do
760- let mv ← Tactic.getMainGoal
761- let mv ← SmtTranslate.smt_translate mv
762- replaceMainGoal [mv]
763-
764- end Tactic
758+ end Smt.Preprocess
0 commit comments