fact stringlengths 6 3.84k | type stringclasses 11
values | library stringclasses 32
values | imports listlengths 1 14 | filename stringlengths 20 95 | symbolic_name stringlengths 1 90 | docstring stringlengths 7 20k ⌀ |
|---|---|---|---|---|---|---|
Cache.int : Cache sℤ :=
{ rα := some q(inferInstance), dsα := none, czα := some q(inferInstance) } | def | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | Cache.int | A precomputed `Cache` for `ℤ`. |
partial eval {u : Lean.Level} {α : Q(Type u)} (sα : Q(CommSemiring $α))
(c : Cache sα) (e : Q($α)) : AtomM (Result (ExSum sα) e) := Lean.withIncRecDepth do
let els := do
try evalCast sα (← derive e)
catch _ => evalAtom sα e
let .const n _ := (← withReducible <| whnf e).getAppFn | els
match n, c.rα, c.... | def | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | eval | Checks whether `e` would be processed by `eval` as a ring expression,
or otherwise if it is an atom or something simplifiable via `norm_num`.
We use this in `ring_nf` to avoid rewriting atoms unnecessarily.
Returns:
* `none` if `eval` would process `e` as an algebraic ring expression
* `some none` if `eval` would tre... |
CSLift (α : Type u) (β : outParam (Type u)) where
/-- `lift` is the "canonical injection" from `α` to `β` -/
lift : α → β
/-- `lift` is an injective function -/
inj : Function.Injective lift | class | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | CSLift | `CSLift α β` is a typeclass used by `ring` for lifting operations from `α`
(which is not a commutative semiring) into a commutative semiring `β` by using an injective map
`lift : α → β`. |
CSLiftVal {α} {β : outParam (Type u)} [CSLift α β] (a : α) (b : outParam β) : Prop where
/-- The output value `b` is equal to the lift of `a`. This can be supplied by the default
instance which sets `b := lift a`, but `ring` will treat this as an atom so it is more useful
when there are other instances which dist... | class | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | CSLiftVal | `CSLiftVal a b` means that `b = lift a`. This is used by `ring` to construct an expression `b`
from the input expression `a`, and then run the usual ring algorithm on `b`. |
of_lift {α β} [inst : CSLift α β] {a b : α} {a' b' : β}
[h1 : CSLiftVal a a'] [h2 : CSLiftVal b b'] (h : a' = b') : a = b :=
inst.2 <| by rwa [← h1.1, ← h2.1]
open Lean Parser.Tactic Elab Command Elab.Tactic | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | of_lift | null |
of_eq {α} {a b c : α} (_ : (a : α) = c) (_ : b = c) : a = b := by subst_vars; rfl | theorem | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | of_eq | null |
proveEq (g : MVarId) : AtomM Unit := do
let some (α, e₁, e₂) := (← whnfR <|← instantiateMVars <|← g.getType).eq?
| throwError "ring failed: not an equality"
let .sort u ← whnf (← inferType α) | unreachable!
let v ← try u.dec catch _ => throwError "not a type{indentExpr α}"
have α : Q(Type v) := α
let sα ←... | def | Tactic | [
"Mathlib.Tactic.NormNum.Inv",
"Mathlib.Tactic.NormNum.Pow",
"Mathlib.Util.AtomM"
] | Mathlib/Tactic/Ring/Basic.lean | proveEq | This is a routine which is used to clean up the unsolved subgoal
of a failed `ring1` application. It is overridden in `Mathlib/Tactic/Ring/RingNF.lean`
to apply the `ring_nf` simp set to the goal.
-/
initialize ringCleanupRef : IO.Ref (Expr → MetaM Expr) ← IO.mkRef pure
/-- Frontend of `ring1`: attempt to close a goal... |
amwo_of_cs (α : Type*) [CommSemiring α] : AddMonoidWithOne α := inferInstance | abbrev | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | amwo_of_cs | `CommSemiring` implies `AddMonoidWithOne`. |
le_of_po (α : Type*) [PartialOrder α] : LE α := inferInstance | abbrev | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | le_of_po | `PartialOrder` implies `LE`. |
lt_of_po (α : Type*) [PartialOrder α] : LT α := inferInstance | abbrev | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | lt_of_po | `PartialOrder` implies `LT`. |
add_le_add_right {α : Type*} [CommSemiring α] [PartialOrder α] [IsOrderedRing α]
{b c : α} (bc : b ≤ c) (a : α) :
b + a ≤ c + a :=
_root_.add_le_add_right bc a | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | add_le_add_right | null |
add_le_of_nonpos_left {α : Type*} [CommSemiring α] [PartialOrder α] [IsOrderedRing α]
(a : α) {b : α} (h : b ≤ 0) :
b + a ≤ a :=
_root_.add_le_of_nonpos_left h | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | add_le_of_nonpos_left | null |
le_add_of_nonneg_left {α : Type*} [CommSemiring α] [PartialOrder α] [IsOrderedRing α]
(a : α) {b : α} (h : 0 ≤ b) :
a ≤ b + a :=
_root_.le_add_of_nonneg_left h | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | le_add_of_nonneg_left | null |
add_lt_add_right {α : Type*} [CommSemiring α] [PartialOrder α] [IsStrictOrderedRing α]
{b c : α} (bc : b < c) (a : α) :
b + a < c + a :=
_root_.add_lt_add_right bc a | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | add_lt_add_right | null |
add_lt_of_neg_left {α : Type*} [CommSemiring α] [PartialOrder α] [IsStrictOrderedRing α]
(a : α) {b : α} (h : b < 0) :
b + a < a :=
_root_.add_lt_of_neg_left a h | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | add_lt_of_neg_left | null |
lt_add_of_pos_left {α : Type*} [CommSemiring α] [PartialOrder α] [IsStrictOrderedRing α]
(a : α) {b : α} (h : 0 < b) :
a < b + a :=
_root_.lt_add_of_pos_left a h | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | lt_add_of_pos_left | null |
ExceptType | tooSmall | notComparable
export ExceptType (tooSmall notComparable) | inductive | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | ExceptType | Inductive type carrying the two kinds of errors which can arise in the metaprograms
`Mathlib.Tactic.Ring.evalLE.lean` and `Mathlib.Tactic.Ring.evalLT.lean`. |
evalLE {v : Level} {α : Q(Type v)}
(ics : Q(CommSemiring $α)) (_ : Q(PartialOrder $α)) (_ : Q(IsOrderedRing $α))
{a b : Q($α)} (va : Ring.ExSum q($ics) a) (vb : Ring.ExSum q($ics) b) :
MetaM (Except ExceptType Q($a ≤ $b)) := do
let lα : Q(LE $α) := q(le_of_po $α)
assumeInstancesCommute
let ⟨_, pz⟩ ← N... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | evalLE | In a commutative semiring, given `Ring.ExSum` objects `va`, `vb` which differ by a positive
(additive) constant, construct a proof of `$a < $b`, where `a` (resp. `b`) is the expression in the
semiring to which `va` (resp. `vb`) evaluates. |
evalLT {v : Level} {α : Q(Type v)}
(ics : Q(CommSemiring $α)) (_ : Q(PartialOrder $α)) (_ : Q(IsStrictOrderedRing $α))
{a b : Q($α)} (va : Ring.ExSum q($ics) a) (vb : Ring.ExSum q($ics) b) :
MetaM (Except ExceptType Q($a < $b)) := do
let lα : Q(LT $α) := q(lt_of_po $α)
assumeInstancesCommute
let ⟨_, p... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | evalLT | In a commutative semiring, given `Ring.ExSum` objects `va`, `vb` which differ by a positive
(additive) constant, construct a proof of `$a < $b`, where `a` (resp. `b`) is the expression in the
semiring to which `va` (resp. `vb`) evaluates. |
le_congr {α : Type*} [LE α] {a b c d : α} (h1 : a = b) (h2 : b ≤ c) (h3 : d = c) :
a ≤ d := by
rwa [h1, h3] | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | le_congr | null |
lt_congr {α : Type*} [LT α] {a b c d : α} (h1 : a = b) (h2 : b < c) (h3 : d = c) :
a < d := by
rwa [h1, h3]
attribute [local instance] monadLiftOptionMetaM in | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | lt_congr | null |
proveLE (g : MVarId) : MetaM Unit := do
let some (α, e₁, e₂) := (← whnfR <|← instantiateMVars <|← g.getType).le?
| throwError "ring failed: not of the form `A ≤ B`"
let .sort u ← whnf (← inferType α) | unreachable!
let v ← try u.dec catch _ => throwError "not a type{indentExpr α}"
have α : Q(Type v) := α
... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | proveLE | Prove goals of the form `A ≤ B` in an ordered commutative semiring, if the ring-normal forms of
`A` and `B` differ by a nonnegative (additive) constant. |
proveLT (g : MVarId) : MetaM Unit := do
let some (α, e₁, e₂) := (← whnfR <|← instantiateMVars <|← g.getType).lt?
| throwError "ring failed: not of the form `A < B`"
let .sort u ← whnf (← inferType α) | unreachable!
let v ← try u.dec catch _ => throwError "not a type{indentExpr α}"
have α : Q(Type v) := α
... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.NormNum.Ineq"
] | Mathlib/Tactic/Ring/Compare.lean | proveLT | Prove goals of the form `A < B` in an ordered commutative semiring, if the ring-normal forms of
`A` and `B` differ by a positive (additive) constant. |
@[command_elab namePolyVarsOver, inherit_doc namePolyVarsOver]
elabNameVariablesOver : CommandElab
| `(command|name_poly_vars $vars:ident,* over $R:term) => do
let vars := vars.getElems
let size := vars.size
let sizeStx : TSyntax `term := quote size
for h : idx in [:size] do
let var := vars[idx]
let var... | def | Tactic | [
"Mathlib.Algebra.MvPolynomial.Basic"
] | Mathlib/Tactic/Ring/NamePolyVars.lean | elabNameVariablesOver | null |
ExBase.isAtom : ExBase sα a → Bool
| .atom _ => true
| _ => false | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | ExBase.isAtom | True if this represents an atomic expression. |
ExProd.isAtom : ExProd sα a → Bool
| .mul va₁ (.const 1 _) (.const 1 _) => va₁.isAtom
| _ => false | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | ExProd.isAtom | True if this represents an atomic expression. |
ExSum.isAtom : ExSum sα a → Bool
| .add va₁ va₂ => match va₂ with -- FIXME: this takes a while to compile as one match
| .zero => va₁.isAtom
| _ => false
| _ => false | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | ExSum.isAtom | True if this represents an atomic expression. |
RingMode where
/-- Sum-of-products form, like `x + x * y * 2 + z ^ 2`. -/
| SOP
/-- Raw form: the representation `ring` uses internally. -/
| raw
deriving Inhabited, BEq, Repr | inductive | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | RingMode | The normalization style for `ring_nf`. |
Config extends AtomM.Recurse.Config where
/-- if true, then fail if no progress is made -/
failIfUnchanged := true
/-- The normalization style. -/
mode := RingMode.SOP
deriving Inhabited, BEq, Repr
attribute [nolint unusedArguments] Mathlib.Tactic.RingNF.instReprConfig.repr | structure | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | Config | Configuration for `ring_nf`. |
evalExpr (e : Expr) : AtomM Simp.Result := do
let e ← withReducible <| whnf e
guard e.isApp -- all interesting ring expressions are applications
let ⟨u, α, e⟩ ← inferTypeQ' e
let sα ← synthInstanceQ q(CommSemiring $α)
let c ← mkCache sα
let ⟨a, _, pa⟩ ← match ← isAtomOrDerivable q($sα) c q($e) with
| none... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | evalExpr | Function elaborating `RingNF.Config`. -/
declare_config_elab elabConfig Config
/--
Evaluates an expression `e` into a normalized representation as a polynomial.
This is a variant of `Mathlib.Tactic.Ring.eval`, the main driver of the `ring` tactic.
It differs in
* operating on `Expr` (input) and `Simp.Result` (output)... |
add_assoc_rev (a b c : R) : a + (b + c) = a + b + c := (add_assoc ..).symm | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | add_assoc_rev | null |
mul_assoc_rev (a b c : R) : a * (b * c) = a * b * c := (mul_assoc ..).symm | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | mul_assoc_rev | null |
mul_neg {R} [Ring R] (a b : R) : a * -b = -(a * b) := by simp | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | mul_neg | null |
add_neg {R} [Ring R] (a b : R) : a + -b = a - b := (sub_eq_add_neg ..).symm | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | add_neg | null |
nat_rawCast_0 : (Nat.rawCast 0 : R) = 0 := by simp | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | nat_rawCast_0 | null |
nat_rawCast_1 : (Nat.rawCast 1 : R) = 1 := by simp | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | nat_rawCast_1 | null |
nat_rawCast_2 [Nat.AtLeastTwo n] : (Nat.rawCast n : R) = OfNat.ofNat n := rfl | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | nat_rawCast_2 | null |
int_rawCast_neg {R} [Ring R] : (Int.rawCast (.negOfNat n) : R) = -Nat.rawCast n := by simp | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | int_rawCast_neg | null |
nnrat_rawCast {R} [DivisionSemiring R] :
(NNRat.rawCast n d : R) = Nat.rawCast n / Nat.rawCast d := by simp | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | nnrat_rawCast | null |
rat_rawCast_neg {R} [DivisionRing R] :
(Rat.rawCast (.negOfNat n) d : R) = Int.rawCast (.negOfNat n) / Nat.rawCast d := by simp | theorem | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | rat_rawCast_neg | null |
cleanup (cfg : RingNF.Config) (r : Simp.Result) : MetaM Simp.Result := do
match cfg.mode with
| .raw => pure r
| .SOP => do
let thms : SimpTheorems := {}
let thms ← [``add_zero, ``add_assoc_rev, ``_root_.mul_one, ``mul_assoc_rev,
``_root_.pow_one, ``mul_neg, ``add_neg].foldlM (·.addConst ·) thms
... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | cleanup | A cleanup routine, which simplifies normalized polynomials to a more human-friendly format. |
@[tactic ringNFConv] elabRingNFConv : Tactic := fun stx ↦ match stx with
| `(conv| ring_nf $[!%$tk]? $cfg:optConfig) => withMainContext do
let mut cfg ← elabConfig cfg
if tk.isSome then cfg := { cfg with red := .default, zetaDelta := true }
let s ← IO.mkRef {}
Conv.applySimpResult
(← AtomM.recur... | def | Tactic | [
"Mathlib.Tactic.Ring.Basic",
"Mathlib.Tactic.TryThis",
"Mathlib.Tactic.Conv",
"Mathlib.Util.AtLocation",
"Mathlib.Util.AtomM.Recurse",
"Mathlib.Util.Qq"
] | Mathlib/Tactic/Ring/RingNF.lean | elabRingNFConv | Overrides the default error message in `ring1` to use a prettified version of the goal. -/
initialize ringCleanupRef.set fun e => do
return (← cleanup {} { expr := e }).expr
open Elab.Tactic Parser.Tactic
/--
Simplification tactic for expressions in the language of commutative (semi)rings,
which rewrites all ring e... |
Literal
| pos : Nat → Literal
| neg : Nat → Literal | inductive | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Literal | A literal is a positive or negative occurrence of an atomic propositional variable.
Note that unlike DIMACS, 0 is a valid variable index. |
Literal.ofInt (i : Int) : Literal :=
if i < 0 then Literal.neg (-i-1).toNat else Literal.pos (i-1).toNat | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Literal.ofInt | Construct a literal. Positive numbers are translated to positive literals,
and negative numbers become negative literals. The input is assumed to be nonzero. |
Literal.negate : Literal → Literal
| pos i => neg i
| neg i => pos i | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Literal.negate | Swap the polarity of a literal. |
Clause := List Literal | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause | A clause is a list of literals, thought of as a disjunction like `a ∨ b ∨ ¬c`. |
Clause.nil : Clause := [] | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause.nil | The empty clause |
Clause.cons : Literal → Clause → Clause := List.cons | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause.cons | Append a literal to a clause. |
Fmla := List Clause | abbrev | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla | A formula is a list of clauses, thought of as a conjunction like `(a ∨ b) ∧ c ∧ (¬c ∨ ¬d)`. |
Fmla.one (c : Clause) : Fmla := [c] | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.one | A single clause as a formula. |
Fmla.and (a b : Fmla) : Fmla := a ++ b | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.and | A conjunction of formulas. |
Fmla.subsumes (f f' : Fmla) : Prop where
prop : ∀ x, x ∈ f' → x ∈ f | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.subsumes | Formula `f` subsumes `f'` if all the clauses in `f'` are in `f`.
We use this to prove that all clauses in the formula are subsumed by it. |
Fmla.subsumes_self (f : Fmla) : f.subsumes f := ⟨fun _ h ↦ h⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.subsumes_self | null |
Fmla.subsumes_left (f f₁ f₂ : Fmla) (H : f.subsumes (f₁.and f₂)) : f.subsumes f₁ :=
⟨fun _ h ↦ H.1 _ <| List.mem_append.2 <| Or.inl h⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.subsumes_left | null |
Fmla.subsumes_right (f f₁ f₂ : Fmla) (H : f.subsumes (f₁.and f₂)) : f.subsumes f₂ :=
⟨fun _ h ↦ H.1 _ <| List.mem_append.2 <| Or.inr h⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.subsumes_right | null |
Valuation := Nat → Prop | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation | A valuation is an assignment of values to all the propositional variables. |
Valuation.neg (v : Valuation) : Literal → Prop
| Literal.pos i => ¬ v i
| Literal.neg i => v i | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.neg | `v.neg lit` asserts that literal `lit` is falsified in the valuation. |
Valuation.satisfies (v : Valuation) : Clause → Prop
| [] => False
| l::c => v.neg l → v.satisfies c | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.satisfies | `v.satisfies c` asserts that clause `c` satisfied by the valuation.
It is written in a negative way: A clause like `a ∨ ¬b ∨ c` is rewritten as
`¬a → b → ¬c → False`, so we are asserting that it is not the case that
all literals in the clause are falsified. |
Valuation.satisfies_fmla (v : Valuation) (f : Fmla) : Prop where
prop : ∀ c, c ∈ f → v.satisfies c | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.satisfies_fmla | `v.satisfies_fmla f` asserts that formula `f` is satisfied by the valuation.
A formula is satisfied if all clauses in it are satisfied. |
Fmla.proof (f : Fmla) (c : Clause) : Prop :=
∀ v : Valuation, v.satisfies_fmla f → v.satisfies c | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.proof | `f.proof c` asserts that `c` is derivable from `f`. |
Fmla.proof_of_subsumes {f : Fmla} {c : Clause}
(H : Fmla.subsumes f (Fmla.one c)) : f.proof c :=
fun _ h ↦ h.1 _ <| H.1 _ <| List.Mem.head .. | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.proof_of_subsumes | If `f` subsumes `c` (i.e. `c ∈ f`), then `f.proof c`. |
Valuation.by_cases {v : Valuation} {l}
(h₁ : v.neg l.negate → False) (h₂ : v.neg l → False) : False :=
match l with
| Literal.pos _ => h₂ h₁
| Literal.neg _ => h₁ h₂ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.by_cases | The core unit-propagation step.
We have a local context of assumptions `¬l'` (sometimes called an assignment)
and we wish to add `¬l` to the context, that is, we want to prove `l` is also falsified.
This is because there is a clause `a ∨ b ∨ ¬l` in the global context
such that all literals in the clause are falsified ... |
Valuation.implies (v : Valuation) (p : Prop) : List Prop → Nat → Prop
| [], _ => p
| a::as, n => (v n ↔ a) → v.implies p as (n + 1) | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.implies | `v.implies p [a, b, c] 0` definitionally unfolds to `(v 0 ↔ a) → (v 1 ↔ b) → (v 2 ↔ c) → p`.
This is used to introduce assumptions about the first `n` values of `v` during reification. |
Valuation.mk : List Prop → Valuation
| [], _ => False
| a::_, 0 => a
| _::as, n + 1 => mk as n | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.mk | `Valuation.mk [a, b, c]` is a valuation which is `a` at 0, `b` at 1 and `c` at 2, and false
everywhere else. |
Valuation.mk_implies {p} {as ps} (as₁) : as = List.reverseAux as₁ ps →
(Valuation.mk as).implies p ps as₁.length → p := by
induction ps generalizing as₁ with
| nil => exact fun _ ↦ id
| cons a as ih =>
refine fun e H ↦ @ih (a::as₁) e (H ?_)
subst e; clear ih H
suffices ∀ n n', n' = List.length as₁... | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Valuation.mk_implies | The fundamental relationship between `mk` and `implies`:
`(mk ps).implies p ps 0` is equivalent to `p`. |
Fmla.reify (v : Valuation) (f : Fmla) (p : Prop) : Prop where
prop : ¬ v.satisfies_fmla f → p
variable {v : Valuation} | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.reify | Asserts that `¬⟦f⟧_v` implies `p`. |
Fmla.refute {p : Prop} {ps} (f : Fmla) (hf : f.proof [])
(hv : ∀ v, Valuation.implies v (Fmla.reify v f p) ps 0) : p :=
(Valuation.mk_implies [] rfl (hv _)).1 (hf _) | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.refute | If `f` is unsatisfiable, and every `v` which agrees with `ps` implies `¬⟦f⟧_v → p`, then `p`.
Equivalently, there exists a valuation `v` which agrees with `ps`,
and every such valuation yields `¬⟦f⟧_v` because `f` is unsatisfiable. |
Fmla.reify_or {f₁ : Fmla} {a : Prop} {f₂ : Fmla} {b : Prop}
(h₁ : Fmla.reify v f₁ a) (h₂ : Fmla.reify v f₂ b) : Fmla.reify v (f₁.and f₂) (a ∨ b) := by
refine ⟨fun H ↦ by_contra fun hn ↦ H ⟨fun c h ↦ by_contra fun hn' ↦ ?_⟩⟩
rcases List.mem_append.1 h with h | h
· exact hn <| Or.inl <| h₁.1 fun Hc ↦ hn' <| Hc.... | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.reify_or | Negation turns AND into OR, so `¬⟦f₁ ∧ f₂⟧_v ≡ ¬⟦f₁⟧_v ∨ ¬⟦f₂⟧_v`. |
Clause.reify (v : Valuation) (c : Clause) (p : Prop) : Prop where
prop : ¬ v.satisfies c → p | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause.reify | Asserts that `¬⟦c⟧_v` implies `p`. |
Fmla.reify_one {c : Clause} {a : Prop} (h : Clause.reify v c a) :
Fmla.reify v (Fmla.one c) a :=
⟨fun H ↦ h.1 fun h ↦ H ⟨fun | _, List.Mem.head .. => h⟩⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Fmla.reify_one | Reification of a single clause formula. |
Literal.reify (v : Valuation) (l : Literal) (p : Prop) : Prop where
prop : v.neg l → p | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Literal.reify | Asserts that `¬⟦l⟧_v` implies `p`. |
Clause.reify_and {l : Literal} {a : Prop} {c : Clause} {b : Prop}
(h₁ : Literal.reify v l a) (h₂ : Clause.reify v c b) :
Clause.reify v (Clause.cons l c) (a ∧ b) :=
⟨fun H ↦ ⟨h₁.1 (by_contra fun hn ↦ H hn.elim), h₂.1 fun h ↦ H fun _ ↦ h⟩⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause.reify_and | Negation turns OR into AND, so `¬⟦l ∨ c⟧_v ≡ ¬⟦l⟧_v ∧ ¬⟦c⟧_v`. |
Clause.reify_zero : Clause.reify v Clause.nil True := ⟨fun _ ↦ trivial⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause.reify_zero | The reification of the empty clause is `True`: `¬⟦⊥⟧_v ≡ True`. |
Clause.reify_one {l : Literal} {a : Prop}
(h₁ : Literal.reify v l a) : Clause.reify v (Clause.nil.cons l) a :=
⟨fun H ↦ ((Clause.reify_and h₁ Clause.reify_zero).1 H).1⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause.reify_one | The reification of a singleton clause `¬⟦l⟧_v ≡ ¬⟦l⟧_v`. |
Literal.reify_pos {a : Prop} {n : ℕ} (h : v n ↔ a) : (Literal.pos n).reify v ¬a := ⟨mt h.2⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Literal.reify_pos | The reification of a positive literal `¬⟦a⟧_v ≡ ¬a`. |
Literal.reify_neg {a : Prop} {n : ℕ} (h : v n ↔ a) : (Literal.neg n).reify v a := ⟨h.1⟩ | theorem | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Literal.reify_neg | The reification of a negative literal `¬⟦¬a⟧_v ≡ a`. |
Clause where
/-- The list of literals as read from the input file -/
lits : Array Int
/-- The clause expression of type `Clause` -/
expr : Expr
/-- A proof of `⊢ ctx.proof c`.
Note that we do not use `have` statements to cache these proofs:
this is literally the proof expression itself. As a result, the p... | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | Clause | The representation of a global clause. |
buildClause (arr : Array Int) : Expr :=
let nil := mkConst ``Sat.Clause.nil
let cons := mkConst ``Sat.Clause.cons
arr.foldr (fun i e ↦ mkApp2 cons (toExpr <| Sat.Literal.ofInt i) e) nil | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | buildClause | Construct the clause expression from the input list. For example `[1, -2]` is translated to
`Clause.cons (Literal.pos 1) (Clause.cons (Literal.neg 2) Clause.nil)`. |
partial buildConj (arr : Array (Array Int)) (start stop : Nat) : Expr :=
match stop - start with
| 0 => panic! "empty"
| 1 => mkApp (mkConst ``Sat.Fmla.one) (buildClause arr[start]!)
| len =>
let mid := start + len / 2
mkApp2 (mkConst ``Sat.Fmla.and) (buildConj arr start mid) (buildConj arr mid stop) | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | buildConj | Constructs the formula expression from the input CNF, as a balanced tree of `Fmla.and` nodes. |
partial buildClauses (arr : Array (Array Int)) (ctx : Expr) (start stop : Nat)
(f p : Expr) (accum : Nat × HashMap Nat Clause) : Nat × HashMap Nat Clause :=
match stop - start with
| 0 => panic! "empty"
| 1 =>
let c := f.appArg!
let proof := mkApp3 (mkConst ``Sat.Fmla.proof_of_subsumes) ctx c p
le... | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | buildClauses | Constructs the proofs of `⊢ ctx.proof c` for each clause `c` in `ctx`.
The proofs are stashed in a `HashMap` keyed on the clause ID. |
LClause where
/-- The list of literals as read from the input file -/
lits : Array Int
/-- The clause expression of type `Clause` -/
expr : Expr
/-- The bound variable index of the hypothesis asserting `⊢ ctx.proof c`,
_counting from the outside and 1-based_. (We use this numbering because we will need to
... | structure | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | LClause | A localized clause reference.
It is the same as `Clause` except that the proof is now a local variable. |
partial buildProofStep (db : HashMap Nat Clause)
(ns pf : Array Int) (ctx clause : Expr) : Except String Expr := Id.run do
let mut lams := #[]
let mut args := #[]
let mut gctx : HashMap Nat LClause := {}
for i in pf do
let i := i.natAbs
let some cl := db[i]? | return Except.error "missing clause"
... | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | buildProofStep | Construct an individual proof step `⊢ ctx.proof c`.
* `db`: the current global context
* `ns`, `clause`: the new clause
* `pf`: the LRAT proof trace
* `ctx`: the main formula
The proof has three steps:
1. Introduce local assumptions `have h1 : ctx.proof c1 := p1` for each clause `c1`
referenced in t... |
LRATStep
| /-- An addition step, with the clause ID, the clause literal list, and the proof trace -/
add (id : Nat) (lits : Array Int) (proof : Array Int) : LRATStep
| /-- A (multiple) deletion step, which deletes all the listed clause IDs from the context -/
del (ids : Array Nat) : LRATStep | inductive | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | LRATStep | An LRAT step is either an addition or a deletion step. |
partial buildProof (arr : Array (Array Int)) (ctx ctx' : Expr)
(steps : Array LRATStep) : MetaM Expr := do
let p := mkApp (mkConst ``Sat.Fmla.subsumes_self) ctx
let mut db := (buildClauses arr ctx 0 arr.size ctx' p default).2
for step in steps do
match step with
| LRATStep.del ds => db := ds.foldl (·.... | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | buildProof | Build the main proof of `⊢ ctx.proof []` using the LRAT proof trace.
* `arr`: The input CNF
* `ctx`: The abbreviated formula, a constant like `foo.ctx_1`
* `ctx'`: The definitional expansion of the formula, a tree of `Fmla.and` nodes
* `steps`: The input LRAT proof trace |
partial buildReify (ctx ctx' proof : Expr) (nvars : Nat) : Expr × Expr := Id.run do
let (e, pr) := reifyFmla ctx'
let mut pr := pr
for i in [0:nvars] do
let j := nvars-i-1
let ty := mkApp2 (mkConst ``Iff) (mkApp (mkBVar j) (mkRawNatLit j)) (mkBVar nvars)
pr := mkLambda `h default ty pr
pr := mkLambd... | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | buildReify | Build the type and value of the reified theorem. This rewrites all the SAT definitions
into standard operators on `Prop`, for example if the formula is `[[1, 2], [-1, 2], [-2]]` then
this produces a proof of `⊢ ∀ a b : Prop, (a ∧ b) ∨ (¬a ∧ b) ∨ ¬b`. We use the input `nvars` to
decide how many quantifiers to use.
Most... |
parseNat : String.Parser Nat := Json.Parser.natMaybeZero | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | parseNat | Parse a natural number |
parseInt : String.Parser Int := do
if (← peek!) = '-' then skip; pure <| -(← parseNat) else parseNat | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | parseInt | Parse an integer |
partial parseInts (arr : Array Int := #[]) : String.Parser (Array Int) := do
match ← parseInt <* ws with
| 0 => pure arr
| n => parseInts (arr.push n) | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | parseInts | Parse a list of integers terminated by 0 |
partial parseNats (arr : Array Nat := #[]) : String.Parser (Array Nat) := do
match ← parseNat <* ws with
| 0 => pure arr
| n => parseNats (arr.push n) | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | parseNats | Parse a list of natural numbers terminated by 0 |
parseDimacs : String.Parser (Nat × Array (Array Int)) := do
pstring "p cnf" *> ws
let nvars ← parseNat <* ws
let nclauses ← parseNat <* ws
let mut clauses := Array.mkEmpty nclauses
for _ in [:nclauses] do
clauses := clauses.push (← parseInts)
pure (nvars, clauses) | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | parseDimacs | Parse a DIMACS format `.cnf` file.
This is not very robust; we assume the file has had comments stripped. |
parseLRAT : String.Parser (Array LRATStep) := many do
let step ← parseNat <* ws
if (← peek!) = 'd' then skip <* ws; pure <| LRATStep.del (← parseNats)
else ws; pure <| LRATStep.add step (← parseInts) (← parseInts) | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | parseLRAT | Parse an LRAT file into a list of steps. |
fromLRATAux (cnf lrat : String) (name : Name) : MetaM (Nat × Expr × Expr × Expr) := do
let Parsec.ParseResult.success _ (nvars, arr) := Parser.parseDimacs cnf.mkIterator
| throwError "parse CNF failed"
if arr.isEmpty then throwError "empty CNF"
let ctx' := buildConj arr 0 arr.size
let ctxName ← mkAuxDeclNam... | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | fromLRATAux | Core of `fromLRAT`. Constructs the context and main proof definitions,
but not the reification theorem. Returns:
* `nvars`: the number of variables specified in the CNF file
* `ctx`: The abbreviated formula, a constant like `foo.ctx_1`
* `ctx'`: The definitional expansion of the formula, a tree of `Fmla.and` nod... |
fromLRAT (cnf lrat : String) (name : Name) : MetaM Unit := do
let (nvars, ctx, ctx', proof) ← fromLRATAux cnf lrat name
let (type, value) := buildReify ctx ctx' proof nvars
addDecl <| Declaration.thmDecl { name, levelParams := [], type, value }
open Elab Term | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | fromLRAT | Main entry point. Given strings `cnf` and `lrat` with unparsed file data, and a name `name`,
adds `theorem name : type := proof` where `type` is a propositional theorem like
`∀ (a a_1 : Prop), (¬a ∧ ¬a_1 ∨ a ∧ ¬a_1) ∨ ¬a ∧ a_1 ∨ a ∧ a_1`.
Also creates auxiliaries named `name.ctx_1` (for the CNF formula)
and `name.proo... |
foo := from_lrat
"p cnf 2 4 1 2 0 -1 2 0 1 -2 0 -1 -2 0"
"5 -2 0 4 3 0 5 d 3 4 0 6 1 0 5 1 0 6 d 1 0 7 0 5 2 6 0"
```
produces a theorem:
```
foo : ∀ (a a_1 : Prop), (¬a ∧ ¬a_1 ∨ a ∧ ¬a_1) ∨ ¬a ∧ a_1 ∨ a ∧ a_1
```
* You can use this term after `have :=` or in `def foo :=` to produce the term
without const... | def | Tactic | [
"Mathlib.Algebra.Group.Nat.Defs",
"Mathlib.Tactic.ByContra"
] | Mathlib/Tactic/Sat/FromLRAT.lean | foo | null |
private exists_of_imp_eq {α : Sort u} {p : α → Prop} (a : α) (h : ∀ b, p b → a = b) :
(∃ b, p b) = p a := by
grind | theorem | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/Simproc/ExistsAndEq.lean | exists_of_imp_eq | null |
partial findImpEqProof (p : Expr) :
MetaM <| Option (Expr × Expr) := do
lambdaTelescope p fun xs body => do
let #[x] := xs | return none
withLocalDecl .anonymous .default body fun h => withNewMCtxDepth do
let some ⟨res, proof⟩ ← go x h | return none
let pf1 ← mkLambdaFVars #[x, h] proof
... | def | Tactic | [
"Mathlib.Init"
] | Mathlib/Tactic/Simproc/ExistsAndEq.lean | findImpEqProof | For an expression `p` of the form `fun (x : α) ↦ (body : Prop)`, checks whether
`body` implies `x = a` for some `a`, and constructs a proof of `(∃ x, p x) = p a` using
`exists_of_imp_eq`. |
FactorsHelper (n p : ℕ) (l : List ℕ) : Prop :=
p.Prime → (p :: l).IsChain (· ≤ ·) ∧ (∀ a ∈ l, Nat.Prime a) ∧ l.prod = n
/-! The argument explicitness in this section is chosen to make only the numerals in the factors
list appear in the proof term. -/ | def | Tactic | [
"Mathlib.Data.Nat.Factors",
"Mathlib.Tactic.NormNum.Prime"
] | Mathlib/Tactic/Simproc/Factors.lean | FactorsHelper | A proof of the partial computation of `primeFactorsList`.
Asserts that `l` is a sorted list of primes multiplying to `n` and lower bounded by a prime `p`. |
FactorsHelper.nil {a : ℕ} : FactorsHelper 1 a [] := fun _ =>
⟨.singleton _, List.forall_mem_nil _, List.prod_nil⟩ | theorem | Tactic | [
"Mathlib.Data.Nat.Factors",
"Mathlib.Tactic.NormNum.Prime"
] | Mathlib/Tactic/Simproc/Factors.lean | FactorsHelper.nil | null |
FactorsHelper.cons_of_le
{n m : ℕ} (a : ℕ) {b : ℕ} {l : List ℕ} (h₁ : IsNat (b * m) n) (h₂ : a ≤ b)
(h₃ : minFac b = b) (H : FactorsHelper m b l) : FactorsHelper n a (b :: l) := fun pa =>
have pb : b.Prime := Nat.prime_def_minFac.2 ⟨le_trans pa.two_le h₂, h₃⟩
let ⟨f₁, f₂, f₃⟩ := H pb
⟨List.IsChain.cons_co... | theorem | Tactic | [
"Mathlib.Data.Nat.Factors",
"Mathlib.Tactic.NormNum.Prime"
] | Mathlib/Tactic/Simproc/Factors.lean | FactorsHelper.cons_of_le | null |
FactorsHelper.cons
{n m : ℕ} {a : ℕ} (b : ℕ) {l : List ℕ} (h₁ : IsNat (b * m) n) (h₂ : Nat.blt a b)
(h₃ : IsNat (minFac b) b) (H : FactorsHelper m b l) : FactorsHelper n a (b :: l) :=
H.cons_of_le _ h₁ (Nat.blt_eq.mp h₂).le h₃.out | theorem | Tactic | [
"Mathlib.Data.Nat.Factors",
"Mathlib.Tactic.NormNum.Prime"
] | Mathlib/Tactic/Simproc/Factors.lean | FactorsHelper.cons | null |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.