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 |
|---|---|---|---|---|---|---|---|---|---|---|
aux_attr : user_attribute (name_map name) name | { name := `to_additive_aux,
descr := "Auxiliary attribute for `to_additive`. DON'T USE IT",
parser := failed,
cache_cfg := ⟨λ ns,
ns.mfoldl
(λ dict n', do
let n := match n' with
| name.mk_string s pre := if s = "_to_addit... | def | to_additive.aux_attr | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | An auxiliary attribute used to store the names of the additive versions of declarations
that have been processed by `to_additive`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
ignore_args_attr : user_attribute (name_map $ list ℕ) (list ℕ) | { name := `to_additive_ignore_args,
descr :=
"Auxiliary attribute for `to_additive` stating that certain arguments are not additivized.",
cache_cfg :=
⟨λ ns, ns.mfoldl
(λ dict n, do
param ← ignore_args_attr.get_param_untyped n, -- see Note [user attribute parameters]
return $ ... | def | to_additive.ignore_args_attr | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [
"expr.to_nat"
] | An attribute that tells `@[to_additive]` that certain arguments of this definition are not
involved when using `@[to_additive]`.
This helps the heuristic of `@[to_additive]` by also transforming definitions if `ℕ` or another
fixed type occurs as one of these arguments. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
relevant_arg_attr : user_attribute (name_map ℕ) ℕ | { name := `to_additive_relevant_arg,
descr :=
"Auxiliary attribute for `to_additive` stating which arguments are the types with a " ++
"multiplicative structure.",
cache_cfg :=
⟨λ ns, ns.mfoldl
(λ dict n, do
param ← relevant_arg_attr.get_param_untyped n, -- see Note [user attribut... | def | to_additive.relevant_arg_attr | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | An attribute that is automatically added to declarations tagged with `@[to_additive]`, if needed.
This attribute tells which argument is the type where this declaration uses the multiplicative
structure. If there are multiple argument, we typically tag the first one.
If this argument contains a fixed type, this declar... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
reorder_attr : user_attribute (name_map $ list ℕ) (list ℕ) | { name := `to_additive_reorder,
descr :=
"Auxiliary attribute for `to_additive` that stores arguments that need to be reordered.",
cache_cfg :=
⟨λ ns, ns.mfoldl
(λ dict n, do
param ← reorder_attr.get_param_untyped n, -- see Note [user attribute parameters]
return $ dict.insert... | def | to_additive.reorder_attr | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [
"expr.to_nat"
] | An attribute that stores all the declarations that needs their arguments reordered when
applying `@[to_additive]`. Currently, we only support swapping consecutive arguments.
The list of the natural numbers contains the positions of the first of the two arguments
to be swapped.
If the first two arguments are swapped, th... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
first_multiplicative_arg (nm : name) : tactic ℕ | do
d ← get_decl nm,
let (es, _) := d.type.pi_binders,
l ← es.mmap_with_index $ λ n bi, do
{ let tgt := bi.type.pi_codomain,
let n_bi := bi.type.pi_binders.fst.length,
tt ← has_attribute' `to_additive tgt.get_app_fn.const_name | return none,
let n2 := tgt.get_app_args.head.get_app_fn.match_var.map $ ... | def | to_additive.first_multiplicative_arg | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | Find the first argument of `nm` that has a multiplicative type-class on it.
Returns 1 if there are no types with a multiplicative class as arguments.
E.g. `prod.group` returns 1, and `pi.has_one` returns 2. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
map_namespace (src tgt : name) : command | do let n := src.mk_string "_to_additive",
let decl := declaration.thm n [] `(unit) (pure (reflect ())),
add_decl decl,
aux_attr.set n tgt tt | def | to_additive.map_namespace | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | A command that can be used to have future uses of `to_additive` change the `src` namespace
to the `tgt` namespace.
For example:
```
run_cmd to_additive.map_namespace `quotient_group `quotient_add_group
```
Later uses of `to_additive` on declarations in the `quotient_group` namespace will be created
in the `quotient_a... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
value_type : Type | (replace_all : bool)
(trace : bool)
(tgt : name)
(doc : option string)
(allow_auto_name : bool) | structure | to_additive.value_type | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | `value_type` is the type of the arguments that can be provided to `to_additive`.
`to_additive.parser` parses the provided arguments:
* `replace_all`: replace all multiplicative declarations, do not use the heuristic.
* `trace`: output the generated additive declaration.
* `tgt : name`: the name of the target (the addit... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_comm_prefix : bool → string → string | | tt s := "comm_" ++ s
| ff s := s | def | to_additive.add_comm_prefix | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | `add_comm_prefix x s` returns `"comm_" ++ s` if `x = tt` and `s` otherwise. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
tr : bool → list string → list string | | is_comm ("one" :: "le" :: s) := add_comm_prefix is_comm "nonneg" :: tr ff s
| is_comm ("one" :: "lt" :: s) := add_comm_prefix is_comm "pos" :: tr ff s
| is_comm ("le" :: "one" :: s) := add_comm_prefix is_comm "nonpos" :: tr ff s
| is_comm ("lt" :: "one" :: s) := add_comm_prefix... | def | to_additive.tr | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | Dictionary used by `to_additive.guess_name` to autogenerate names. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
guess_name : string → string | string.map_tokens ''' $
λ s, string.intercalate (string.singleton '_') $
tr ff (s.split_on '_') | def | to_additive.guess_name | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [
"string.map_tokens"
] | Autogenerate target name for `to_additive`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
target_name (src tgt : name) (dict : name_map name) (allow_auto_name : bool) :
tactic name | (if tgt.get_prefix ≠ name.anonymous ∨ allow_auto_name -- `tgt` is a full name
then pure tgt
else match src with
| (name.mk_string s pre) :=
do let tgt_auto := guess_name s,
guard (tgt.to_string ≠ tgt_auto ∨ tgt = src)
<|> trace ("`to_additive " ++ src.to_string ++ "`: correctly a... | def | to_additive.target_name | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | Return the provided target name or autogenerate one if one was not provided. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
parser : lean.parser value_type | do
bang ← option.is_some <$> (tk "!")?,
ques ← option.is_some <$> (tk "?")?,
tgt ← ident?,
e ← texpr?,
doc ← match e with
| some pe := some <$> ((to_expr pe >>= eval_expr string) : tactic string)
| none := pure none
end,
return ⟨bang, ques, tgt.get_or_else name.anonymous, doc, ff⟩ | def | to_additive.parser | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | the parser for the arguments to `to_additive`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
proceed_fields_aux (src tgt : name) (prio : ℕ) (f : name → tactic (list string)) :
command | do
src_fields ← f src,
tgt_fields ← f tgt,
guard (src_fields.length = tgt_fields.length) <|>
fail ("Failed to map fields of " ++ src.to_string),
(src_fields.zip tgt_fields).mmap' $
λ names, guard (names.fst = names.snd) <|>
aux_attr.set (src.append names.fst) (tgt.append names.snd) tt prio | def | to_additive.proceed_fields_aux | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
proceed_fields (env : environment) (src tgt : name) (prio : ℕ) : command | let aux := proceed_fields_aux src tgt prio in
do
aux (λ n, pure $ list.map name.to_string $ (env.structure_fields n).get_or_else []) >>
aux (λ n, (list.map (λ (x : name), "to_" ++ x.to_string) <$> get_tagged_ancestors n)) >>
aux (λ n, (env.constructors_of n).mmap $
λ cs, match cs with
| (name.... | def | to_additive.proceed_fields | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [
"aux"
] | Add the `aux_attr` attribute to the structure fields of `src`
so that future uses of `to_additive` will map them to the corresponding `tgt` fields. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
attr : user_attribute unit value_type | { name := `to_additive,
descr := "Transport multiplicative to additive",
parser := parser,
after_set := some $ λ src prio persistent, do
guard persistent <|> fail "`to_additive` can't be used as a local attribute",
env ← get_env,
val ← attr.get_param src,
dict ← aux_attr.get_cache,
... | def | to_additive.attr | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [
"continuity",
"measurability",
"tactic.alias.get_alias_target"
] | The attribute `to_additive` can be used to automatically transport theorems
and definitions (but not inductive types and structures) from a multiplicative
theory to an additive theory.
To use this attribute, just write:
```
@[to_additive]
theorem mul_comm' {α} [comm_semigroup α] (x y : α) : x * y = y * x := comm_semi... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
linter.to_additive_doc : linter | { test := (λ d, do
let mul_name := d.to_name,
dict ← to_additive.aux_attr.get_cache,
match dict.find mul_name with
| some add_name := do
mul_doc ← try_core $ doc_string mul_name,
add_doc ← try_core $ doc_string add_name,
match mul_doc.is_some, add_doc.is_some with
| tt, ff := ret... | def | linter.to_additive_doc | tactic | src/tactic/to_additive.lean | [
"tactic.transform_decl",
"tactic.algebra",
"tactic.lint.basic",
"tactic.alias"
] | [
"linter"
] | A linter that checks that multiplicative and additive lemmas have both doc strings if one of
them has one | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
rel_data | (in_type : expr)
(out_type : expr)
(relation : expr) | structure | transfer.rel_data | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
has_to_tactic_format_rel_data : has_to_tactic_format rel_data | ⟨λr, do
R ← pp r.relation,
α ← pp r.in_type,
β ← pp r.out_type,
return format!"({R}: rel ({α}) ({β}))" ⟩ | instance | transfer.has_to_tactic_format_rel_data | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
rule_data | (pr : expr)
(uparams : list name) -- levels not in pat
(params : list (expr × bool)) -- fst : local constant, snd = tt → param appears in pattern
(uargs : list name) -- levels not in pat
(args : list (expr × rel_data)) -- fst : local constant
(pat : pattern) -... | structure | transfer.rule_data | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
has_to_tactic_format_rule_data : has_to_tactic_format rule_data | ⟨λr, do
pr ← pp r.pr,
up ← pp r.uparams,
mp ← pp r.params,
ua ← pp r.uargs,
ma ← pp r.args,
pat ← pp r.pat.target,
output ← pp r.output,
return format!"{{ ⟨{pat}⟩ pr: {pr} → {output}, {up} {mp} {ua} {ma} }}" ⟩ | instance | transfer.has_to_tactic_format_rule_data | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_lift_fun : expr → tactic (list rel_data × expr) | | e :=
do
{ guardb (is_constant_of (get_app_fn e) ``relator.lift_fun),
[α, β, γ, δ, R, S] ← return $ get_app_args e,
(ps, r) ← get_lift_fun S,
return (rel_data.mk α β R :: ps, r)} <|>
return ([], e) | def | transfer.get_lift_fun | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [
"relator.lift_fun"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
mark_occurences (e : expr) : list expr → list (expr × bool) | | [] := []
| (h :: t) := let xs := mark_occurences t in
(h, occurs h e || any xs (λ⟨e, oc⟩, oc && occurs h e)) :: xs | def | transfer.mark_occurences | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
analyse_rule (u' : list name) (pr : expr) : tactic rule_data | do
t ← infer_type pr,
(params, app (app r f) g) ← mk_local_pis t,
(arg_rels, R) ← get_lift_fun r,
args ← (enum arg_rels).mmap $ λ⟨n, a⟩,
prod.mk <$> mk_local_def (mk_simple_name ("a_" ++ repr n)) a.in_type <*> pure a,
a_vars ← return $ prod.fst <$> args,
p ← head_beta (app_of_list f a_vars),
... | def | transfer.analyse_rule | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
analyse_decls : list name → tactic (list rule_data) | mmap (λn, do
d ← get_decl n,
c ← return d.univ_params.length,
ls ← (repeat () c).mmap (λ_, mk_fresh_name),
analyse_rule ls (const n (ls.map level.param))) | def | transfer.analyse_decls | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
split_params_args :
list (expr × bool) → list expr → list (expr × option expr) × list expr | | ((lc, tt) :: ps) (e :: es) := let (ps', es') :=
split_params_args ps es in ((lc, some e) :: ps', es')
| ((lc, ff) :: ps) es := let (ps', es') :=
split_params_args ps es in ((lc, none) :: ps', es')
| _ es := ([], es) | def | transfer.split_params_args | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
param_substitutions (ctxt : list expr) :
list (expr × option expr) → tactic (list (name × expr) × list expr) | | (((local_const n _ bi t), s) :: ps) := do
(e, m) ← match s with
| (some e) := return (e, [])
| none :=
let ctxt' := list.filter (λv, occurs v t) ctxt in
let ty := pis ctxt' t in
if bi = binder_info.inst_implicit then do
guard (bi = binder_info.inst_implicit),
e ← instantiate_mvars t... | def | transfer.param_substitutions | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
compute_transfer : list rule_data → list expr → expr → tactic (expr × expr × list expr) | | rds ctxt e := do
-- Select matching rule
(i, ps, args, ms, rd) ← first (rds.map (λrd, do
(l, m) ← match_pattern rd.pat e semireducible,
level_map ← rd.uparams.mmap $ λl, prod.mk l <$> mk_meta_univ,
inst_univ ← return $ λe, instantiate_univ_params e (level_map ++ zip rd.uargs l),
(ps, args) ←... | def | transfer.compute_transfer | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
tactic.transfer (ds : list name) : tactic unit | do
rds ← analyse_decls ds,
tgt ← target,
(guard (¬ tgt.has_meta_var) <|>
fail "Target contains (universe) meta variables. This is not supported by transfer."),
(new_tgt, pr, ms) ← compute_transfer rds [] ((const `iff [] : expr) tgt),
new_pr ← mk_meta_var new_tgt,
/- Setup final tactic state -/
exac... | def | tactic.transfer | tactic | src/tactic/transfer.lean | [
"init.meta.tactic",
"init.meta.match_tactic",
"init.meta.mk_dec_eq_instance",
"init.data.list.instances",
"logic.relator"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
copy_attribute' (attr_name : name) (src : name) (tgt : name) (p : option bool := none) :
tactic unit | do
get_decl tgt <|> fail!"unknown declaration {tgt}",
-- if the source doesn't have the attribute we do not error and simply return
mwhen (succeeds (has_attribute attr_name src)) $
do (p', prio) ← has_attribute attr_name src,
let p := p.get_or_else p',
s ← try_or_report_error (set_basic_attribute ... | def | tactic.copy_attribute' | tactic | src/tactic/transform_decl.lean | [
"tactic.core"
] | [
"get_user_attribute_name",
"succeeds",
"try_or_report_error"
] | `copy_attribute' attr_name src tgt p d_name` copy (user) attribute `attr_name` from
`src` to `tgt` if it is defined for `src`; unlike `copy_attribute` the primed version also copies
the parameter of the user attribute, in the user attribute case. Make it persistent if `p` is
`tt`; if `p` is `none`, the copied ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
additive_test_aux (f : name → option name) (ignore : name_map $ list ℕ) :
bool → expr → bool | | b (var n) := tt
| b (sort l) := tt
| b (const n ls) := b || (f n).is_some
| b (mvar n m t) := tt
| b (local_const n m bi t) := tt
| b (app e f) := additive_test_aux tt e &&
-- this might be inefficient.
-- If it becomes a performance problem: we can gi... | def | tactic.additive_test_aux | tactic | src/tactic/transform_decl.lean | [
"tactic.core"
] | [] | Auxilliary function for `additive_test`. The bool argument *only* matters when applied
to exactly a constant. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
additive_test (f : name → option name) (replace_all : bool) (ignore : name_map $ list ℕ)
(e : expr) : bool | if replace_all then tt else additive_test_aux f ignore ff e | def | tactic.additive_test | tactic | src/tactic/transform_decl.lean | [
"tactic.core"
] | [] | `additive_test f replace_all ignore e` tests whether the expression `e` contains no constant
`nm` that is not applied to any arguments, and such that `f nm = none`.
This is used in `@[to_additive]` for deciding which subexpressions to transform: we only transform
constants if `additive_test` applied to their first argu... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
transform_decl_with_prefix_fun_aux (f : name → option name)
(replace_all trace : bool) (relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ)
(pre tgt_pre : name) : name → command | λ src,
do
-- if this declaration is not `pre` or an internal declaration, we do nothing.
tt ← return (src = pre ∨ src.is_internal : bool) |
if (f src).is_some then skip else fail!("@[to_additive] failed.
The declaration {pre} depends on the declaration {src} which is in the namespace {pre}, but " ++
"does not h... | def | tactic.transform_decl_with_prefix_fun_aux | tactic | src/tactic/transform_decl.lean | [
"tactic.core"
] | [
"name.map_prefix"
] | transform the declaration `src` and all declarations `pre._proof_i` occurring in `src`
using the dictionary `f`.
`replace_all`, `trace`, `ignore` and `reorder` are configuration options.
`pre` is the declaration that got the `@[to_additive]` attribute and `tgt_pre` is the target of this
declaration. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
transform_decl_with_prefix_fun (f : name → option name) (replace_all trace : bool)
(relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ) (src tgt : name) (attrs : list name)
: command | do -- In order to ensure that attributes are copied correctly we must transform declarations and
-- attributes in the right order:
-- first generate the transformed main declaration
transform_decl_with_prefix_fun_aux f replace_all trace relevant ignore reorder src tgt src,
ls ← get_eqn_lemmas_for tt src,
... | def | tactic.transform_decl_with_prefix_fun | tactic | src/tactic/transform_decl.lean | [
"tactic.core"
] | [] | Make a new copy of a declaration,
replacing fragments of the names of identifiers in the type and the body using the function `f`.
This is used to implement `@[to_additive]`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
transform_decl_with_prefix_dict (dict : name_map name) (replace_all trace : bool)
(relevant : name_map ℕ) (ignore reorder : name_map $ list ℕ) (src tgt : name) (attrs : list name)
: command | transform_decl_with_prefix_fun dict.find replace_all trace relevant ignore reorder src tgt attrs | def | tactic.transform_decl_with_prefix_dict | tactic | src/tactic/transform_decl.lean | [
"tactic.core"
] | [] | Make a new copy of a declaration, replacing fragments of the names of identifiers in the type and
the body using the dictionary `dict`.
This is used to implement `@[to_additive]`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
transport (s e : expr) : tactic unit | do
(_, α, β) ← infer_type e >>= relation_lhs_rhs <|>
fail format!"second argument to `transport` was not an equivalence-type relation",
-- We explode the goal into individual fields using `refine_struct`.
-- Later we'll want to also consider falling back to `fconstructor`,
-- but for now this suffices.
se... | def | tactic.transport | tactic | src/tactic/transport.lean | [
"tactic.equiv_rw"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
transport (s : parse texpr?) (e : parse $ (tk "using" *> texpr)) : itactic | do
s ← match s with
| some s := to_expr s
| none := (do
t ← target,
let n := t.get_app_fn.const_name,
ctx ← local_context,
ctx.any_of (λ e, (do t ← infer_type e, guard (t.get_app_fn.const_name = n), return e))) <|>
fail "`transport` could not find an appropriate source object. Try ... | def | tactic.interactive.transport | tactic | src/tactic/transport.lean | [
"tactic.equiv_rw"
] | [
"tactic.transport"
] | Given a goal `⊢ S β` for some type class `S`, and an equivalence `e : α ≃ β`.
`transport using e` will look for a hypothesis `s : S α`,
and attempt to close the goal by transporting `s` across the equivalence `e`.
```lean
example {α : Type} [ring α] {β : Type} (e : α ≃ β) : ring β :=
by transport using e.
```
You can... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
trunc_cases_subsingleton (e : expr) (ids : list name) : tactic expr | do
-- When the target is a subsingleton,
-- we can just use induction along `trunc.rec_on_subsingleton`,
-- generating just a single goal.
[(_, [e], _)] ← tactic.induction e ids `trunc.rec_on_subsingleton,
return e | def | tactic.trunc_cases_subsingleton | tactic | src/tactic/trunc_cases.lean | [
"tactic.chain",
"data.quot"
] | [
"trunc.rec_on_subsingleton"
] | Auxiliary tactic for `trunc_cases`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
trunc_cases_nondependent (e : expr) (ids : list name) : tactic expr | do
-- We may as well just use `trunc.lift_on`.
-- (It would be nice if we could use the `induction` tactic with non-dependent recursors, too?)
-- (In fact, the general strategy works just as well here,
-- except that it leaves a beta redex in the invariance goal.)
to_expr ``(trunc.lift_on %%e) >>= tactic.fapp... | def | tactic.trunc_cases_nondependent | tactic | src/tactic/trunc_cases.lean | [
"tactic.chain",
"data.quot"
] | [] | Auxiliary tactic for `trunc_cases`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
trunc_cases_dependent (e : expr) (ids : list name) : tactic expr | do
-- If all else fails, just use the general induction principle.
[(_, [e], _), (_, [e_a, e_b, e_p], _)] ← tactic.induction e ids,
-- However even now we can do something useful:
-- the invariance goal has a useless `e_p : true` hypothesis,
-- and after casing on that we may be able to simplify away
-- the... | def | tactic.trunc_cases_dependent | tactic | src/tactic/trunc_cases.lean | [
"tactic.chain",
"data.quot"
] | [
"eq_rec_constant"
] | Auxiliary tactic for `trunc_cases`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
trunc_cases (e : parse texpr) (ids : parse with_ident_list) : tactic unit | do
e ← to_expr e,
-- If `ids = []` and `e` is a local constant, we'll want to give
-- the new unboxed hypothesis the same name.
let ids := if ids = [] ∧ e.is_local_constant then [e.local_pp_name] else ids,
-- Make a note of the expr `e`, or reuse `e` if it is already a local constant.
e ← if e.is_local_cons... | def | tactic.interactive.trunc_cases | tactic | src/tactic/trunc_cases.lean | [
"tactic.chain",
"data.quot"
] | [
"succeeds"
] | `trunc_cases e` performs case analysis on a `trunc` expression `e`,
attempting the following strategies:
1. when the goal is a subsingleton, calling `induction e using trunc.rec_on_subsingleton`,
2. when the goal does not depend on `e`, calling `fapply trunc.lift_on e`,
and using `intro` and `clear` afterwards to ma... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_splitting_expr : expr → tactic expr | | `(@ite _ %%cond %%dec_inst _ _ = _) := pure `(@decidable.em %%cond %%dec_inst)
| `(%%(app x y) = _) := pure y
| e := fail!"expected an expression of the form: f x = y. Got:\n{e}" | def | tactic.unfold_cases.find_splitting_expr | tactic | src/tactic/unfold_cases.lean | [
"tactic.split_ifs"
] | [] | Given an equation `f x = y`, this tactic tries to infer an expression that can be
used to do distinction by cases on to make progress.
Pre-condition: assumes that the outer-most application cannot be beta-reduced
(e.g. `whnf` or `dsimp`). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unfold_cases_core (inner : interactive.itactic) : tactic unit | inner <|>
(do split_ifs [], all_goals unfold_cases_core, skip) <|>
do
tgt ← target,
e ← find_splitting_expr tgt,
focus1 $ do
cases e,
all_goals $ (dsimp_target >> unfold_cases_core) <|> skip,
skip | def | tactic.unfold_cases.unfold_cases_core | tactic | src/tactic/unfold_cases.lean | [
"tactic.split_ifs"
] | [] | Tries to finish the current goal using the `inner` tactic. If the tactic
fails, it tries to find an expression on which to do a distinction by
cases and calls itself recursively.
The order of operations is significant. Because the unfolding can potentially
be infinite, it is important to apply the `inner` tact... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unfold_tgt : expr → tactic unit | | `(%%l@(app _ _) = %%r) :=
match l.get_app_fn with
| const n ls := delta_target [n]
| e := fail!"couldn't unfold:\n{e}"
end
| e := fail!"expected an expression of the form: f x = y. Got:\n{e}" | def | tactic.unfold_cases.unfold_tgt | tactic | src/tactic/unfold_cases.lean | [
"tactic.split_ifs"
] | [] | Given a target of the form `⊢ f x₁ ... xₙ = y`, unfolds `f` using a delta reduction. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unfold_cases (inner : itactic) : tactic unit | focus1 $ do
tactic.intros,
tgt ← target,
unfold_tgt tgt,
try dsimp_target,
unfold_cases_core inner | def | tactic.interactive.unfold_cases | tactic | src/tactic/unfold_cases.lean | [
"tactic.split_ifs"
] | [] | This tactic unfolds the definition of a function or `match` expression.
Then it recursively introduces a distinction by cases. The decision what expression
to do the distinction on is driven by the pattern matching expression.
A typical use case is using `unfold_cases { refl }` to collapse cases that need to be
... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unification_step_result : Type
| simplified (next_equations : list name)
| not_simplified
| goal_solved | inductive | tactic.unify_equations.unification_step_result | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | The result of a unification step:
- `simplified hs` means that the step succeeded and produced some new (simpler)
equations `hs`. `hs` can be empty.
- `goal_solved` means that the step succeeded and solved the goal (by deriving a
contradiction from the given equation).
- `not_simplified` means that the step failed... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
unification_step : Type | ∀ (equ lhs_type rhs_type lhs rhs lhs_whnf rhs_whnf : expr) (u : level),
tactic unification_step_result | def | tactic.unify_equations.unification_step | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | A unification step is a tactic that attempts to simplify a given equation and
returns a `unification_step_result`. The inputs are:
- `equ`, the equation being processed. Must be a local constant.
- `lhs_type` and `rhs_type`, the types of equ's LHS and RHS. For homogeneous
equations, these are defeq.
- `lhs` and `rhs... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_heterogeneous : unification_step | λ equ lhs_type rhs_type lhs rhs _ _ _,
do
{ is_def_eq lhs_type rhs_type,
p ← to_expr ``(@eq_of_heq %%lhs_type %%lhs %%rhs %%equ),
t ← to_expr ``(@eq %%lhs_type %%lhs %%rhs),
equ' ← note equ.local_pp_name t p,
clear equ,
pure $ simplified [equ'.local_pp_name] } <|>
pure not_simplified | def | tactic.unify_equations.unify_heterogeneous | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | For `equ : t == u` with `t : T` and `u : U`, if `T` and `U` are defeq,
we replace `equ` with `equ : t = u`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_defeq : unification_step | λ equ lhs_type _ _ _ lhs_whnf rhs_whnf _,
do
{ is_def_eq lhs_whnf rhs_whnf,
clear equ,
pure $ simplified [] } <|>
pure not_simplified | def | tactic.unify_equations.unify_defeq | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | For `equ : t = u`, if `t` and `u` are defeq, we delete `equ`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_var : unification_step | λ equ type _ lhs rhs lhs_whnf rhs_whnf u,
do
{ let lhs_is_local := lhs_whnf.is_local_constant,
let rhs_is_local := rhs_whnf.is_local_constant,
guard $ lhs_is_local ∨ rhs_is_local,
let t :=
if lhs_is_local
then (const `eq [u]) type lhs_whnf rhs
else (const `eq [u]) type lhs rhs_whnf,
change_core ... | def | tactic.unify_equations.unify_var | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | For `equ : x = t` or `equ : t = x`, where `x` is a local constant, we
substitute `x` with `t` in the goal. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
injection_with' (h : expr) (ns : list name)
(base := `h) (offset := some 1) :
tactic (option (list expr) × list name) | do
H ← infer_type h,
(lhs, rhs, constructor_left, constructor_right, inj_name) ← do
{ (lhs, rhs) ← match_eq H,
constructor_left ← get_app_fn_const_whnf lhs semireducible ff,
constructor_right ← get_app_fn_const_whnf rhs semireducible ff,
inj_name ← resolve_constant $ constructor_left ++ "inj_arrow",
... | def | tactic.unify_equations.injection_with' | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [
"list.replicate"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
unify_constructor_headed : unification_step | λ equ _ _ _ _ _ _ _,
do
{ (next, _) ← injection_with' equ [] `_ none,
try $ clear equ,
pure $
match next with
| none := goal_solved
| some next := simplified $ next.map expr.local_pp_name
end } <|>
pure not_simplified | def | tactic.unify_equations.unify_constructor_headed | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | Given `equ : C x₁ ... xₙ = D y₁ ... yₘ` with `C` and `D` constructors of the
same datatype `I`:
- If `C ≠ D`, we solve the goal by contradiction using the no-confusion rule.
- If `C = D`, we clear `equ` and add equations `x₁ = y₁`, ..., `xₙ = yₙ`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_sizeof (type : expr) : tactic pexpr | do
n ← get_app_fn_const_whnf type semireducible ff,
resolve_name $ n ++ `sizeof | def | tactic.unify_equations.get_sizeof | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | For `type = I x₁ ... xₙ`, where `I` is an inductive type, `get_sizeof type`
returns the constant `I.sizeof`. Fails if `type` is not of this form or if no
such constant exists. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_add_one_ne (n m : ℕ) : n + (m + 1) ≠ n | begin
apply ne_of_gt,
apply nat.lt_add_of_pos_right,
apply nat.pos_of_ne_zero,
contradiction
end | lemma | tactic.unify_equations.add_add_one_ne | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
match_n_plus_m (md) : ℕ → expr → tactic (ℕ × expr) | λ n e, do
e ← whnf e md,
match e with
| `(nat.succ %%e) := match_n_plus_m (n + 1) e
| _ := pure (n, e)
end | def | tactic.unify_equations.match_n_plus_m | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | `match_n_plus_m n e` matches `e` of the form `nat.succ (... (nat.succ e')...)`.
It returns `n` plus the number of `succ` constructors and `e'`. The matching is
performed up to normalisation with transparency `md`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
contradict_n_eq_n_plus_m (md : transparency) (equ lhs rhs : expr) :
tactic expr | do
⟨lhs_n, lhs_e⟩ ← match_n_plus_m md 0 lhs,
⟨rhs_n, rhs_e⟩ ← match_n_plus_m md 0 rhs,
is_def_eq lhs_e rhs_e md <|> fail
("contradict_n_eq_n_plus_m:\nexpected {lhs_e} and {rhs_e} to be definitionally " ++
"equal at transparency {md}."),
let common := lhs_e,
guard (lhs_n ≠ rhs_n) <|> fail
"contradi... | def | tactic.unify_equations.contradict_n_eq_n_plus_m | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | Given `equ : n + m = n` or `equ : n = n + m` with `n` and `m` natural numbers
and `m` a nonzero literal, this tactic produces a proof of `false`. More
precisely, the two sides of the equation must be of the form
`nat.succ (... (nat.succ e)...)` with different numbers of `nat.succ`
constructors. Matching is performed wi... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_cyclic : unification_step | λ equ type _ _ _ lhs_whnf rhs_whnf _,
do
{ -- Establish `sizeof lhs = sizeof rhs`.
sizeof ← get_sizeof type,
hyp_lhs ← to_expr ``(%%sizeof %%lhs_whnf),
hyp_rhs ← to_expr ``(%%sizeof %%rhs_whnf),
hyp_type ← to_expr ``(@eq ℕ %%hyp_lhs %%hyp_rhs),
hyp_proof ← to_expr ``(@congr_arg %%type ℕ %%lhs_whnf %%rhs_whnf ... | def | tactic.unify_equations.unify_cyclic | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | Given `equ : t = u` with `t, u : I` and `I.sizeof t ≠ I.sizeof u`, we solve the
goal by contradiction. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
orelse_step (s t : unification_step) : unification_step | λ equ lhs_type rhs_type lhs rhs lhs_whnf rhs_whnf u,
do
r ← s equ lhs_type rhs_type lhs rhs lhs_whnf rhs_whnf u,
match r with
| simplified _ := pure r
| goal_solved := pure r
| not_simplified := t equ lhs_type rhs_type lhs rhs lhs_whnf rhs_whnf u
end | def | tactic.unify_equations.orelse_step | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | `orelse_step s t` first runs the unification step `s`. If this was successful
(i.e. `s` simplified or solved the goal), it returns the result of `s`.
Otherwise, it runs `t` and returns its result. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_homogeneous : unification_step | list.foldl orelse_step (λ _ _ _ _ _ _ _ _, pure not_simplified)
[unify_defeq, unify_var, unify_constructor_headed, unify_cyclic] | def | tactic.unify_equations.unify_homogeneous | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | For `equ : t = u`, try the following methods in order: `unify_defeq`,
`unify_var`, `unify_constructor_headed`, `unify_cyclic`. If any of them is
successful, stop and return its result. If none is successful, fail. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_equation_once (equ : name) : tactic unification_step_result | do
eque ← get_local equ,
t ← infer_type eque,
match t with
| (app (app (app (const `eq [u]) type) lhs) rhs) := do
lhs_whnf ← whnf_ginductive lhs,
rhs_whnf ← whnf_ginductive rhs,
unify_homogeneous eque type type lhs rhs lhs_whnf rhs_whnf u
| (app (app (app (app (const `heq [u]) lhs_type) lhs) rhs_t... | def | tactic.unify_equation_once | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | If `equ` is the display name of a local constant with type `t = u` or `t == u`,
then `unify_equation_once equ` simplifies it once using
`unify_equations.unify_homogeneous` or `unify_equations.unify_heterogeneous`.
Otherwise it fails. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_equations : list name → tactic bool | | [] := pure ff
| (h :: hs) := do
res ← unify_equation_once h,
match res with
| simplified hs' := unify_equations $ hs' ++ hs
| not_simplified := unify_equations hs
| goal_solved := pure tt
end | def | tactic.unify_equations | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [] | Given a list of display names of local hypotheses that are (homogeneous or
heterogeneous) equations, `unify_equations` performs first-order unification on
each hypothesis in order. See `tactic.interactive.unify_equations` for an
example and an explanation of what unification does.
Returns true iff the goal has been so... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
unify_equations (eqs : interactive.parse (many ident)) :
tactic unit | tactic.unify_equations eqs *> skip | def | tactic.interactive.unify_equations | tactic | src/tactic/unify_equations.lean | [
"tactic.core"
] | [
"tactic.unify_equations"
] | `unify_equations eq₁ ... eqₙ` performs a form of first-order unification on the
hypotheses `eqᵢ`. The `eqᵢ` must be homogeneous or heterogeneous equations.
Unification means that the equations are simplified using various facts about
constructors. For instance, consider this goal:
```
P : ∀ n, fin n → Prop
n m : ℕ
f :... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
binder_priority : binder_info → ℕ | | binder_info.implicit := 1
| binder_info.strict_implicit := 2
| binder_info.default := 3
| binder_info.inst_implicit := 4
| binder_info.aux_decl := 5 | def | where.binder_priority | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Assigns a priority to each binder for determining the order in which variables are traced. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
binder_less_important (u v : binder_info) : bool | (binder_priority u) < (binder_priority v) | def | where.binder_less_important | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | The relation on binder priorities. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
select_for_which {α β γ : Type} (p : α → β × γ) [decidable_eq β] (b' : β) :
list α → list γ × list α | | [] := ([], [])
| (a :: rest) :=
let (cs, others) := select_for_which rest, (b, c) := p a in
if b = b' then (c :: cs, others) else (cs, a :: others) | def | where.select_for_which | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Selects the elements of the given `list α` which under the image of `p : α → β × γ` have `β`
component equal to `b'`. Returns the `γ` components of the selected elements under the image of `p`,
and the elements of the original `list α` which were not selected. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
collect_by_aux {α β γ : Type} (p : α → β × γ) [decidable_eq β] :
list β → list α → list (β × list γ) | | [] [] := []
| [] _ := undefined_core "didn't find every key entry!"
| (b :: rest) as := let (cs, as) := select_for_which p b as in (b, cs) :: collect_by_aux rest as | def | where.collect_by_aux | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Helper function for `collect_by`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
collect_by {α β γ : Type} (l : list α) (p : α → β × γ) [decidable_eq β] :
list (β × list γ) | collect_by_aux p (l.map $ prod.fst ∘ p).dedup l | def | where.collect_by | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Returns the elements of `l` under the image of `p`, collecting together elements with the same
`β` component, deleting duplicates. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
sort_variable_list (l : list (name × binder_info × expr)) :
list (expr × binder_info × list name) | let l := collect_by l $ λ v, (v.2.2, (v.1, v.2.1)) in
let l := l.map $ λ el, (el.1, collect_by el.2 $ λ v, (v.2, v.1)) in
(list.join $ l.map $ λ e, prod.mk e.1 <$> e.2).qsort (λ v u, binder_less_important v.2.1 u.2.1) | def | where.sort_variable_list | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Sort the variables by their priority as defined by `where.binder_priority`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
collect_implicit_names : list name → list string × list string | | [] := ([], [])
| (n :: ns) :=
let n := to_string n, (ns, ins) := collect_implicit_names ns in
if n.front = '_' then (ns, n :: ins) else (n :: ns, ins) | def | where.collect_implicit_names | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Separate out the names of implicit variables (commonly instances with no name). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
format_variable : expr × binder_info × list name → tactic string | | (e, bi, ns) := do
let (l, r) := bi.brackets,
e ← pp e,
let (ns, ins) := collect_implicit_names ns,
let ns := " ".intercalate $ ns.map to_string,
let ns := if ns.length = 0 then [] else [sformat!"{l}{ns} : {e}{r}"],
let ins := ins.map $ λ _, sformat!"{l}{e}{r}",
return $ " ".intercalate $ ns ++ ins | def | where.format_variable | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Format an individual variable definition for printing. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
compile_variable_list (l : list (name × binder_info × expr)) : tactic string | " ".intercalate <$> (sort_variable_list l).mmap format_variable | def | where.compile_variable_list | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Turn a list of triples of variable names, binder info, and types, into a pretty list. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
strip_namespace (ns n : name) : name | n.replace_prefix ns name.anonymous | def | where.strip_namespace | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Strips the namespace prefix `ns` from `n`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_open_namespaces (ns : name) : tactic (list name) | do opens ← list.dedup <$> tactic.open_namespaces,
return $ (opens.erase ns).map $ strip_namespace ns | def | where.get_open_namespaces | tactic | src/tactic/where.lean | [
"tactic.core"
] | [
"list.dedup"
] | `get_open_namespaces ns` returns a list of the open namespaces, given that we are currently in
the namespace `ns` (which we do not include). | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explain_anonymous_name : name → string | | name.anonymous := "[root namespace]"
| ns := to_string ns | def | where.explain_anonymous_name | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | Give a slightly friendlier name for `name.anonymous` in the context of your current namespace. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_str_namespace (ns : name) : lean.parser string | return sformat!"namespace {explain_anonymous_name ns}" | def | where.build_str_namespace | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces the current namespace. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_str_open_namespaces (ns : name) : tactic string | do l ← get_open_namespaces ns,
let str := " ".intercalate $ l.map to_string,
if l.empty then return ""
else return sformat!"open {str}" | def | where.build_str_open_namespaces | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces the open namespaces. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_str_variables : lean.parser string | do l ← get_variables,
str ← compile_variable_list l,
if l.empty then return ""
else return sformat!"variables {str}" | def | where.build_str_variables | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces the variables. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_str_includes : lean.parser string | do l ← get_included_variables,
let str := " ".intercalate $ l.map $ λ n, to_string n.1,
if l.empty then return ""
else return sformat!"include {str}" | def | where.build_str_includes | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces the includes. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_str_end (ns : name) : tactic string | return sformat!"end {explain_anonymous_name ns}" | def | where.build_str_end | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces the namespace end. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
append_nl (s : string) (n : ℕ) : tactic string | return $ s ++ (list.as_string $ (list.range n).map $ λ _, '\n') | def | where.append_nl | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces newlines. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
append_line (s : string) (t : lean.parser string) : lean.parser string | do v ← t,
return $ s ++ v ++ (if v.length = 0 then "" else "\n") | def | where.append_line | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output helper which traces lines, adding a newline if nonempty. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_msg : lean.parser string | do let msg := "",
ns ← get_current_namespace,
msg ← append_line msg $ build_str_namespace ns,
msg ← append_nl msg 1,
msg ← append_line msg $ build_str_open_namespaces ns,
msg ← append_line msg $ build_str_variables,
msg ← append_line msg $ build_str_includes,
msg ← append_nl msg 3,
msg ← app... | def | where.build_msg | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | `#where` output main function. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
where_cmd (_ : parse $ tk "#where") : lean.parser unit | do msg ← build_msg,
trace msg | def | where.where_cmd | tactic | src/tactic/where.lean | [
"tactic.core"
] | [] | When working in a Lean file with namespaces, parameters, and variables, it can be confusing to
identify what the current "parser context" is. The command `#where` identifies and prints
information about the current location, including the active namespace, open namespaces, and
declared variables.
It is a bug for `#whe... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
decl_reducibility
| reducible
| semireducible
| irreducible | inductive | tactic.decl_reducibility | tactic | src/tactic/with_local_reducibility.lean | [
"tactic.core"
] | [
"irreducible"
] | Possible reducibility attributes for a declaration:
reducible, semireducible (the default), irreducible. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
get_decl_reducibility (n : name) : tactic decl_reducibility | do is_irred ← has_attribute' `irreducible n,
if is_irred then pure decl_reducibility.irreducible else
do is_red ← has_attribute' `reducible n,
if is_red then pure decl_reducibility.reducible else
do e ← get_env,
if e.contains n then pure decl_reducibility.semireducible else
fail format!"get_decl_reducibilit... | def | tactic.get_decl_reducibility | tactic | src/tactic/with_local_reducibility.lean | [
"tactic.core"
] | [
"irreducible"
] | Get the reducibility attribute of a declaration.
Fails if the name does not refer to an existing declaration. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
decl_reducibility.to_attribute : decl_reducibility → name | | decl_reducibility.reducible := `reducible
| decl_reducibility.semireducible := `semireducible
| decl_reducibility.irreducible := `irreducible | def | tactic.decl_reducibility.to_attribute | tactic | src/tactic/with_local_reducibility.lean | [
"tactic.core"
] | [
"irreducible"
] | Return the attribute (as a `name`) corresponding to a reducibility level. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
set_decl_reducibility (n : name) (r : decl_reducibility) (persistent := ff)
: tactic unit | set_basic_attribute r.to_attribute n persistent | def | tactic.set_decl_reducibility | tactic | src/tactic/with_local_reducibility.lean | [
"tactic.core"
] | [] | Set the reducibility attribute of a declaration.
If `persistent := ff`, this is scoped to the enclosing `section`, like `local attribute`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
with_local_reducibility {α : Type*} (n : name) (r : decl_reducibility)
(body : tactic α) : tactic α | do r' ← get_decl_reducibility n,
bracket (set_decl_reducibility n r) body (set_decl_reducibility n r') | def | tactic.with_local_reducibility | tactic | src/tactic/with_local_reducibility.lean | [
"tactic.core"
] | [] | Execute a tactic with a temporarily modified reducibility attribute for a declaration. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
take_pi_args : nat → expr → list name | | (n+1) (expr.pi h _ _ e) := h :: take_pi_args n e
| _ _ := [] | def | tactic.take_pi_args | tactic | src/tactic/wlog.lean | [
"tactic.core",
"tactic.dependencies"
] | [] | A helper function to retrieve the names of the first `n` arguments to a Pi-expression. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
wlog (H : parse ident) (t : parse (tk ":" *> texpr))
(revert : parse ((tk "generalizing" *> ((none <$ tk "*") <|> some <$> ident*)) <|> pure none))
(h : parse (tk "with" *> ident)?) :
tactic unit | do
-- if there is no `with` clause, use `this` as default name
let h := h.get_or_else `this,
t ← i_to_expr ``(%%t : Sort*),
-- compute which constants must be reverted (by default: everything)
(num_generalized, goal, rctx) ← retrieve (do
assert_core H t, swap,
-- use `revert_lst'` to ensure that the o... | def | tactic.interactive.wlog | tactic | src/tactic/wlog.lean | [
"tactic.core",
"tactic.dependencies"
] | [] | `wlog h : P` will add an assumption `h : P` to the main goal,
and add a side goal that requires showing that the case `h : ¬ P` can be reduced to the case
where `P` holds (typically by symmetry).
The side goal will be at the top of the stack. In this side goal, there will be two assumptions:
- `h : ¬ P`: the assumptio... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
zify_attr : user_attribute simp_lemmas unit | { name := `zify,
descr := "Used to tag lemmas for use in the `zify` tactic",
cache_cfg :=
{ mk_cache :=
λ ns, mmap (λ n, do c ← mk_const n, return (c, tt)) ns >>= simp_lemmas.mk.append_with_symm,
dependencies := [] } } | def | zify.zify_attr | tactic | src/tactic/zify.lean | [
"data.int.cast.lemmas",
"data.int.char_zero",
"tactic.norm_cast"
] | [] | The `zify` attribute is used by the `zify` tactic. It applies to lemmas that shift propositions
between `nat` and `int`.
`zify` lemmas should have the form `∀ a₁ ... aₙ : ℕ, Pz (a₁ : ℤ) ... (aₙ : ℤ) ↔ Pn a₁ ... aₙ`.
For example, `int.coe_nat_le_coe_nat_iff : ∀ (m n : ℕ), ↑m ≤ ↑n ↔ m ≤ n` is a `zify` lemma. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
lift_to_z (e : expr) : tactic (expr × expr) | do sl ← zify_attr.get_cache,
sl ← sl.add_simp `ge_iff_le, sl ← sl.add_simp `gt_iff_lt,
(e', prf, _) ← simplify sl [] e,
return (e', prf) | def | zify.lift_to_z | tactic | src/tactic/zify.lean | [
"data.int.cast.lemmas",
"data.int.char_zero",
"tactic.norm_cast"
] | [
"ge_iff_le",
"gt_iff_lt"
] | Given an expression `e`, `lift_to_z e` looks for subterms of `e` that are propositions "about"
natural numbers and change them to propositions about integers.
Returns an expression `e'` and a proof that `e = e'`.
Includes `ge_iff_le` and `gt_iff_lt` in the simp set. These can't be tagged with `zify` as we
want to use... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
int.coe_nat_ne_coe_nat_iff (a b : ℕ) : (a : ℤ) ≠ b ↔ a ≠ b | by simp | lemma | int.coe_nat_ne_coe_nat_iff | tactic | src/tactic/zify.lean | [
"data.int.cast.lemmas",
"data.int.char_zero",
"tactic.norm_cast"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
tactic.zify (extra_lems : list simp_arg_type) : expr → tactic (expr × expr) | λ z,
do (z1, p1) ← zify.lift_to_z z <|> fail "failed to find an applicable zify lemma",
(z2, p2) ← norm_cast.derive_push_cast extra_lems z1,
prod.mk z2 <$> mk_eq_trans p1 p2 | def | tactic.zify | tactic | src/tactic/zify.lean | [
"data.int.cast.lemmas",
"data.int.char_zero",
"tactic.norm_cast"
] | [
"norm_cast.derive_push_cast",
"zify.lift_to_z"
] | `zify extra_lems e` is used to shift propositions in `e` from `ℕ` to `ℤ`.
This is often useful since `ℤ` has well-behaved subtraction.
The list of extra lemmas is used in the `push_cast` step.
Returns an expression `e'` and a proof that `e = e'`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
tactic.zify_proof (extra_lems : list simp_arg_type) (h : expr) : tactic expr | do (_, pf) ← infer_type h >>= tactic.zify extra_lems,
mk_eq_mp pf h | def | tactic.zify_proof | tactic | src/tactic/zify.lean | [
"data.int.cast.lemmas",
"data.int.char_zero",
"tactic.norm_cast"
] | [
"tactic.zify"
] | A variant of `tactic.zify` that takes `h`, a proof of a proposition about natural numbers,
and returns a proof of the zified version of that propositon. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
tactic.interactive.zify (sl : parse simp_arg_list) (l : parse location) : tactic unit | do locs ← l.get_locals,
replace_at (tactic.zify sl) locs l.include_goal >>= guardb | def | tactic.interactive.zify | tactic | src/tactic/zify.lean | [
"data.int.cast.lemmas",
"data.int.char_zero",
"tactic.norm_cast"
] | [
"tactic.zify"
] | The `zify` tactic is used to shift propositions from `ℕ` to `ℤ`.
This is often useful since `ℤ` has well-behaved subtraction.
```lean
example (a b c x y z : ℕ) (h : ¬ x*y*z < 0) : c < a + 3*b :=
begin
zify,
zify at h,
/-
h : ¬↑x * ↑y * ↑z < 0
⊢ ↑c < ↑a + 3 * ↑b
-/
end
```
`zify` can be given extra lemmas ... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
apply_congr (q : parse texpr?) : conv unit | do
congr_lemmas ← match q with
-- If the user specified a lemma, use that one,
| some e := do
gs ← get_goals,
e ← to_expr e, -- to_expr messes with the goals? (see tests)
set_goals gs,
return [e]
-- otherwise, look up everything tagged `@[congr]`
| none := do
congr_lemma_names ← attribute.... | def | conv.interactive.apply_congr | tactic.converter | src/tactic/converter/apply_congr.lean | [
"tactic.interactive",
"tactic.converter.interactive"
] | [] | Apply a congruence lemma inside `conv` mode.
When called without an argument `apply_congr` will try applying all lemmas marked with `@[congr]`.
Otherwise `apply_congr e` will apply the lemma `e`.
Recall that a goal that appears as `∣ X` in `conv` mode
represents a goal of `⊢ X = ?m`,
i.e. an equation with a metavaria... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
current_relation : old_conv name | λr lhs, return ⟨r, lhs, none⟩ | def | old_conv.current_relation | tactic.converter | src/tactic/converter/binders.lean | [
"order.complete_lattice"
] | [
"old_conv"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
head_beta : old_conv unit | λ r e, do n ← tactic.head_beta e, return ⟨(), n, none⟩ | def | old_conv.head_beta | tactic.converter | src/tactic/converter/binders.lean | [
"order.complete_lattice"
] | [
"old_conv"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
congr_arg : old_conv unit → old_conv unit | congr_core (return ()) | def | old_conv.congr_arg | tactic.converter | src/tactic/converter/binders.lean | [
"order.complete_lattice"
] | [
"old_conv"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
congr_fun : old_conv unit → old_conv unit | λc, congr_core c (return ()) | def | old_conv.congr_fun | tactic.converter | src/tactic/converter/binders.lean | [
"order.complete_lattice"
] | [
"old_conv"
] | 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.