Skip to content

Commit b5b0d32

Browse files
committed
add DTr to runMono
1 parent 526cab6 commit b5b0d32

3 files changed

Lines changed: 35 additions & 14 deletions

File tree

Auto/Lib/Pos.lean

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,14 +40,14 @@ private theorem ofNat'WFAux (n n' : Nat) : n = n' + 2 → n / 2 < n := by
4040
case hLtK => apply Nat.le_refl
4141

4242
def ofNat'WF (n : Nat) :=
43-
match _ : n with
43+
match h : n with
4444
| 0 => xH
4545
| 1 => xH
4646
| _ + 2 =>
4747
match n % 2 with
4848
| 0 => .xO (ofNat'WF (n / 2))
4949
| _ => .xI (ofNat'WF (n / 2))
50-
decreasing_by simp only [*]; apply ofNat'WFAux _ _ rfl
50+
decreasing_by rw [h]; apply ofNat'WFAux _ _ rfl
5151

5252
def ofNat'WF.inductionOn.{u}
5353
{motive : Nat → Sort u} (x : Nat)

Auto/Tactic.lean

Lines changed: 30 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -380,16 +380,17 @@ def callNative_checker
380380
open LamReif Embedding.Lam in
381381
def callMkMVar_checker
382382
(nonempties : Array REntry) (valids : Array REntry) :
383-
ReifM (MVarId × Expr × LamTerm × Array Nat) := do
383+
ReifM (Array (REntry × DTr) × Array (REntry × DTr) × MVarId × Expr × LamTerm × Nat × Array Nat) := do
384384
let tyVal ← LamReif.getTyVal
385385
let varVal ← LamReif.getVarVal
386386
let lamEVarTy ← LamReif.getLamEVarTy
387387
let nonemptiesWithDTr ← nonempties.mapM (fun re =>
388388
do return (re, ← collectDerivFor re))
389389
let validsWithDTr ← valids.mapM (fun re =>
390390
do return (re, ← collectDerivFor re))
391-
MetaState.runAtMetaM' <| (Lam2DAAF.callMkMVarWithAtomAsFVar nonemptiesWithDTr validsWithDTr).run'
391+
let result ← MetaState.runAtMetaM' <| (Lam2DAAF.callMkMVarWithAtomAsFVar nonemptiesWithDTr validsWithDTr).run'
392392
{ tyVal := tyVal, varVal := varVal, lamEVarTy := lamEVarTy }
393+
return (nonemptiesWithDTr, validsWithDTr, result)
393394

394395
open LamReif Embedding.Lam in
395396
/--
@@ -539,23 +540,39 @@ def evalAuto : Tactic
539540
/--
540541
Run `auto`'s preprocessing and monomorphization to abstract the
541542
problem into an essentially higher-order problem
543+
544+
Input
545+
· `declName?` : The name of the declaration where you're calling `mono` from
546+
· `lemmas` : An array of lemmas that you want to monomorphize. They are meant to
547+
be generated by `collectAllLemmas`
548+
· `inhFacts` : An array of inhabitation lemmas that you want to monomorphize. They
549+
are meant to be generated by `collectAllLemmas`
550+
551+
Return Value
552+
· `e : Expr` : An term of type `False`, which contains one metavariable yet to be assigned
553+
· `id : MVarId` : The ID of the metavariable in `e` yet to be assigned
554+
· `derivs : Array (FVarId × DTr)`
555+
The `DTr`s associated with (monomorphized) lemmas and inhabitation lemmas
556+
in the context of `id`. Using this information you can obtain the
557+
correspondence between monomorphized lemmas and the original lemmas
542558
-/
543559
def runMono
544-
(declName? : Option Name) (lemmas : Array Lemma) (inhFacts : Array Lemma) : MetaM (Expr × MVarId) :=
560+
(declName? : Option Name) (lemmas : Array Lemma) (inhFacts : Array Lemma) :
561+
MetaM (Expr × MVarId × Array (FVarId × DTr)) :=
545562
Meta.withDefault do
546563
traceLemmas `auto.runAuto.printLemmas s!"All lemmas received by {decl_name%}:" lemmas
547564
let lemmas ← rewriteIteCondDecide lemmas
548-
let ((proof, mvarId), _) ← Monomorphization.monomorphize lemmas inhFacts (@id (Reif.ReifM (Expr × MVarId)) do
565+
let ((proof, goalId, derivs), _) ← Monomorphization.monomorphize lemmas inhFacts (@id (Reif.ReifM _) do
549566
let s ← get
550567
let u ← computeMaxLevel s.facts
551568
(reifMAction s.facts s.inhTys s.inds).run' {u := u})
552569
trace[auto.tactic] "Auto found proof of {← Meta.inferType proof}"
553570
trace[auto.tactic.printProof] "{proof}"
554-
return (proof, mvarId)
571+
return (proof, goalId, derivs)
555572
where
556573
reifMAction
557574
(uvalids : Array UMonoFact) (uinhs : Array UMonoFact)
558-
(minds : Array (Array SimpleIndVal)) : LamReif.ReifM (Expr × MVarId) := do
575+
(minds : Array (Array SimpleIndVal)) : LamReif.ReifM (Expr × MVarId × Array (FVarId × DTr)) := do
559576
let exportFacts ← LamReif.reifFacts uvalids
560577
let mut exportFacts := exportFacts.map (Embedding.Lam.REntry.valid [])
561578
let _ ← LamReif.reifInhabitations uinhs
@@ -567,7 +584,8 @@ where
567584
let (exportFacts', _) ← LamReif.preprocess exportFacts exportInds
568585
exportFacts := exportFacts'.append (← LamReif.auxLemmas exportFacts)
569586
-- **Query the dummy prover which creates a metavariable**
570-
let (goalId, proof, proofLamTerm, etoms) ← callMkMVar_checker exportInhs exportFacts
587+
let (nonemptyWithDTrs, validWithDTrs, goalId, proof, proofLamTerm, natoms, etoms) ←
588+
callMkMVar_checker exportInhs exportFacts
571589
LamReif.newAssertion proof (.leaf "by_native::queryNative") proofLamTerm
572590
let etomInstantiated ← LamReif.validOfInstantiateForall (.valid [] proofLamTerm) (etoms.map .etom)
573591
let forallElimed ← LamReif.validOfElimForalls etomInstantiated exportInhs
@@ -576,7 +594,10 @@ where
576594
Reif.setDeclName? declName?
577595
let checker ← LamReif.buildCheckerExprFor contra
578596
let contra ← Meta.mkAppM ``Embedding.Lam.LamThmValid.getFalse #[checker]
579-
return (contra, goalId)
597+
let (_, goalId) ← goalId.introN (natoms + etoms.size)
598+
let (goalCtx, goalId) ← goalId.introN (exportInhs.size + exportFacts.size)
599+
let goalCtxWithDeriv := goalCtx.zip ((nonemptyWithDTrs ++ validWithDTrs).map Prod.snd)
600+
return (contra, goalId, goalCtxWithDeriv)
580601

581602
@[tactic mono]
582603
def evalMono : Tactic
@@ -586,13 +607,12 @@ def evalMono : Tactic
586607
| throwError "{decl_name%} :: Unexpected result after applying Classical.byContradiction"
587608
let (ngoal, absurd) ← MVarId.intro1 nngoal
588609
replaceMainGoal [absurd]
589-
let mvarId ← withMainContext do
610+
let (mvarId, _) ← withMainContext do
590611
let (lemmas, inhFacts) ← collectAllLemmas hints uords (goalBinders.push ngoal)
591612
let declName? ← Elab.Term.getDeclName?
592613
let (proof, mvarId) ← runMono declName? lemmas inhFacts
593614
absurd.assign proof
594615
return mvarId
595-
let (_, mvarId) ← mvarId.intros
596616
replaceMainGoal [mvarId]
597617
| _ => throwUnsupportedSyntax
598618

Auto/Translation/Lam2DAtomAsFVar.lean

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -227,9 +227,10 @@ def callNativeWithAtomAsFVar
227227
trace[auto.lam2D.printProof] "Found proof of {proofLamTerm}\n\n{proof}"
228228
return (proof, proofLamTerm, ⟨usedEtoms⟩, ⟨usedInhs.map Prod.fst⟩, ⟨usedHyps.map Prod.fst⟩))
229229

230+
@[inherit_doc callNativeWithAtomAsFVar]
230231
def callMkMVarWithAtomAsFVar
231232
(nonemptiesWithDTr : Array (REntry × DTr)) (validsWithDTr : Array (REntry × DTr)) :
232-
ExternM (MVarId × Expr × LamTerm × Array Nat) := MetaState.withTemporaryLCtx {} {} <| do
233+
ExternM (MVarId × Expr × LamTerm × Nat × Array Nat) := MetaState.withTemporaryLCtx {} {} <| do
233234
let (ss, ts, lemmas, inhLemmas) ← withAll nonemptiesWithDTr validsWithDTr
234235
let getFid (lem : Lemma) : ExternM FVarId := do
235236
match lem.proof with
@@ -260,6 +261,6 @@ def callMkMVarWithAtomAsFVar
260261
let proof ← Meta.mkLambdaFVars (fvars.map Expr.fvar) (← instantiateMVars (.mvar mProofId))
261262
let proof ← Meta.instantiateLambda proof (atomsToAbstract.map Prod.snd)
262263
return (proof, goalId))
263-
return (goalId, proof, proofLamTerm, etomsToAbstract.map Prod.snd)
264+
return (goalId, proof, proofLamTerm, atomsToAbstract.size, etomsToAbstract.map Prod.snd)
264265

265266
end Auto.Lam2DAAF

0 commit comments

Comments
 (0)