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 |
|---|---|---|---|---|---|---|---|---|---|---|
uses_hyp (e : expr) (h : expr) : bool | e.fold ff $ λ t _ r, r || (t = h) | def | tactic.interactive.uses_hyp | tactic | src/tactic/rewrite.lean | [
"data.dlist",
"tactic.core"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
assoc_rw_hyp : list rw_rule → expr → tactic unit | | [] hyp := skip
| (r::rs) hyp := do
save_info r.pos,
eq_lemmas ← get_rule_eqn_lemmas r,
orelse'
(do e ← to_expr' r.rule, when (¬ uses_hyp e hyp) $ assoc_rewrite_hyp e hyp >>= assoc_rw_hyp rs)
(eq_lemmas.mfirst $ λ n, do e ← mk_const n, assoc_rewrite_hyp e hyp >>= assoc_rw_hyp rs)
(eq_lemmas.empt... | def | tactic.interactive.assoc_rw_hyp | tactic | src/tactic/rewrite.lean | [
"data.dlist",
"tactic.core"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
assoc_rw_core (rs : parse rw_rules) (loca : parse location) : tactic unit | match loca with
| loc.wildcard := loca.try_apply (assoc_rw_hyp rs.rules) (assoc_rw_goal rs.rules)
| _ := loca.apply (assoc_rw_hyp rs.rules) (assoc_rw_goal rs.rules)
end >> try reflexivity
>> try (returnopt rs.end_pos >>= save_info) | def | tactic.interactive.assoc_rw_core | tactic | src/tactic/rewrite.lean | [
"data.dlist",
"tactic.core"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
assoc_rewrite (q : parse rw_rules) (l : parse location) : tactic unit | propagate_tags (assoc_rw_core q l) | def | tactic.interactive.assoc_rewrite | tactic | src/tactic/rewrite.lean | [
"data.dlist",
"tactic.core"
] | [] | `assoc_rewrite [h₀,← h₁] at ⊢ h₂` behaves like `rewrite [h₀,← h₁] at ⊢ h₂`
with the exception that associativity is used implicitly to make rewriting
possible.
It works for any function `f` for which an `is_associative f` instance can be found.
```
example {α : Type*} (f : α → α → α) [is_associative α f] (a b c d x :... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
assoc_rw (q : parse rw_rules) (l : parse location) : tactic unit | assoc_rewrite q l | def | tactic.interactive.assoc_rw | tactic | src/tactic/rewrite.lean | [
"data.dlist",
"tactic.core"
] | [] | synonym for `assoc_rewrite` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner {α} [comm_semiring α] (a x : α) (n : ℕ) (b : α) | a * x ^ n + b | def | tactic.ring.horner | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring"
] | The normal form that `ring` uses is mediated by the function `horner a x n b := a * x ^ n + b`.
The reason we use a definition rather than the (more readable) expression on the right is because
this expression contains a number of typeclass arguments in different positions, while `horner`
contains only one `comm_semiri... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
cache | (α : expr)
(univ : level)
(comm_semiring_inst : expr)
(red : transparency)
(ic : ref instance_cache)
(nc : ref instance_cache)
(atoms : ref (buffer expr)) | structure | tactic.ring.cache | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | This cache contains data required by the `ring` tactic during execution. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring_m (α : Type) : Type | reader_t cache tactic α | def | tactic.ring.ring_m | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | The monad that `ring` works in. This is a reader monad containing a mutable cache (using `ref`
for mutability), as well as the list of atoms-up-to-defeq encountered thus far, used for atom
sorting. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_cache : ring_m cache | reader_t.read | def | tactic.ring.get_cache | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Get the `ring` data from the monad. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_atom (n : ℕ) : ring_m expr | ⟨λ c, do es ← read_ref c.atoms, pure (es.read' n)⟩ | def | tactic.ring.get_atom | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Get an already encountered atom by its index. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_atom (e : expr) : ring_m ℕ | ⟨λ c, do
let red := c.red,
es ← read_ref c.atoms,
es.iterate failed (λ n e' t, t <|> (is_def_eq e e' red $> n)) <|>
(es.size <$ write_ref c.atoms (es.push_back e))⟩ | def | tactic.ring.add_atom | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Get the index corresponding to an atomic expression, if it has already been encountered, or
put it in the list of atoms and return the new index, otherwise. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lift {α} (m : tactic α) : ring_m α | reader_t.lift m | def | tactic.ring.lift | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"lift"
] | Lift a tactic into the `ring_m` monad. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring_m.run' (red : transparency) (atoms : ref (buffer expr))
(e : expr) {α} (m : ring_m α) : tactic α | do α ← infer_type e,
u ← mk_meta_univ,
infer_type α >>= unify (expr.sort (level.succ u)),
u ← get_univ_assignment u,
ic ← mk_instance_cache α,
(ic, c) ← ic.get ``comm_semiring,
nc ← mk_instance_cache `(ℕ),
using_new_ref ic $ λ r,
using_new_ref nc $ λ nr,
reader_t.run m ⟨α, u, c, red, r, nr, a... | def | tactic.ring.ring_m.run' | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring"
] | Run a `ring_m` tactic in the tactic monad. This version of `ring_m.run` uses an external
atoms ref, so that subexpressions can be named across multiple `ring_m` calls. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring_m.run (red : transparency) (e : expr) {α} (m : ring_m α) : tactic α | using_new_ref mk_buffer $ λ atoms, ring_m.run' red atoms e m | def | tactic.ring.ring_m.run | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Run a `ring_m` tactic in the tactic monad. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ic_lift' (icf : cache → ref instance_cache) {α}
(f : instance_cache → tactic (instance_cache × α)) : ring_m α | ⟨λ c, do
let r := icf c,
ic ← read_ref r,
(ic', a) ← f ic,
a <$ write_ref r ic'⟩ | def | tactic.ring.ic_lift' | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Lift an instance cache tactic (probably from `norm_num`) to the `ring_m` monad. This version
is abstract over the instance cache in question (either the ring `α`, or `ℕ` for exponents). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ic_lift {α} : (instance_cache → tactic (instance_cache × α)) → ring_m α | ic_lift' cache.ic | def | tactic.ring.ic_lift | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Lift an instance cache tactic (probably from `norm_num`) to the `ring_m` monad. This uses
the instance cache corresponding to the ring `α`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nc_lift {α} : (instance_cache → tactic (instance_cache × α)) → ring_m α | ic_lift' cache.nc | def | tactic.ring.nc_lift | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Lift an instance cache tactic (probably from `norm_num`) to the `ring_m` monad. This uses
the instance cache corresponding to `ℕ`, which is used for computations in the exponent. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
cache.cs_app (c : cache) (n : name) : list expr → expr | (@expr.const tt n [c.univ] c.α c.comm_semiring_inst).mk_app | def | tactic.ring.cache.cs_app | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Apply a theorem that expects a `comm_semiring` instance. This is a special case of
`ic_lift mk_app`, but it comes up often because `horner` and all its theorems have this assumption;
it also does not require the tactic monad which improves access speed a bit. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr : Type
| const (e : expr) (coeff : ℚ) : horner_expr
| xadd (e : expr) (a : horner_expr) (x : expr × ℕ) (n : expr × ℕ) (b : horner_expr) : horner_expr | inductive | tactic.ring.horner_expr | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Every expression in the language of commutative semirings can be viewed as a sum of monomials,
where each monomial is a product of powers of atoms. We fix a global order on atoms (up to
definitional equality), and then separate the terms according to their smallest atom. So the top
level expression is `a * x^n + b` whe... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_expr.e : horner_expr → expr | | (horner_expr.const e _) := e
| (horner_expr.xadd e _ _ _ _) := e | def | tactic.ring.horner_expr.e | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Get the expression corresponding to a `horner_expr`. This can be calculated recursively from
the structure, but we cache the exprs in all subterms so that this function can be computed in
constant time. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr.is_zero : horner_expr → bool | | (horner_expr.const _ c) := c = 0
| _ := ff | def | tactic.ring.horner_expr.is_zero | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Is this expr the constant `0`? | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr.xadd' (c : cache) (a : horner_expr)
(x : expr × ℕ) (n : expr × ℕ) (b : horner_expr) : horner_expr | horner_expr.xadd (c.cs_app ``horner [a, x.1, n.1, b]) a x n b | def | tactic.ring.horner_expr.xadd' | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Construct a `xadd` node, generating the cached expr using the input cache. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr.to_string : horner_expr → string | | (const e c) := to_string (e, c)
| (xadd e a x (_, n) b) :=
"(" ++ a.to_string ++ ") * (" ++ to_string x.1 ++ ")^"
++ to_string n ++ " + " ++ b.to_string | def | tactic.ring.horner_expr.to_string | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Pretty printer for `horner_expr`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr.pp : horner_expr → tactic format | | (const e c) := pp (e, c)
| (xadd e a x (_, n) b) := do
pa ← a.pp, pb ← b.pp, px ← pp x.1,
return $ "(" ++ pa ++ ") * (" ++ px ++ ")^" ++ to_string n ++ " + " ++ pb | def | tactic.ring.horner_expr.pp | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Pretty printer for `horner_expr`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr.refl_conv (e : horner_expr) : ring_m (horner_expr × expr) | do p ← lift $ mk_eq_refl e, return (e, p) | def | tactic.ring.horner_expr.refl_conv | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"lift"
] | Reflexivity conversion for a `horner_expr`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
zero_horner {α} [comm_semiring α] (x n b) :
@horner α _ 0 x n b = b | by simp [horner] | theorem | tactic.ring.zero_horner | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_horner {α} [comm_semiring α] (a₁ x n₁ n₂ b n')
(h : n₁ + n₂ = n') :
@horner α _ (horner a₁ x n₁ 0) x n₂ b = horner a₁ x n' b | by simp [h.symm, horner, pow_add, mul_assoc] | theorem | tactic.ring.horner_horner | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_assoc",
"pow_add"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_horner : horner_expr → expr × ℕ → expr × ℕ → horner_expr → ring_m (horner_expr × expr) | | ha@(const a coeff) x n b := do
c ← get_cache,
if coeff = 0 then
return (b, c.cs_app ``zero_horner [x.1, n.1, b])
else (xadd' c ha x n b).refl_conv
| ha@(xadd a a₁ x₁ n₁ b₁) x n b := do
c ← get_cache,
if x₁.2 = x.2 ∧ b₁.e.to_nat = some 0 then do
(n', h) ← nc_lift $ λ nc, norm_num.prove_add_nat' nc n₁... | def | tactic.ring.eval_horner | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"norm_num.prove_add_nat'"
] | Evaluate `horner a n x b` where `a` and `b` are already in normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
const_add_horner {α} [comm_semiring α] (k a x n b b') (h : k + b = b') :
k + @horner α _ a x n b = horner a x n b' | by simp [h.symm, horner]; cc | theorem | tactic.ring.const_add_horner | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_add_const {α} [comm_semiring α] (a x n b k b') (h : b + k = b') :
@horner α _ a x n b + k = horner a x n b' | by simp [h.symm, horner, add_assoc] | theorem | tactic.ring.horner_add_const | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_add_horner_lt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₁ + k = n₂) (h₂ : (a₁ + horner a₂ x k 0 : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₁ b' | by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]; cc | theorem | tactic.ring.horner_add_horner_lt | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_comm",
"mul_left_comm",
"pow_add"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_add_horner_gt {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ b₂ k a' b')
(h₁ : n₂ + k = n₁) (h₂ : (horner a₁ x k 0 + a₂ : α) = a') (h₃ : b₁ + b₂ = b') :
@horner α _ a₁ x n₁ b₁ + horner a₂ x n₂ b₂ = horner a' x n₂ b' | by simp [h₂.symm, h₃.symm, h₁.symm, horner, pow_add, mul_add, mul_comm, mul_left_comm]; cc | theorem | tactic.ring.horner_add_horner_gt | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_comm",
"mul_left_comm",
"pow_add"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_add_horner_eq {α} [comm_semiring α] (a₁ x n b₁ a₂ b₂ a' b' t)
(h₁ : a₁ + a₂ = a') (h₂ : b₁ + b₂ = b') (h₃ : horner a' x n b' = t) :
@horner α _ a₁ x n b₁ + horner a₂ x n b₂ = t | by simp [h₃.symm, h₂.symm, h₁.symm, horner, add_mul, mul_comm (x ^ n)]; cc | theorem | tactic.ring.horner_add_horner_eq | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_comm"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_add : horner_expr → horner_expr → ring_m (horner_expr × expr) | | (const e₁ c₁) (const e₂ c₂) := ic_lift $ λ ic, do
let n := c₁ + c₂,
(ic, e) ← ic.of_rat n,
(ic, p) ← norm_num.prove_add_rat ic e₁ e₂ e c₁ c₂ n,
return (ic, const e n, p)
| he₁@(const e₁ c₁) he₂@(xadd e₂ a x n b) := do
c ← get_cache,
if c₁ = 0 then ic_lift $ λ ic, do
(ic, p) ← ic.mk_app ``zero_add [e₂]... | def | tactic.ring.eval_add | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"norm_num.prove_add_rat"
] | Evaluate `a + b` where `a` and `b` are already in normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_neg {α} [comm_ring α] (a x n b a' b')
(h₁ : -a = a') (h₂ : -b = b') :
-@horner α _ a x n b = horner a' x n b' | by simp [h₂.symm, h₁.symm, horner]; cc | theorem | tactic.ring.horner_neg | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_ring"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_neg : horner_expr → ring_m (horner_expr × expr) | | (const e coeff) := do
(e', p) ← ic_lift $ λ ic, norm_num.prove_neg ic e,
return (const e' (-coeff), p)
| (xadd e a x n b) := do
c ← get_cache,
(a', h₁) ← eval_neg a,
(b', h₂) ← eval_neg b,
p ← ic_lift $ λ ic, ic.mk_app ``horner_neg [a, x.1, n.1, b, a', b', h₁, h₂],
return (xadd' c a' x n b', p) | def | tactic.ring.eval_neg | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"norm_num.prove_neg"
] | Evaluate `-a` where `a` is already in normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_const_mul {α} [comm_semiring α] (c a x n b a' b')
(h₁ : c * a = a') (h₂ : c * b = b') :
c * @horner α _ a x n b = horner a' x n b' | by simp [h₂.symm, h₁.symm, horner, mul_add, mul_assoc] | theorem | tactic.ring.horner_const_mul | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_assoc"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_mul_const {α} [comm_semiring α] (a x n b c a' b')
(h₁ : a * c = a') (h₂ : b * c = b') :
@horner α _ a x n b * c = horner a' x n b' | by simp [h₂.symm, h₁.symm, horner, add_mul, mul_right_comm] | theorem | tactic.ring.horner_mul_const | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_right_comm"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_const_mul (k : expr × ℚ) :
horner_expr → ring_m (horner_expr × expr) | | (const e coeff) := do
(e', p) ← ic_lift $ λ ic, norm_num.prove_mul_rat ic k.1 e k.2 coeff,
return (const e' (k.2 * coeff), p)
| (xadd e a x n b) := do
c ← get_cache,
(a', h₁) ← eval_const_mul a,
(b', h₂) ← eval_const_mul b,
return (xadd' c a' x n b',
c.cs_app ``horner_const_mul [k.1, a, x.1, n.1, b, a... | def | tactic.ring.eval_const_mul | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"norm_num.prove_mul_rat"
] | Evaluate `k * a` where `k` is a rational numeral and `a` is in normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_mul_horner_zero {α} [comm_semiring α] (a₁ x n₁ b₁ a₂ n₂ aa t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ 0 = t | by rw [← h₂, ← h₁];
simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc] | theorem | tactic.ring.horner_mul_horner_zero | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_assoc",
"mul_comm",
"mul_left_comm"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner_mul_horner {α} [comm_semiring α]
(a₁ x n₁ b₁ a₂ n₂ b₂ aa haa ab bb t)
(h₁ : @horner α _ a₁ x n₁ b₁ * a₂ = aa)
(h₂ : horner aa x n₂ 0 = haa)
(h₃ : a₁ * b₂ = ab) (h₄ : b₁ * b₂ = bb)
(H : haa + horner ab x n₁ bb = t) :
horner a₁ x n₁ b₁ * horner a₂ x n₂ b₂ = t | by rw [← H, ← h₂, ← h₁, ← h₃, ← h₄];
simp [horner, mul_add, mul_comm, mul_left_comm, mul_assoc] | theorem | tactic.ring.horner_mul_horner | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_assoc",
"mul_comm",
"mul_left_comm"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_mul : horner_expr → horner_expr → ring_m (horner_expr × expr) | | (const e₁ c₁) (const e₂ c₂) := do
(e', p) ← ic_lift $ λ ic, norm_num.prove_mul_rat ic e₁ e₂ c₁ c₂,
return (const e' (c₁ * c₂), p)
| (const e₁ c₁) e₂ :=
if c₁ = 0 then do
c ← get_cache,
α0 ← ic_lift $ λ ic, ic.mk_app ``has_zero.zero [],
p ← ic_lift $ λ ic, ic.mk_app ``zero_mul [e₂],
return (const... | def | tactic.ring.eval_mul | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"lift",
"mul_comm",
"norm_num.prove_mul_rat",
"one_mul",
"zero_mul"
] | Evaluate `a * b` where `a` and `b` are in normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_pow {α} [comm_semiring α] (a x n m n' a') (h₁ : n * m = n') (h₂ : a ^ m = a') :
@horner α _ a x n 0 ^ m = horner a' x n' 0 | by simp [h₁.symm, h₂.symm, horner, mul_pow, pow_mul] | theorem | tactic.ring.horner_pow | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_pow",
"pow_mul"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pow_succ {α} [comm_semiring α] (a n b c)
(h₁ : (a:α) ^ n = b) (h₂ : b * a = c) : a ^ (n + 1) = c | by rw [← h₂, ← h₁, pow_succ'] | theorem | tactic.ring.pow_succ | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"pow_succ",
"pow_succ'"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_pow : horner_expr → expr × ℕ → ring_m (horner_expr × expr) | | e (_, 0) := do
c ← get_cache,
α1 ← ic_lift $ λ ic, ic.mk_app ``has_one.one [],
p ← ic_lift $ λ ic, ic.mk_app ``pow_zero [e],
return (const α1 1, p)
| e (_, 1) := do
p ← ic_lift $ λ ic, ic.mk_app ``pow_one [e],
return (e, p)
| (const e coeff) (e₂, m) := ic_lift $ λ ic, do
(ic, e', p) ← norm_num.prove_pow... | def | tactic.ring.eval_pow | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"norm_num.prove_mul_rat",
"norm_num.prove_pow",
"pow_one",
"pow_succ",
"pow_zero"
] | Evaluate `a ^ n` where `a` is in normal form and `n` is a natural numeral. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_atom {α} [comm_semiring α] (x : α) : x = horner 1 x 1 0 | by simp [horner] | theorem | tactic.ring.horner_atom | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_atom (e : expr) : ring_m (horner_expr × expr) | do c ← get_cache,
i ← add_atom e,
α0 ← ic_lift $ λ ic, ic.mk_app ``has_zero.zero [],
α1 ← ic_lift $ λ ic, ic.mk_app ``has_one.one [],
return (xadd' c (const α1 1) (e, i) (`(1), 1) (const α0 0),
c.cs_app ``horner_atom [e]) | def | tactic.ring.eval_atom | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Evaluate `a` where `a` is an atom. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
eval_norm_atom (norm_atom : expr → tactic (expr × expr))
(e : expr) : ring_m (horner_expr × expr) | do o ← lift $ try_core (guard (e.get_app_args.length > 0) >> norm_atom e),
match o with
| none := eval_atom e
| some (e', p) := do
(e₂, p₂) ← eval_atom e',
prod.mk e₂ <$> lift (mk_eq_trans p p₂)
end | def | tactic.ring.eval_norm_atom | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"lift"
] | Evaluate `a` where `a` is an atom. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
subst_into_pow {α} [monoid α] (l r tl tr t)
(prl : (l : α) = tl) (prr : (r : ℕ) = tr) (prt : tl ^ tr = t) : l ^ r = t | by rw [prl, prr, prt] | lemma | tactic.ring.subst_into_pow | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"monoid"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
unfold_sub {α} [add_group α] (a b c : α)
(h : a + -b = c) : a - b = c | by rw [sub_eq_add_neg, h] | lemma | tactic.ring.unfold_sub | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"add_group"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
unfold_div {α} [division_ring α] (a b c : α)
(h : a * b⁻¹ = c) : a / b = c | by rw [div_eq_mul_inv, h] | lemma | tactic.ring.unfold_div | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"div_eq_mul_inv",
"division_ring"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval (norm_atom : expr → tactic (expr × expr)) : expr → ring_m (horner_expr × expr) | | `(%%e₁ + %%e₂) := do
(e₁', p₁) ← eval e₁,
(e₂', p₂) ← eval e₂,
(e', p') ← eval_add e₁' e₂',
p ← ic_lift $ λ ic, ic.mk_app ``norm_num.subst_into_add [e₁, e₂, e₁', e₂', e', p₁, p₂, p'],
return (e', p)
| e@`(@has_sub.sub %%α %%inst %%e₁ %%e₂) :=
mcond (succeeds (lift $ mk_app ``comm_ring [α] >>= mk_instance)... | def | tactic.ring.eval | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_ring",
"lift",
"monoid.has_pow",
"norm_num.derive",
"norm_num.subst_into_add",
"norm_num.subst_into_mul",
"norm_num.subst_into_neg",
"succeeds"
] | Evaluate a ring expression `e` recursively to normal form, together with a proof of
equality. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
eval' (red : transparency) (atoms : ref (buffer expr))
(norm_atom : expr → tactic (expr × expr)) (e : expr) : tactic (expr × expr) | ring_m.run' red atoms e $ do (e', p) ← eval norm_atom e, return (e', p) | def | tactic.ring.eval' | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Evaluate a ring expression `e` recursively to normal form, together with a proof of
equality. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_def' {α} [comm_semiring α] (a x n b) : @horner α _ a x n b = x ^ n * a + b | by simp [horner, mul_comm] | theorem | tactic.ring.horner_def' | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"comm_semiring",
"mul_comm"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mul_assoc_rev {α} [semigroup α] (a b c : α) : a * (b * c) = a * b * c | by simp [mul_assoc] | theorem | tactic.ring.mul_assoc_rev | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"mul_assoc",
"semigroup"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pow_add_rev {α} [monoid α] (a : α) (m n : ℕ) : a ^ m * a ^ n = a ^ (m + n) | by simp [pow_add] | theorem | tactic.ring.pow_add_rev | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"monoid",
"pow_add"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pow_add_rev_right {α} [monoid α] (a b : α) (m n : ℕ) :
b * a ^ m * a ^ n = b * a ^ (m + n) | by simp [pow_add, mul_assoc] | theorem | tactic.ring.pow_add_rev_right | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"monoid",
"mul_assoc",
"pow_add"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
add_neg_eq_sub {α} [add_group α] (a b : α) : a + -b = a - b | (sub_eq_add_neg a b).symm | theorem | tactic.ring.add_neg_eq_sub | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"add_group"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
normalize_mode | raw | SOP | horner | inductive | tactic.ring.normalize_mode | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | If `ring` fails to close the goal, it falls back on normalizing the expression to a "pretty"
form so that you can see why it failed. This setting adjusts the resulting form:
* `raw` is the form that `ring` actually uses internally, with iterated applications of `horner`.
Not very readable but useful if you don't... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
normalize' (atoms : ref (buffer expr))
(red : transparency) (mode := normalize_mode.horner) (recursive := tt) :
expr → opt_param _ ff → tactic (expr × expr) | | e inner := do
pow_lemma ← simp_lemmas.mk.add_simp ``pow_one,
let lemmas := match mode with
| normalize_mode.SOP :=
[``horner_def', ``add_zero, ``mul_one, ``mul_add, ``mul_sub,
``mul_assoc_rev, ``pow_add_rev, ``pow_add_rev_right,
``mul_neg, ``add_neg_eq_sub]
| normalize_mode.horner :=
[``horner... | def | tactic.ring.normalize' | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"mul_neg",
"mul_one",
"neg_mul",
"norm_num.derive",
"one_mul",
"pow_one"
] | A `ring`-based normalization simplifier that rewrites ring expressions into the specified mode.
See `normalize`. This version takes a list of atoms to persist across multiple calls.
* `atoms`: a mutable reference containing the atom set from the previous call
* `red`: the reducibility setting to use when comparing ato... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
normalize (red : transparency) (mode := normalize_mode.horner)
(recursive := tt) (e : expr) : tactic (expr × expr) | using_new_ref mk_buffer $ λ atoms, normalize' atoms red mode recursive e | def | tactic.normalize | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"normalize"
] | A `ring`-based normalization simplifier that rewrites ring expressions into the specified mode.
* `raw` is the form that `ring` actually uses internally, with iterated applications of `horner`.
Not very readable but useful if you don't want any postprocessing.
This results in terms like `horner (horner (horn... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring_nf_cfg | (recursive := tt) | structure | tactic.ring_nf_cfg | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Configuration for `ring_nf`.
* `recursive`: if true, atoms inside ring expressions will be reduced recursively | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring1 (red : parse (tk "!")?) : tactic unit | let transp := if red.is_some then semireducible else reducible in
do `(%%e₁ = %%e₂) ← target >>= instantiate_mvars,
((e₁', p₁), (e₂', p₂)) ← ring_m.run transp e₁ $
prod.mk <$> eval (λ _, failed) e₁ <*> eval (λ _, failed) e₂,
is_def_eq e₁' e₂',
p ← mk_eq_symm p₂ >>= mk_eq_trans p₁,
tactic.exact p | def | interactive.ring1 | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Tactic for solving equations in the language of *commutative* (semi)rings.
This version of `ring` fails if the target is not an equality
that is provable by the axioms of commutative (semi)rings. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring.mode : lean.parser ring.normalize_mode | with_desc "(SOP|raw|horner)?" $
do mode ← ident?, match mode with
| none := pure ring.normalize_mode.horner
| some `horner := pure ring.normalize_mode.horner
| some `SOP := pure ring.normalize_mode.SOP
| some `raw := pure ring.normalize_mode.raw
| _ := failed
end | def | interactive.ring.mode | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [] | Parser for `ring_nf`'s `mode` argument, which can only be the "keywords" `raw`, `horner` or
`SOP`. (Because these are not actually keywords we use a name parser and postprocess the result.) | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring_nf (red : parse (tk "!")?) (SOP : parse ring.mode) (loc : parse location)
(cfg : ring_nf_cfg := {}) : tactic unit | do ns ← loc.get_locals,
let transp := if red.is_some then semireducible else reducible,
tt ← using_new_ref mk_buffer $ λ atoms,
tactic.replace_at (normalize' atoms transp SOP cfg.recursive) ns loc.include_goal
| fail "ring_nf failed to simplify",
when loc.include_goal $ try tactic.reflexivity | def | interactive.ring_nf | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"tactic.replace_at"
] | Simplification tactic for expressions in the language of commutative (semi)rings,
which rewrites all ring expressions into a normal form. When writing a normal form,
`ring_nf SOP` will use sum-of-products form instead of horner form.
`ring_nf!` will use a more aggressive reducibility setting to identify atoms. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring (red : parse (tk "!")?) : tactic unit | ring1 red <|>
(ring_nf red normalize_mode.horner (loc.ns [none]) >> trace "Try this: ring_nf") | def | interactive.ring | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"ring"
] | Tactic for solving equations in the language of *commutative* (semi)rings.
`ring!` will use a more aggressive reducibility setting to identify atoms.
If the goal is not solvable, it falls back to rewriting all ring expressions
into a normal form, with a suggestion to use `ring_nf` instead, if this is the intent.
See a... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring_nf (red : parse (lean.parser.tk "!")?) (SOP : parse ring.mode)
(cfg : ring.ring_nf_cfg := {}) : conv unit | let transp := if red.is_some then semireducible else reducible in
replace_lhs (normalize transp SOP cfg.recursive)
<|> fail "ring_nf failed to simplify" | def | conv.interactive.ring_nf | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"normalize"
] | Normalises expressions in commutative (semi-)rings inside of a `conv` block using the tactic `ring`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring (red : parse (lean.parser.tk "!")?) : conv unit | let transp := if red.is_some then semireducible else reducible in
discharge_eq_lhs (ring1 red)
<|> (replace_lhs (normalize transp normalize_mode.horner) >> trace "Try this: ring_nf")
<|> fail "ring failed to simplify" | def | conv.interactive.ring | tactic | src/tactic/ring.lean | [
"tactic.norm_num",
"data.fin.basic"
] | [
"normalize",
"ring"
] | Normalises expressions in commutative (semi-)rings inside of a `conv` block using the tactic `ring`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
reflect' (u : level) (α : expr) : tree expr → expr | | tree.nil := (expr.const ``tree.nil [u] : expr) α
| (tree.node a t₁ t₂) :=
(expr.const ``tree.node [u] : expr) α a t₁.reflect' t₂.reflect' | def | tree.reflect' | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"tree"
] | `(reflect' t u α)` quasiquotes a tree `(t: tree expr)` of quoted
values of type `α` at level `u` into an `expr` which reifies to a `tree α`
containing the reifications of the `expr`s from the original `t`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_or_zero {α} [has_zero α] (t : tree α) (n : pos_num) : α | t.get_or_else n 0 | def | tree.get_or_zero | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"pos_num",
"tree"
] | Returns an element indexed by `n`, or zero if `n` isn't a valid index.
See `tree.get`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
csring_expr
/- (atom n) is an opaque element of the csring. For example,
a local variable in the context. n indexes into a storage
of such atoms - a `tree α`. -/
| atom : pos_num → csring_expr
/- (const n) is technically the csring's one, added n times.
Or the zero if n is 0. -/
| const : num → csring_expr
| add : csri... | inductive | tactic.ring2.csring_expr | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"num",
"pos_num"
] | A reflected/meta representation of an expression in a commutative
semiring. This representation is a direct translation of such
expressions - see `horner_expr` for a normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval {α} [comm_semiring α] (t : tree α) : csring_expr → α | | (atom n) := t.get_or_zero n
| (const n) := n
| (add x y) := eval x + eval y
| (mul x y) := eval x * eval y
| (pow x n) := eval x ^ (n : ℕ) | def | tactic.ring2.csring_expr.eval | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"tree"
] | Evaluates a reflected `csring_expr` into an element of the
original `comm_semiring` type `α`, retrieving opaque elements
(atoms) from the tree `t`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
horner_expr
/- (const n) is a constant n in the csring, similarly to the same
constructor in `csring_expr`. This one, however, can be negative. -/
| const : znum → horner_expr
/- (horner a x n b) is a*xⁿ + b, where x is the x-th atom
in the atom tree. -/
| horner : horner_expr → pos_num → num → horner_expr → horner_exp... | inductive | tactic.ring2.horner_expr | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"num",
"pos_num",
"znum"
] | An efficient representation of expressions in a commutative
semiring using the sparse Horner normal form. This type admits
non-optimal instantiations (e.g. `P` can be represented as `P+0+0`),
so to get good performance out of it, care must be taken to maintain
an optimal, *canonical* form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
is_cs : horner_expr → Prop | | (const n) := ∃ m:num, n = m.to_znum
| (horner a x n b) := is_cs a ∧ is_cs b | def | tactic.ring2.horner_expr.is_cs | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"num"
] | True iff the `horner_expr` argument is a valid `csring_expr`.
For that to be the case, all its constants must be non-negative. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
atom (n : pos_num) : horner_expr | horner 1 n 1 0 | def | tactic.ring2.horner_expr.atom | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"pos_num"
] | Represent a `csring_expr.atom` in Horner form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
to_string : horner_expr → string | | (const n) := _root_.repr n
| (horner a x n b) :=
"(" ++ to_string a ++ ") * x" ++ _root_.repr x ++ "^"
++ _root_.repr n ++ " + " ++ to_string b | def | tactic.ring2.horner_expr.to_string | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
horner' (a : horner_expr)
(x : pos_num) (n : num) (b : horner_expr) : horner_expr | match a with
| const q := if q = 0 then b else horner a x n b
| horner a₁ x₁ n₁ b₁ :=
if x₁ = x ∧ b₁ = 0 then horner a₁ x (n₁ + n) b
else horner a x n b
end | def | tactic.ring2.horner_expr.horner' | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"num",
"pos_num"
] | Alternative constructor for (horner a x n b) which maintains canonical
form by simplifying special cases of `a`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_const (k : znum) (e : horner_expr) : horner_expr | if k = 0 then e else begin
induction e with n a x n b A B,
{ exact const (k + n) },
{ exact horner a x n B }
end | def | tactic.ring2.horner_expr.add_const | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"znum"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
add_aux (a₁ : horner_expr) (A₁ : horner_expr → horner_expr) (x₁ : pos_num) :
horner_expr → num → horner_expr → (horner_expr → horner_expr) → horner_expr | | (const n₂) n₁ b₁ B₁ := add_const n₂ (horner a₁ x₁ n₁ b₁)
| (horner a₂ x₂ n₂ b₂) n₁ b₁ B₁ :=
let e₂ := horner a₂ x₂ n₂ b₂ in
match pos_num.cmp x₁ x₂ with
| ordering.lt := horner a₁ x₁ n₁ (B₁ e₂)
| ordering.gt := horner a₂ x₂ n₂ (add_aux b₂ n₁ b₁ B₁)
| ordering.eq :=
match num.sub' n₁ n₂ with
... | def | tactic.ring2.horner_expr.add_aux | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"num",
"num.sub'",
"pos_num",
"pos_num.cmp"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
add : horner_expr → horner_expr → horner_expr | | (const n₁) e₂ := add_const n₁ e₂
| (horner a₁ x₁ n₁ b₁) e₂ := add_aux a₁ (add a₁) x₁ e₂ n₁ b₁ (add b₁) | def | tactic.ring2.horner_expr.add | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
neg (e : horner_expr) : horner_expr | begin
induction e with n a x n b A B,
{ exact const (-n) },
{ exact horner A x n B }
end | def | tactic.ring2.horner_expr.neg | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mul_const (k : znum) (e : horner_expr) : horner_expr | if k = 0 then 0 else if k = 1 then e else begin
induction e with n a x n b A B,
{ exact const (n * k) },
{ exact horner A x n B }
end | def | tactic.ring2.horner_expr.mul_const | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"znum"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mul_aux (a₁ x₁ n₁ b₁) (A₁ B₁ : horner_expr → horner_expr) :
horner_expr → horner_expr | | (const n₂) := mul_const n₂ (horner a₁ x₁ n₁ b₁)
| e₂@(horner a₂ x₂ n₂ b₂) :=
match pos_num.cmp x₁ x₂ with
| ordering.lt := horner (A₁ e₂) x₁ n₁ (B₁ e₂)
| ordering.gt := horner (mul_aux a₂) x₂ n₂ (mul_aux b₂)
| ordering.eq := let haa := horner' (mul_aux a₂) x₁ n₂ 0 in
if b₂ = 0 then haa else haa.add (horne... | def | tactic.ring2.horner_expr.mul_aux | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"pos_num.cmp"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mul : horner_expr → horner_expr → horner_expr | | (const n₁) := mul_const n₁
| (horner a₁ x₁ n₁ b₁) := mul_aux a₁ x₁ n₁ b₁ (mul a₁) (mul b₁). | def | tactic.ring2.horner_expr.mul | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pow (e : horner_expr) : num → horner_expr | | 0 := 1
| (num.pos p) := begin
induction p with p ep p ep,
{ exact e },
{ exact (ep.mul ep).mul e },
{ exact ep.mul ep }
end | def | tactic.ring2.horner_expr.pow | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"num"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
inv (e : horner_expr) : horner_expr | 0 | def | tactic.ring2.horner_expr.inv | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
of_csexpr : csring_expr → horner_expr | | (csring_expr.atom n) := atom n
| (csring_expr.const n) := const n.to_znum
| (csring_expr.add x y) := (of_csexpr x).add (of_csexpr y)
| (csring_expr.mul x y) := (of_csexpr x).mul (of_csexpr y)
| (csring_expr.pow x n) := (of_csexpr x).pow n | def | tactic.ring2.horner_expr.of_csexpr | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [] | Brings expressions into Horner normal form. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
cseval {α} [comm_semiring α] (t : tree α) : horner_expr → α | | (const n) := n.abs
| (horner a x n b) := tactic.ring.horner (cseval a) (t.get_or_zero x) n (cseval b) | def | tactic.ring2.horner_expr.cseval | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"tactic.ring.horner",
"tree"
] | Evaluates a reflected `horner_expr` - see `csring_expr.eval`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
cseval_atom {α} [comm_semiring α] (t : tree α)
(n : pos_num) : (atom n).is_cs ∧ cseval t (atom n) = t.get_or_zero n | ⟨⟨⟨1, rfl⟩, ⟨0, rfl⟩⟩, (tactic.ring.horner_atom _).symm⟩ | theorem | tactic.ring2.horner_expr.cseval_atom | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"pos_num",
"tactic.ring.horner_atom",
"tree"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_add_const {α} [comm_semiring α] (t : tree α)
(k : num) {e : horner_expr} (cs : e.is_cs) :
(add_const k.to_znum e).is_cs ∧
cseval t (add_const k.to_znum e) = k + cseval t e | begin
simp [add_const],
cases k; simp! *,
simp [show znum.pos k ≠ 0, from dec_trivial],
induction e with n a x n b A B; simp *,
{ rcases cs with ⟨n, rfl⟩,
refine ⟨⟨n + num.pos k, by simp [add_comm]; refl⟩, _⟩,
cases n; simp! },
{ rcases B cs.2 with ⟨csb, h⟩, simp! [*, cs.1],
rw [← tactic.ring.ho... | theorem | tactic.ring2.horner_expr.cseval_add_const | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"num",
"tactic.ring.horner_add_const",
"tree"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_horner' {α} [comm_semiring α] (t : tree α)
(a x n b) (h₁ : is_cs a) (h₂ : is_cs b) :
(horner' a x n b).is_cs ∧ cseval t (horner' a x n b) =
tactic.ring.horner (cseval t a) (t.get_or_zero x) n (cseval t b) | begin
cases a with n₁ a₁ x₁ n₁ b₁; simp [horner']; split_ifs,
{ simp! [*, tactic.ring.horner] },
{ exact ⟨⟨h₁, h₂⟩, rfl⟩ },
{ refine ⟨⟨h₁.1, h₂⟩, eq.symm _⟩, simp! *,
apply tactic.ring.horner_horner, simp },
{ exact ⟨⟨h₁, h₂⟩, rfl⟩ }
end | theorem | tactic.ring2.horner_expr.cseval_horner' | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"tactic.ring.horner",
"tactic.ring.horner_horner",
"tree"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_add {α} [comm_semiring α] (t : tree α)
{e₁ e₂ : horner_expr} (cs₁ : e₁.is_cs) (cs₂ : e₂.is_cs) :
(add e₁ e₂).is_cs ∧
cseval t (add e₁ e₂) = cseval t e₁ + cseval t e₂ | begin
induction e₁ with n₁ a₁ x₁ n₁ b₁ A₁ B₁ generalizing e₂; simp!,
{ rcases cs₁ with ⟨n₁, rfl⟩,
simpa using cseval_add_const t n₁ cs₂ },
induction e₂ with n₂ a₂ x₂ n₂ b₂ A₂ B₂ generalizing n₁ b₁,
{ rcases cs₂ with ⟨n₂, rfl⟩,
simp! [cseval_add_const t n₂ cs₁, add_comm] },
cases cs₁ with csa₁ csb₁, ca... | theorem | tactic.ring2.horner_expr.cseval_add | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"int.coe_nat_inj'",
"num.sub'",
"num.to_nat_to_int",
"pos_num.cmp",
"pos_num.cmp_to_nat",
"tactic.ring.const_add_horner",
"tactic.ring.horner_add_const",
"tactic.ring.horner_add_horner_eq",
"tactic.ring.horner_add_horner_gt",
"tactic.ring.horner_add_horner_lt",
"tree",
"znum... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_mul_const {α} [comm_semiring α] (t : tree α)
(k : num) {e : horner_expr} (cs : e.is_cs) :
(mul_const k.to_znum e).is_cs ∧
cseval t (mul_const k.to_znum e) = cseval t e * k | begin
simp [mul_const],
split_ifs with h h,
{ cases (num.to_znum_inj.1 h : k = 0),
exact ⟨⟨0, rfl⟩, (mul_zero _).symm⟩ },
{ cases (num.to_znum_inj.1 h : k = 1),
exact ⟨cs, (mul_one _).symm⟩ },
induction e with n a x n b A B; simp *,
{ rcases cs with ⟨n, rfl⟩,
suffices, refine ⟨⟨n * k, this⟩, _⟩,... | theorem | tactic.ring2.horner_expr.cseval_mul_const | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"mul_one",
"mul_zero",
"num",
"tactic.ring.horner_mul_const",
"tree"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_mul {α} [comm_semiring α] (t : tree α)
{e₁ e₂ : horner_expr} (cs₁ : e₁.is_cs) (cs₂ : e₂.is_cs) :
(mul e₁ e₂).is_cs ∧
cseval t (mul e₁ e₂) = cseval t e₁ * cseval t e₂ | begin
induction e₁ with n₁ a₁ x₁ n₁ b₁ A₁ B₁ generalizing e₂; simp!,
{ rcases cs₁ with ⟨n₁, rfl⟩,
simpa [mul_comm] using cseval_mul_const t n₁ cs₂ },
induction e₂ with n₂ a₂ x₂ n₂ b₂ A₂ B₂,
{ rcases cs₂ with ⟨n₂, rfl⟩,
simpa! using cseval_mul_const t n₂ cs₁ },
cases cs₁ with csa₁ csb₁, cases id cs₂ wi... | theorem | tactic.ring2.horner_expr.cseval_mul | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"mul_comm",
"pos_num.cmp",
"pos_num.cmp_to_nat",
"tactic.ring.horner_const_mul",
"tactic.ring.horner_mul_const",
"tactic.ring.horner_mul_horner",
"tactic.ring.horner_mul_horner_zero",
"tree"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_pow {α} [comm_semiring α] (t : tree α)
{x : horner_expr} (cs : x.is_cs) :
∀ (n : num), (pow x n).is_cs ∧
cseval t (pow x n) = cseval t x ^ (n : ℕ) | | 0 := ⟨⟨1, rfl⟩, (pow_zero _).symm⟩
| (num.pos p) := begin
simp [pow], induction p with p ep p ep,
{ simp * },
{ simp [pow_bit1],
cases cseval_mul t ep.1 ep.1 with cs₀ h₀,
cases cseval_mul t cs₀ cs with cs₁ h₁,
simp * },
{ simp [pow_bit0],
cases cseval_mul t ep.1 ep.1 with cs₀ h₀,
simp * }
... | theorem | tactic.ring2.horner_expr.cseval_pow | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"num",
"pow_bit0",
"pow_bit1",
"pow_zero",
"tree"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cseval_of_csexpr {α} [comm_semiring α] (t : tree α) :
∀ (r : csring_expr), (of_csexpr r).is_cs ∧ cseval t (of_csexpr r) = r.eval t | | (csring_expr.atom n) := cseval_atom _ _
| (csring_expr.const n) := ⟨⟨n, rfl⟩, by cases n; refl⟩
| (csring_expr.add x y) :=
let ⟨cs₁, h₁⟩ := cseval_of_csexpr x,
⟨cs₂, h₂⟩ := cseval_of_csexpr y,
⟨cs, h⟩ := cseval_add t cs₁ cs₂ in ⟨cs, by simp! [h, *]⟩
| (csring_expr.mul x y) :=
let ⟨cs₁, h₁⟩ := cseval_... | theorem | tactic.ring2.horner_expr.cseval_of_csexpr | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"tree"
] | For any given tree `t` of atoms and any reflected expression `r`,
the Horner form of `r` is a valid csring expression, and under `t`,
the Horner form evaluates to the same thing as `r`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
correctness {α} [comm_semiring α] (t : tree α) (r₁ r₂ : csring_expr)
(H : horner_expr.of_csexpr r₁ = horner_expr.of_csexpr r₂) :
r₁.eval t = r₂.eval t | by repeat {rw ← (horner_expr.cseval_of_csexpr t _).2}; rw H | theorem | tactic.ring2.correctness | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"tree"
] | The main proof-by-reflection theorem. Given reflected csring expressions
`r₁` and `r₂` plus a storage `t` of atoms, if both expressions go to the
same Horner normal form, then the original non-reflected expressions are
equal. `H` follows from kernel reduction and is therefore `rfl`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
reflect_expr : expr → csring_expr × dlist expr | | `(%%e₁ + %%e₂) :=
let (r₁, l₁) := reflect_expr e₁, (r₂, l₂) := reflect_expr e₂ in
(r₁.add r₂, l₁ ++ l₂)
/-| `(%%e₁ - %%e₂) :=
let (r₁, l₁) := reflect_expr e₁, (r₂, l₂) := reflect_expr e₂ in
(r₁.add r₂.neg, l₁ ++ l₂)
| `(- %%e) := let (r, l) := reflect_expr e in (r.neg, l)-/
| `(%%e₁ * %%e₂) :=
let (r₁, l₁) ... | def | tactic.ring2.reflect_expr | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"expr.to_nat",
"num.of_nat'"
] | Reflects a csring expression into a `csring_expr`, together
with a dlist of atoms, i.e. opaque variables over which the
expression is a polynomial. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
csring_expr.replace (t : tree expr) : csring_expr → state_t (list expr) option csring_expr | | (csring_expr.atom _) := do e ← get,
p ← monad_lift (t.index_of (<) e.head),
put e.tail, pure (csring_expr.atom p)
| (csring_expr.const n) := pure (csring_expr.const n)
| (csring_expr.add x y) := csring_expr.add <$> x.replace <*> y.replace
| (csring_expr.mul x y) := csring_expr.mul <$> x.replace <*> y.replace
| (... | def | tactic.ring2.csring_expr.replace | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"tree"
] | In the output of `reflect_expr`, `atom`s are initialized with incorrect indices.
The indices cannot be computed until the whole tree is built, so another pass over
the expressions is needed - this is what `replace` does. The computation (expressed
in the state monad) fixes up `atom`s to match their positions in the ato... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ring2 : tactic unit | do `[repeat {rw ← nat.pow_eq_pow}],
`(%%e₁ = %%e₂) ← target
| fail "ring2 tactic failed: the goal is not an equality",
α ← infer_type e₁,
expr.sort (level.succ u) ← infer_type α,
let (r₁, l₁) := reflect_expr e₁,
let (r₂, l₂) := reflect_expr e₂,
let L := (l₁ ++ l₂).to_list,
let s := tree.of_rbnode (rbtre... | def | tactic.interactive.ring2 | tactic | src/tactic/ring2.lean | [
"tactic.ring",
"data.num.lemmas",
"data.tree"
] | [
"comm_semiring",
"rbtree_of",
"tree.of_rbnode"
] | `ring2` solves equations in the language of rings.
It supports only the commutative semiring operations, i.e. it does not normalize subtraction or
division.
This variant on the `ring` tactic uses kernel computation instead
of proof generation. In general, you should use `ring` instead of `ring2`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.