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 |
|---|---|---|---|---|---|---|---|---|---|---|
mk_mul : list pexpr → pexpr | | [] := ``(1)
| [e] := e
| (e::es) := ``(%%e * %%(mk_mul es)) | def | linear_combo.mk_mul | tactic | src/tactic/linear_combination.lean | [
"tactic.ring"
] | [] | `mk_mul [p₀, p₁, ..., pₙ]` produces the pexpr `p₀ * p₁ * ... * pₙ`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
as_linear_combo : bool → list pexpr → pexpr → list (pexpr × pexpr) | | neg ms e :=
let (head, args) := pexpr.get_app_fn_args e in
match head.get_frozen_name, args with
| ``has_add.add, [e1, e2] := as_linear_combo neg ms e1 ++ as_linear_combo neg ms e2
| ``has_sub.sub, [e1, e2] := as_linear_combo neg ms e1 ++ as_linear_combo (bnot neg) ms e2
| ``has_mul.mul, [e1, e2] := as_line... | def | linear_combo.as_linear_combo | tactic | src/tactic/linear_combination.lean | [
"tactic.ring"
] | [
"pexpr.get_app_fn_args"
] | `as_linear_combo neg ms e` is used to parse the argument to `linear_combination`.
This argument is a sequence of literals `x`, `-x`, or `c*x` combined with `+` or `-`,
given by the pexpr `e`.
The `neg` and `ms` arguments are used recursively; called at the top level, its usage should be
`as_linear_combo ff [] e`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
_root_.tactic.interactive.linear_combination
(input : parse (as_linear_combo ff [] <$> texpr)?)
(_ : parse (tk "with")?)
(config : linear_combination_config := {})
: tactic unit | let (h_eqs_names, coeffs) := list.unzip (input.get_or_else []) in
linear_combination h_eqs_names coeffs config | def | tactic.interactive.linear_combination | tactic | src/tactic/linear_combination.lean | [
"tactic.ring"
] | [] | `linear_combination` attempts to simplify the target by creating a linear combination
of a list of equalities and subtracting it from the target.
The tactic will create a linear
combination by adding the equalities together from left to right, so the order
of the input hypotheses does matter. If the `normalize... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
localized_attr : user_attribute (rb_lmap name string) unit | { name := "_localized",
descr := "(interal) attribute that flags localized commands",
parser := failed,
cache_cfg := ⟨λ ns, (do dcls ← ns.mmap (λ n, mk_const n >>= eval_expr (name × string)),
return $ rb_lmap.of_list dcls), []⟩ } | def | localized_attr | tactic | src/tactic/localized.lean | [
"meta.rb_map",
"tactic.core"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_localized (ns : list name) : tactic (list string) | do m ← localized_attr.get_cache,
ns.mfoldl (λ l nm, match m.find nm with
| [] := fail format!"locale {nm} does not exist"
| new_l := return $ l.append new_l
end) [] | def | get_localized | tactic | src/tactic/localized.lean | [
"meta.rb_map",
"tactic.core"
] | [] | Get all commands in the given locale and return them as a list of strings | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
open_locale_cmd (_ : parse $ tk "open_locale") : parser unit | do ns ← many ident,
cmds ← get_localized ns,
cmds.mmap' emit_code_here | def | open_locale_cmd | tactic | src/tactic/localized.lean | [
"meta.rb_map",
"tactic.core"
] | [
"get_localized"
] | Execute all commands in the given locale | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
localized_cmd (_ : parse $ tk "localized") : parser unit | do cmd ← parser.pexpr, cmd ← i_to_expr cmd, cmd ← eval_expr string cmd,
let cmd := "local " ++ cmd,
emit_code_here cmd,
tk "in",
nm ← ident,
env ← get_env,
let dummy_decl_name := mk_num_name `_localized_decl
((string.hash (cmd ++ nm.to_string) + env.fingerprint) % unsigned_sz),
add_decl (decla... | def | localized_cmd | tactic | src/tactic/localized.lean | [
"meta.rb_map",
"tactic.core"
] | [
"string.hash"
] | Add a new command to a locale and execute it right now.
The new command is added as a declaration to the environment with name `_localized_decl.<number>`.
This declaration has attribute `_localized` and as value a name-string pair. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
print_localized_commands (ns : list name) : tactic unit | do cmds ← get_localized ns, cmds.mmap' trace | def | print_localized_commands | tactic | src/tactic/localized.lean | [
"meta.rb_map",
"tactic.core"
] | [
"get_localized"
] | Print all commands in a given locale | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_full_namespace (ns : name) : name | `local_cache ++ ns | def | tactic.local_cache.internal.mk_full_namespace | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
save_data (dn : name) (a : α) [reflected _ a] : tactic unit | tactic.add_decl $ mk_definition dn [] (reflect α) (reflect a) | def | tactic.local_cache.internal.save_data | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
load_data (dn : name) : tactic α | do e ← tactic.get_env,
d ← e.get dn,
tactic.eval_expr α d.value | def | tactic.local_cache.internal.load_data | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
poke_data (dn : name) : tactic bool | do e ← tactic.get_env,
return (e.get dn).to_bool | def | tactic.local_cache.internal.poke_data | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
run_once_under_name {α : Type} [reflected _ α] [has_reflect α] (t : tactic α)
(cache_name : name) : tactic α | do load_data cache_name <|>
do
{ a ← t,
save_data cache_name a,
return a } | def | tactic.local_cache.internal.run_once_under_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cache_scope | -- Returns the name of the def used to store the contents of is cache,
-- making a new one and recording this in private state if neccesary.
(get_name : name → tactic name)
-- Same as above but fails instead of making a new name, and never
-- mutates state.
(try_get_name : name → tactic name)
-- Asks whether the namesp... | structure | tactic.local_cache.internal.cache_scope | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_name_aux (ns : name) (mk_new : options → name → tactic name) : tactic name | do o ← tactic.get_options,
let opt := mk_full_namespace ns,
match o.get_string opt "" with
| "" := mk_new o opt
| s := return $ name.from_components $ s.split (= '.')
end | def | tactic.local_cache.internal.block_local.get_name_aux | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [
"name.from_components"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_name (ns : name) : tactic name | get_name_aux ns $ λ o opt,
do n ← mk_user_fresh_name,
tactic.set_options $ o.set_string opt n.to_string,
return n | def | tactic.local_cache.internal.block_local.get_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
try_get_name (ns : name) : tactic name | get_name_aux ns $ λ o opt, fail format!"no cache for \"{ns}\"" | def | tactic.local_cache.internal.block_local.try_get_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
present (ns : name) : tactic bool | do o ← tactic.get_options,
match o.get_string (mk_full_namespace ns) "" with
| "" := return ff
| s := return tt
end | def | tactic.local_cache.internal.block_local.present | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
clear (ns : name) : tactic unit | do o ← tactic.get_options,
set_options $ o.set_string (mk_full_namespace ns) "" | def | tactic.local_cache.internal.block_local.clear | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
FNV_OFFSET_BASIS | 0xcbf29ce484222325 | def | tactic.local_cache.internal.def_local.FNV_OFFSET_BASIS | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
FNV_PRIME | 0x100000001b3 | def | tactic.local_cache.internal.def_local.FNV_PRIME | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
RADIX | by apply_normed 2^64 | def | tactic.local_cache.internal.def_local.RADIX | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
hash_byte (seed : ℕ) (c : char) : ℕ | let n : ℕ := c.to_nat in ((seed.lxor n) * FNV_PRIME) % RADIX | def | tactic.local_cache.internal.def_local.hash_byte | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
hash_string (s : string) : ℕ | s.to_list.foldl hash_byte FNV_OFFSET_BASIS | def | tactic.local_cache.internal.def_local.hash_string | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
hash_context : tactic string | do ns ← open_namespaces,
dn ← decl_name,
let flat := ((list.cons dn ns).map to_string).foldl string.append "",
return $ (to_string dn) ++ (to_string (hash_string flat)) | def | tactic.local_cache.internal.def_local.hash_context | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_root_name (ns : name) : tactic name | do hc ← hash_context,
return $ mk_full_namespace $ hc ++ ns | def | tactic.local_cache.internal.def_local.get_root_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
apply_tag (n : name) (tag : ℕ) : name | n ++ to_string format!"t{tag}" | def | tactic.local_cache.internal.def_local.apply_tag | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mk_dead_name (n : name) : name | n ++ `dead | def | tactic.local_cache.internal.def_local.mk_dead_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
kill_name (n : name) : tactic unit | save_data (mk_dead_name n) () | def | tactic.local_cache.internal.def_local.kill_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
is_name_dead (n : name) : tactic bool | do { witness : unit ← load_data $ mk_dead_name n, return true }
<|> return false | def | tactic.local_cache.internal.def_local.is_name_dead | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_with_status_tag_aux (rn : name) : ℕ → tactic (ℕ × bool) | | tag := do let n := apply_tag rn tag,
present ← poke_data n,
if ¬present then fail format!"{rn} never seen in cache!"
else do is_dead ← is_name_dead n,
if is_dead then get_with_status_tag_aux (tag + 1)
<|> return (tag, false)
... | def | tactic.local_cache.internal.def_local.get_with_status_tag_aux | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_tag_with_status (rn : name) : tactic (ℕ × bool) | get_with_status_tag_aux rn 0 | def | tactic.local_cache.internal.def_local.get_tag_with_status | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_name (ns : name) : tactic name | do rn ← get_root_name ns,
(tag, alive) ← get_tag_with_status rn <|> return (0, true),
return $ apply_tag rn $ if alive then tag
else tag + 1 | def | tactic.local_cache.internal.def_local.get_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
try_get_name (ns : name) : tactic name | do rn ← get_root_name ns,
(tag, alive) ← get_tag_with_status rn,
if alive then return $ apply_tag rn tag
else fail format!"no cache for \"{ns}\"" | def | tactic.local_cache.internal.def_local.try_get_name | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
present (ns : name) : tactic bool | do rn ← get_root_name ns,
(prod.snd <$> get_tag_with_status rn) <|> return false | def | tactic.local_cache.internal.def_local.present | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
clear (ns : name) : tactic unit | do { n ← try_get_name ns, kill_name n }
<|> skip | def | tactic.local_cache.internal.def_local.clear | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
cache_scope.block_local : cache_scope | ⟨ block_local.get_name,
block_local.try_get_name,
block_local.present,
block_local.clear ⟩ | def | tactic.local_cache.cache_scope.block_local | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | This scope propogates the cache within a `begin ... end` or `by` block
and its decendants. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
cache_scope.def_local : cache_scope | ⟨ def_local.get_name,
def_local.try_get_name,
def_local.present,
def_local.clear ⟩ | def | tactic.local_cache.cache_scope.def_local | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | This scope propogates the cache within an entire `def`/`lemma`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
present (ns : name) (s : cache_scope := block_local) : tactic bool | s.present ns | def | tactic.local_cache.present | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | Asks whether the namespace `ns` currently has a value-in-cache. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
clear (ns : name) (s : cache_scope := block_local) : tactic unit | s.clear ns | def | tactic.local_cache.clear | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | Clear cache associated to namespace `ns`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get (ns : name) (α : Type) [reflected _ α] [has_reflect α]
(s : cache_scope := block_local) :
tactic (option α) | do dn ← some <$> s.try_get_name ns <|> return none,
match dn with
| none := return none
| some dn := some <$> load_data dn
end | def | tactic.local_cache.get | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | Gets the (optionally present) value-in-cache for `ns`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
run_once {α : Type} [reflected _ α] [has_reflect α] (ns : name) (t : tactic α)
(s : cache_scope := cache_scope.block_local) : tactic α | s.get_name ns >>= run_once_under_name t | def | tactic.run_once | tactic | src/tactic/local_cache.lean | [
"tactic.norm_num"
] | [] | Using the namespace `ns` as its key, when called for the first
time `run_once ns t` runs `t`, then saves and returns the result.
Upon subsequent invocations in the same tactic block, with the scope
of the caching being inherited by child tactic blocks) we return the
cached result directly.
You can ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
select : ℕ → ℕ → tactic unit | | 0 0 := skip
| 0 (n + 1) := left >> skip
| (m + 1) (n + 1) := right >> select m n
| (n + 1) 0 := failure | def | mk_iff.select | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | `select m n` runs `tactic.right` `m` times, and then `tactic.left` `(n-m)` times.
Fails if `n < m`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
compact_relation :
list expr → list (expr × expr) → list (option expr) × list (expr × expr) | | [] ps := ([], ps)
| (b :: bs) ps :=
match ps.span (λap:expr × expr, ¬ ap.2 =ₐ b) with
| (_, []) := let (bs, ps) := compact_relation bs ps in (b::bs, ps)
| (ps₁, (a, _) :: ps₂) :=
let i := a.instantiate_local b.local_uniq_name,
(bs, ps) := compact_relation (bs.map i) ((ps₁ +... | def | mk_iff.compact_relation | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | `compact_relation bs as_ps`: Produce a relation of the form:
```lean
R as := ∃ bs, Λ_i a_i = p_i[bs]
```
This relation is user-visible, so we compact it by removing each `b_j` where a `p_i = b_j`, and
hence `a_i = b_j`. We need to take care when there are `p_i` and `p_j` with `p_i = p_j = b_k`.
TODO: this is a variant... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
constr_to_prop (univs : list level) (g : list expr) (idxs : list expr) (c : name) :
tactic ((list (option expr) × (expr ⊕ ℕ)) × expr) | do e ← get_env,
decl ← get_decl c,
some type' ← return $ decl.instantiate_type_univ_params univs,
type ← drop_pis g type',
(args, res) ← open_pis type,
let idxs_inst := res.get_app_args.drop g.length,
let (bs, eqs) := compact_relation args (idxs.zip idxs_inst),
let bs' := bs.filter_map id,
eqs ← eqs.mma... | def | mk_iff.constr_to_prop | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
to_cases (s : list $ list (option expr) × (expr ⊕ ℕ)) : tactic unit | do h ← intro1,
i ← induction h,
focus ((s.zip i).enum.map $ λ⟨p, (shape, t), _, vars, _⟩, do
let si := (shape.zip vars).filter_map (λ⟨c, v⟩, c >>= λ _, some v),
select p (s.length - 1),
match t with
| sum.inl e := do
si.init.mmap' existsi,
some v ← return $ vars.nth (shape.length - 1),
... | def | mk_iff.to_cases | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
list_option_merge {α : Type*} {β : Type*} : list (option α) → list β → list (option β) | | [] _ := []
| (none :: xs) ys := none :: list_option_merge xs ys
| (some _ :: xs) (y :: ys) := some y :: list_option_merge xs ys
| (some _ :: xs) [] := [] | def | mk_iff.list_option_merge | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | Iterate over two lists, if the first element of the first list is `none`, insert `none` into the
result and continue with the tail of first list. Otherwise, wrap the first element of the second
list with `some` and continue with the tails of both lists. Return when either list is empty.
Example:
```
list_option_merge ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
to_inductive
(cs : list name) (gs : list expr) (s : list (list (option expr) × (expr ⊕ ℕ))) (h : expr) :
tactic unit | match s.length with
| 0 := induction h >> skip
| (n + 1) := do
r ← elim_gen_sum n h,
focus ((cs.zip (r.zip s)).map $ λ⟨constr_name, h, bs, e⟩, do
let n := (bs.filter_map id).length,
match e with
| sum.inl e := elim_gen_prod (n - 1) h [] [] >> skip
| sum.inr 0 := do
(hs, h, _) ← elim_gen_... | def | mk_iff.to_inductive | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mk_iff_of_inductive_prop (i : name) (r : name) : tactic unit | do e ← get_env,
guard (e.is_inductive i),
let constrs := e.constructors_of i,
let params := e.inductive_num_params i,
let indices := e.inductive_num_indices i,
let rec := match e.recursor_of i with
| some rec := rec
| none := i.append `rec
end,
decl ← get_decl i,
let type := decl.type,
let ... | def | tactic.mk_iff_of_inductive_prop | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [] | `mk_iff_of_inductive_prop i r` makes an `iff` rule for the inductively-defined proposition `i`.
The new rule `r` has the shape `∀ps is, i as ↔ ⋁_j, ∃cs, is = cs`, where `ps` are the type
parameters, `is` are the indices, `j` ranges over all possible constructors, the `cs` are the
parameters for each of the constructors... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_iff_of_inductive_prop_cmd (_ : parse (tk "mk_iff_of_inductive_prop")) :
parser unit | do i ← ident, r ← ident, tactic.mk_iff_of_inductive_prop i r | def | mk_iff_of_inductive_prop_cmd | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [
"tactic.mk_iff_of_inductive_prop"
] | `mk_iff_of_inductive_prop i r` makes an `iff` rule for the inductively-defined proposition `i`.
The new rule `r` has the shape `∀ps is, i as ↔ ⋁_j, ∃cs, is = cs`, where `ps` are the type
parameters, `is` are the indices, `j` ranges over all possible constructors, the `cs` are the
parameters for each of the constructors... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_iff_attr : user_attribute unit (option name) | { name := `mk_iff,
descr := "Generate an `iff` lemma for an inductive `Prop`.",
parser := ident?,
after_set := some $ λ n _ _, do
tgt ← mk_iff_attr.get_param n,
tactic.mk_iff_of_inductive_prop n (tgt.get_or_else (n.append_suffix "_iff")) } | def | mk_iff_attr | tactic | src/tactic/mk_iff_of_inductive_prop.lean | [
"tactic.core",
"tactic.lint"
] | [
"tactic.mk_iff_of_inductive_prop"
] | Applying the `mk_iff` attribute to an inductively-defined proposition `mk_iff` makes an `iff` rule
`r` with the shape `∀ps is, i as ↔ ⋁_j, ∃cs, is = cs`, where `ps` are the type parameters, `is` are
the indices, `j` ranges over all possible constructors, the `cs` are the parameters for each of the
constructors, and the... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_simp_attribute_cmd (_ : parse $ tk "mk_simp_attribute") : lean.parser unit | do n ← ident,
d ← parser.pexpr,
d ← to_expr ``(%%d : option string),
descr ← eval_expr (option string) d,
with_list ← (tk "with" *> many ident) <|> return [],
mk_simp_attr n with_list,
add_doc_string (name.append `simp_attr n) $ descr.get_or_else $ "simp set for " ++ to_string n | def | tactic.mk_simp_attribute_cmd | tactic | src/tactic/mk_simp_attribute.lean | [
"tactic.doc_commands"
] | [] | The command `mk_simp_attribute simp_name "description"` creates a simp set with name `simp_name`.
Lemmas tagged with `@[simp_name]` will be included when `simp with simp_name` is called.
`mk_simp_attribute simp_name none` will use a default description.
Appending the command with `with attr1 attr2 ...` will include al... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
return_unused {α : Type*} : list α → list bool → list α | | un [] := un
| [] bo := []
| (u::us) (b::bs) := if b then u::return_unused us bs else return_unused us bs | def | tactic.move_op.return_unused | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | Given a list `un` of `α`s and a list `bo` of `bool`s, return the sublist of `un`
consisting of the entries of `un` whose corresponding entry in `bo` is `tt`.
Used for error management: `un` is the list of user inputs, `bo` is the list encoding which input
is unused (`tt`) and which input is used (`ff`).
`return_unused... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_left_or_right : list (bool × expr) → list expr → list bool →
tactic (list expr × list expr × list expr × list bool) | | [] l_un l_m := return ([], [], l_un, l_m)
| (be::l) l_un l_m := do
(ex :: _) ← l_un.mfilter $ λ e', succeeds $ unify be.2 e' |
move_left_or_right l l_un (l_m.append [tt]),
(l_tt, l_ff, l_un, l_m) ← move_left_or_right l (l_un.erase ex) (l_m.append [ff]),
if be.1 then return (ex::l_tt, l_ff, l_un, l_m) e... | def | tactic.move_op.move_left_or_right | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [
"succeeds"
] | Given a list `lp` of `bool × pexpr` and a list `l_un` of `expr`, scan the elements of `lp` one
at a time and produce 3 sublists of `l_un`.
If `(tf,pe)` is the first element of `lp`, we look for the first element of `l_un` that unifies with
`pe.to_expr`. If no such element exists, then we discard `(tf,pe)` and move al... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
final_sort (lp : list (bool × pexpr)) (sl : list expr) : tactic (list expr × list bool) | do
lp_exp : list (bool × expr) ← lp.mmap $ λ x, (do e ← to_expr x.2 tt ff, return (x.1, e)),
(l1, l2, l3, is_unused) ← move_left_or_right lp_exp sl [],
return (l1 ++ l3 ++ l2, is_unused) | def | tactic.move_op.final_sort | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [
"lp"
] | We adapt `move_left_or_right` to our goal:
1. we convert a list of pairs `bool × pexpr` to a list of pairs `bool × expr`,
2. we use the extra input `sl : list expr` to perform the unification and sorting step
`move_left_or_right`,
3. we jam the third factor inside the first two. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
as_given_op (op : pexpr) : expr → tactic expr | | (expr.app (expr.app F a) b) := do
to_expr op tt ff >>= unify F,
return F
| _ := failed | def | tactic.move_op.as_given_op | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | `as_given_op op e` unifies the head term of `e`, which is a ≥2-argument function application,
with the binary operation `op`, failing if it cannot. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
reorder_oper (op : pexpr) (lp : list (bool × pexpr)) :
expr → tactic (expr × list bool) | | F'@(expr.app F b) := do
is_op ← try_core (as_given_op op F'),
match is_op with
| some op := do
(sort_list, is_unused) ← list_binary_operands op F' >>= final_sort lp,
sort_all ← sort_list.mmap (λ e, do
(e, lu) ← reorder_oper e,
pure (e, [lu, is_unused].transpose.map list... | def | tactic.move_op.reorder_oper | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [
"lp"
] | `(e, unused) ← reorder_oper op lp e` converts an expression `e` to a similar looking one.
The tactic scans the expression `e` looking for subexpressions that begin with the given binary
operation `op`. As soon as `reorder_oper` finds one such subexpression,
* it extracts the "`op`-summands" in the subexpression,
* it ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
reorder_hyp (op : pexpr) (lp : list (bool × pexpr)) (na : option name) :
tactic (bool × list bool) | do
(thyp, hyploc) ← match na with
| none := do
t ← target,
return (t, none)
| some na := do
hl ← get_local na,
th ← infer_type hl,
return (th, some hl)
end,
(reordered, is_unused) ← reorder_oper op lp thyp,
unify reordered thyp >> return (tt, is_unused) <|> do
-- the current `do` blo... | def | tactic.move_op.reorder_hyp | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [
"lp",
"mul_assoc",
"mul_comm",
"mul_left_comm"
] | Passes the user input `na` to `reorder_oper` at a single location, that could either be
`none` (referring to the goal) or `some name` (referring to hypothesis `name`). Replaces the
given hypothesis/goal with the rearranged one that `reorder_hyp` receives from `reorder_oper`.
Returns a pair consisting of a boolean and ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_op_arg (prec : nat) : parser (bool × pexpr) | prod.mk <$> (option.is_some <$> (tk "<-")?) <*> parser.pexpr prec | def | tactic.move_op.move_op_arg | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | `move_op_arg` is a single elementary argument that `move_op` takes for the
variables to be moved. It is either a `pexpr`, or a `pexpr` preceded by a `←`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_pexpr_list_or_texpr : parser (list (bool × pexpr)) | list_of (move_op_arg 0) <|> list.ret <$> move_op_arg tac_rbp <|> return [] | def | tactic.move_op.move_pexpr_list_or_texpr | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | `move_pexpr_list_or_texpr` is either a list of `move_op_arg`, possibly empty, or a single
`move_op_arg`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_op (args : parse move_pexpr_list_or_texpr) (locat : parse location) (op : pexpr) :
tactic unit | do
locas ← locat.get_locals,
tg ← target,
let locas_with_tg := if locat.include_goal then locas ++ [tg] else locas,
ner ← locas_with_tg.mmap (λ e, reorder_hyp op args e.local_pp_name <|> reorder_hyp op args none),
let (unch_tgts, unus_vars) := ner.unzip,
str_unva ← match
(return_unused args (unus_vars.transpose.map l... | def | tactic.move_op | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [
"expr.replace_mvars",
"format.intercalate"
] | `move_op args locat op` is the non-interactive version of the main tactics `move_add` and
`move_mul` of this file. Given as input `args` (a list of terms of a sequence of operands),
`locat` (hypotheses or goal where the tactic should act) and `op` (the operation to use),
`move_op` attempts to perform the rearrangement... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_add (args : parse move_pexpr_list_or_texpr) (locat : parse location) :
tactic unit | move_op args locat ``((+)) | def | tactic.interactive.move_add | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | Calling `move_add [a, ← b, c]`, recursively looks inside the goal for expressions involving a sum.
Whenever it finds one, it moves the summands that unify to `a, b, c`, removing all parentheses.
Repetitions are allowed, and are processed following the user-specified ordering.
The terms preceded by a `←` get placed to t... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_mul (args : parse move_pexpr_list_or_texpr) (locat : parse location) :
tactic unit | move_op args locat ``(has_mul.mul) | def | tactic.interactive.move_mul | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | See the doc-string for `tactic.interactive.move_add` and mentally
replace addition with multiplication throughout. ;-) | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
move_oper
(op : parse pexpr_list) (args : parse move_pexpr_list_or_texpr) (locat : parse location) :
tactic unit | do
[op] ← pure op | fail "only one operation is allowed",
move_op args locat op | def | tactic.interactive.move_oper | tactic | src/tactic/move_add.lean | [
"tactic.core",
"algebra.group.basic"
] | [] | `move_oper` behaves like `move_add` except that it also takes an associative, commutative,
binary operation as input. The operation must be passed as a list consisting of a single element.
For instance
```lean
example (a b : ℕ) : max a b = max b a :=
by move_oper [max] [← a, b] at *
```
solves the goal. For more deta... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
noncomm_ring | `[simp only [-- Expand everything out.
add_mul, mul_add, sub_eq_add_neg,
-- Right associate all products.
mul_assoc,
-- Expand powers to numerals.
pow_bit0, pow_bit1, pow_one,
-- Replace multiplication by numerals with `zsmul`.
b... | def | tactic.interactive.noncomm_ring | tactic | src/tactic/noncomm_ring.lean | [
"tactic.abel"
] | [
"bit0_mul",
"bit1_mul",
"mul_assoc",
"mul_bit0",
"mul_bit1",
"mul_neg",
"mul_one",
"mul_smul_comm",
"mul_zero",
"neg_mul",
"one_mul",
"pow_bit0",
"pow_bit1",
"pow_one",
"smul_mul_assoc",
"zero_mul"
] | A tactic for simplifying identities in not-necessarily-commutative rings.
An example:
```lean
example {R : Type*} [ring R] (a b c : R) : a * (b + c + c - b) = 2*a*c :=
by noncomm_ring
``` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nontriviality_by_elim (α : expr) (lems : interactive.parse simp_arg_list) : tactic unit | do
alternative ← to_expr ``(subsingleton_or_nontrivial %%α),
n ← get_unused_name "_inst",
tactic.cases alternative [n, n],
(solve1 $ do
reset_instance_cache,
apply_instance <|>
interactive.simp none none ff lems [`nontriviality] (interactive.loc.ns [none])) <|>
fail format!"Could not prove g... | def | tactic.nontriviality_by_elim | tactic | src/tactic/nontriviality.lean | [
"logic.nontrivial"
] | [] | Tries to generate a `nontrivial α` instance by performing case analysis on
`subsingleton_or_nontrivial α`,
attempting to discharge the subsingleton branch using lemmas with `@[nontriviality]` attribute,
including `subsingleton.le` and `eq_iff_true_of_subsingleton`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nontriviality_by_assumption (α : expr) : tactic unit | do
n ← get_unused_name "_inst",
to_expr ``(nontrivial %%α) >>= assert n,
apply_instance <|> `[solve_by_elim [nontrivial_of_ne, nontrivial_of_lt]],
reset_instance_cache | def | tactic.nontriviality_by_assumption | tactic | src/tactic/nontriviality.lean | [
"logic.nontrivial"
] | [
"nontrivial_of_lt",
"nontrivial_of_ne"
] | Tries to generate a `nontrivial α` instance using `nontrivial_of_ne` or `nontrivial_of_lt`
and local hypotheses. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
nontriviality (t : parse texpr?)
(lems : parse (tk "using" *> simp_arg_list <|> pure [])) :
tactic unit | do
α ← match t with
| some α := to_expr α
| none :=
(do t ← mk_mvar, e ← to_expr ``(@eq %%t _ _), target >>= unify e, return t) <|>
(do t ← mk_mvar, e ← to_expr ``(@has_le.le %%t _ _ _), target >>= unify e, return t) <|>
(do t ← mk_mvar, e ← to_expr ``(@ne %%t _ _), target >>= unify e, return t) <|>
... | def | tactic.interactive.nontriviality | tactic | src/tactic/nontriviality.lean | [
"logic.nontrivial"
] | [] | Attempts to generate a `nontrivial α` hypothesis.
The tactic first looks for an instance using `apply_instance`.
If the goal is an (in)equality, the type `α` is inferred from the goal.
Otherwise, the type needs to be specified in the tactic invocation, as `nontriviality α`.
The `nontriviality` tactic will first look... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_instance_fast (e : expr) (timeout := 1000) : tactic expr | try_for timeout (mk_instance e) | def | tactic.mk_instance_fast | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Runs `mk_instance` with a time limit.
This is a work around to the fact that in some cases
mk_instance times out instead of failing,
for example: `has_lift_t ℤ ℕ`
`mk_instance_fast` is used when we assume the type class search
should end instantly. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
trace_norm_cast {α} [has_to_tactic_format α] (msg : string) (a : α) : tactic unit | when_tracing `norm_cast $ do
a ← pp a,
trace ("[norm_cast] " ++ msg ++ a : format) | def | norm_cast.trace_norm_cast | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Output a trace message if `trace.norm_cast` is enabled. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
label
| elim : label
| move : label
| squash : label | inductive | norm_cast.label | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | `label` is a type used to classify `norm_cast` lemmas.
* elim lemma: LHS has 0 head coes and ≥ 1 internal coe
* move lemma: LHS has 1 head coe and 0 internal coes, RHS has 0 head coes and ≥ 1 internal coes
* squash lemma: LHS has ≥ 1 head coes and 0 internal coes, RHS has fewer head coes | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
to_string : label → string | | elim := "elim"
| move := "move"
| squash := "squash" | def | norm_cast.label.to_string | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Convert `label` into `string`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
of_string : string -> option label | | "elim" := some elim
| "move" := some move
| "squash" := some squash
| _ := none | def | norm_cast.label.of_string | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Convert `string` into `label`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
count_head_coes : expr → ℕ | | `(coe %%e) := count_head_coes e + 1
| `(coe_sort %%e) := count_head_coes e + 1
| `(coe_fn %%e) := count_head_coes e + 1
| _ := 0 | def | norm_cast.count_head_coes | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Count how many coercions are at the top of the expression. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
count_coes : expr → tactic ℕ | | `(coe %%e) := (+1) <$> count_coes e
| `(coe_sort %%e) := (+1) <$> count_coes e
| `(coe_fn %%e) := (+1) <$> count_coes e
| (app `(coe_fn %%e) x) := (+) <$> count_coes x <*> (+1) <$> count_coes e
| (expr.lam n bi t e) := do
l ← mk_local' n bi t,
count_coes $ e.instantiate_var l
| e := do
as ← e.get_simp_args,
l... | def | norm_cast.count_coes | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [
"list.sum"
] | Count how many coercions are inside the expression, including the top ones. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
count_internal_coes (e : expr) : tactic ℕ | do
ncoes ← count_coes e,
pure $ ncoes - count_head_coes e | def | norm_cast.count_internal_coes | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Count how many coercions are inside the expression, excluding the top ones. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
classify_type (ty : expr) : tactic label | do
(_, ty) ← open_pis ty,
(lhs, rhs) ← match ty with
| `(%%lhs = %%rhs) := pure (lhs, rhs)
| `(%%lhs ↔ %%rhs) := pure (lhs, rhs)
| _ := fail "norm_cast: lemma must be = or ↔"
end,
lhs_coes ← count_coes lhs,
when (lhs_coes = 0) $ fail "norm_cast: badly shaped lemma, lhs must contain at least one coe",
let lhs_he... | def | norm_cast.classify_type | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Classifies a declaration of type `ty` as a `norm_cast` rule. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_cast_cache | (up : simp_lemmas)
(down : simp_lemmas)
(squash : simp_lemmas) | structure | norm_cast.norm_cast_cache | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | The cache for `norm_cast` attribute stores three `simp_lemma` objects. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
empty_cache : norm_cast_cache | { up := simp_lemmas.mk,
down := simp_lemmas.mk,
squash := simp_lemmas.mk, } | def | norm_cast.empty_cache | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Empty `norm_cast_cache`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_elim (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache | do
new_up ← cache.up.add e,
return
{ up := new_up,
down := cache.down,
squash := cache.squash, } | def | norm_cast.add_elim | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | `add_elim cache e` adds `e` as an `elim` lemma to `cache`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_move (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache | do
new_up ← cache.up.add e tt,
new_down ← cache.down.add e,
return
{ up := new_up,
down := new_down,
squash := cache.squash, } | def | norm_cast.add_move | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | `add_move cache e` adds `e` as a `move` lemma to `cache`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_squash (cache : norm_cast_cache) (e : expr) : tactic norm_cast_cache | do
new_squash ← cache.squash.add e,
new_down ← cache.down.add e,
return
{ up := cache.up,
down := new_down,
squash := new_squash, } | def | norm_cast.add_squash | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | `add_squash cache e` adds `e` as an `squash` lemma to `cache`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_cast_attr_ty : Type | user_attribute norm_cast_cache (option label) | def | norm_cast.norm_cast_attr_ty | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | The type of the `norm_cast` attribute.
The optional label is used to overwrite the classifier. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_label_param (attr : norm_cast_attr_ty) (decl : name) : tactic (option label) | do
p ← attr.get_param_untyped decl,
match p with
| `(none) := pure none
| `(some label.elim) := pure label.elim
| `(some label.move) := pure label.move
| `(some label.squash) := pure label.squash
| _ := fail p
end | def | norm_cast.get_label_param | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Efficient getter for the `@[norm_cast]` attribute parameter that does not call `eval_expr`.
See Note [user attribute parameters]. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_lemma (attr : norm_cast_attr_ty) (cache : norm_cast_cache) (decl : name) :
tactic norm_cast_cache | do
e ← mk_const decl,
param ← get_label_param attr decl,
l ← param <|> (infer_type e >>= classify_type),
match l with
| elim := add_elim cache e
| move := add_move cache e
| squash := add_squash cache e
end | def | norm_cast.add_lemma | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | `add_lemma cache decl` infers the proper `norm_cast` attribute for `decl` and adds it to `cache`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ge_from_le {α} [has_le α] : ∀ (x y : α), x ≥ y ↔ y ≤ x | λ _ _, iff.rfl | lemma | norm_cast.ge_from_le | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
gt_from_lt {α} [has_lt α] : ∀ (x y : α), x > y ↔ y < x | λ _ _, iff.rfl | lemma | norm_cast.gt_from_lt | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
ne_from_not_eq {α} : ∀ (x y : α), x ≠ y ↔ ¬(x = y) | λ _ _, iff.rfl | lemma | norm_cast.ne_from_not_eq | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mk_cache (attr : thunk norm_cast_attr_ty) (names : list name) :
tactic norm_cast_cache | do
-- names has the declarations in reverse order
cache ← names.mfoldr (λ name cache, add_lemma (attr ()) cache name) empty_cache,
--some special lemmas to handle binary relations
let up := cache.up,
up ← up.add_simp ``ge_from_le,
up ← up.add_simp ``gt_from_lt,
up ← up.add_simp ``ne_from_not_eq,
let down := cache.dow... | def | norm_cast.mk_cache | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [
"coe_coe"
] | `mk_cache names` creates a `norm_cast_cache`. It infers the proper `norm_cast` attributes
for names in `names`, and collects the lemmas attributed with specific `norm_cast` attributes. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
norm_cast_attr : user_attribute norm_cast_cache (option label) | { name := `norm_cast,
descr := "attribute for norm_cast",
parser :=
(do some l ← (label.of_string ∘ to_string) <$> ident, return l)
<|> return none,
after_set := some (λ decl prio persistent, do
param ← get_label_param norm_cast_attr decl,
match param with
| some l :=
when ... | def | norm_cast.norm_cast_attr | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | The `norm_cast` attribute. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
make_guess (decl : name) : tactic label | do
e ← mk_const decl,
ty ← infer_type e,
classify_type ty | def | norm_cast.make_guess | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Classify a declaration as a `norm_cast` rule. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_label (decl : name) : tactic label | do
param ← get_label_param norm_cast_attr decl,
param <|> make_guess decl | def | norm_cast.get_label | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Gets the `norm_cast` classification label for a declaration. Applies the
override specified on the attribute, if necessary. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
push_cast (hs : parse tactic.simp_arg_list) (l : parse location) : tactic unit | tactic.interactive.simp none none tt hs [`push_cast] l {discharger := tactic.assumption} | def | tactic.interactive.push_cast | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | `push_cast` rewrites the expression to move casts toward the leaf nodes.
For example, `↑(a + b)` will be written to `↑a + ↑b`.
Equivalent to `simp only with push_cast`.
Can also be used at hypotheses.
`push_cast` can also be used at hypotheses and with extra simp rules.
```lean
example (a b : ℕ) (h1 : ((a + b : ℕ) : ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
prove_eq_using (s : simp_lemmas) (a b : expr) : tactic expr | do
(a', a_a', _) ← simplify s [] a {fail_if_unchanged := ff},
(b', b_b', _) ← simplify s [] b {fail_if_unchanged := ff},
on_exception (trace_norm_cast "failed: " (to_expr ``(%%a' = %%b') >>= pp)) $
is_def_eq a' b' reducible,
b'_b ← mk_eq_symm b_b',
mk_eq_trans a_a' b'_b | def | norm_cast.prove_eq_using | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Prove `a = b` using the given simp set. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
prove_eq_using_down (a b : expr) : tactic expr | do
cache ← norm_cast_attr.get_cache,
trace_norm_cast "proving: " (to_expr ``(%%a = %%b) >>= pp),
prove_eq_using cache.down a b | def | norm_cast.prove_eq_using_down | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | Prove `a = b` by simplifying using move and squash lemmas. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
splitting_procedure : expr → tactic (expr × expr) | | (app (app op x) y) :=
(do
`(@coe %%α %%δ %%coe1 %%xx) ← return x,
`(@coe %%β %%γ %%coe2 %%yy) ← return y,
success_if_fail $ is_def_eq α β,
is_def_eq δ γ,
(do
coe3 ← mk_app `has_lift_t [α, β] >>= mk_instance_fast,
new_x ← to_expr ``(@coe %%β %%δ %%coe2 (@coe %%α %%β %%coe3 %%xx)),
let new_e := a... | def | norm_cast.splitting_procedure | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | This is the main heuristic used alongside the elim and move lemmas.
The goal is to help casts move past operators by adding intermediate casts.
An expression of the shape: op (↑(x : α) : γ) (↑(y : β) : γ)
is rewritten to: op (↑(↑(x : α) : β) : γ) (↑(y : β) : γ)
when (↑(↑(x : α) : β) : γ) = (↑(x : α) : γ) can... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
prove : tactic unit | assumption | def | norm_cast.prove | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [
"prove"
] | Discharging function used during simplification in the "squash" step.
TODO: norm_cast takes a list of expressions to use as lemmas for the discharger
TODO: a tactic to print the results the discharger fails to proove | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
upward_and_elim (s : simp_lemmas) (e : expr) : tactic (expr × expr) | (do
r ← mcond (is_prop e) (return `iff) (return `eq),
(new_e, pr) ← s.rewrite e prove r,
pr ← match r with
| `iff := mk_app `propext [pr]
| _ := return pr
end,
return (new_e, pr)
) <|> splitting_procedure e | def | norm_cast.upward_and_elim | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [
"prove"
] | Core rewriting function used in the "squash" step, which moves casts upwards
and eliminates them.
It tries to rewrite an expression using the elim and move lemmas.
On failure, it calls the splitting procedure heuristic. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
numeral_to_coe (e : expr) : tactic (expr × expr) | do
α ← infer_type e,
success_if_fail $ is_def_eq α `(ℕ),
n ← e.to_nat,
h1 ← mk_app `has_lift_t [`(ℕ), α] >>= mk_instance_fast,
let new_e : expr := reflect n,
new_e ← to_expr ``(@coe ℕ %%α %%h1 %%new_e),
pr ← prove_eq_using_down e new_e,
return (new_e, pr) | def | norm_cast.numeral_to_coe | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [] | If possible, rewrite `(n : α)` to `((n : ℕ) : α)` where `n` is a numeral and `α ≠ ℕ`.
Returns a pair of the new expression and proof that they are equal. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
coe_to_numeral (e : expr) : tactic (expr × expr) | do
`(@coe ℕ %%α %%h1 %%e') ← return e,
n ← e'.to_nat,
-- replace e' by normalized numeral
is_def_eq (reflect n) e' reducible,
let e := e.app_fn (reflect n),
new_e ← expr.of_nat α n,
pr ← prove_eq_using_down e new_e,
return (new_e, pr) | def | norm_cast.coe_to_numeral | tactic | src/tactic/norm_cast.lean | [
"tactic.converter.interactive",
"tactic.hint"
] | [
"expr.of_nat"
] | If possible, rewrite `((n : ℕ) : α)` to `(n : α)` where `n` is a numeral.
Returns a pair of the new expression and proof that they are equal. | 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.