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 |
|---|---|---|---|---|---|---|---|---|---|---|
prove_neg (ic : instance_cache) (a : expr) : tactic (instance_cache × expr × expr) | match match_sign a with
| sum.inl a := do
(ic, p) ← ic.mk_app ``neg_neg [a],
return (ic, a, p)
| sum.inr ff := do
(ic, p) ← ic.mk_app ``neg_zero [],
return (ic, a, p)
| sum.inr tt := do
(ic, a') ← ic.mk_app ``has_neg.neg [a],
p ← mk_eq_refl a',
return (ic, a', p)
end | def | norm_num.prove_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Given `a` a rational numeral, returns `(b, ⊢ -a = b)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sub_pos {α} [add_group α] (a b b' c : α) (hb : -b = b') (h : a + b' = c) : a - b = c | by rwa [← hb, ← sub_eq_add_neg] at h | theorem | norm_num.sub_pos | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"add_group"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
sub_neg {α} [add_group α] (a b c : α) (h : a + b = c) : a - -b = c | by rwa sub_neg_eq_add | theorem | norm_num.sub_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"add_group"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
prove_sub (ic : instance_cache) (a b : expr) : tactic (instance_cache × expr × expr) | match match_sign b with
| sum.inl b := do
(ic, c, p) ← prove_add_rat' ic a b,
(ic, p) ← ic.mk_app ``sub_neg [a, b, c, p],
return (ic, c, p)
| sum.inr ff := do
(ic, p) ← ic.mk_app ``sub_zero [a],
return (ic, a, p)
| sum.inr tt := do
(ic, b', pb) ← prove_neg ic b,
(ic, c, p) ← prove_add_rat' ic a b',
(ic,... | def | norm_num.prove_sub | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Given `a`,`b` rational numerals, returns `(c, ⊢ a - b = c)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sub_nat_pos (a b c : ℕ) (h : b + c = a) : a - b = c | h ▸ add_tsub_cancel_left _ _ | theorem | norm_num.sub_nat_pos | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"add_tsub_cancel_left"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
sub_nat_neg (a b c : ℕ) (h : a + c = b) : a - b = 0 | tsub_eq_zero_iff_le.mpr $ h ▸ nat.le_add_right _ _ | theorem | norm_num.sub_nat_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
prove_sub_nat (ic : instance_cache) (a b : expr) : tactic (expr × expr) | do na ← a.to_nat, nb ← b.to_nat,
if nb ≤ na then do
(ic, c) ← ic.of_nat (na - nb),
(ic, p) ← prove_add_nat ic b c a,
return (c, `(sub_nat_pos).mk_app [a, b, c, p])
else do
(ic, c) ← ic.of_nat (nb - na),
(ic, p) ← prove_add_nat ic a c b,
return (`(0 : ℕ), `(sub_nat_neg).mk_app [a, b, c, p]) | def | norm_num.prove_sub_nat | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Given `a : nat`,`b : nat` natural numerals, returns `(c, ⊢ a - b = c)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
eval_field : expr → tactic (expr × expr) | | `(%%e₁ + %%e₂) := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
c ← infer_type e₁ >>= mk_instance_cache,
let n₃ := n₁ + n₂,
(c, e₃) ← c.of_rat n₃,
(_, p) ← prove_add_rat c e₁ e₂ e₃ n₁ n₂ n₃,
return (e₃, p)
| `(%%e₁ * %%e₂) := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
c ← infer_type e₁ >>= mk_instance_cache,
prod.snd ... | def | norm_num.eval_field | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Evaluates the basic field operations `+`,`neg`,`-`,`*`,`inv`,`/` on numerals.
Also handles nat subtraction. Does not do recursive simplification; that is,
`1 + 1 + 1` will not simplify but `2 + 1` will. This is handled by the top level
`simp` call in `norm_num.derive`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
pow_bit0 [monoid α] (a c' c : α) (b : ℕ)
(h : a ^ b = c') (h₂ : c' * c' = c) : a ^ bit0 b = c | h₂ ▸ by simp [pow_bit0, h] | lemma | norm_num.pow_bit0 | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"monoid",
"pow_bit0"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pow_bit1 [monoid α] (a c₁ c₂ c : α) (b : ℕ)
(h : a ^ b = c₁) (h₂ : c₁ * c₁ = c₂) (h₃ : c₂ * a = c) : a ^ bit1 b = c | by rw [← h₃, ← h₂]; simp [pow_bit1, h] | lemma | norm_num.pow_bit1 | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"monoid",
"pow_bit1"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
prove_pow (a : expr) (na : ℚ) :
instance_cache → expr → tactic (instance_cache × expr × expr) | | ic b :=
match match_numeral b with
| zero := do
(ic, p) ← ic.mk_app ``pow_zero [a],
(ic, o) ← ic.mk_app ``has_one.one [],
return (ic, o, p)
| one := do
(ic, p) ← ic.mk_app ``pow_one [a],
return (ic, a, p)
| bit0 b := do
(ic, c', p) ← prove_pow ic b,
nc' ← expr.to_rat c',
(ic, c... | def | norm_num.prove_pow | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"expr.to_rat",
"pow_bit0",
"pow_bit1",
"pow_one",
"pow_zero"
] | Given `a` a rational numeral and `b : nat`, returns `(c, ⊢ a ^ b = c)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
zpow_pos {α} [div_inv_monoid α] (a : α) (b : ℤ) (b' : ℕ) (c : α)
(hb : b = b') (h : a ^ b' = c) : a ^ b = c | by rw [← h, hb, zpow_coe_nat] | lemma | norm_num.zpow_pos | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"div_inv_monoid",
"zpow_coe_nat"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
zpow_neg {α} [div_inv_monoid α] (a : α) (b : ℤ) (b' : ℕ) (c c' : α)
(b0 : 0 < b') (hb : b = b') (h : a ^ b' = c) (hc : c⁻¹ = c') : a ^ -b = c' | by rw [← hc, ← h, hb, zpow_neg_coe_of_pos _ b0] | lemma | norm_num.zpow_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"div_inv_monoid",
"zpow_neg",
"zpow_neg_coe_of_pos"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
prove_zpow (ic zc nc : instance_cache) (a : expr) (na : ℚ) (b : expr) :
tactic (instance_cache × instance_cache × instance_cache × expr × expr) | match match_sign b with
| sum.inl b := do
(zc, nc, b', hb) ← prove_nat_uncast zc nc b,
(nc, b0) ← prove_pos nc b',
(ic, c, h) ← prove_pow a na ic b',
(ic, c', hc) ← c.to_rat >>= prove_inv ic c,
(ic, p) ← ic.mk_app ``zpow_neg [a, b, b', c, c', b0, hb, h, hc],
pure (ic, zc, nc, c', p)
| sum.in... | def | norm_num.prove_zpow | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"zpow_neg",
"zpow_zero"
] | Given `a` a rational numeral and `b : ℤ`, returns `(c, ⊢ a ^ b = c)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
eval_pow : expr → tactic (expr × expr) | | `(@has_pow.pow %%α %%β %%m %%e₁ %%e₂) := do
n₁ ← e₁.to_rat,
c ← mk_instance_cache α,
match β with
| `(ℕ) := do
(c, m') ← c.mk_app ``monoid.has_pow [],
is_def_eq m m',
prod.snd <$> prove_pow e₁ n₁ c e₂
| `(ℤ) := do
(c, m') ← c.mk_app ``div_inv_monoid.has_pow [],
is_def_eq m m',
zc ← m... | def | norm_num.eval_pow | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"div_inv_monoid.has_pow",
"monoid.has_pow"
] | Evaluates expressions of the form `a ^ b`, `monoid.npow a b` or `nat.pow a b`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
true_intro (p : expr) : tactic (expr × expr) | prod.mk `(true) <$> mk_app ``eq_true_intro [p] | def | norm_num.true_intro | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Given `⊢ p`, returns `(true, ⊢ p = true)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
false_intro (p : expr) : tactic (expr × expr) | prod.mk `(false) <$> mk_app ``eq_false_intro [p] | def | norm_num.false_intro | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Given `⊢ ¬ p`, returns `(false, ⊢ p = false)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
not_refl_false_intro {α} (a : α) : (a ≠ a) = false | eq_false_intro $ not_not_intro rfl | theorem | norm_num.not_refl_false_intro | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
gt_intro {α} [has_lt α] (a b : α) (c) (h : a < b = c) : b > a = c | h | theorem | norm_num.gt_intro | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
ge_intro {α} [has_le α] (a b : α) (c) (h : a ≤ b = c) : b ≥ a = c | h | theorem | norm_num.ge_intro | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_ineq : expr → tactic (expr × expr) | | `(%%e₁ < %%e₂) := do
n₁ ← e₁.to_rat, n₂ ← e₂.to_rat,
c ← infer_type e₁ >>= mk_instance_cache,
if n₁ < n₂ then
do (_, p) ← prove_lt_rat c e₁ e₂ n₁ n₂, true_intro p
else if n₁ = n₂ then do
(_, p) ← c.mk_app ``lt_irrefl [e₁],
false_intro p
else do
(c, p') ← prove_lt_rat c e₂ e₁ n₂ n₁,
(_, p... | def | norm_num.eval_ineq | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Evaluates the inequality operations `=`,`<`,`>`,`≤`,`≥`,`≠` on numerals. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nat_succ_eq (a b c : ℕ) (h₁ : a = b) (h₂ : b + 1 = c) : nat.succ a = c | by rwa h₁ | theorem | norm_num.nat_succ_eq | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
prove_nat_succ (ic : instance_cache) : expr → tactic (instance_cache × ℕ × expr × expr) | | `(nat.succ %%a) := do
(ic, n, b, p₁) ← prove_nat_succ a,
let n' := n + 1,
(ic, c) ← ic.of_nat n',
(ic, p₂) ← prove_add_nat ic b `(1) c,
return (ic, n', c, `(nat_succ_eq).mk_app [a, b, c, p₁, p₂])
| e := do
n ← e.to_nat,
p ← mk_eq_refl e,
return (ic, n, e, p) | def | norm_num.prove_nat_succ | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Evaluates the expression `nat.succ ... (nat.succ n)` where `n` is a natural numeral.
(We could also just handle `nat.succ n` here and rely on `simp` to work bottom up, but we figure
that towers of successors coming from e.g. `induction` are a common case.) | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
int_to_nat_pos (a : ℤ) (b : ℕ) (h : (by haveI := @nat.cast_coe ℤ; exact b : ℤ) = a) :
a.to_nat = b | by rw ← h; simp | theorem | norm_num.int_to_nat_pos | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"nat.cast_coe"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
int_to_nat_neg (a : ℤ) (h : 0 < a) : (-a).to_nat = 0 | by simp only [int.to_nat_of_nonpos, h.le, neg_nonpos] | theorem | norm_num.int_to_nat_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"int.to_nat_of_nonpos",
"to_nat"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
nat_abs_pos (a : ℤ) (b : ℕ) (h : (by haveI := @nat.cast_coe ℤ; exact b : ℤ) = a) :
a.nat_abs = b | by rw ← h; simp | theorem | norm_num.nat_abs_pos | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"nat.cast_coe"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
nat_abs_neg (a : ℤ) (b : ℕ) (h : (by haveI := @nat.cast_coe ℤ; exact b : ℤ) = a) :
(-a).nat_abs = b | by rw ← h; simp | theorem | norm_num.nat_abs_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"nat.cast_coe"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
neg_succ_of_nat (a b : ℕ) (c : ℤ) (h₁ : a + 1 = b)
(h₂ : (by haveI := @nat.cast_coe ℤ; exact b : ℤ) = c) :
-[1+ a] = -c | by rw [← h₂, ← h₁]; refl | theorem | norm_num.neg_succ_of_nat | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"nat.cast_coe"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_nat_int : expr → tactic (expr × expr) | | e@`(nat.succ _) := do
ic ← mk_instance_cache `(ℕ),
(_, _, ep) ← prove_nat_succ ic e,
return ep
| `(int.to_nat %%a) := do
n ← a.to_int,
ic ← mk_instance_cache `(ℤ),
if n ≥ 0 then do
nc ← mk_instance_cache `(ℕ),
(_, _, b, p) ← prove_nat_uncast ic nc a,
pure (b, `(int_to_nat_pos).mk_app [a, b, p]... | def | norm_num.eval_nat_int | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Evaluates `nat.succ`, `int.to_nat`, `int.nat_abs`, `int.neg_succ_of_nat`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
int_to_nat_cast (a : ℕ) (b : ℤ)
(h : (by haveI := @nat.cast_coe ℤ; exact a : ℤ) = b) :
↑a = b | eq.trans (by simp) h | theorem | norm_num.int_to_nat_cast | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"nat.cast_coe"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_cast : expr → tactic (expr × expr) | | `(@coe ℕ %%α %%inst %%a) := do
if inst.is_app_of ``coe_to_lift then
if inst.app_arg.is_app_of ``nat.cast_coe then do
n ← a.to_nat,
ic ← mk_instance_cache α,
nc ← mk_instance_cache `(ℕ),
(ic, b) ← ic.of_nat n,
(_, _, _, p) ← prove_nat_uncast ic nc b,
pure (b, p)
else if in... | def | norm_num.eval_cast | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"char_zero",
"int.cast_coe",
"nat.cast_coe",
"rat.cast_coe"
] | Evaluates the `↑n` cast operation from `ℕ`, `ℤ`, `ℚ` to an arbitrary type `α`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
derive.step (e : expr) : tactic (expr × expr) | eval_field e <|> eval_pow e <|> eval_ineq e <|> eval_cast e <|> eval_nat_int e | def | norm_num.derive.step | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | This version of `derive` does not fail when the input is already a numeral | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
attr : user_attribute (expr → tactic (expr × expr)) unit | { name := `norm_num,
descr := "Add norm_num derivers",
cache_cfg :=
{ mk_cache := λ ns, do
{ t ← ns.mfoldl
(λ (t : expr → tactic (expr × expr)) n, do
t' ← eval_expr (expr → tactic (expr × expr)) (expr.const n []),
pure (λ e, t' e <|> t e))
(λ _, failed),
pure... | def | norm_num.attr | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | An attribute for adding additional extensions to `norm_num`. To use this attribute, put
`@[norm_num]` on a tactic of type `expr → tactic (expr × expr)`; the tactic will be called on
subterms by `norm_num`, and it is responsible for identifying that the expression is a numerical
function applied to numerals, for example... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_step : tactic (expr → tactic (expr × expr)) | norm_num.attr.get_cache | def | norm_num.get_step | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Look up the `norm_num` extensions in the cache and return a tactic extending `derive.step` with
additional reduction procedures. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
derive' (step : expr → tactic (expr × expr)) : expr → tactic (expr × expr) | | e := do
e ← instantiate_mvars e,
(_, e', pr) ← ext_simplify_core
() {} simp_lemmas.mk (λ _, failed) (λ _ _ _ _ _, failed)
(λ _ _ _ _ e, do
(new_e, pr) ← step e,
guard (¬ new_e =ₐ e),
pure ((), new_e, some pr, tt))
`eq e,
pure (e', pr) | def | norm_num.derive' | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Simplify an expression bottom-up using `step` to simplify the subexpressions. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
derive (e : expr) : tactic (expr × expr) | do f ← get_step, derive' f e | def | norm_num.derive | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Simplify an expression bottom-up using the default `norm_num` set to simplify the
subexpressions. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
tactic.norm_num1 (step : expr → tactic (expr × expr))
(loc : interactive.loc) : tactic unit | do ns ← loc.get_locals,
success ← tactic.replace_at (norm_num.derive' step) ns loc.include_goal,
when loc.include_goal $ try tactic.triv,
when (¬ ns.empty) $ try tactic.contradiction,
monad.unlessb success $ done <|> fail "norm_num failed to simplify" | def | norm_num.tactic.norm_num1 | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"norm_num.derive'",
"tactic.replace_at"
] | Basic version of `norm_num` that does not call `simp`. It uses the provided `step` tactic
to simplify the expression; use `get_step` to get the default `norm_num` set and `derive.step` for
the basic builtin set of simplifications. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
tactic.norm_num (step : expr → tactic (expr × expr))
(hs : list simp_arg_type) (l : interactive.loc) : tactic unit | do
-- Build and discard the simp lemma set, to validate it.
mk_simp_set_core ff [] (simp_arg_type.except ``one_div :: hs) tt,
repeat1 $ orelse' (tactic.norm_num1 step l) $
interactive.simp_core {} (tactic.norm_num1 step (interactive.loc.ns [none]))
ff (simp_arg_type.except ``one_div :: hs) [] l >> skip | def | norm_num.tactic.norm_num | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"one_div"
] | Normalize numerical expressions. It uses the provided `step` tactic to simplify the expression;
use `get_step` to get the default `norm_num` set and `derive.step` for the basic builtin set of
simplifications. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
_root_.expr.norm_num (step : expr → tactic (expr × expr))
(no_dflt : bool := ff) (hs : list simp_arg_type := []) (attr_names : list name := []) :
expr → tactic (expr × expr) | let simp_step (e : expr) := do
(e', p, _) ← e.simp {} (tactic.norm_num1 step (interactive.loc.ns [none]))
no_dflt attr_names (simp_arg_type.except ``one_div :: hs),
return (e', p)
in or_refl_conv $ λ e, do
(e', p') ← norm_num.derive' step e <|> simp_step e,
(e'', p'') ← _root_.expr.no... | def | expr.norm_num | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"norm_num.derive'",
"one_div"
] | Carry out similar operations as `tactic.norm_num` but on an `expr` rather than a location.
Given an expression `e`, returns `(e', ⊢ e = e')`.
The `no_dflt`, `hs`, and `attr_names` are passed on to `simp`.
Unlike `norm_num`, this tactic does not fail. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_num1 (loc : parse location) : tactic unit | do f ← get_step, tactic.norm_num1 f loc | def | norm_num.tactic.interactive.norm_num1 | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Basic version of `norm_num` that does not call `simp`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_num (hs : parse simp_arg_list) (l : parse location) : tactic unit | do f ← get_step, tactic.norm_num f hs l | def | norm_num.tactic.interactive.norm_num | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Normalize numerical expressions. Supports the operations
`+` `-` `*` `/` `^` and `%` over numerical types such as
`ℕ`, `ℤ`, `ℚ`, `ℝ`, `ℂ` and some general algebraic types,
and can prove goals of the form `A = B`, `A ≠ B`, `A < B` and `A ≤ B`,
where `A` and `B` are numerical expressions.
It also has a relatively simple ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
apply_normed (x : parse texpr) : tactic unit | do x₁ ← to_expr x,
(x₂,_) ← derive x₁,
tactic.exact x₂ | def | norm_num.tactic.interactive.apply_normed | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Normalizes a numerical expression and tries to close the goal with the result. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_num1 : conv unit | replace_lhs derive | def | norm_num.conv.interactive.norm_num1 | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Basic version of `norm_num` that does not call `simp`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_num (hs : parse simp_arg_list) : conv unit | repeat1 $ orelse' norm_num1 $
conv.interactive.simp ff (simp_arg_type.except ``one_div :: hs) []
{ discharger := tactic.interactive.norm_num1 (loc.ns [none]) } | def | norm_num.conv.interactive.norm_num | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"one_div"
] | Normalize numerical expressions. Supports the operations
`+` `-` `*` `/` `^` and `%` over numerical types such as
`ℕ`, `ℤ`, `ℚ`, `ℝ`, `ℂ` and some general algebraic types,
and can prove goals of the form `A = B`, `A ≠ B`, `A < B` and `A ≤ B`,
where `A` and `B` are numerical expressions.
It also has a relatively simple ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_num_cmd (_ : parse $ tk "#norm_num") : lean.parser unit | do
no_dflt ← only_flag,
hs ← simp_arg_list,
attr_names ← with_ident_list,
o ← optional (tk ":"),
e ← texpr,
/- Retrieve the `pexpr`s parsed as part of the simp args, and collate them into a big list. -/
let hs_es := list.join $ hs.map $ option.to_list ∘ simp_arg_type.to_pexpr,
/- Synthesize a `tactic_... | def | norm_num.tactic.norm_num_cmd | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"norm_num.get_step",
"option.to_list"
] | The basic usage is `#norm_num e`, where `e` is an expression,
which will print the `norm_num` form of `e`.
Syntax: `#norm_num` (`only`)? (`[` simp lemma list `]`)? (`with` simp sets)? `:`? expression
This accepts the same options as the `#simp` command.
You can specify additional simp lemmas as usual, for example usi... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nat_div (a b q r m : ℕ) (hm : q * b = m) (h : r + m = a) (h₂ : r < b) : a / b = q | by rw [← h, ← hm, nat.add_mul_div_right _ _ (lt_of_le_of_lt (nat.zero_le _) h₂),
nat.div_eq_of_lt h₂, zero_add] | lemma | norm_num.norm_num.nat_div | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
int_div (a b q r m : ℤ) (hm : q * b = m) (h : r + m = a) (h₁ : 0 ≤ r) (h₂ : r < b) :
a / b = q | by rw [← h, ← hm, int.add_mul_div_right _ _ (ne_of_gt (lt_of_le_of_lt h₁ h₂)),
int.div_eq_zero_of_lt h₁ h₂, zero_add] | lemma | norm_num.norm_num.int_div | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"int.add_mul_div_right",
"int.div_eq_zero_of_lt"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
nat_mod (a b q r m : ℕ) (hm : q * b = m) (h : r + m = a) (h₂ : r < b) : a % b = r | by rw [← h, ← hm, nat.add_mul_mod_self_right, nat.mod_eq_of_lt h₂] | lemma | norm_num.norm_num.nat_mod | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
int_mod (a b q r m : ℤ) (hm : q * b = m) (h : r + m = a) (h₁ : 0 ≤ r) (h₂ : r < b) :
a % b = r | by rw [← h, ← hm, int.add_mul_mod_self, int.mod_eq_of_lt h₁ h₂] | lemma | norm_num.norm_num.int_mod | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"int.add_mul_mod_self",
"int.mod_eq_of_lt"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
int_div_neg (a b c' c : ℤ) (h : a / b = c') (h₂ : -c' = c) : a / -b = c | h₂ ▸ h ▸ int.div_neg _ _ | lemma | norm_num.norm_num.int_div_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"int.div_neg"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
int_mod_neg (a b c : ℤ) (h : a % b = c) : a % -b = c | (int.mod_neg _ _).trans h | lemma | norm_num.norm_num.int_mod_neg | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"int.mod_neg"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
prove_div_mod (ic : instance_cache) :
expr → expr → bool → tactic (instance_cache × expr × expr) | | a b mod :=
match match_neg b with
| some b := do
(ic, c', p) ← prove_div_mod a b mod,
if mod then
return (ic, c', `(int_mod_neg).mk_app [a, b, c', p])
else do
(ic, c, p₂) ← prove_neg ic c',
return (ic, c, `(int_div_neg).mk_app [a, b, c', c, p, p₂])
| none := do
nb ← b.to_nat,
... | def | norm_num.norm_num.prove_div_mod | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Given `a`,`b` numerals in `nat` or `int`,
* `prove_div_mod ic a b ff` returns `(c, ⊢ a / b = c)`
* `prove_div_mod ic a b tt` returns `(c, ⊢ a % b = c)` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
dvd_eq_nat (a b c : ℕ) (p) (h₁ : b % a = c) (h₂ : (c = 0) = p) : (a ∣ b) = p | (propext $ by rw [← h₁, nat.dvd_iff_mod_eq_zero]).trans h₂ | theorem | norm_num.norm_num.dvd_eq_nat | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
dvd_eq_int (a b c : ℤ) (p) (h₁ : b % a = c) (h₂ : (c = 0) = p) : (a ∣ b) = p | (propext $ by rw [← h₁, int.dvd_iff_mod_eq_zero]).trans h₂ | theorem | norm_num.norm_num.dvd_eq_int | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [
"int.dvd_iff_mod_eq_zero"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
eval_nat_int_ext : expr → tactic (expr × expr) | | `(%%a / %%b) := do
c ← infer_type a >>= mk_instance_cache,
prod.snd <$> prove_div_mod c a b ff
| `(%%a % %%b) := do
c ← infer_type a >>= mk_instance_cache,
prod.snd <$> prove_div_mod c a b tt
| `(%%a ∣ %%b) := do
α ← infer_type a,
ic ← mk_instance_cache α,
th ← if α = `(nat) then return (`(dvd_eq_nat):e... | def | norm_num.norm_num.eval_nat_int_ext | tactic | src/tactic/norm_num.lean | [
"data.rat.cast",
"data.rat.meta_defs",
"data.int.lemmas"
] | [] | Evaluates some extra numeric operations on `nat` and `int`, specifically
`/` and `%`, and `∣` (divisibility). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
eval : expr → tactic (expr × expr) | λ e, do
(swapt, fun_ty, coe_fn_inst, fexpr, c) ← e.match_app_coe_fn
<|> fail "did not get an app coe_fn expr",
guard (fexpr.get_app_fn.const_name = ``equiv.swap) <|> fail "coe_fn not of equiv.swap",
[α, deceq_inst, a, b] ← pure fexpr.get_app_args <|>
fail "swap did not have exactly two args applied",
na... | def | norm_swap.eval | tactic | src/tactic/norm_swap.lean | [
"logic.equiv.defs",
"tactic.norm_fin"
] | [
"equiv.swap",
"equiv.swap_apply_left",
"equiv.swap_apply_of_ne_of_ne",
"equiv.swap_apply_right"
] | A `norm_num` plugin for normalizing `equiv.swap a b c`
where `a b c` are numerals of `ℕ`, `ℤ`, `ℚ` or `fin n`.
```
example : equiv.swap 1 2 1 = 2 := by norm_num
``` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
tactic.interactive.observe (trc : parse $ optional (tk "?"))
(h : parse ident?) (t : parse (tk ":" *> texpr)) : tactic unit | do
let h' := h.get_or_else `this,
t ← to_expr ``(%%t : Prop),
assert h' t,
s ← focus1 (tactic.library_search { try_this := ff }) <|> fail "observe failed",
s ← s.get_rest "Try this: exact ",
ppt ← pp t,
let pph : string := (h.map (λ n : name, n.to_string ++ " ")).get_or_else "",
when trc.is_some $ trace... | def | tactic.interactive.observe | tactic | src/tactic/observe.lean | [
"tactic.suggest"
] | [
"tactic.library_search"
] | `observe hp : p` asserts the proposition `p`, and tries to prove it using `library_search`.
If no proof is found, the tactic fails.
In other words, this tactic is equivalent to `have hp : p, { library_search }`.
If `hp` is omitted, then the placeholder `this` is used.
The variant `observe? hp : p` will emit a trace m... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
obviously' | tactic.sorry_if_contains_sorry <|>
tactic.tidy <|>
tactic.fail (
"`obviously` failed to solve a subgoal.\n" ++
"You may need to explicitly provide a proof of the corresponding structure field.") | def | obviously' | tactic | src/tactic/obviously.lean | [
"tactic.tidy",
"tactic.replacer"
] | [
"tactic.sorry_if_contains_sorry",
"tactic.tidy"
] | The default implementation of `obviously`
discharges any goals which contain `sorry` in their type using `sorry`,
and then calls `tidy`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
pi_instance_derive_field : tactic unit | do b ← target >>= is_prop,
field ← get_current_field,
if b then do
vs ← introv [] <|> pure [],
hs ← intros <|> pure [],
reset_instance_cache,
xn ← get_unused_name,
try (() <$ ext1 [rcases_patt.one xn] <|> () <$ intro xn),
xv ← option.iget <$> try_core (get_local xn),
applyc fiel... | def | tactic.pi_instance_derive_field | tactic | src/tactic/pi_instances.lean | [
"order.basic"
] | [
"field",
"option.iget"
] | Attempt to clear a goal obtained by refining a `pi_instance` goal. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
pi_instance : tactic unit | refine_struct ``( { ..pi.partial_order, .. } );
propagate_tags (try $ pi_instance_derive_field >> done) | def | tactic.pi_instance | tactic | src/tactic/pi_instances.lean | [
"order.basic"
] | [] | `pi_instance` constructs an instance of `my_class (Π i : I, f i)`
where we know `Π i, my_class (f i)`. If an order relation is required,
it defaults to `pi.partial_order`. Any field of the instance that
`pi_instance` cannot construct is left untouched and generated as a new goal. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
poly
| const : ℚ → poly
| var : ℕ → poly
| add : poly → poly → poly
| sub : poly → poly → poly
| mul : poly → poly → poly
| pow : poly → ℕ → poly
| neg : poly → poly | inductive | polyrith.poly | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | A datatype representing the semantics of multivariable polynomials.
Each `poly` can be converted into a string. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
poly.mk_string : poly → string | | (poly.const z) := to_string z
| (poly.var n) := "var" ++ to_string n
| (poly.add p q) := "(" ++ poly.mk_string p ++ " + " ++ poly.mk_string q ++ ")"
| (poly.sub p q) := "(" ++ poly.mk_string p ++ " - " ++ poly.mk_string q ++ ")"
| (poly.mul p q) := "(" ++ poly.mk_string p ++ " * " ++ poly.mk_string q ++ ")"
| (poly.p... | def | polyrith.poly.mk_string | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly",
"poly.const"
] | This converts a poly object into a string representing it. The string
maintains the semantic structure of the poly object.
The output of this function must be valid Python syntax, and it assumes the variables `varN` from
`scripts/polyrith.py.` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
poly_form_of_atom (red : transparency) (vars : list expr) (e : expr) :
tactic (list expr × poly) | do
index_of_e ← vars.mfoldl_with_index
(λ n last e', match last with
| none := tactic.try_core $ tactic.is_def_eq e e' red >> return n
| some k := return k
end) none,
return (match index_of_e with
| some k := (vars, poly.var k)
| none := (vars.concat e, poly.var vars.length)
end) | def | polyrith.poly_form_of_atom | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | `(vars, p) ← poly_form_of_atom red vars e` is the atomic case for `poly_form_of_expr`.
If `e` appears with index `k` in `vars`, it returns the singleton sum `p = poly.var k`.
Otherwise it updates `vars`, adding `e` with index `n`, and returns the singleton `p = poly.var n`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
poly_form_of_expr (red : transparency) : list expr → expr → tactic (list expr × poly) | | m `(%%e1 * %%e2) :=
do (m', comp1) ← poly_form_of_expr m e1,
(m', comp2) ← poly_form_of_expr m' e2,
return (m', comp1 * comp2)
| m `(%%e1 + %%e2) :=
do (m', comp1) ← poly_form_of_expr m e1,
(m', comp2) ← poly_form_of_expr m' e2,
return (m', comp1 + comp2)
| m `(%%e1 - %%e2) :=
do (m',... | def | polyrith.poly_form_of_expr | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly",
"poly.const"
] | `poly_form_of_expr red map e` computes the polynomial 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 definitio... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
poly.to_pexpr : list expr → poly → tactic pexpr | | _ (poly.const z) := return z.to_pexpr
| m (poly.var n) :=
do
some (e) ← return $ m.nth n | fail! "unknown variable poly.var {n}",
return ``(%%e)
| m (poly.add p q) :=
do
p_pexpr ← poly.to_pexpr m p,
q_pexpr ← poly.to_pexpr m q,
return ``(%%p_pexpr + %%q_pexpr)
| m (poly.sub p q) :=
do
p_... | def | polyrith.poly.to_pexpr | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly",
"poly.const"
] | This can convert a `poly` into a `pexpr` that would evaluate to a polynomial.
To do so, it uses a list `m` of expressions, the atomic expressions that appear in the `poly`.
The index of an expression in this list corresponds to its `poly.var` argument: that is,
if `e` is the `k`th element of `m`, then it is represented... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
var_parser : parser poly | do
str "poly.var " >> poly.var <$> parser.nat | def | polyrith.var_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | A parser object that parses `string`s of the form `"poly.var n"`
to the appropriate `poly` object representing a variable.
Here, `n` is a natural number | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
const_fraction_parser : parser poly | str "poly.const " >> poly.const <$> parser.rat | def | polyrith.const_fraction_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"parser.rat",
"poly",
"poly.const"
] | A parser object that parses `string`s of the form `"poly.const r"`
to the appropriate `poly` object representing a rational coefficient.
Here, `r` is a rational number | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_parser (cont : parser poly) : parser poly | str "poly.add " >> poly.add <$> cont <*> (ch ' ' >> cont) | def | polyrith.add_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"cont",
"poly"
] | A parser object that parses `string`s of the form `"poly.add p q"`
to the appropriate `poly` object representing the sum of two `poly`s.
Here, `p` and `q` are themselves string forms of `poly`s. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sub_parser (cont : parser poly) : parser poly | str "poly.sub " >> poly.sub <$> cont <*> (ch ' ' >> cont) | def | polyrith.sub_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"cont",
"poly"
] | A parser object that parses `string`s of the form `"poly.sub p q"`
to the appropriate `poly` object representing the subtraction of two `poly`s.
Here, `p` and `q` are themselves string forms of `poly`s. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mul_parser (cont : parser poly) : parser poly | str "poly.mul " >> poly.mul <$> cont <*> (ch ' ' >> cont) | def | polyrith.mul_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"cont",
"poly"
] | A parser object that parses `string`s of the form `"poly.mul p q"`
to the appropriate `poly` object representing the product of two `poly`s.
Here, `p` and `q` are themselves string forms of `poly`s. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
pow_parser (cont : parser poly) : parser poly | str "poly.pow " >> poly.pow <$> cont <*> (ch ' ' >> nat) | def | polyrith.pow_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"cont",
"poly"
] | A parser object that parses `string`s of the form `"poly.pow p n"`
to the appropriate `poly` object representing a `poly` raised to the
power of a natural number. Here, `p` is the string form of a `poly`
and `n` is a natural number. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
neg_parser (cont : parser poly) : parser poly | str "poly.neg " >> poly.neg <$> cont | def | polyrith.neg_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"cont",
"poly"
] | A parser object that parses `string`s of the form `"poly.neg p"`
to the appropriate `poly` object representing the negation of a `poly`.
Here, `p` is the string form of a `poly`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
poly_parser : parser poly | ch '('
*> (var_parser <|> const_fraction_parser <|> add_parser poly_parser
<|> sub_parser poly_parser <|> mul_parser poly_parser <|> pow_parser poly_parser
<|> neg_parser poly_parser)
<* ch ')' | def | polyrith.poly_parser | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | A parser for `poly` that uses an s-essresion style formats such as
`(poly.add (poly.var 0) (poly.const 1)`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sage_json_success | (success : {b : bool // b = tt})
(trace : option string := none)
(data : option (list poly) := none) | structure | polyrith.sage_json_success | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | A schema for success messages from the python script | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sage_json_failure | (success : {b : bool // b = ff})
(error_name : string)
(error_value : string) | structure | polyrith.sage_json_failure | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | A schema for failure messages from the python script | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
convert_sage_output (j : json) : tactic (option (list poly)) | do
r : sage_json_success ⊕ sage_json_failure ← decorate_ex "internal json error: "
-- try the error format first, so that if both fail we get the message from the success parser
(sum.inr <$> of_json sage_json_failure j <|> sum.inl <$> of_json sage_json_success j),
match r with
| sum.inr f :=
fail!"p... | def | polyrith.convert_sage_output | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | Parse the json output from `scripts/polyrith.py` into either an error message, a list of `poly`
objects, or `none` if only trace output was requested. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
equality_to_left_side : expr → tactic expr | | `(%%lhs = %%rhs) := to_expr ``(%%lhs - %%rhs)
| e := fail "expression is not an equality" | def | polyrith.equality_to_left_side | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | Convert an expression of the form `lhs = rhs` into the form `lhs - rhs` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
parse_target_to_poly : tactic (list expr × poly × expr) | do
e@`(@eq %%R _ _) ← target,
left_side ← equality_to_left_side e,
(m, p) ← poly_form_of_expr transparency.reducible [] left_side,
return (m, p, R) | def | polyrith.parse_target_to_poly | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | `(vars, poly, typ) ← parse_target_to_poly` interprets the current target (an equality over
some field) into a `poly`. The result is a list of the atomic expressions in the target,
the `poly` itself, and an `expr` representing the type of the field. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_equalities_of_type (expt : expr) (l : list expr) : tactic (list expr) | l.mfilter $ λ h_eq, succeeds $ do
`(@eq %%R _ _) ← infer_type h_eq,
unify expt R | def | polyrith.get_equalities_of_type | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"succeeds"
] | Filter `l` to the elements which are equalities of type `expt`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
parse_ctx_to_polys (expt : expr) (m : list expr) (only_on : bool) (hyps : list pexpr) :
tactic (list expr × list expr × list poly) | do
hyps ← hyps.mmap i_to_expr,
hyps ← if only_on then return hyps else (++ hyps) <$> local_context,
eq_names ← get_equalities_of_type expt hyps,
eqs ← eq_names.mmap infer_type,
eqs_to_left ← eqs.mmap equality_to_left_side,
-- convert the expressions to polynomials, tracking the variables in `m`
(m, poly_l... | def | polyrith.parse_ctx_to_polys | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"poly"
] | The purpose of this tactic is to collect all the hypotheses
and proof terms (specified by the user) that are equalities
of the same type as the target. It takes in an `expr` representing
the type, a list of expressions representing the atoms
(typically this starts as only containing
information about the target), a `bo... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sage_output (arg_list : list string := []) : tactic json | do
path ← get_mathlib_dir,
let args := [path ++ "../scripts/polyrith_sage.py"] ++ arg_list,
s ← unsafe_run_io $ io.cmd { cmd := "python3", args := args},
some j ← pure (json.parse s) | fail!"Invalid json: {s}",
pure j | def | polyrith.sage_output | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"get_mathlib_dir",
"path"
] | This tactic calls python from the command line with the args in `arg_list`.
The output printed to the console is returned as a `string`.
It assumes that `python3` is available on the path. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_parens : expr → tactic format | | e@`(_ + _) := pformat!"({e})"
| e@`(_ - _) := pformat!"({e})"
| e := pformat!"{e}" | def | polyrith.add_parens | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | Adds parentheses around additions and subtractions, for printing at
precedence 65. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
component_to_lc_format : expr × expr → tactic (bool × format) | | (ex, `(@has_one.one _ _)) := prod.mk ff <$> pformat!"{ex}"
| (ex, `(@has_one.one _ _ / %%cf)) := do f ← add_parens cf, prod.mk ff <$> pformat!"{ex} / {f}"
| (ex, `(-%%cf)) := do (neg, fmt) ← component_to_lc_format (ex, cf), return (!neg, fmt)
| (ex, cf) := do f ← add_parens cf, prod.mk ff <$> pformat!"{f} * {ex}" | def | polyrith.component_to_lc_format | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | Given a pair of `expr`s, where one represents the hypothesis/proof term,
and the other representes the coefficient attached to it, this tactic
creates a string combining the two in the appropriate format for
`linear_combination`.
The boolean value returned is `tt` if the format needs to be negated
to accurately reflec... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
intersperse_ops_aux : list (bool × format) → format | | [] := ""
| ((ff, fmt) :: t) := " +" ++ format.soft_break ++ fmt ++ intersperse_ops_aux t
| ((tt, fmt) :: t) := " -" ++ format.soft_break ++ fmt ++ intersperse_ops_aux t | def | polyrith.intersperse_ops_aux | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"format.soft_break"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
intersperse_ops : list (bool × format) → format | | [] := ""
| ((ff, fmt)::t) := fmt ++ intersperse_ops_aux t
| ((tt, fmt)::t) := "-" ++ fmt ++ intersperse_ops_aux t | def | polyrith.intersperse_ops | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | Given a `list (bool × format)`, this function uses `+` and `-` to conjoin the
`format`s in the list. A `format` is negated if its corresponding `bool` is `tt`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
components_to_lc_format (components : list (expr × expr)) : tactic format | intersperse_ops <$> components.mmap component_to_lc_format
/-!
# Connecting with Python
The following section contains code that allows lean to communicate with a python script.
-/
declare_trace polyrith | def | polyrith.components_to_lc_format | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | This tactic repeats the process above for a `list` of pairs of `expr`s. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
create_args (only_on : bool) (hyps : list pexpr) :
tactic (list expr × list expr × expr × list string) | do
(m, p, R) ← parse_target_to_poly,
(eq_names, m, polys) ← parse_ctx_to_polys R m only_on hyps,
let args := [to_string R, to_string m.length,
(polys.map poly.mk_string).to_string, p.mk_string],
return $ (eq_names, m, R, to_string (is_trace_enabled_for `polyrith) :: args) | def | polyrith.create_args | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | The first half of `tactic.polyrith` produces a list of arguments to be sent to Sage. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
process_output (eq_names : list expr) (m : list expr) (R : expr) (sage_out : json) :
tactic format | focus1 $ do
some coeffs_as_poly ← convert_sage_output sage_out | fail!"internal error: No output available",
coeffs_as_pexpr ← coeffs_as_poly.mmap (poly.to_pexpr m),
let eq_names_pexpr := eq_names.map to_pexpr,
coeffs_as_expr ← coeffs_as_pexpr.mmap $ λ e, to_expr ``(%%e : %%R),
linear_combo.linear_combination... | def | polyrith.process_output | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"filter",
"linear_combo.linear_combination"
] | The second half of `tactic.polyrith` processes the output from Sage into
a call to `linear_combination`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
no_hypotheses_case : tactic (option format) | (do `[ring], return $ some "ring") <|>
fail "polyrith did not find any relevant hypotheses and the goal is not provable by ring" | def | polyrith.no_hypotheses_case | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"ring"
] | Tactic for the special case when no hypotheses are available. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
no_variables_case : tactic (option format) | (do `[ring], return $ some "ring") <|>
fail "polyrith did not find any variables and the goal is not provable by ring" | def | polyrith.no_variables_case | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"ring"
] | Tactic for the special case when there are no variables. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
_root_.tactic.polyrith (only_on : bool) (hyps : list pexpr) : tactic (option format) | do
sleep 10, -- otherwise can lead to weird errors when actively editing code with polyrith calls
(eq_names, m, R, args) ← create_args only_on hyps,
if eq_names.length = 0 then no_hypotheses_case else
if m.length = 0 then no_variables_case else do
sage_out ← sage_output args,
if is_trace_enabled_for `polyri... | def | tactic.polyrith | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [] | This is the main body of the `polyrith` tactic. It takes in the following inputs:
* `(only_on : bool)` - This represents whether the user used the key word "only"
* `(hyps : list pexpr)` - the hypotheses/proof terms selecteed by the user
First, the tactic converts the target into a `poly`, and finds out what type it
i... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
_root_.tactic.interactive.polyrith (restr : parse (tk "only")?)
(hyps : parse pexpr_list?) : tactic unit | do
some f ← tactic.polyrith restr.is_some (hyps.get_or_else []) | skip,
trace!"Try this: {f}" | def | tactic.interactive.polyrith | tactic | src/tactic/polyrith.lean | [
"tactic.linear_combination",
"data.buffer.parser.numeral",
"data.json"
] | [
"tactic.polyrith"
] | Attempts to prove polynomial equality goals through polynomial arithmetic
on the hypotheses (and additional proof terms if the user specifies them).
It proves the goal by generating an appropriate call to the tactic
`linear_combination`. If this call succeeds, the call to `linear_combination`
is suggested to the user.
... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
positivity.strictness : Type
| positive : expr → positivity.strictness
| nonnegative : expr → positivity.strictness
| nonzero : expr → positivity.strictness | inductive | tactic.positivity.strictness | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [] | Inductive type recording either `positive` and an expression (typically a proof of a fact
`0 < x`) or `nonnegative` and an expression (typically a proof of a fact `0 ≤ x`). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
lt_of_eq_of_lt'' {α} [preorder α] {b b' a : α} : b = b' → a < b' → a < b | λ h1 h2, lt_of_lt_of_eq h2 h1.symm | lemma | tactic.lt_of_eq_of_lt'' | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [
"lt_of_lt_of_eq"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
norm_num.positivity (e : expr) : tactic strictness | do
(e', p) ← norm_num.derive e <|> refl_conv e,
e'' ← e'.to_rat,
typ ← infer_type e',
ic ← mk_instance_cache typ,
if e'' > 0 then do
(ic, p₁) ← norm_num.prove_pos ic e',
positive <$> mk_app ``lt_of_eq_of_lt'' [p, p₁]
else if e'' = 0 then
nonnegative <$> mk_app ``ge_of_eq [p]
else do
(ic, p... | def | tactic.norm_num.positivity | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [
"ge_of_eq",
"norm_num.derive",
"norm_num.prove_ne_zero'",
"norm_num.prove_pos"
] | First base case of the `positivity` tactic. We try `norm_num` to prove directly that an
expression `e` is positive, nonnegative or non-zero. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
positivity_canon : expr → tactic strictness | | `(%%a) := nonnegative <$> mk_app ``zero_le [a] | def | tactic.positivity_canon | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [] | Second base case of the `positivity` tactic: Any element of a canonically ordered additive
monoid is nonnegative. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
order_rel : Type
| le : order_rel -- `0 ≤ a`
| lt : order_rel -- `0 < a`
| ne : order_rel -- `a ≠ 0`
| ne' : order_rel | inductive | tactic.positivity.order_rel | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [] | Inductive type recording whether the goal `positivity` is called on is nonnegativity, positivity
or different from `0`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
orelse (tac1 tac2 : tactic strictness) : tactic strictness | do
res1 ← try_core tac1,
match res1 with
| none := tac2
| some p1@(positive _) := pure p1
| some (nonnegative e1) := do
res2 ← try_core tac2,
match res2 with
| some p2@(positive _) := pure p2
| some (nonzero e2) := positive <$> mk_app ``lt_of_le_of_ne' [e1, e2]
| _ := pure (nonne... | def | tactic.positivity.orelse | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [
"lt_of_le_of_ne'",
"orelse"
] | Given two tactics whose result is `strictness`, report a `strictness`:
- if at least one gives `positive`, report `positive` and one of the expressions giving a proof of
positivity
- if one reports `nonnegative` and the other reports `nonzero`, report `positive`
- else if at least one reports `nonnegative`, report `n... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
positivity_fail {α : Type*} (e a b : expr) (pa pb : strictness) : tactic α | do
e' ← pp e,
a' ← pp a,
b' ← pp b,
let f : strictness → format → format := λ p c, match p with
| positive _ := "0 < " ++ c
| nonnegative _ := "0 ≤ " ++ c
| nonzero _ := c ++ " ≠ 0"
end,
fail (↑"`positivity` can't say anything about `" ++ e' ++ "` knowing only `" ++ f pa a' ++
"` and `" ++ f pb b'... | def | tactic.positivity.positivity_fail | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [] | This tactic fails with a message saying that `positivity` couldn't prove anything about `e`
if we only know that `a` and `b` are positive/nonnegative/nonzero (according to `pa` and `pb`). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ne_of_ne_of_eq' {α : Type*} {a b c : α} (ha : a ≠ c) (h : a = b) : b ≠ c | by rwa ←h | lemma | tactic.positivity.ne_of_ne_of_eq' | tactic | src/tactic/positivity.lean | [
"tactic.norm_num",
"algebra.order.field.power",
"algebra.order.hom.basic",
"data.nat.factorial.basic"
] | [] | 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.