Dataset Viewer
Auto-converted to Parquet Duplicate
fact
stringlengths
4
7.31k
type
stringclasses
10 values
library
stringclasses
3 values
imports
listlengths
0
35
filename
stringclasses
124 values
symbolic_name
stringlengths
1
63
docstring
stringclasses
1 value
runDuperOnTPTP(fileName : String) (formulas : List (Expr × Expr × Array Name × Bool)) (instanceMaxHeartbeats : Nat) : MetaM Unit := do let generateDatatypeExhaustivenessFacts ← getCollectDataTypesM let state ← withNewMCtxDepth do let formulas ← unfoldDefinitions (formulas.map (fun (e, proof, paramNames, isFromGoal) => (e, proof, paramNames, isFromGoal, true))) /- `collectAssumptions` should not be wrapped by `withoutModifyingCoreEnv` because new definitional equations might be generated during `collectAssumptions` -/ withoutModifyingCoreEnv <| do -- Add the constant `skolemSorry` to the environment let skSorryName ← addSkolemSorry let (_, state) ← ProverM.runWithExprs (ctx := {startTime := ← IO.monoMsNow, initHeartbeats := ← IO.getNumHeartbeats}) (s := {instanceMaxHeartbeats := instanceMaxHeartbeats, skolemSorryName := skSorryName}) (ProverM.saturateNoPreprocessingClausification generateDatatypeExhaustivenessFacts) formulas pure state match state.result with | Result.contradiction => IO.println s!"SZS status Theorem for {fileName}" | Result.saturated => IO.println s!"SZS status GaveUp for {fileName}" | Result.unknown => IO.println s!"SZS status Timeout for {fileName}"
def
root
[ "import Duper", "import Duper.TPTP", "import Duper.TPTPParser.PrattParser" ]
Main.lean
runDuperOnTPTP
run(path : String) (_github : Bool) : MetaM Unit := do let prop := mkSort levelZero let type := mkSort levelOne let sortu := mkSort (.param `u) let sortu1 := mkSort (.param `u1) let sortu2 := mkSort (.param `u2) addDecl (.axiomDecl {name := `Nat, levelParams := [], type := type, isUnsafe := false}) addDecl (.axiomDecl {name := `Iota, levelParams := [], type := type, isUnsafe := false}) addDecl (.axiomDecl {name := `Bool, levelParams := [], type := type, isUnsafe := false}) addDecl (.axiomDecl {name := `Bool.false, levelParams := [], type := mkConst `Bool, isUnsafe := false}) addDecl (.axiomDecl {name := `sorryAx, levelParams := [`u], type := mkForall `α .default sortu $ mkForall `synthetic .default (mkConst `Bool) $ mkBVar 1, isUnsafe := false}) addDecl (.axiomDecl {name := `Eq, levelParams := [`u], type := mkForall `α .implicit sortu $ ← mkArrow (mkBVar 0) $ ← mkArrow (mkBVar 1) $ prop, isUnsafe := false}) addDecl (.axiomDecl {name := `Ne, levelParams := [`u], type := mkForall `α .implicit sortu $ ← mkArrow (mkBVar 0) $ ← mkArrow (mkBVar 1) $ prop, isUnsafe := false}) addDecl (.axiomDecl {name := `True, levelParams := [], type := prop, isUnsafe := false}) addDecl (.axiomDecl {name := `False, levelParams := [], type := prop, isUnsafe := false}) addDecl (.axiomDecl {name := `Or, levelParams := [], type := ← mkArrow prop (← mkArrow prop prop), isUnsafe := false}) addDecl (.axiomDecl {name := `And, levelParams := [], type := ← mkArrow prop (← mkArrow prop prop), isUnsafe := false}) addDecl (.axiomDecl {name := `Iff, levelParams := [], type := ← mkArrow prop (← mkArrow prop prop), isUnsafe := false}) addDecl (.axiomDecl {name := `Not, levelParams := [], type := ← mkArrow prop prop, isUnsafe := false}) addDecl (.axiomDecl {name := `Exists, levelParams := [`u], type := mkForall `α .implicit sortu $ ← mkArrow (← mkArrow (mkBVar 0) prop) prop, isUnsafe := false}) addDecl (.axiomDecl {name := `Duper.Skolem.some, levelParams := [`u], type := mkForall `α .implicit sortu $ ← mkArrow (← mkArrow (mkBVar 0) prop) $ ← mkArrow (mkBVar 1) (mkBVar 2), isUnsafe := false}) addDecl (.axiomDecl {name := `Nonempty, levelParams := [`u], type := mkForall `α .default sortu prop, isUnsafe := false}) addDecl (.axiomDecl { name := `Eq.ndrec, levelParams := [`u1, `u2], type := mkForall `α .implicit sortu2 $ mkForall `a .implicit (.bvar 0) $ mkForall `motive .implicit (mkForall `x .default (.bvar 1) sortu1) $ mkForall `m .default (mkApp (.bvar 0) (.bvar 1)) $ mkForall `b .implicit (.bvar 3) $
def
root
[ "import Duper", "import Duper.TPTP", "import Duper.TPTPParser.PrattParser" ]
Main.lean
run
main: List String → IO UInt32 := fun args => do if args.length == 0 then println! "Please provide problem file." return 1 else let env ← mkEmptyEnvironment let github := (args.length > 1 && args[1]! == "--github") let maxHeartbeats := if github then 50 * 1000 * 1000 else 0 let _ ← Meta.MetaM.toIO (ctxCore := {fileName := "none", fileMap := .ofString "", maxRecDepth := 10000, maxHeartbeats := maxHeartbeats}) (sCore := {env}) (ctx := {}) (s := {}) (run args[0]! github) return 0
def
root
[ "import Duper", "import Duper.TPTP", "import Duper.TPTPParser.PrattParser" ]
Main.lean
main
backwardSimpRules: ProverM (Array BackwardSimpRule) := do let subsumptionTrie ← getSubsumptionTrie return #[ (backwardDemodulation (← getDemodMainPremiseIdx)).toBackwardSimpRule, (backwardClauseSubsumption subsumptionTrie).toBackwardSimpRule, (backwardEqualitySubsumption subsumptionTrie).toBackwardSimpRule, (backwardContextualLiteralCutting subsumptionTrie).toBackwardSimpRule, (backwardPositiveSimplifyReflect subsumptionTrie).toBackwardSimpRule, (backwardNegativeSimplifyReflect subsumptionTrie).toBackwardSimpRule ] /-- Uses the givenClause to attempt to simplify other clauses in the active set. For each clause that backwardSimplify is able to produce a simplification for, backwardSimplify removes the clause adds any newly simplified clauses to the passive set. Additionally, for each clause removed from the active set in this way, all descendents of said clause should also be removed from the current state's allClauses and passiveSet -/
def
Duper
[ "import Duper.ProverM", "import Duper.Simp", "import Duper.Rules.ClauseSubsumption", "import Duper.Rules.ContextualLiteralCutting", "import Duper.Rules.Demodulation", "import Duper.Rules.EqualitySubsumption", "import Duper.Rules.SimplifyReflect" ]
Duper/BackwardSimplification.lean
backwardSimpRules
backwardSimplify(givenClause : Clause) : ProverM Unit := do trace[duper.prover.saturate] "backward simplify with {givenClause}" let backwardSimpRules ← backwardSimpRules for i in [0 : backwardSimpRules.size] do let simpRule := backwardSimpRules[i]! simpRule givenClause
def
Duper
[ "import Duper.ProverM", "import Duper.Simp", "import Duper.Rules.ClauseSubsumption", "import Duper.Rules.ContextualLiteralCutting", "import Duper.Rules.Demodulation", "import Duper.Rules.EqualitySubsumption", "import Duper.Rules.SimplifyReflect" ]
Duper/BackwardSimplification.lean
backwardSimplify
Litwhere sign : Bool lvl : Level ty : Expr lhs : Expr rhs : Expr deriving Inhabited, BEq, Hashable
structure
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
Lit
LitSide| lhs | rhs deriving Inhabited, BEq, Hashable
inductive
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
LitSide
Lit.toString(l : Lit) := ToString.toString l.lhs ++ if l.sign then " = " else " ≠ " ++ ToString.toString l.rhs
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
Lit.toString
LitSide.format(ls : LitSide) : MessageData := match ls with | lhs => m!"lhs" | rhs => m!"rhs"
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
LitSide.format
toggleSide(side : LitSide) : LitSide := match side with | LitSide.lhs => LitSide.rhs | LitSide.rhs => LitSide.lhs
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
toggleSide
LitPoswhere side : LitSide pos : ExprPos deriving Inhabited, BEq, Hashable
structure
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
LitPos
toExpr(lit : Lit) : Expr := if lit.sign then mkApp3 (mkConst ``Eq [lit.lvl]) lit.ty lit.lhs lit.rhs else mkApp3 (mkConst ``Ne [lit.lvl]) lit.ty lit.lhs lit.rhs
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
toExpr
fromSingleExpr(e : Expr) (sign := true) : Lit := Lit.mk (sign := true) (lvl := levelOne) (ty := mkSort levelZero) (lhs := Expr.consumeMData e) (rhs := if sign then mkConst ``True else mkConst ``False)
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
fromSingleExpr
fromExpr: Expr → Lit | .app (.app (.app (.const ``Eq lvl) ty) lhs) rhs => ⟨true, lvl[0]!, ty, lhs, rhs⟩ | .app (.app (.app (.const ``Ne lvl) ty) lhs) rhs => ⟨false, lvl[0]!, ty, lhs, rhs⟩ | e@(_) => dbg_trace "Lit.fromExpr :: Unexpected Expression: {e}"; Lit.fromSingleExpr e
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
fromExpr
map(f : Expr → Expr) (l : Lit) := -- Should we really map into `ty`? {l with ty := f l.ty, lhs := f l.lhs, rhs := f l.rhs}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
map
instantiateLevelParamsArray(l : Lit) (paramNames : Array Name) (levels : Array Level) := {l with lvl := l.lvl.instantiateParams paramNames.toList levels.toList ty := l.ty.instantiateLevelParamsArray paramNames levels lhs := l.lhs.instantiateLevelParamsArray paramNames levels rhs := l.rhs.instantiateLevelParamsArray paramNames levels}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
instantiateLevelParamsArray
mapWithPos(f : Expr → Expr × Array ExprPos) (l : Lit) := let (l', lposes) := f l.lhs let (r', rposes) := f l.rhs -- Does not map into `ty` let lit' := {l with lhs := l', rhs := r'} let lp' := lposes.map (fun p => LitPos.mk .lhs p) let rp' := rposes.map (fun p => LitPos.mk .rhs p) (lit', lp' ++ rp')
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
mapWithPos
mapMWithPos[Monad m] [MonadLiftT MetaM m] (f : Expr → m (Expr × Array ExprPos)) (l : Lit) : m (Lit × Array LitPos) := do let (l', lposes) ← f l.lhs let (r', rposes) ← f l.rhs -- Does not map into `ty` let lit' := {l with lhs := l', rhs := r'} let lp' := lposes.map (fun p => LitPos.mk .lhs p) let rp' := rposes.map (fun p => LitPos.mk .rhs p) return (lit', lp' ++ rp')
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
mapMWithPos
mapByPos(f : Expr → Array ExprPos → Expr) (l : Lit) (poses : Array LitPos) := Id.run <| do let mut lposes := #[] let mut rposes := #[] for ⟨side, pos⟩ in poses do if side == .lhs then lposes := lposes.push pos else rposes := rposes.push pos -- Does not map into `ty` let l' := f l.lhs lposes let r' := f l.rhs rposes return {l with lhs := l', rhs := r'}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
mapByPos
mapMByPos[Monad m] [MonadLiftT MetaM m] (f : Expr → Array ExprPos → m Expr) (l : Lit) (poses : Array LitPos) : m Lit := do let mut lposes := #[] let mut rposes := #[] for ⟨side, pos⟩ in poses do if side == .lhs then lposes := lposes.push pos else rposes := rposes.push pos -- Does not map into `ty` let l' ← f l.lhs lposes let r' ← f l.rhs rposes return {l with lhs := l', rhs := r'}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
mapMByPos
mapM{m : Type → Type w} [Monad m] (f : Expr → m Expr) (l : Lit) : m Lit := do return {l with ty := ← f l.ty, lhs := ← f l.lhs, rhs := ← f l.rhs}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
mapM
fold{α : Type v} (f : α → Expr → α) (init : α) (l : Lit) : α := f (f init l.lhs) l.rhs
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
fold
foldWithTypeM{β : Type v} {m : Type v → Type w} [Monad m] (f : β → Expr → m β) (init : β) (l : Lit) : m β := do f (← f (← f init l.ty) l.lhs) l.rhs
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
foldWithTypeM
foldM{β : Type v} {m : Type v → Type w} [Monad m] (f : β → Expr → LitPos → m β) (init : β) (l : Lit) : m β := do f (← f init l.lhs ⟨LitSide.lhs, ExprPos.empty⟩) l.rhs ⟨LitSide.rhs, ExprPos.empty⟩
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
foldM
foldGreenM{β : Type} [Monad m] [MonadLiftT MetaM m] (f : β → Expr → LitPos → m β) (init : β) (l : Lit) : m β := do let fLhs := fun acc e p => f acc e ⟨LitSide.lhs, p⟩ let fRhs := fun acc e p => f acc e ⟨LitSide.rhs, p⟩ l.rhs.foldGreenM fRhs (← l.lhs.foldGreenM fLhs init)
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
foldGreenM
getAtPos! [Monad m] [MonadLiftT MetaM m] (l : Lit) (pos : LitPos) : m Expr := match pos.side with | LitSide.lhs => l.lhs.getAtPos! pos.pos | LitSide.rhs => l.rhs.getAtPos! pos.pos
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
getAtPos
replaceAtPos? [Monad m] [MonadLiftT MetaM m] (l : Lit) (pos : LitPos) (replacement : Expr) : m (Option Lit) := do match pos.side with | LitSide.lhs => match ← l.lhs.replaceAtPos? pos.pos replacement with | some newLhs => return some {l with lhs := newLhs} | none => return none | LitSide.rhs => match ← l.rhs.replaceAtPos? pos.pos replacement with | some newRhs => return some {l with rhs := newRhs} | none => return none
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
replaceAtPos
replaceAtPosUpdateType? (l : Lit) (pos : LitPos) (replacement : Expr) : MetaM (Option Lit) := do let repPos ← replaceAtPos! l pos replacement try let ty ← Meta.inferType repPos.lhs let sort ← Meta.inferType ty let sortReduced ← Meta.reduce sort false false true if ! sortReduced.isSort then trace[Meta.debug] "replaceAtPosUpdateType? :: {sortReduced} is not a sort" return none let lvl := sortReduced.sortLevel! let res : Lit := {repPos with ty := ty, lvl := lvl} if ← Meta.isTypeCorrect res.toExpr then return some res else return none catch _ => return none /-- This function acts as Meta.kabstract except that it takes a LitPos rather than Occurrences and expects the given expression to consist only of applications up to the given ExprPos. Additionally, since the exact position is given, we don't need to pass in Meta.kabstract's second argument p -/
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
replaceAtPosUpdateType
abstractAtPos! (l : Lit) (pos : LitPos) : MetaM Lit := do match pos.side with | LitSide.lhs => return {l with lhs := ← l.lhs.abstractAtPos! pos.pos} | LitSide.rhs => return {l with rhs := ← l.rhs.abstractAtPos! pos.pos}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
abstractAtPos
symm(l : Lit) : Lit := {l with lhs := l.rhs rhs := l.lhs}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
symm
makeLhs(lit : Lit) (side : LitSide) := match side with | LitSide.lhs => lit | LitSide.rhs => lit.symm
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
makeLhs
getSide(lit : Lit) (side : LitSide) := match side with | LitSide.lhs => lit.lhs | LitSide.rhs => lit.rhs
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
getSide
getOtherSide(lit : Lit) (side : LitSide) := getSide lit (LitSide.toggleSide side)
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
getOtherSide
compare(ord : Expr → Expr → Bool → MetaM Comparison) (alreadyReduced : Bool) (l₁ l₂ : Lit) : MetaM Comparison := do let l₁ ← if alreadyReduced then pure l₁ else l₁.mapM (fun e => betaEtaReduceInstMVars e) let l₂ ← if alreadyReduced then pure l₂ else l₂.mapM (fun e => betaEtaReduceInstMVars e) let cll ← ord l₁.lhs l₂.lhs true if cll == Incomparable then return Incomparable let clr ← ord l₁.lhs l₂.rhs true if clr == Incomparable then return Incomparable let crl ← ord l₁.rhs l₂.lhs true if crl == Incomparable then return Incomparable let crr ← ord l₁.rhs l₂.rhs true if crr == Incomparable then return Incomparable match cll, clr, crl, crr with | GreaterThan, GreaterThan, _, _ => return GreaterThan | _, _, GreaterThan, GreaterThan => return GreaterThan | LessThan, _, LessThan, _ => return LessThan | _, LessThan, _, LessThan => return LessThan | GreaterThan, _, _, GreaterThan => return GreaterThan | LessThan, _, _, LessThan => return LessThan | _, GreaterThan, GreaterThan, _ => return GreaterThan | _, LessThan, LessThan, _ => return LessThan | _, _, _, _ => do let csign := match l₁.sign, l₂.sign with
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
compare
Clausewhere (paramNames : Array Name) (bVarTypes : Array Expr) (lits : Array Lit) deriving Inhabited, BEq, Hashable
structure
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
Clause
ClausePosextends LitPos where lit : Nat deriving Inhabited, BEq, Hashable
structure
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
ClausePos
ClausePos.format(pos : ClausePos) : MessageData := m!"\{lit: {pos.lit}, side: {pos.side}, ExprPos: {pos.pos}}"
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
ClausePos.format
empty: Clause := ⟨#[], #[], #[]⟩
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
empty
litsToExpr: List Lit → Expr | [] => mkConst ``False | [l] => l.toExpr | l :: ls => mkApp2 (mkConst ``Or) l.toExpr (litsToExpr ls)
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
litsToExpr
mapMUpdateType[instMonad : Monad m] (c : Clause) (f : Expr → m Expr) := do let bVarTypes ← c.bVarTypes.mapM f let lits ← c.lits.mapM (Lit.mapM f) return {c with bVarTypes := bVarTypes, lits := lits}
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
mapMUpdateType
toForallExpr(c : Clause) : Expr := c.bVarTypes.foldr (fun ty b => mkForall Name.anonymous BinderInfo.default ty b) c.toExpr
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
toForallExpr
toLambdaExpr(c : Clause) : Expr := c.bVarTypes.foldr (fun ty b => mkLambda Name.anonymous BinderInfo.default ty b) c.toExpr
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
toLambdaExpr
fromForallExpr(paramNames : Array Name) (e : Expr) : Clause := let (bvarTypes, e) := deForall e ⟨paramNames, bvarTypes.toArray, (litsFromExpr e).toArray⟩ where deForall : Expr → List Expr × Expr | .forallE _ ty body _ => let (l, e) := deForall body; (ty::l, e) | e@(_) => ([], e) litsFromExpr : Expr → List Lit | .app (.app (.const ``Or _) litexpr) other => Lit.fromExpr litexpr :: litsFromExpr other | .const ``False _ => [] | e@(_) => [Lit.fromExpr e]
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
fromForallExpr
weight(c : Clause) : Nat := c.lits.foldl (fun acc lit => acc + lit.lhs.weight + lit.rhs.weight) 0 /-- Determines the precedence clause `c` should have for clause selection. Lower values indicate higher precedence -/
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
weight
selectionPrecedence(c : Clause) (goalDistance : Nat) : Nat := /- TODO: Experiment with different coefficients for c.weight and goalDistance. Zipperposition's goal_oriented clause selection function has (among other heuristics) c.weight given a coefficient of 4 and goalDistance given a coefficient of 1 (meaning the returned precedence would be `4 * c.weight + goalDistance`) -/ c.weight + goalDistance
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
selectionPrecedence
ClauseAndClausePos.format(c : Clause × ClausePos) : MessageData := m!"({c.1}, {c.2})"
def
Duper
[ "import Lean", "import Duper.Util.Misc", "import Duper.Expr", "import Duper.Order" ]
Duper/Clause.lean
ClauseAndClausePos.format
kFair:= 70
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
kFair
kBest:= 3
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
kBest
kHighest:= 10 register_option forceProbeRetry : Nat := { defValue := 500 descr := "Iteration limit for forceProbe" }
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
kHighest
getForceProbeRetry(opts : Options) : Nat := forceProbeRetry.get opts
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
getForceProbeRetry
logForceProbeRetry(max : Nat) : CoreM Unit := do let msg := s!"forceProbe exceeded iteration limit {max}" logInfo msg register_option kStep : Nat := { defValue := 40 descr := "Maximum steps a unification problem can take before it's postponed" } -- Clause Streams -- The first `Clause` is the (simplified)GivenClause -- The second `Clause` is the conclusion
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
logForceProbeRetry
ClauseProof:= Clause × Clause × RuleM.Proof
abbrev
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ClauseProof
ClauseStream.takeAsProverM(cs : ClauseStream) : ProverM (Option ((Option ClauseProof) × ClauseStream)) := do -- No more unification problem left if cs.ug.isEmpty then return none let (opu, ug') ← cs.ug.takeWithRetry (kStep.get (← getOptions)) if let some u := opu then let res ← ProverM.runRuleM <| do -- set `mctx` as the mctx of the unification problem setMCtx u.mctx cs.postUnification if let some clauseProof := res then return some ((cs.simplifiedGivenClause, clauseProof), {cs with ug := ug'}) else return some (none, {cs with ug := ug'}) else if ug'.isEmpty then return none else return some (none, {cs with ug := ug'})
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ClauseStream.takeAsProverM
penalty(c : Clause) : ProverM Nat := pure 1
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
penalty
updateWeight(α? : Option ClauseProof) (weight : Nat) (nProbed : Nat) : ProverM Nat := do if let some (clause, _) := α? then return weight + (← penalty clause) * Nat.max 1 (nProbed - 64) else return weight + Nat.max 2 (nProbed - 16) /-- Following `Making Higher-Order Superposition Work`. Extract an `Option Clause` from the stream. Add the rest of the stream to the heap. -/
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
updateWeight
ClauseStreamHeap.extractClause{σ} [OptionMStream ProverM σ ClauseProof] (Q : ClauseStreamHeap σ) (nProbed : Nat) (precs : Array Nat) (s : σ) : ProverM (Option ClauseProof × ClauseStreamHeap σ) := do have : Inhabited σ := ⟨s⟩ let next? ← MStream.next? s if let some (α?, stream') := next? then -- If this stream is not empty, extract clause from the -- stream and add it back to the heap let weight₀ := precs[0]! let weight ← updateWeight α? weight₀ nProbed let precs' := precs.set! 0 weight let Q' := Q.insertWithNProbed stream' precs' (nProbed + 1) return (α?, Q') else -- If this stream is already empty, then do nothing return (none, Q)
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ClauseStreamHeap.extractClause
ClauseStreamHeap.heuristicProbe{σ} [OptionMStream ProverM σ ClauseProof] (Q : ClauseStreamHeap σ) : ProverM (Array ClauseProof × ClauseStreamHeap σ) := do let mut collectedClauses := #[] let mut highestStream := #[] let mut Q := Q for _ in List.range kHighest do let res := Q.deleteMinWithNProbed 0 if let some (str, Q') := res then highestStream := highestStream.push str Q := Q' else break for (nProbed, precs, stream) in highestStream do let (mc, Q') ← ClauseStreamHeap.extractClause Q nProbed precs stream if let some mc := mc then collectedClauses := collectedClauses.push mc Q := Q' return (collectedClauses, Q)
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ClauseStreamHeap.heuristicProbe
ClauseStreamHeap.fairProbe{σ} [OptionMStream ProverM σ ClauseProof] (nOldest : Nat) (Q : ClauseStreamHeap σ) : ProverM (Array ClauseProof × ClauseStreamHeap σ) := do let mut collectedClauses := #[] let mut oldestStream := #[] let mut Q := Q for _ in List.range nOldest do -- Delete min from age heap let res := Q.deleteMinWithNProbed 1 if let some (str, Q') := res then oldestStream := oldestStream.push str Q := Q' else break for (nProbed, precs, stream) in oldestStream do let (mc, Q') ← ClauseStreamHeap.extractClause Q nProbed precs stream if let some mc := mc then collectedClauses := collectedClauses.push mc Q := Q' return (collectedClauses, Q) /-- Here `c` is `simplifiedGivenClause`. This function is responsible for adding results of inference rules to the passive set. -/
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ClauseStreamHeap.fairProbe
ProverM.postProcessInferenceResult(cp : ClauseProof) : ProverM Unit := do let (given, c, proof) := cp let allClauses ← getAllClauses let parentClauseInfoOpts ← proof.parents.mapM (fun p => match allClauses.get? p.clause with | some pi => pure pi | none => throwError "ProverM.postProcessInferenceResult: Unable to find parent clause {p.clause.toForallExpr}") -- c's generation number is one greater than the sum of its parents generation numbers let generationNumber := parentClauseInfoOpts.foldl (fun acc parentInfo => acc + parentInfo.generationNumber) 1 -- c's goalDistance is at most maxGoalDistance and is otherwise one greater than the distance of the parent closest to the goal let goalDistance := parentClauseInfoOpts.foldl (fun acc parentInfo => Nat.min acc (parentInfo.goalDistance + 1)) maxGoalDistance match ← immediateSimplification given c with | some subsumingClause => -- subsumingClause subsumes c so we can remove c and only need to add subsumingClause removeClause given [subsumingClause] if c == subsumingClause then addNewToPassive c proof goalDistance generationNumber (proof.parents.map (fun p => p.clause)) else throwError "Unable to find {subsumingClause} in resultClauses" | none => -- No result clause subsumes c, so add each result clause to the passive set addNewToPassive c proof goalDistance generationNumber (proof.parents.map (fun p => p.clause))
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ProverM.postProcessInferenceResult
ProverM.performInferences(rules : List (Clause → MClause → Nat → RuleM (Array ClauseStream))) (given : Clause) : ProverM Unit := do trace[duper.prover.saturate] "perform inference with given clause {given}" let mut cs := #[] let cInfo ← getClauseInfo! given let cNum := cInfo.number for rule in rules do let curStreams ← runRuleM do let c ← loadClause given rule given c cNum cs := cs.append curStreams let mut Q ← getQStreamSet for stream in cs do let (mc, Q') ← Q.extractClause 0 #[0, Q.nextId] stream Q := Q' if let some clauseProof := mc then postProcessInferenceResult clauseProof setQStreamSet Q -- Run probe in ProverM -- Take clause and proof from the stream, and run `postProcessInferenceResult`
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ProverM.performInferences
ProverM.runProbe(probe : ClauseStreamHeap ClauseStream → ProverM (Array ClauseProof × ClauseStreamHeap ClauseStream)) := do let Q ← getQStreamSet let (arrcp, Q') ← probe Q setQStreamSet Q' let _ ← arrcp.mapM ProverM.postProcessInferenceResult /-- We have to repeatedly call `runProbe` and test `(← getPassiveSet).isEmpty` If we return immediately when `fairProbe` yields a nonempty list of clauses, it is possible that all of these clauses are redundant and `postProcessInferenceResult` will remove all of them, which will cause `saturate` to think that the prover has saturated. -/
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ProverM.runProbe
ProverM.runForceProbe: ProverM Unit := do let maxIter := getForceProbeRetry (← getOptions) let mut fpiter := 0 while (← getQStreamSet).size != 0 ∧ (← getPassiveSet).isEmpty do runProbe (ClauseStreamHeap.fairProbe (← getQStreamSet).size) fpiter := fpiter + 1 if fpiter >= maxIter then logForceProbeRetry maxIter break
def
Duper
[ "import Batteries.Data.BinomialHeap", "import Duper.Util.IdStrategyHeap", "import Duper.Clause", "import Duper.DUnif.UnifRules", "import Duper.ProverM", "import Lean" ]
Duper/ClauseStreamHeap.lean
ProverM.runForceProbe
Keywhere | const : Name → Nat → Key | fvar : FVarId → Nat → Key | lit : Literal → Key | star : Key | other : Key | arrow : Key | proj : Name → Nat → Key deriving Inhabited, BEq, Repr
inductive
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Key
Key.hash: Key → UInt64 | Key.const n a => mixHash 5237 $ mixHash (hash n) (hash a) | Key.fvar n a => mixHash 3541 (hash a) --$ mixHash (hash n) (hash a) | Key.lit v => mixHash 1879 $ hash v | Key.star => 7883 | Key.other => 2411 | Key.arrow => 17 | Key.proj s i => mixHash 11 $ mixHash (hash s) (hash i)
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Key.hash
Trie(α : Type) where | node (vs : Array α) (children : Array (Key × Trie α)) : Trie α /- The filterSet argument is a temporary hack to simulate deletions from the discrimination tree. If that turns out to be too slow though, I'll have to remove it and rewrite delete to actually remove elements from the tree -/
inductive
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Trie
DiscrTree(α : Type) where root : PersistentHashMap Key (Trie α) := {} filterSet : HashSet Clause := {} -- Keeps track of the set of clauses that should be filtered out (i.e. "removed" clauses)
structure
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
DiscrTree
Key.ctorIdx: Key → Nat | Key.star => 0 | Key.other => 1 | Key.lit .. => 2 | Key.fvar .. => 3 | Key.const .. => 4 | Key.arrow => 5 | Key.proj .. => 6
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Key.ctorIdx
Key.lt: Key → Key → Bool | Key.lit v₁, Key.lit v₂ => v₁ < v₂ | Key.fvar n₁ a₁, Key.fvar n₂ a₂ => a₁ < a₂ -- Name.quickLt n₁.name n₂.name || (n₁ == n₂ && a₁ < a₂) | Key.const n₁ a₁, Key.const n₂ a₂ => Name.quickLt n₁ n₂ || (n₁ == n₂ && a₁ < a₂) | Key.proj s₁ i₁, Key.proj s₂ i₂ => Name.quickLt s₁ s₂ || (s₁ == s₂ && i₁ < i₂) | k₁, k₂ => k₁.ctorIdx < k₂.ctorIdx
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Key.lt
Key.format: Key → Format | Key.star => "*" | Key.other => "◾" | Key.lit (Literal.natVal v) => Std.format v | Key.lit (Literal.strVal v) => repr v | Key.const k _ => Std.format k | Key.proj s i => Std.format s ++ "." ++ Std.format i | Key.fvar k _ => Std.format k.name | Key.arrow => "→"
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Key.format
Key.arity: Key → Nat | Key.const _ a => a | Key.fvar _ a => a | Key.arrow => 2 | Key.proj .. => 1 | _ => 0
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Key.arity
empty: DiscrTree α := { root := {} }
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
empty
Trie.format[ToMessageData α] : Trie α → MessageData | Trie.node vs cs => MessageData.group $ MessageData.paren $ "node" ++ (if vs.isEmpty then MessageData.nil else " " ++ toMessageData vs) ++ MessageData.joinSep (cs.toList.map $ fun ⟨k, c⟩ => MessageData.paren (toMessageData k ++ " => " ++ format c)) ","
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Trie.format
Trie.formatClause: Trie (Clause × α) → MessageData | Trie.node vs cs => MessageData.group $ MessageData.paren $ "node" ++ (if vs.isEmpty then MessageData.nil else " " ++ toMessageData (Array.map (fun x => x.1) vs)) ++ MessageData.joinSep (cs.toList.map $ fun ⟨k, c⟩ => MessageData.paren (toMessageData k ++ " => " ++ formatClause c)) ","
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
Trie.formatClause
format[ToMessageData α] (d : DiscrTree α) : MessageData := let (_, r) := d.root.foldl (fun (p : Bool × MessageData) k c => (false, p.2 ++ MessageData.paren (toMessageData k ++ " => " ++ toMessageData c))) (true, Format.nil) MessageData.group r
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
format
formatClauses(d : DiscrTree (Clause × α)) : MessageData := let (_, r) := d.root.foldl (fun (p : Bool × MessageData) k c => (false, p.2 ++ MessageData.paren (toMessageData k ++ " => " ++ toMessageData c))) (true, Format.nil) MessageData.group r
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
formatClauses
tmpMVarId: MVarId := { name := `_discr_tree_tmp }
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
tmpMVarId
tmpStar:= mkMVar tmpMVarId
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
tmpStar
ignoreArg(a : Expr) (i : Nat) (infos : Array Meta.ParamInfo) : RuleM Bool := do if h : i < infos.size then let info := infos.get ⟨i, h⟩ if info.isInstImplicit then return true else if info.isImplicit || info.isStrictImplicit then return not (← Meta.isType a) else return false -- Previously: isProof a else return false -- Previously: isProof a private partial def pushArgsAux (infos : Array Meta.ParamInfo) : Nat → Expr → Array Expr → RuleM (Array Expr) | i, Expr.app f a, todo => do if (← ignoreArg a i infos) then pushArgsAux infos (i-1) f (todo.push tmpStar) else pushArgsAux infos (i-1) f (todo.push a) | _, _, todo => return todo
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
ignoreArg
mkNoindexAnnotation(e : Expr) : Expr := mkAnnotation `noindex e
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
mkNoindexAnnotation
hasNoindexAnnotation(e : Expr) : Bool := annotation? `noindex e |>.isSome
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
hasNoindexAnnotation
pushArgs(root : Bool) (todo : Array Expr) (e : Expr) : RuleM (Key × Array Expr) := do if hasNoindexAnnotation e then return (Key.star, todo) else let fn := e.getAppFn let push (k : Key) (nargs : Nat) : RuleM (Key × Array Expr) := do let info ← Meta.getFunInfoNArgs fn nargs let todo ← pushArgsAux info.paramInfo (nargs-1) e todo return (k, todo) match fn with | Expr.lit v => return (Key.lit v, todo) | Expr.const c _ => let nargs := e.getAppNumArgs push (Key.const c nargs) nargs | Expr.proj s i a .. => return (Key.proj s i, todo.push a) | Expr.fvar fvarId => let nargs := e.getAppNumArgs push (Key.fvar fvarId nargs) nargs | Expr.mvar mvarId => if mvarId == tmpMVarId then -- We use `tmp to mark some implicit arguments and proofs return (Key.star, todo) else return (Key.star, todo) | Expr.forallE _ d b _ => if b.hasLooseBVars then return (Key.other, todo) else return (Key.arrow, todo.push d |>.push b)
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
pushArgs
mkPathAux(root : Bool) (todo : Array Expr) (keys : Array Key) : RuleM (Array Key) := do if todo.isEmpty then return keys else let e := todo.back let todo := todo.pop let (k, todo) ← pushArgs root todo e mkPathAux false todo (keys.push k)
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
mkPathAux
initCapacity:= 8
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
initCapacity
mkPath(e : Expr) : RuleM (Array Key) := do let todo : Array Expr := Array.mkEmpty initCapacity let keys : Array Key := Array.mkEmpty initCapacity mkPathAux (root := true) (todo.push e) keys private partial def createNodes (keys : Array Key) (v : α) (i : Nat) : Trie α := if h : i < keys.size then let k := keys.get ⟨i, h⟩ let c := createNodes keys v (i+1) Trie.node #[] #[(k, c)] else Trie.node #[v] #[]
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
mkPath
insertVal[BEq α] (vs : Array α) (v : α) : Array α := if vs.contains v then vs else vs.push v private partial def insertAux [BEq α] (keys : Array Key) (v : α) : Nat → Trie α → Trie α | i, Trie.node vs cs => if h : i < keys.size then let k := keys.get ⟨i, h⟩ let c := Id.run $ cs.binInsertM (fun a b => a.1 < b.1) (fun ⟨_, s⟩ => let c := insertAux keys v (i+1) s; (k, c)) -- merge with existing (fun _ => let c := createNodes keys v (i+1); (k, c)) (k, default) Trie.node vs c else Trie.node (insertVal vs v) cs
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
insertVal
insertCore[BEq α] (d : DiscrTree α) (keys : Array Key) (v : α) : DiscrTree α := if keys.isEmpty then panic! "invalid key sequence" else let k := keys[0]! match d.root.find? k with | none => let c := createNodes keys v 1 { d with root := d.root.insert k c } | some c => let c := insertAux keys v 1 c { d with root := d.root.insert k c } /- Original, more general insert code for discrimination trees
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
insertCore
insert[BEq α] (d : DiscrTree α) (e : Expr) (v : α) : RuleM (DiscrTree α) := do let keys ← mkPath e return d.insertCore keys v -/
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
insert
getKeyArgs(e : Expr) (isMatch root : Bool) : RuleM (Key × Array Expr) := do match e.getAppFn with | Expr.lit v => return (Key.lit v, #[]) | Expr.const c _ => let nargs := e.getAppNumArgs return (Key.const c nargs, e.getAppRevArgs) | Expr.fvar fvarId => let nargs := e.getAppNumArgs return (Key.fvar fvarId nargs, e.getAppRevArgs) | Expr.mvar _ => if isMatch then return (Key.other, #[]) else do return (Key.star, #[]) | Expr.proj s i a .. => return (Key.proj s i, #[a]) | Expr.forallE _ d b _ => if b.hasLooseBVars then return (Key.other, #[]) else return (Key.arrow, #[d, b]) | _ => return (Key.other, #[])
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getKeyArgs
getMatchKeyArgs(e : Expr) (root : Bool) : RuleM (Key × Array Expr) := getKeyArgs e (isMatch := true) (root := root)
abbrev
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getMatchKeyArgs
getUnifyKeyArgs(e : Expr) (root : Bool) : RuleM (Key × Array Expr) := getKeyArgs e (isMatch := false) (root := root)
abbrev
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getUnifyKeyArgs
getStarResult(d : DiscrTree α) : Array α := let result : Array α := Array.mkEmpty initCapacity match d.root.find? Key.star with | none => result | some (Trie.node vs _) => result ++ vs
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getStarResult
findKey(cs : Array (Key × Trie α)) (k : Key) : Option (Key × Trie α) := cs.binSearch (k, default) (fun a b => a.1 < b.1) private partial def getMatchLoop (todo : Array Expr) (c : Trie α) (result : Array α) : RuleM (Array α) := do match c with | Trie.node vs cs => if todo.isEmpty then return result ++ vs else if cs.isEmpty then return result else let e := todo.back let todo := todo.pop let first := cs[0]! /- Recall that `Key.star` is the minimal key -/ let (k, args) ← getMatchKeyArgs e (root := false) /- We must always visit `Key.star` edges since they are wildcards. Thus, `todo` is not used linearly when there is `Key.star` edge and there is an edge for `k` and `k != Key.star`. -/ let visitStar (result : Array α) : RuleM (Array α) := if first.1 == Key.star then getMatchLoop todo first.2 result else return result let visitNonStar (k : Key) (args : Array Expr) (result : Array α) : RuleM (Array α) := match findKey cs k with | none => return result | some c => getMatchLoop (todo ++ args) c.2 result let result ← visitStar result match k with | Key.star => return result
abbrev
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
findKey
getMatchRoot(d : DiscrTree α) (k : Key) (args : Array Expr) (result : Array α) : RuleM (Array α) := match d.root.find? k with | none => return result | some c => getMatchLoop args c result private partial def getMatch' (d : DiscrTree α) (e : Expr) : RuleM (Array α) := do Core.checkMaxHeartbeats "getMatch" let result := getStarResult d let (k, args) ← getMatchKeyArgs e (root := true) match k with | Key.star => return result | _ => getMatchRoot d k args result /-- Find values that match `e` in `d`. -/
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getMatchRoot
getMatch(d : DiscrTree (Clause × α)) (e : Expr) : RuleM (Array (Clause × α)) := do let unfiltered_result ← getMatch' d e let filterSet := d.filterSet return Array.filter (fun c => not (filterSet.contains c.1)) unfiltered_result private partial def getUnify' (d : DiscrTree α) (e : Expr) : RuleM (Array α) := do Core.checkMaxHeartbeats "getUnify" let (k, args) ← getUnifyKeyArgs e (root := true) match k with | Key.star => d.root.foldlM (init := #[]) fun result k c => process k.arity #[] c result | _ => let result := getStarResult d match d.root.find? k with | none => return result | some c => process 0 args c result where process (skip : Nat) (todo : Array Expr) (c : Trie α) (result : Array α) : RuleM (Array α) := do match skip, c with | skip+1, Trie.node vs cs => if cs.isEmpty then return result else cs.foldlM (init := result) fun result ⟨k, c⟩ => process (skip + k.arity) todo c result | 0, Trie.node vs cs => do if todo.isEmpty then return result ++ vs else if cs.isEmpty then return result else let e := todo.back
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getMatch
getUnify(d : DiscrTree (Clause × α)) (e : Expr) : RuleM (Array (Clause × α)) := do let unfiltered_result ← getUnify' d e let filterSet := d.filterSet return Array.filter (fun c => not (filterSet.contains c.1)) unfiltered_result
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
getUnify
delete(d : DiscrTree α) (c : Clause) : RuleM (DiscrTree α) := do let root := d.root let filterSet := d.filterSet.insert c return { root := root, filterSet := filterSet }
def
Duper
[ "import Lean", "import Duper.RuleM" ]
Duper/DiscrTree.lean
delete
ExprPos:= Array Nat
abbrev
Duper
[ "import Lean" ]
Duper/Expr.lean
ExprPos
empty: ExprPos := #[]
def
Duper
[ "import Lean" ]
Duper/Expr.lean
empty
hasAnyMVar(e : Expr) (p : MVarId → Bool) : Bool := let rec @[specialize] visit (e : Expr) := if !e.hasMVar then false else match e with | Expr.forallE _ d b _ => visit d || visit b | Expr.lam _ d b _ => visit d || visit b | Expr.mdata _ e => visit e | Expr.letE _ t v b _ => visit t || visit v || visit b | Expr.app f a => visit f || visit a | Expr.proj _ _ e => visit e | Expr.mvar mvarId => p mvarId | _ => false visit e /-- This should be used in place of Lean.Expr.isMVar so that mvars surrounded by mdata are not missed. -/
def
Duper
[ "import Lean" ]
Duper/Expr.lean
hasAnyMVar
isMVar'(e : Expr) := e.consumeMData.isMVar /-- Given `t` and `b`, determines whether `.forallE _ t b _` is an implication -/
def
Duper
[ "import Lean" ]
Duper/Expr.lean
isMVar'
End of preview. Expand in Data Studio

Lean4-Duper

Structured declarations from Duper - a proof-producing superposition theorem prover for Lean 4. Source: github.com/leanprover-community/duper

Schema

Column Type Description
fact string Declaration body (without type keyword)
type string Declaration type (Lemma, Definition, etc.)
library string Source module
imports list Import statements
filename string Source file path
symbolic_name string Declaration identifier

Statistics

  • Total entries: 1556
  • Unique files: 124
  • Declaration types: abbrev, axiom, class, def, inductive, instance, lemma, opaque, structure, theorem

Usage

from datasets import load_dataset
ds = load_dataset("phanerozoic/Lean4-Duper")

License

apache-2.0

Downloads last month
17

Collection including phanerozoic/Lean4-Duper