@@ -380,16 +380,17 @@ def callNative_checker
380380open LamReif Embedding.Lam in
381381def 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
394395open 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-/
543559def 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 )
555572where
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]
582603def 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
0 commit comments