statement
stringlengths
1
2.88k
proof
stringlengths
0
13.9k
type
stringclasses
10 values
symbolic_name
stringlengths
1
131
library
stringclasses
417 values
filename
stringlengths
17
80
imports
listlengths
0
16
deps
listlengths
0
64
docstring
stringlengths
0
10.2k
source_url
stringclasses
1 value
commit
stringclasses
1 value
comp.add (c1 c2 : comp) : comp
⟨c1.str.max c2.str, c1.coeffs.add c2.coeffs⟩
def
linarith.comp.add
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
`comp.add c1 c2` adds the expressions represented by `c1` and `c2`. The coefficient of variable `a` in `c1.add c2` is the sum of the coefficients of `a` in `c1` and `c2`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp.cmp : comp → comp → ordering
| ⟨str1, coeffs1⟩ ⟨str2, coeffs2⟩ := match str1.cmp str2 with | ordering.lt := ordering.lt | ordering.gt := ordering.gt | ordering.eq := coeffs1.cmp coeffs2 end
def
linarith.comp.cmp
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
`comp` has a lex order. First the `ineq`s are compared, then the `coeff`s.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp.is_contr (c : comp) : bool
c.coeffs.empty ∧ c.str = ineq.lt
def
linarith.comp.is_contr
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
A `comp` represents a contradiction if its expression has no coefficients and its strength is <, that is, it represents the fact `0 < 0`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp.to_format : has_to_format comp
⟨λ p, to_fmt p.coeffs ++ to_string p.str ++ "0"⟩
instance
linarith.comp.to_format
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
preprocessor : Type
(name : string) (transform : expr → tactic (list expr))
structure
linarith.preprocessor
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
A preprocessor transforms a proof of a proposition into a proof of a different propositon. The return type is `list expr`, since some preprocessing steps may create multiple new hypotheses, and some may remove a hypothesis from the list. A "no-op" preprocessor should return its input as a singleton list.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
global_preprocessor : Type
(name : string) (transform : list expr → tactic (list expr))
structure
linarith.global_preprocessor
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
Some preprocessors need to examine the full list of hypotheses instead of working item by item. As with `preprocessor`, the input to a `global_preprocessor` is replaced by, not added to, its output.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
branch : Type
expr × list expr
def
linarith.branch
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
Some preprocessors perform branching case splits. A `branch` is used to track one of these case splits. The first component, an `expr`, is the goal corresponding to this branch of the split, given as a metavariable. The `list expr` component is the list of hypotheses for `linarith` in this branch. Every `expr` in this ...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
global_branching_preprocessor : Type
(name : string) (transform : list expr → tactic (list branch))
structure
linarith.global_branching_preprocessor
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
Some preprocessors perform branching case splits. A `global_branching_preprocessor` produces a list of branches to run. Each branch is independent, so hypotheses that appear in multiple branches should be duplicated. The preprocessor is responsible for making sure that each branch contains the correct goal metavariable...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
preprocessor.globalize (pp : preprocessor) : global_preprocessor
{ name := pp.name, transform := list.mfoldl (λ ret e, do l' ← pp.transform e, return (l' ++ ret)) [] }
def
linarith.preprocessor.globalize
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[ "ret" ]
A `preprocessor` lifts to a `global_preprocessor` by folding it over the input list.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
global_preprocessor.branching (pp : global_preprocessor) : global_branching_preprocessor
{ name := pp.name, transform := λ l, do g ← tactic.get_goal, singleton <$> prod.mk g <$> pp.transform l }
def
linarith.global_preprocessor.branching
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[ "tactic.get_goal" ]
A `global_preprocessor` lifts to a `global_branching_preprocessor` by producing only one branch.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
global_branching_preprocessor.process (pp : global_branching_preprocessor) (l : list expr) : tactic (list branch)
do l ← pp.transform l, when (l.length > 1) $ linarith_trace format!"Preprocessing: {pp.name} has branched, with branches:", l.mmap' $ λ l, tactic.set_goals [l.1] >> linarith_trace_proofs (to_string format!"Preprocessing: {pp.name}") l.2, return l
def
linarith.global_branching_preprocessor.process
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
`process pp l` runs `pp.transform` on `l` and returns the result, tracing the result if `trace.linarith` is on.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
preprocessor_to_gb_preprocessor : has_coe preprocessor global_branching_preprocessor
⟨global_preprocessor.branching ∘ preprocessor.globalize⟩
instance
linarith.preprocessor_to_gb_preprocessor
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
global_preprocessor_to_gb_preprocessor : has_coe global_preprocessor global_branching_preprocessor
⟨global_preprocessor.branching⟩
instance
linarith.global_preprocessor_to_gb_preprocessor
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
certificate_oracle : Type
list comp → ℕ → tactic (rb_map ℕ ℕ)
def
linarith.certificate_oracle
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
A `certificate_oracle` is a function `produce_certificate : list comp → ℕ → tactic (rb_map ℕ ℕ)`. `produce_certificate hyps max_var` tries to derive a contradiction from the comparisons in `hyps` by eliminating all variables ≤ `max_var`. If successful, it returns a map `coeff : ℕ → ℕ` as a certificate. This map represe...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linarith_config : Type
(discharger : tactic unit := `[ring]) (restrict_type : option Type := none) (restrict_type_reflect : reflected _ restrict_type . tactic.apply_instance) (exfalso : bool := tt) (transparency : tactic.transparency := reducible) (split_hypotheses : bool := tt) (split_ne : bool := ff) (preprocessors : option (list global_br...
structure
linarith.linarith_config
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[ "ring" ]
A configuration object for `linarith`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linarith_config.update_reducibility (cfg : linarith_config) (reduce_semi : bool) : linarith_config
if reduce_semi then { cfg with transparency := semireducible, discharger := `[ring!] } else cfg
def
linarith.linarith_config.update_reducibility
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
`cfg.update_reducibility reduce_semi` will change the transparency setting of `cfg` to `semireducible` if `reduce_semi` is true. In this case, it also sets the discharger to `ring!`, since this is typically needed when using stronger unification.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
get_rel_sides : expr → tactic (expr × expr)
| `(%%a < %%b) := return (a, b) | `(%%a ≤ %%b) := return (a, b) | `(%%a = %%b) := return (a, b) | `(%%a ≥ %%b) := return (a, b) | `(%%a > %%b) := return (a, b) | _ := tactic.failed
def
linarith.get_rel_sides
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
`get_rel_sides e` returns the left and right hand sides of `e` if `e` is a comparison, and fails otherwise. This function is more naturally in the `option` monad, but it is convenient to put in `tactic` for compositionality.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
parse_into_comp_and_expr : expr → option (ineq × expr)
| `(%%e < 0) := (ineq.lt, e) | `(%%e ≤ 0) := (ineq.le, e) | `(%%e = 0) := (ineq.eq, e) | _ := none
def
linarith.parse_into_comp_and_expr
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[]
`parse_into_comp_and_expr e` checks if `e` is of the form `t < 0`, `t ≤ 0`, or `t = 0`. If it is, it returns the comparison along with `t`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mk_single_comp_zero_pf (c : ℕ) (h : expr) : tactic (ineq × expr)
do tp ← infer_type h >>= instantiate_mvars, some (iq, e) ← return $ parse_into_comp_and_expr tp, if c = 0 then do e' ← mk_app ``zero_mul [e], return (ineq.eq, e') else if c = 1 then return (iq, h) else do tp ← (prod.snd <$> (infer_type h >>= instantiate_mvars >>= get_rel_sides)) >>= infer_type, c...
def
linarith.mk_single_comp_zero_pf
tactic.linarith
src/tactic/linarith/datatypes.lean
[ "tactic.linarith.lemmas", "tactic.ring" ]
[ "zero_mul" ]
`mk_single_comp_zero_pf c h` assumes that `h` is a proof of `t R 0`. It produces a pair `(R', h')`, where `h'` is a proof of `c*t R' 0`. Typically `R` and `R'` will be the same, except when `c = 0`, in which case `R'` is `=`. If `c = 1`, `h'` is the same as `h` -- specifically, it does *not* change the type to `1*t R 0...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp_source : Type | assump : ℕ → comp_source | add : comp_source → comp_source → comp_source | scale : ℕ → comp_source → comp_source
inductive
linarith.comp_source
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`comp_source` tracks the source of a comparison. The atomic source of a comparison is an assumption, indexed by a natural number. Two comparisons can be added to produce a new comparison, and one comparison can be scaled by a natural number to produce a new comparison.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp_source.flatten : comp_source → rb_map ℕ ℕ
| (comp_source.assump n) := mk_rb_map.insert n 1 | (comp_source.add c1 c2) := (comp_source.flatten c1).add (comp_source.flatten c2) | (comp_source.scale n c) := (comp_source.flatten c).map (λ v, v * n)
def
linarith.comp_source.flatten
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Given a `comp_source` `cs`, `cs.flatten` maps an assumption index to the number of copies of that assumption that appear in the history of `cs`. For example, suppose `cs` is produced by scaling assumption 2 by 5, and adding to that the sum of assumptions 1 and 2. `cs.flatten` maps `1 ↦ 1, 2 ↦ 6`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp_source.to_string : comp_source → string
| (comp_source.assump e) := to_string e | (comp_source.add c1 c2) := comp_source.to_string c1 ++ " + " ++ comp_source.to_string c2 | (comp_source.scale n c) := to_string n ++ " * " ++ comp_source.to_string c
def
linarith.comp_source.to_string
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Formats a `comp_source` for printing.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
comp_source.has_to_format : has_to_format comp_source
⟨λ a, comp_source.to_string a⟩
instance
linarith.comp_source.has_to_format
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp : Type
(c : comp) (src : comp_source) (history : rb_set ℕ) (effective : rb_set ℕ) (implicit : rb_set ℕ) (vars : rb_set ℕ)
structure
linarith.pcomp
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
A `pcomp` stores a linear comparison `Σ cᵢ*xᵢ R 0`, along with information about how this comparison was derived. The original expressions fed into `linarith` are each assigned a unique natural number label. The *historical set* `pcomp.history` stores the labels of expressions that were used in deriving the current `pc...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.maybe_minimal (c : pcomp) (elimed_ge : ℕ) : bool
c.history.size ≤ 1 + ((c.implicit.filter (≥ elimed_ge)).union c.effective).size
def
linarith.pcomp.maybe_minimal
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Any comparison whose history is not minimal is redundant, and need not be included in the new set of comparisons. `elimed_ge : ℕ` is a natural number such that all variables with index ≥ `elimed_ge` have been removed from the system. This test is an overapproximation to minimality. It gives necessary but not sufficien...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.cmp (p1 p2 : pcomp) : ordering
p1.c.cmp p2.c
def
linarith.pcomp.cmp
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
The `comp_source` field is ignored when comparing `pcomp`s. Two `pcomp`s proving the same comparison, with different sources, are considered equivalent.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.scale (c : pcomp) (n : ℕ) : pcomp
{c with c := c.c.scale n, src := c.src.scale n}
def
linarith.pcomp.scale
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`pcomp.scale c n` scales the coefficients of `c` by `n` and notes this in the `comp_source`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.add (c1 c2 : pcomp) (elim_var : ℕ) : pcomp
let c := c1.c.add c2.c, src := c1.src.add c2.src, history := c1.history.union c2.history, vars := c1.vars.union c2.vars, effective := (c1.effective.union c2.effective).insert elim_var, implicit := (vars.sdiff (rb_set.of_list c.vars)).sdiff effective in ⟨c, src, history, effective, implicit, vars⟩
def
linarith.pcomp.add
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`pcomp.add c1 c2 elim_var` creates the result of summing the linear comparisons `c1` and `c2`, during the process of eliminating the variable `elim_var`. The computation assumes, but does not enforce, that `elim_var` appears in both `c1` and `c2` and does not appear in the sum. Computing the sum of the two comparisons ...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.assump (c : comp) (n : ℕ) : pcomp
{ c := c, src := comp_source.assump n, history := mk_rb_set.insert n, effective := mk_rb_set, implicit := mk_rb_set, vars := rb_set.of_list c.vars }
def
linarith.pcomp.assump
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`pcomp.assump c n` creates a `pcomp` whose comparison is `c` and whose source is `comp_source.assump n`, that is, `c` is derived from the `n`th hypothesis. The history is the singleton set `{n}`. No variables have been eliminated (effectively or implicitly).
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.to_format : has_to_format pcomp
⟨λ p, to_fmt p.c.coeffs ++ to_string p.c.str ++ "0"⟩
instance
linarith.pcomp.to_format
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mk_pcomp_set : rb_set pcomp
rb_map.mk_core unit pcomp.cmp
def
linarith.mk_pcomp_set
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Creates an empty set of `pcomp`s, sorted using `pcomp.cmp`. This should always be used instead of `mk_rb_map` for performance reasons.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
elim_var (c1 c2 : comp) (a : ℕ) : option (ℕ × ℕ)
let v1 := c1.coeff_of a, v2 := c2.coeff_of a in if v1 * v2 < 0 then let vlcm := nat.lcm v1.nat_abs v2.nat_abs, v1' := vlcm / v1.nat_abs, v2' := vlcm / v2.nat_abs in some ⟨v1', v2'⟩ else none
def
linarith.elim_var
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
If `c1` and `c2` both contain variable `a` with opposite coefficients, produces `v1` and `v2` such that `a` has been cancelled in `v1*c1 + v2*c2`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pelim_var (p1 p2 : pcomp) (a : ℕ) : option pcomp
do (n1, n2) ← elim_var p1.c p2.c a, return $ (p1.scale n1).add (p2.scale n2) a
def
linarith.pelim_var
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`pelim_var p1 p2` calls `elim_var` on the `comp` components of `p1` and `p2`. If this returns `v1` and `v2`, it creates a new `pcomp` equal to `v1*p1 + v2*p2`, and tracks this in the `comp_source`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
pcomp.is_contr (p : pcomp) : bool
p.c.is_contr
def
linarith.pcomp.is_contr
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
A `pcomp` represents a contradiction if its `comp` field represents a contradiction.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
elim_with_set (a : ℕ) (p : pcomp) (comps : rb_set pcomp) : rb_set pcomp
comps.fold mk_pcomp_set $ λ pc s, match pelim_var p pc a with | some pc := if pc.maybe_minimal a then s.insert pc else s | none := s end
def
linarith.elim_with_set
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`elim_var_with_set a p comps` collects the result of calling `pelim_var p p' a` for every `p' ∈ comps`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linarith_structure : Type
(max_var : ℕ) (comps : rb_set pcomp)
structure
linarith.linarith_structure
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
The state for the elimination monad. * `max_var`: the largest variable index that has not been eliminated. * `comps`: a set of comparisons The elimination procedure proceeds by eliminating variable `v` from `comps` progressively in decreasing order.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linarith_monad : Type → Type
state_t linarith_structure (except_t pcomp id)
def
linarith.linarith_monad
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
The linarith monad extends an exceptional monad with a `linarith_structure` state. An exception produces a contradictory `pcomp`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
get_max_var : linarith_monad ℕ
linarith_structure.max_var <$> get
def
linarith.get_max_var
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Returns the current max variable.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
get_comps : linarith_monad (rb_set pcomp)
linarith_structure.comps <$> get
def
linarith.get_comps
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Return the current comparison set.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
validate : linarith_monad unit
do ⟨_, comps⟩ ← get, match comps.to_list.find (λ p : pcomp, p.is_contr) with | none := return () | some c := throw c end
def
linarith.validate
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
Throws an exception if a contradictory `pcomp` is contained in the current state.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
update (max_var : ℕ) (comps : rb_set pcomp) : linarith_monad unit
state_t.put ⟨max_var, comps⟩ >> validate
def
linarith.update
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[ "update" ]
Updates the current state with a new max variable and comparisons, and calls `validate` to check for a contradiction.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
split_set_by_var_sign (a : ℕ) (comps : rb_set pcomp) : rb_set pcomp × rb_set pcomp × rb_set pcomp
comps.fold ⟨mk_pcomp_set, mk_pcomp_set, mk_pcomp_set⟩ $ λ pc ⟨pos, neg, not_present⟩, let n := pc.c.coeff_of a in if n > 0 then ⟨pos.insert pc, neg, not_present⟩ else if n < 0 then ⟨pos, neg.insert pc, not_present⟩ else ⟨pos, neg, not_present.insert pc⟩
def
linarith.split_set_by_var_sign
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`split_set_by_var_sign a comps` partitions the set `comps` into three parts. * `pos` contains the elements of `comps` in which `a` has a positive coefficient. * `neg` contains the elements of `comps` in which `a` has a negative coefficient. * `not_present` contains the elements of `comps` in which `a` has coefficient 0...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
monad.elim_var (a : ℕ) : linarith_monad unit
do vs ← get_max_var, when (a ≤ vs) $ do ⟨pos, neg, not_present⟩ ← split_set_by_var_sign a <$> get_comps, let cs' := pos.fold not_present (λ p s, s.union (elim_with_set a p neg)), update (vs - 1) cs'
def
linarith.monad.elim_var
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[ "update" ]
`monad.elim_var a` performs one round of Fourier-Motzkin elimination, eliminating the variable `a` from the `linarith` state.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
elim_all_vars : linarith_monad unit
do mv ← get_max_var, (list.range $ mv + 1).reverse.mmap' monad.elim_var
def
linarith.elim_all_vars
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`elim_all_vars` eliminates all variables from the linarith state, leaving it with a set of ground comparisons. If this succeeds without exception, the original `linarith` state is consistent.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mk_linarith_structure (hyps : list comp) (max_var : ℕ) : linarith_structure
let pcomp_list : list pcomp := hyps.enum.map $ λ ⟨n, cmp⟩, pcomp.assump cmp n, pcomp_set := rb_set.of_list_core mk_pcomp_set pcomp_list in ⟨max_var, pcomp_set⟩
def
linarith.mk_linarith_structure
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`mk_linarith_structure hyps vars` takes a list of hypotheses and the largest variable present in those hypotheses. It produces an initial state for the elimination monad.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
fourier_motzkin.produce_certificate : certificate_oracle
λ hyps max_var, let state := mk_linarith_structure hyps max_var in match except_t.run (state_t.run (validate >> elim_all_vars) state) with | (except.ok (a, _)) := tactic.failed | (except.error contr) := return contr.src.flatten end
def
linarith.fourier_motzkin.produce_certificate
tactic.linarith
src/tactic/linarith/elimination.lean
[ "tactic.linarith.datatypes" ]
[]
`produce_certificate hyps vars` tries to derive a contradiction from the comparisons in `hyps` by eliminating all variables ≤ `max_var`. If successful, it returns a map `coeff : ℕ → ℕ` as a certificate. This map represents that we can find a contradiction by taking the sum `∑ (coeff i) * hyps[i]`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
get_contr_lemma_name_and_type : expr → option (name × expr)
| `(@has_lt.lt %%tp %%_ _ _) := return (`lt_of_not_ge, tp) | `(@has_le.le %%tp %%_ _ _) := return (`le_of_not_gt, tp) | `(@eq %%tp _ _) := return (``eq_of_not_lt_of_not_gt, tp) | `(@ne %%tp _ _) := return (`not.intro, tp) | `(@ge %%tp %%_ _ _) := return (`le_of_not_gt, tp) | `(@gt %%tp %%_ _ _) := return (`lt_of_not_ge...
def
linarith.get_contr_lemma_name_and_type
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[]
If `e` is a comparison `a R b` or the negation of a comparison `¬ a R b`, found in the target, `get_contr_lemma_name_and_type e` returns the name of a lemma that will change the goal to an implication, along with the type of `a` and `b`. For example, if `e` is `(a : ℕ) < b`, returns ``(`lt_of_not_ge, ℕ)``.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
apply_contr_lemma : tactic (option (expr × expr))
do t ← target >>= instantiate_mvars, match get_contr_lemma_name_and_type t with | some (nm, tp) := do refine ((expr.const nm []) pexpr.mk_placeholder), v ← intro1, return $ some (tp, v) | none := return none end
def
linarith.apply_contr_lemma
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[]
`apply_contr_lemma` inspects the target to see if it can be moved to a hypothesis by negation. For example, a goal `⊢ a ≤ b` can become `a > b ⊢ false`. If this is the case, it applies the appropriate lemma and introduces the new hypothesis. It returns the type of the terms in the comparison (e.g. the type of `a` and `...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
partition_by_type (l : list expr) : tactic (rb_lmap expr expr)
l.mfoldl (λ m h, do tp ← ineq_prf_tp h, return $ m.insert tp h) mk_rb_map
def
linarith.partition_by_type
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[]
`partition_by_type l` takes a list `l` of proofs of comparisons. It sorts these proofs by the type of the variables in the comparison, e.g. `(a : ℚ) < 1` and `(b : ℤ) > c` will be separated. Returns a map from a type to a list of comparisons over that type.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
try_linarith_on_lists (cfg : linarith_config) (ls : list (list expr)) : tactic expr
(first $ ls.map $ prove_false_by_linarith cfg) <|> fail "linarith failed to find a contradiction"
def
linarith.try_linarith_on_lists
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[]
Given a list `ls` of lists of proofs of comparisons, `try_linarith_on_lists cfg ls` will try to prove `false` by calling `linarith` on each list in succession. It will stop at the first proof of `false`, and fail if no contradiction is found with any list.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
run_linarith_on_pfs (cfg : linarith_config) (hyps : list expr) (pref_type : option expr) : tactic unit
let single_process := λ hyps : list expr, do linarith_trace_proofs ("after preprocessing, linarith has " ++ to_string hyps.length ++ " facts:") hyps, hyp_set ← partition_by_type hyps, linarith_trace format!"hypotheses appear in {hyp_set.size} different types", match pref_type with | some t := prove_...
def
linarith.run_linarith_on_pfs
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[]
Given a list `hyps` of proofs of comparisons, `run_linarith_on_pfs cfg hyps pref_type` preprocesses `hyps` according to the list of preprocessors in `cfg`. This results in a list of branches (typically only one), each of which must succeed in order to close the goal. In each branch, we partition the list of hypothese...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
filter_hyps_to_type (restr_type : expr) (hyps : list expr) : tactic (list expr)
hyps.mfilter $ λ h, do ht ← infer_type h >>= instantiate_mvars, match get_contr_lemma_name_and_type ht with | some (_, htype) := succeeds $ unify htype restr_type | none := return ff end
def
filter_hyps_to_type
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[ "succeeds" ]
`filter_hyps_to_type restr_type hyps` takes a list of proofs of comparisons `hyps`, and filters it to only those that are comparisons over the type `restr_type`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
get_restrict_type (e : expr) : tactic expr
do m ← mk_mvar, unify `(some %%m : option Type) e, instantiate_mvars m
def
get_restrict_type
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[]
A hack to allow users to write `{restr_type := ℚ}` in configuration structures.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
tactic.linarith (reduce_semi : bool) (only_on : bool) (hyps : list pexpr) (cfg : linarith_config := {}) : tactic unit
focus1 $ do t ← target >>= instantiate_mvars, -- if the target is an equality, we run `linarith` twice, to prove ≤ and ≥. if t.is_eq.is_some then linarith_trace "target is an equality: splitting" >> seq' (applyc ``eq_of_not_lt_of_not_gt) tactic.linarith else do hyps ← hyps.mmap $ λ e, i_to_expr e >>= note_anon no...
def
tactic.linarith
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[ "auto.split_hyps", "filter_hyps_to_type", "get_restrict_type" ]
`linarith reduce_semi only_on hyps cfg` tries to close the goal using linear arithmetic. It fails if it does not succeed at doing this. * If `reduce_semi` is true, it will unfold semireducible definitions when trying to match atomic expressions. * `hyps` is a list of proofs of comparisons to include in the search. * I...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
tactic.interactive.linarith (red : parse ((tk "!")?)) (restr : parse ((tk "only")?)) (hyps : parse pexpr_list?) (cfg : linarith_config := {}) : tactic unit
tactic.linarith red.is_some restr.is_some (hyps.get_or_else []) cfg
def
tactic.interactive.linarith
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[ "tactic.linarith" ]
Tries to prove a goal of `false` by linear arithmetic on hypotheses. If the goal is a linear (in)equality, tries to prove it by contradiction. If the goal is not `false` or an inequality, applies `exfalso` and tries linarith on the hypotheses. * `linarith` will use all relevant hypotheses in the local context. * `lina...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
tactic.interactive.nlinarith (red : parse ((tk "!")?)) (restr : parse ((tk "only")?)) (hyps : parse pexpr_list?) (cfg : linarith_config := {}) : tactic unit
tactic.linarith red.is_some restr.is_some (hyps.get_or_else []) { cfg with preprocessors := some $ cfg.preprocessors.get_or_else default_preprocessors ++ [nlinarith_extras] }
def
tactic.interactive.nlinarith
tactic.linarith
src/tactic/linarith/frontend.lean
[ "tactic.linarith.verification", "tactic.linarith.preprocessing" ]
[ "tactic.linarith" ]
An extension of `linarith` with some preprocessing to allow it to solve some nonlinear arithmetic problems. (Based on Coq's `nra` tactic.) See `linarith` for the available syntax of options, which are inherited by `nlinarith`; that is, `nlinarith!` and `nlinarith only [h1, h2]` all work as in `linarith`. The preprocess...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
zero_lt_one {α} [ordered_semiring α] [nontrivial α] : (0 : α) < 1
zero_lt_one
lemma
linarith.zero_lt_one
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "nontrivial", "ordered_semiring", "zero_lt_one" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
eq_of_eq_of_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b = 0) : a + b = 0
by simp *
lemma
linarith.eq_of_eq_of_eq
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "ordered_semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
le_of_eq_of_le {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b ≤ 0) : a + b ≤ 0
by simp *
lemma
linarith.le_of_eq_of_le
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "le_of_eq_of_le", "ordered_semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
lt_of_eq_of_lt {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : b < 0) : a + b < 0
by simp *
lemma
linarith.lt_of_eq_of_lt
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "lt_of_eq_of_lt", "ordered_semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
le_of_le_of_eq {α} [ordered_semiring α] {a b : α} (ha : a ≤ 0) (hb : b = 0) : a + b ≤ 0
by simp *
lemma
linarith.le_of_le_of_eq
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "le_of_le_of_eq", "ordered_semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
lt_of_lt_of_eq {α} [ordered_semiring α] {a b : α} (ha : a < 0) (hb : b = 0) : a + b < 0
by simp *
lemma
linarith.lt_of_lt_of_eq
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "lt_of_lt_of_eq", "ordered_semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mul_neg {α} [strict_ordered_ring α] {a b : α} (ha : a < 0) (hb : 0 < b) : b * a < 0
have (-b)*a > 0, from mul_pos_of_neg_of_neg (neg_neg_of_pos hb) ha, neg_of_neg_pos (by simpa)
lemma
linarith.mul_neg
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "mul_neg", "mul_pos_of_neg_of_neg", "strict_ordered_ring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mul_nonpos {α} [ordered_ring α] {a b : α} (ha : a ≤ 0) (hb : 0 < b) : b * a ≤ 0
have (-b)*a ≥ 0, from mul_nonneg_of_nonpos_of_nonpos (le_of_lt (neg_neg_of_pos hb)) ha, by simpa
lemma
linarith.mul_nonpos
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "mul_nonneg_of_nonpos_of_nonpos", "ordered_ring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mul_eq {α} [ordered_semiring α] {a b : α} (ha : a = 0) (hb : 0 < b) : b * a = 0
by simp *
lemma
linarith.mul_eq
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "ordered_semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
eq_of_not_lt_of_not_gt {α} [linear_order α] (a b : α) (h1 : ¬ a < b) (h2 : ¬ b < a) : a = b
le_antisymm (le_of_not_gt h2) (le_of_not_gt h1)
lemma
linarith.eq_of_not_lt_of_not_gt
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mul_zero_eq {α} {R : α → α → Prop} [semiring α] {a b : α} (_ : R a 0) (h : b = 0) : a * b = 0
by simp [h]
lemma
linarith.mul_zero_eq
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
zero_mul_eq {α} {R : α → α → Prop} [semiring α] {a b : α} (h : a = 0) (_ : R b 0) : a * b = 0
by simp [h]
lemma
linarith.zero_mul_eq
tactic.linarith
src/tactic/linarith/lemmas.lean
[ "algebra.order.ring.defs" ]
[ "semiring" ]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
monom : Type
rb_map ℕ ℕ
def
linarith.monom
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
Variables (represented by natural numbers) map to their power.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
monom.one : monom
rb_map.mk _ _
def
linarith.monom.one
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`1` is represented by the empty monomial, the product of no variables.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
monom.lt : monom → monom → Prop
λ a b, (a.keys < b.keys) || ((a.keys = b.keys) && (a.values < b.values))
def
linarith.monom.lt
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
Compare monomials by first comparing their keys and then their powers.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum : Type
rb_map monom ℤ
def
linarith.sum
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
Linear combinations of monomials are represented by mapping monomials to coefficients.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum.one : sum
rb_map.of_list [(monom.one, 1)]
def
linarith.sum.one
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`1` is represented as the singleton sum of the monomial `monom.one` with coefficient 1.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum.scale_by_monom (s : sum) (m : monom) : sum
s.fold mk_rb_map $ λ m' coeff sm, sm.insert (m.add m') coeff
def
linarith.sum.scale_by_monom
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`sum.scale_by_monom s m` multiplies every monomial in `s` by `m`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum.mul (s1 s2 : sum) : sum
s1.fold mk_rb_map $ λ mn coeff sm, sm.add $ (s2.scale_by_monom mn).scale coeff
def
linarith.sum.mul
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`sum.mul s1 s2` distributes the multiplication of two sums.`
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum.pow (s : sum) : ℕ → sum
| 0 := sum.one | (k+1) := s.mul (sum.pow k)
def
linarith.sum.pow
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
The `n`th power of `s : sum` is the `n`-fold product of `s`, with `s.pow 0 = sum.one`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum_of_monom (m : monom) : sum
mk_rb_map.insert m 1
def
linarith.sum_of_monom
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`sum_of_monom m` lifts `m` to a sum with coefficient `1`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
one : monom
mk_rb_map
def
linarith.one
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
The unit monomial `one` is represented by the empty rb map.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
scalar (z : ℤ) : sum
mk_rb_map.insert one z
def
linarith.scalar
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
A scalar `z` is represented by a `sum` with coefficient `z` and monomial `one`
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
var (n : ℕ) : sum
mk_rb_map.insert (mk_rb_map.insert n 1) 1
def
linarith.var
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
A single variable `n` is represented by a sum with coefficient `1` and monomial `n`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linear_form_of_atom (red : transparency) (m : exmap) (e : expr) : tactic (exmap × sum)
(do (_, k) ← m.find_defeq red e, return (m, var k)) <|> (let n := m.length + 1 in return ((e, n)::m, var n))
def
linarith.linear_form_of_atom
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`linear_form_of_atom red map e` is the atomic case for `linear_form_of_expr`. If `e` appears with index `k` in `map`, it returns the singleton sum `var k`. Otherwise it updates `map`, adding `e` with index `n`, and returns the singleton sum `var n`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linear_form_of_expr (red : transparency) : exmap → expr → tactic (exmap × sum)
| m e@`(%%e1 * %%e2) := do (m', comp1) ← linear_form_of_expr m e1, (m', comp2) ← linear_form_of_expr m' e2, return (m', comp1.mul comp2) | m `(%%e1 + %%e2) := do (m', comp1) ← linear_form_of_expr m e1, (m', comp2) ← linear_form_of_expr m' e2, return (m', comp1.add comp2) | m `(%%e1 - %%e2)...
def
linarith.linear_form_of_expr
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`linear_form_of_expr red map e` computes the linear form of `e`. `map` is a lookup map from atomic expressions to variable numbers. If a new atomic expression is encountered, it is added to the map with a new number. It matches atomic expressions up to reducibility given by `red`. Because it matches up to definitiona...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
sum_to_lf (s : sum) (m : rb_map monom ℕ) : rb_map monom ℕ × rb_map ℕ ℤ
s.fold (m, mk_rb_map) $ λ mn coeff ⟨map, out⟩, match map.find mn with | some n := ⟨map, out.insert n coeff⟩ | none := let n := map.size in ⟨map.insert mn n, out.insert n coeff⟩ end
def
linarith.sum_to_lf
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`sum_to_lf s map` eliminates the monomial level of the `sum` `s`. `map` is a lookup map from monomials to variable numbers. The output `rb_map ℕ ℤ` has the same structure as `sum`, but each monomial key is replaced with its index according to `map`. If any new monomials are encountered, they are assigned variable numb...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
to_comp (red : transparency) (e : expr) (e_map : exmap) (monom_map : rb_map monom ℕ) : tactic (comp × exmap × rb_map monom ℕ)
do (iq, e) ← parse_into_comp_and_expr e, (m', comp') ← linear_form_of_expr red e_map e, let ⟨nm, mm'⟩ := sum_to_lf comp' monom_map, return ⟨⟨iq, mm'.to_list⟩, m', nm⟩
def
linarith.to_comp
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`to_comp red e e_map monom_map` converts an expression of the form `t < 0`, `t ≤ 0`, or `t = 0` into a `comp` object. `e_map` maps atomic expressions to indices; `monom_map` maps monomials to indices. Both of these are updated during processing and returned.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
to_comp_fold (red : transparency) : exmap → list expr → rb_map monom ℕ → tactic (list comp × exmap × rb_map monom ℕ)
| m [] mm := return ([], m, mm) | m (h::t) mm := do (c, m', mm') ← to_comp red h m mm, (l, mp, mm') ← to_comp_fold m' t mm', return (c::l, mp, mm')
def
linarith.to_comp_fold
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`to_comp_fold red e_map exprs monom_map` folds `to_comp` over `exprs`, updating `e_map` and `monom_map` as it goes.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
linear_forms_and_max_var (red : transparency) (pfs : list expr) : tactic (list comp × ℕ)
do pftps ← pfs.mmap (λ e, infer_type e >>= instantiate_mvars), (l, _, map) ← to_comp_fold red [] pftps mk_rb_map, return (l, map.size - 1)
def
linarith.linear_forms_and_max_var
tactic.linarith
src/tactic/linarith/parsing.lean
[ "tactic.linarith.datatypes" ]
[]
`linear_forms_and_vars red pfs` is the main interface for computing the linear forms of a list of expressions. Given a list `pfs` of proofs of comparisons, it produces a list `c` of `comps` of the same length, such that `c[i]` represents the linear form of the type of `pfs[i]`. It also returns the largest variable ind...
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
rem_neg (prf : expr) : expr → tactic expr
| `(_ ≤ _) := mk_app ``lt_of_not_ge [prf] | `(_ < _) := mk_app ``le_of_not_gt [prf] | `(_ > _) := mk_app ``le_of_not_gt [prf] | `(_ ≥ _) := mk_app ``lt_of_not_ge [prf] | e := failed
def
linarith.rem_neg
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
If `prf` is a proof of `¬ e`, where `e` is a comparison, `rem_neg prf e` flips the comparison in `e` and returns a proof. For example, if `prf : ¬ a < b`, ``rem_neg prf `(a < b)`` returns a proof of `a ≥ b`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
rearr_comp_aux : expr → expr → tactic expr
| prf `(%%a ≤ 0) := return prf | prf `(%%a < 0) := return prf | prf `(%%a = 0) := return prf | prf `(%%a ≥ 0) := mk_app ``neg_nonpos_of_nonneg [prf] | prf `(%%a > 0) := mk_app `neg_neg_of_pos [prf] | prf `(0 ≥ %%a) := to_expr ``(id_rhs (%%a ≤ 0) %%prf) | prf `(0 > %%a) := to_expr ``(id_rhs (%%a < 0) %%prf) | prf ...
def
linarith.rearr_comp_aux
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
rearr_comp (e : expr) : tactic expr
infer_type e >>= instantiate_mvars >>= rearr_comp_aux e
def
linarith.rearr_comp
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
`rearr_comp e` takes a proof `e` of an equality, inequality, or negation thereof, and turns it into a proof of a comparison `_ R 0`, where `R ∈ {=, ≤, <}`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
is_nat_int_coe : expr → option expr
| `(@coe ℕ ℤ %%_ %%n) := some n | _ := none
def
linarith.is_nat_int_coe
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
If `e` is of the form `((n : ℕ) : ℤ)`, `is_nat_int_coe e` returns `n : ℕ`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mk_coe_nat_nonneg_prf (e : expr) : tactic expr
mk_app `int.coe_nat_nonneg [e]
def
linarith.mk_coe_nat_nonneg_prf
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[ "int.coe_nat_nonneg" ]
If `e : ℕ`, returns a proof of `0 ≤ (e : ℤ)`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
get_nat_comps : expr → list expr
| `(%%a + %%b) := (get_nat_comps a).append (get_nat_comps b) | `(%%a * %%b) := (get_nat_comps a).append (get_nat_comps b) | e := match is_nat_int_coe e with | some e' := [e'] | none := [] end
def
linarith.get_nat_comps
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
`get_nat_comps e` returns a list of all subexpressions of `e` of the form `((t : ℕ) : ℤ)`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
mk_non_strict_int_pf_of_strict_int_pf (pf : expr) : tactic expr
do tp ← infer_type pf >>= instantiate_mvars, match tp with | `(%%a < %%b) := to_expr ``(int.add_one_le_iff.mpr %%pf) | `(%%a > %%b) := to_expr ``(int.add_one_le_iff.mpr %%pf) | `(¬ %%a ≤ %%b) := to_expr ``(int.add_one_le_iff.mpr (le_of_not_gt %%pf)) | `(¬ %%a ≥ %%b) := to_expr ``(int.add_one_le_iff.mpr (le_of_not_gt %%...
def
linarith.mk_non_strict_int_pf_of_strict_int_pf
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
If `pf` is a proof of a strict inequality `(a : ℤ) < b`, `mk_non_strict_int_pf_of_strict_int_pf pf` returns a proof of `a + 1 ≤ b`, and similarly if `pf` proves a negated weak inequality.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
is_nat_prop : expr → bool
| `(@eq ℕ %%_ _) := tt | `(@has_le.le ℕ %%_ _ _) := tt | `(@has_lt.lt ℕ %%_ _ _) := tt | `(@ge ℕ %%_ _ _) := tt | `(@gt ℕ %%_ _ _) := tt | `(¬ %%p) := is_nat_prop p | _ := ff
def
linarith.is_nat_prop
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
`is_nat_prop tp` is true iff `tp` is an inequality or equality between natural numbers or the negation thereof.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
is_strict_int_prop : expr → bool
| `(@has_lt.lt ℤ %%_ _ _) := tt | `(@gt ℤ %%_ _ _) := tt | `(¬ @has_le.le ℤ %%_ _ _) := tt | `(¬ @ge ℤ %%_ _ _) := tt | _ := ff
def
linarith.is_strict_int_prop
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
`is_strict_int_prop tp` is true iff `tp` is a strict inequality between integers or the negation of a weak inequality between integers.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
filter_comparisons_aux : expr → bool
| `(¬ %%p) := p.app_symbol_in [`has_lt.lt, `has_le.le, `gt, `ge] | tp := tp.app_symbol_in [`has_lt.lt, `has_le.le, `gt, `ge, `eq]
def
linarith.filter_comparisons_aux
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
filter_comparisons : preprocessor
{ name := "filter terms that are not proofs of comparisons", transform := λ h, (do tp ← infer_type h >>= instantiate_mvars, is_prop tp >>= guardb, guardb (filter_comparisons_aux tp), return [h]) <|> return [] }
def
linarith.filter_comparisons
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
Removes any expressions that are not proofs of inequalities, equalities, or negations thereof.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
remove_negations : preprocessor
{ name := "replace negations of comparisons", transform := λ h, do tp ← infer_type h >>= instantiate_mvars, match tp with | `(¬ %%p) := singleton <$> rem_neg h p | _ := return [h] end }
def
linarith.remove_negations
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
Replaces proofs of negations of comparisons with proofs of the reversed comparisons. For example, a proof of `¬ a < b` will become a proof of `a ≥ b`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
nat_to_int : global_preprocessor
{ name := "move nats to ints", transform := λ l, -- we lock the tactic state here because a `simplify` call inside of -- `zify_proof` corrupts the tactic state when run under `io.run_tactic`. do l ← lock_tactic_state $ l.mmap $ λ h, infer_type h >>= instantiate_mvars >>= guardb ∘ is_nat_prop >> zify_proof [] h ...
def
linarith.nat_to_int
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
If `h` is an equality or inequality between natural numbers, `nat_to_int` lifts this inequality to the integers. It also adds the facts that the integers involved are nonnegative. To avoid adding the same nonnegativity facts many times, it is a global preprocessor.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83
strengthen_strict_int : preprocessor
{ name := "strengthen strict inequalities over int", transform := λ h, do tp ← infer_type h >>= instantiate_mvars, guardb (is_strict_int_prop tp) >> singleton <$> mk_non_strict_int_pf_of_strict_int_pf h <|> return [h] }
def
linarith.strengthen_strict_int
tactic.linarith
src/tactic/linarith/preprocessing.lean
[ "data.prod.lex", "tactic.cancel_denoms", "tactic.linarith.datatypes", "tactic.zify" ]
[]
`strengthen_strict_int h` turns a proof `h` of a strict integer inequality `t1 < t2` into a proof of `t1 ≤ t2 + 1`.
https://github.com/leanprover-community/mathlib
65a1391a0106c9204fe45bc73a039f056558cb83