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 |
|---|---|---|---|---|---|---|---|---|---|---|
is_acceptable_rewrite : expr → bool | | (expr.pi n bi d b) := is_acceptable_rewrite b
| `(%%a = %%b) := tt
| `(%%a ↔ %%b) := tt
| _ := ff | def | tactic.rewrite_search.is_acceptable_rewrite | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Returns true if expression is an equation or iff. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
is_acceptable_hyp (r : expr) : tactic bool | do t ← infer_type r >>= whnf, return $ is_acceptable_rewrite t ∧ ¬t.has_meta_var | def | tactic.rewrite_search.is_acceptable_hyp | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Returns true if the expression is an equation or iff and has no metavariables. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
rules_from_hyps : tactic (list (expr × bool)) | do hyps ← local_context,
rules_from_exprs <$> hyps.mfilter is_acceptable_hyp | def | tactic.rewrite_search.rules_from_hyps | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Collect all hypotheses in the local context that are usable as rewrite rules. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
rewrite_search_attr : user_attribute | { name := `rewrite,
descr := "declare that this definition should be considered by `rewrite_search`" } | def | tactic.rewrite_search.rewrite_search_attr | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Use this attribute to make `rewrite_search` use this definition during search. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
rules_from_rewrite_attr : tactic (list (expr × bool)) | do names ← attribute.get_instances `rewrite,
rules_from_exprs <$> names.mmap mk_const | def | tactic.rewrite_search.rules_from_rewrite_attr | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Gather rewrite rules from lemmas explicitly tagged with `rewrite. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
collect_rules : tactic (list (expr × bool)) | do from_attr ← rules_from_rewrite_attr,
from_hyps ← rules_from_hyps,
return $ from_attr ++ from_hyps | def | tactic.rewrite_search.collect_rules | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Collect rewrite rules to use from the environment. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
from_tracked (rule_index : ℕ) (tracked : ℕ × tracked_rewrite) : rewrite | do let (rw_index, rw) := tracked,
let h : how := ⟨rule_index, rw_index, rw.addr⟩,
⟨rw.exp, rw.proof, h⟩ | def | tactic.rewrite_search.from_tracked | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [] | Constructing our rewrite structure from the `tracked_rewrite` provided by `nth_rewrite`.
rule_index is the index of the rule used from the rules provided.
tracked is an (index, tracked_rewrite) pair for the element of `all_rewrites exp rule` we used. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
rewrites_for_rule (exp : expr) (cfg : config) (numbered_rule: ℕ × expr × bool) :
tactic (list rewrite) | do let (rule_index, rule) := numbered_rule,
tracked ← all_rewrites exp rule cfg.to_cfg,
return (list.map (from_tracked rule_index) tracked.enum) | def | tactic.rewrite_search.rewrites_for_rule | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [
"exp"
] | Get all rewrites that start at the given expression and use the given rewrite rule. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get_rewrites (rules : list (expr × bool)) (exp : expr) (cfg : config) :
tactic (buffer rewrite) | do lists ← list.mmap (rewrites_for_rule exp cfg) rules.enum,
return (list.foldl buffer.append_list buffer.nil lists) | def | tactic.rewrite_search.get_rewrites | tactic.rewrite_search | src/tactic/rewrite_search/discovery.lean | [
"tactic.nth_rewrite",
"tactic.rewrite_search.types"
] | [
"exp",
"lists"
] | Get all rewrites that start at the given expression and use one of the given rewrite rules. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
dir_pair (α : Type u) | (l r : α) | structure | tactic.rewrite_search.dir_pair | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | A `dir_pair` is a pair of items designed to be accessed according to
`dir`, a "direction" defined in the `expr_lens` library. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
get : dir → α | | dir.F := p.l
| dir.A := p.r | def | tactic.rewrite_search.dir_pair.get | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Get one side of the pair, picking the side according to the direction. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
set : dir → α → dir_pair α | | dir.F v := ⟨v, p.r⟩
| dir.A v := ⟨p.l, v⟩ | def | tactic.rewrite_search.dir_pair.set | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Set one side of the pair, picking the side according to the direction. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
to_list : list α | [p.l, p.r] | def | tactic.rewrite_search.dir_pair.to_list | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Convert the pair to a list of its elements. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
to_string [has_to_string α] (p : dir_pair α) : string | to_string p.l ++ "-" ++ to_string p.r | def | tactic.rewrite_search.dir_pair.to_string | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Convert the pair to a readable string format. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
has_to_string [has_to_string α] : has_to_string (dir_pair α) | ⟨to_string⟩ | instance | tactic.rewrite_search.dir_pair.has_to_string | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
nth_rule (rs : list (expr × bool)) (i : ℕ) : expr × bool | (rs.nth i).iget | def | tactic.rewrite_search.nth_rule | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Helper for getting the nth item in a list of rules | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
pp_rule (r : expr × bool) : tactic string | do pp ← pp r.1, return $ (if r.2 then "←" else "") ++ to_string pp | def | tactic.rewrite_search.pp_rule | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Convert a rule into the string of Lean code used to refer to this rule. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
how.to_rewrite (rs : list (expr × bool)) : how → option (expr × bool) | | h := nth_rule rs h.rule_index | def | tactic.rewrite_search.how.to_rewrite | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
explain_using_location (rs : list (expr × bool)) (s : side) :
how → tactic (option string) | | h := do
rule ← pp_rule $ nth_rule rs h.rule_index,
return $ some ("nth_rewrite_" ++ s.to_xhs ++ " " ++ to_string h.location ++ " " ++ rule) | def | tactic.rewrite_search.explain_using_location | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"side"
] | Explain a single rewrite using `nth_rewrite`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
using_location.explain_rewrites (rs : list (expr × bool)) (s : side)
(steps : list how) : tactic string | do rules ← steps.mmap $ λ h : how, option.to_list <$> explain_using_location rs s h,
return $ string.intercalate ",\n " rules.join | def | tactic.rewrite_search.using_location.explain_rewrites | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"option.to_list",
"side"
] | Explain a list of rewrites using `nth_rewrite`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
app_addr
| node (children : dir_pair (option app_addr)) : app_addr
| rw : list ℕ → app_addr | inductive | tactic.rewrite_search.using_conv.app_addr | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | `app_addr` represents a tree structure that `conv` tactics use for a rewrite. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
app_addr.to_string : app_addr → string | | (node c) := "(node " ++ ((c.to_list.filter_map id).map app_addr.to_string).to_string ++ ")"
| (rw rws) := "(rw " ++ rws.to_string ++ ")" | def | tactic.rewrite_search.using_conv.app_addr.to_string | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
splice_result
| obstructed
| contained
| new (addr : app_addr) | inductive | tactic.rewrite_search.using_conv.splice_result | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | A data structure for the result of a splice operation.
obstructed: There was more of the addr to be added left, but we hit a rw
contained: The added addr was already contained, and did not terminate at an existing rw
new: The added addr terminated at an existing rw or we could create a new one for it | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pack_splice_result (s : expr_lens.dir) :
splice_result → dir_pair (option app_addr) → splice_result | | (new addr) c := new $ app_addr.node $ c.set s (some addr)
| sr _ := sr | def | tactic.rewrite_search.using_conv.pack_splice_result | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"expr_lens.dir"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
splice_in_aux (new_rws : list ℕ) :
option app_addr → list expr_lens.dir → splice_result | | (some $ node _) [] := contained
| (some $ node c) (s :: rest) := pack_splice_result s (splice_in_aux (c.get s) rest) c
| (some $ rw _) (_ :: _) := obstructed
| (some $ rw rws) [] := new $ rw (rws ++ new_rws)
| none [] := new $ rw new_rws
| none l := splice_in_aux (some $ node ⟨none, none⟩) l | def | tactic.rewrite_search.using_conv.splice_in_aux | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"expr_lens.dir"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
to_congr_form : list expr_lens.dir → tactic (list expr_lens.dir) | | [] := return []
| (dir.F :: (dir.A :: rest)) := do
r ← to_congr_form rest,
return (dir.F :: r)
| (dir.A :: rest) := do
r ← to_congr_form rest,
return (dir.A :: r)
| [dir.F] := fail "app list ends in side.L!"
| (dir.F :: (dir.F :: _)) := fail "app list has repeated side.L!" | def | tactic.rewrite_search.using_conv.to_congr_form | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"expr_lens.dir"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
splice_in (a : option app_addr) (rws : list ℕ) (s : list expr_lens.dir) :
tactic splice_result | splice_in_aux rws a <$> to_congr_form s | def | tactic.rewrite_search.using_conv.splice_in | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"expr_lens.dir"
] | Attempt to add new rewrites into the `app_addr` tree. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
build_rw_tactic (rs : list (expr × bool)) (hs : list ℕ) : tactic string | do rws ← (hs.map $ nth_rule rs).mmap pp_rule,
return $ "erw [" ++ (string.intercalate ", " rws) ++ "]" | def | tactic.rewrite_search.using_conv.build_rw_tactic | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Construct a single `erw` tactic for the given rules. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explain_tree_aux (rs : list (expr × bool)) :
app_addr → tactic (option (list string)) | | (app_addr.rw rws) := (λ a, some [a]) <$> build_rw_tactic rs rws
| (app_addr.node ⟨func, arg⟩) := do
sf ← match func with | none := pure none | some func := explain_tree_aux func end,
sa ← match arg with | none := pure none | some arg := explain_tree_aux arg end,
return $ match (sf, sa) with
| (none, none) ... | def | tactic.rewrite_search.using_conv.explain_tree_aux | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
explain_tree (rs : list (expr × bool)) (tree : app_addr) :
tactic (list string) | list.join <$> option.to_list <$> explain_tree_aux rs tree | def | tactic.rewrite_search.using_conv.explain_tree | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"option.to_list",
"tree"
] | Construct a string of Lean code that does a rewrite for the provided tree. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explanation_lines (rs : list (expr × bool)) (s : side) :
option app_addr → list how → tactic (list string) | | none [] := return []
| (some tree) [] := do
tacs ← explain_tree rs tree,
return $ if tacs.length = 0 then []
else ["conv_" ++ s.to_xhs ++ " { " ++ string.intercalate ", " tacs ++ " }"]
| tree (h :: rest) := do
(new_tree, rest_if_fail) ← match h.addr with
| (some addr) := do
new_tree ← splice_in tree [h.... | def | tactic.rewrite_search.using_conv.explanation_lines | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"side",
"tree"
] | Gather all rewrites into trees, then generate a line of code for each tree.
The return value has one `conv_x` tactic on each line. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explain_rewrites (rs : list (expr × bool)) (s : side) (hows : list how) :
tactic string | string.intercalate ",\n " <$> explanation_lines rs s none hows | def | tactic.rewrite_search.using_conv.explain_rewrites | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"side"
] | Explain a list of rewrites using `conv_x` tactics. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explain_rewrites_concisely (steps : list (expr × bool)) (needs_refl : bool) :
tactic string | do rules ← string.intercalate ", " <$> steps.mmap pp_rule,
return $ "erw [" ++ rules ++ "]" ++ (if needs_refl then ", refl" else "") | def | tactic.rewrite_search.explain_rewrites_concisely | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
check_if_simple_rewrite_succeeds (rewrites : list (expr × bool)) (goal : expr) :
tactic bool | lock_tactic_state $ do
m ← mk_meta_var goal,
set_goals [m],
rewrites.mmap' $ λ q, rewrite_target q.1 {symm := q.2, md := semireducible},
(reflexivity reducible >> return ff) <|> (reflexivity >> return tt) | def | tactic.rewrite_search.check_if_simple_rewrite_succeeds | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Fails if we can't just use rewrite.
Otherwise, returns 'tt' if we need a `refl` at the end. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
proof_unit.rewrites (u : proof_unit) (rs : list (expr × bool)) : list (expr × bool) | u.steps.filter_map $ how.to_rewrite rs | def | tactic.rewrite_search.proof_unit.rewrites | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Construct a list of rewrites from a proof unit. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
proof_unit.explain (u : proof_unit) (rs : list (expr × bool))
(explain_using_conv : bool) : tactic string | if explain_using_conv then
using_conv.explain_rewrites rs u.side u.steps
else
using_location.explain_rewrites rs u.side u.steps | def | tactic.rewrite_search.proof_unit.explain | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | Construct an explanation string from a proof unit. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
explain_proof_full (rs : list (expr × bool)) (explain_using_conv : bool) :
list proof_unit → tactic string | | [] := return ""
| (u :: rest) := do
-- Don't use transitivity for the last unit, since it must be redundant.
head ← if rest.length = 0 ∨ u.side = side.L then pure [] else (do
n ← infer_type u.proof >>= (λ e, prod.snd <$> (match_eq e <|> match_iff e)) >>= pp,
pure $ ["transitivity " ++ to_string n]),
uni... | def | tactic.rewrite_search.explain_proof_full | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"filter"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
explain_proof_concisely (rules : list (expr × bool)) (proof : expr)
(l : list proof_unit) : tactic string | do let rws : list (expr × bool) := list.join $ l.map (λ u, do
(r, s) ← u.rewrites rules,
return (r, if u.side = side.L then s else ¬s)),
goal ← infer_type proof,
needs_refl ← check_if_simple_rewrite_succeeds rws goal,
explain_rewrites_concisely rws needs_refl | def | tactic.rewrite_search.explain_proof_concisely | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
explain_search_result (cfg : config) (rules : list (expr × bool)) (proof : expr)
(units : list proof_unit) : tactic unit | if units.empty then trace "Try this: exact rfl" else do
explanation ← explain_proof_concisely rules proof units <|>
explain_proof_full rules cfg.explain_using_conv units,
trace $ "Try this: " ++ explanation | def | tactic.rewrite_search.explain_search_result | tactic.rewrite_search | src/tactic/rewrite_search/explain.lean | [
"tactic.rewrite_search.types",
"tactic.converter.interactive"
] | [
"units"
] | Trace a human-readable explanation in Lean code of a proof generated by rewrite search.
Emit it as `"Try this: <code>"` with each successive line of code indented. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
rewrite_search (explain : parse $ optional (tk "?"))
(rs : parse $ optional (list_of (rw_rule_p $ lean.parser.pexpr 0)))
(cfg : config := {}) : tactic unit | do t ← tactic.target,
if t.has_meta_var then
tactic.fail "rewrite_search is not suitable for goals containing metavariables"
else tactic.skip,
implicit_rules ← collect_rules,
explicit_rules ← (rs.get_or_else []).mmap (λ ⟨_, dir, pe⟩, do e ← to_expr' pe, return (e, dir)),
let rules := implicit_rules ++ exp... | def | tactic.interactive.rewrite_search | tactic.rewrite_search | src/tactic/rewrite_search/frontend.lean | [
"tactic.rewrite_search.explain",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.search"
] | [] | Search for a chain of rewrites to prove an equation or iff statement.
Collects rewrite rules, runs a graph search to find a chain of rewrites to prove the
current target, and generates a string explanation for it.
Takes an optional list of rewrite rules specified in the same way as the `rw` tactic accepts. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
edge | (from_id to_id : ℕ)
(proof : tactic expr)
(how : how) | structure | tactic.rewrite_search.edge | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | An edge represents a proof that can get from one expression to another.
It represents the fact that, starting from the vertex `fr`, the expression in `proof`
can prove the vertex `to`.
`how` contains information that the explainer will use to generate Lean code for the
proof. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
edge.to_string : edge → format | | e := format!"{e.from_id} → {e.to_id}" | def | tactic.rewrite_search.edge.to_string | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Converting an edge to a human-readable string. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
edge.has_to_format : has_to_format edge | ⟨edge.to_string⟩ | instance | tactic.rewrite_search.edge.has_to_format | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
vertex | (id : ℕ)
(exp : expr)
(pp : string)
(side : side)
(parent : option edge) | structure | tactic.rewrite_search.vertex | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [
"exp",
"side"
] | A vertex represents an expression that is equivalent to either the left or right side
of our initial equation.
* `id` is a numerical id used to refer to this vertex in the context of a single graph.
* `exp` is the expression this vertex represents.
* `pp` is the string format of the expression; we store this in the ver... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
graph | (conf : config)
(rules : list (expr × bool))
(vertices : buffer vertex)
(vmap : native.rb_map string (list ℕ))
(solving_edge : option edge)
(lhs : expr)
(rhs : expr) | structure | tactic.rewrite_search.graph | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | The graph represents two trees, one descending from each of the left and right sides
of our initial equation.
* `conf` and `rules` determine what rewrites are used to generate new graph vertices.
Here, the format of a rewrite rule is an expression for rewriting, plus a flag for the
direction to apply it in.
* `vert... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk_graph (conf : config) (rules : list (expr × bool)) (eq : expr)
: tactic graph | do (lhs, rhs) ← tactic.match_eq eq <|> tactic.match_iff eq,
lhs_pp ← to_string <$> tactic.pp lhs,
rhs_pp ← to_string <$> tactic.pp rhs,
let lhs_vertex : vertex := ⟨0, lhs, lhs_pp, side.L, none⟩,
let rhs_vertex : vertex := ⟨1, rhs, rhs_pp, side.R, none⟩,
return ⟨conf, rules, [lhs_vertex, rhs_vertex].to_buffer,... | def | tactic.rewrite_search.mk_graph | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Construct a graph to search for a proof of a given equation.
This graph initially contains only two disconnected vertices corresponding to the two
sides of the equation. When `find_proof` is called, we will run a search and add
new vertices and edges. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
walk_up_parents : option edge → tactic (list edge) | | none := return []
| (some e) := do
v ← g.vertices.read_t e.from_id,
edges ← walk_up_parents v.parent,
return (e :: edges) | def | tactic.rewrite_search.graph.walk_up_parents | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Find a list of edges that connect the given edge to the root of its tree.
The edges are returned in leaf-to-root order, while they are in root-to-leaf direction,
so if you want them in the logical order you must reverse the returned list. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
solution_paths : tactic (list edge × list edge) | do e ← g.solving_edge,
v ← g.vertices.read_t e.to_id,
path1 ← walk_up_parents g e,
path2 ← walk_up_parents g v.parent,
match v.side with
| side.L := return (path2.reverse, path1.reverse)
| side.R := return (path1.reverse, path2.reverse)
end | def | tactic.rewrite_search.graph.solution_paths | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Returns two lists that represent a solution. The first list is a path from LHS to some
interior vertex, the second is a path from the RHS to that interior vertex. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_defeq : expr → list ℕ → tactic (option ℕ) | | exp [] := return none
| exp (id :: rest) := do
v ← g.vertices.read_t id,
((do tactic.is_def_eq v.exp exp, return (some id)) <|> (find_defeq exp rest)) | def | tactic.rewrite_search.graph.find_defeq | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [
"exp"
] | Finds the id of a vertex in a list whose expression is defeq to the provided expression.
Returns none if there is none. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
add_rewrite (v : vertex) (rw : rewrite) : tactic graph | do pp ← to_string <$> tactic.pp rw.exp,
let existing_ids := match g.vmap.find pp with | some ids := ids | none := [] end,
maybe_id ← find_defeq g rw.exp existing_ids,
match maybe_id with
| (some id) := do
existing_vertex ← g.vertices.read_t id,
if v.side = existing_vertex.side then return g
else ret... | def | tactic.rewrite_search.graph.add_rewrite | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [
"trace_if_enabled"
] | Add the new vertex and edge to the graph, that can be proved in one step starting
at a given vertex, with a given rewrite expression.
For efficiency, it's important that this is the only way the graph is mutated,
and it only appends to the end of the `vertices` buffer. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
expand_vertex (v : vertex) : tactic graph | do rws ← get_rewrites g.rules v.exp g.conf,
list.mfoldl (λ g rw, add_rewrite g v rw) g rws.to_list | def | tactic.rewrite_search.graph.expand_vertex | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Add all single-step rewrites starting at a particular vertex to the graph. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_solving_edge : graph → ℕ → tactic graph | | g vertex_id :=
if vertex_id ≥ g.conf.max_iterations then fail "search failed: max iterations reached"
else if h : vertex_id < g.vertices.size then
do let v := g.vertices.read (fin.mk vertex_id h),
g ← expand_vertex g v,
match g.solving_edge with
| some _ := return g
| none := find_solving_edge g (vertex_id ... | def | tactic.rewrite_search.graph.find_solving_edge | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Repeatedly expand edges, starting at a given vertex id, until a solution is found. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
combine_proofs (proofs : list expr) : tactic expr | match proofs with
| [] := fail "cannot combine empty proof list"
| (proof :: rest) := list.mfoldl mk_eq_trans proof rest
end | def | tactic.rewrite_search.graph.combine_proofs | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [] | Use `mk_eq_trans` to combine a list of proof expressions into a single proof expression. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
proof_for_edges : (side × list edge) → tactic (option proof_unit) | | (s, []) := return none
| (s, edges) := do
proofs ← match s with
| side.L := edges.mmap (λ e, e.proof)
| side.R := edges.reverse.mmap (λ e, e.proof >>= mk_eq_symm)
end,
proof ← combine_proofs proofs,
let hows := edges.map (λ e, e.how),
return $ some ⟨proof, s, hows⟩ | def | tactic.rewrite_search.graph.proof_for_edges | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [
"side"
] | Construct a proof unit, given a path through the graph.
This reverses the direction of the proof on the right hand side, with `mk_eq_symm`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_trivial_proof : tactic (graph × expr × list proof_unit) | do is_def_eq g.lhs g.rhs,
exp ← mk_eq_refl g.lhs,
return (g, exp, []) | def | tactic.rewrite_search.graph.find_trivial_proof | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [
"exp"
] | Checks to see if an empty series of rewrites will solve this, because it's an expression
of the form a = a. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
find_proof : tactic (graph × expr × list proof_unit) | find_trivial_proof g <|> do
g ← find_solving_edge g 0,
(left_edges, right_edges) ← solution_paths g,
units ← [(side.L, left_edges), (side.R, right_edges)].mmap_filter proof_for_edges,
proof ← combine_proofs $ units.map $ λ u, u.proof,
return (g, proof, units) | def | tactic.rewrite_search.graph.find_proof | tactic.rewrite_search | src/tactic/rewrite_search/search.lean | [
"data.buffer.basic",
"tactic.rewrite_search.discovery",
"tactic.rewrite_search.types"
] | [
"units",
"units.map"
] | Run the search to find a proof for the provided graph.
Normally, this is the only external method needed to run the graph search. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
side.to_string : side → format | | side.L := "L"
| side.R := "R" | def | tactic.rewrite_search.side.to_string | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"side",
"side.to_string"
] | Convert a side to a human-readable string. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
side.to_xhs : side → string | | side.L := "lhs"
| side.R := "rhs" | def | tactic.rewrite_search.side.to_xhs | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"side"
] | Convert a side to the string "lhs" or "rhs", for use in tactic name generation. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
side.has_to_format : has_to_format side | ⟨side.to_string⟩ | instance | tactic.rewrite_search.side.has_to_format | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"side"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
how | (rule_index : ℕ) (location : ℕ) (addr : option (list expr_lens.dir)) | structure | tactic.rewrite_search.how | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"expr_lens.dir"
] | A `how` contains information needed by the explainer to generate code for a rewrite.
`rule_index` denotes which rule in the static list of rules is used.
`location` describes which match of that rule was used, to work with `nth_rewrite`.
`addr` is a list of "left" and "right" describing which subexpression is rewritten... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
how.to_string : how → format | | h := format!"rewrite {h.rule_index} {h.location} {h.addr.iget.to_string}" | def | tactic.rewrite_search.how.to_string | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [] | Convert a `how` to a human-readable string. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
how.has_to_format : has_to_format how | ⟨how.to_string⟩ | instance | tactic.rewrite_search.how.has_to_format | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
rewrite | (exp : expr)
(proof : tactic expr) -- we defer constructing the proofs until they are needed
(how : how) | structure | tactic.rewrite_search.rewrite | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"exp"
] | `rewrite` represents a single step of rewriting, that proves `exp` using `proof`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
proof_unit | (proof : expr)
(side : side)
(steps : list how) | structure | tactic.rewrite_search.proof_unit | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"side"
] | `proof_unit` represents a sequence of steps that can be applied to one side of the
equation to prove a particular expression. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
config extends tactic.nth_rewrite.cfg | (max_iterations : ℕ := 5000)
(explain_using_conv : bool := tt) | structure | tactic.rewrite_search.config | tactic.rewrite_search | src/tactic/rewrite_search/types.lean | [
"tactic.nth_rewrite"
] | [
"tactic.nth_rewrite.cfg"
] | Configuration options for a rewrite search.
`max_iterations` controls how many vertices are expanded in the graph search.
`explain` generates Lean code to replace the call to `rewrite_search`.
`explain_using_conv` changes the nature of the explanation. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
total_function (α : Type u) (β : Type v) : Type (max u v)
| with_default : list (Σ _ : α, β) → β → total_function | inductive | slim_check.total_function | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Data structure specifying a total function using a list of pairs
and a default value returned when the input is not in the domain of
the partial function.
`with_default f y` encodes `x ↦ f x` when `x ∈ f` and `x ↦ y`
otherwise.
We use `Σ` to encode mappings instead of `×` because we
rely on the association list API d... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
total_function.inhabited [inhabited β] : inhabited (total_function α β) | ⟨ total_function.with_default ∅ default ⟩ | instance | slim_check.total_function.inhabited | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
apply [decidable_eq α] : total_function α β → α → β | | (total_function.with_default m y) x := (m.lookup x).get_or_else y | def | slim_check.total_function.apply | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Apply a total function to an argument. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
repr_aux [has_repr α] [has_repr β] (m : list (Σ _ : α, β)) : string | string.join $ list.qsort (λ x y, x < y)
(m.map $ λ x, sformat!"{repr $ sigma.fst x} ↦ {repr $ sigma.snd x}, ") | def | slim_check.total_function.repr_aux | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Implementation of `has_repr (total_function α β)`.
Creates a string for a given `finmap` and output, `x₀ ↦ y₀, .. xₙ ↦ yₙ`
for each of the entries. The brackets are provided by the calling function. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
repr [has_repr α] [has_repr β] : total_function α β → string | | (total_function.with_default m y) := sformat!"[{repr_aux m}_ ↦ {has_repr.repr y}]" | def | slim_check.total_function.repr | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Produce a string for a given `total_function`.
The output is of the form `[x₀ ↦ f x₀, .. xₙ ↦ f xₙ, _ ↦ y]`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
list.to_finmap' (xs : list (α × β)) : list (Σ _ : α, β) | xs.map prod.to_sigma | def | slim_check.total_function.list.to_finmap' | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"prod.to_sigma"
] | Create a `finmap` from a list of pairs. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
total.sizeof : total_function α β → ℕ | | ⟨m, x⟩ := 1 + @sizeof _ sampleable.wf m + sizeof x | def | slim_check.total_function.total.sizeof | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Redefine `sizeof` to follow the structure of `sampleable` instances. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
shrink : shrink_fn (total_function α β) | | ⟨m, x⟩ := (sampleable.shrink (m, x)).map $ λ ⟨⟨m', x'⟩, h⟩, ⟨⟨list.dedupkeys m', x'⟩,
lt_of_le_of_lt
(by unfold_wf; refine @list.sizeof_dedupkeys _ _ _ (@sampleable.wf _ _) _) h ⟩ | def | slim_check.total_function.shrink | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"list.sizeof_dedupkeys",
"shrink"
] | Shrink a total function by shrinking the lists that represent it. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
pi.sampleable_ext : sampleable_ext (α → β) | { proxy_repr := total_function α β,
interp := total_function.apply,
sample := do
{ xs ← (sampleable.sample (list (α × β)) : gen ((list (α × β)))),
⟨x⟩ ← (uliftable.up $ sample β : gen (ulift.{max u v} β)),
pure $ total_function.with_default (list.to_finmap' xs) x },
shrink := total_function.shrink } | instance | slim_check.total_function.pi.sampleable_ext | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"shrink",
"uliftable.up"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
zero_default : total_function α β → total_function α β | | (with_default A y) := with_default A 0 | def | slim_check.total_function.zero_default | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Map a total_function to one whose default value is zero so that it represents a finsupp. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
zero_default_supp : total_function α β → finset α | | (with_default A y) :=
list.to_finset $ (A.dedupkeys.filter (λ ab, sigma.snd ab ≠ 0)).map sigma.fst | def | slim_check.total_function.zero_default_supp | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"finset",
"list.to_finset"
] | The support of a zero default `total_function`. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
apply_finsupp (tf : total_function α β) : α →₀ β | { support := zero_default_supp tf,
to_fun := tf.zero_default.apply,
mem_support_to_fun := begin
intro a,
rcases tf with ⟨A, y⟩,
simp only [apply, zero_default_supp, list.mem_map, list.mem_filter, exists_and_distrib_right,
list.mem_to_finset, exists_eq_right, sigma.exists, ne.def, zero_default],
... | def | slim_check.total_function.apply_finsupp | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"exists_and_distrib_right",
"exists_eq_right",
"list.lookup",
"list.lookup_dedupkeys",
"list.mem_filter",
"list.mem_lookup",
"list.mem_map",
"list.mem_to_finset",
"list.nodupkeys_dedupkeys",
"option.mem_def",
"with_top.some_eq_coe"
] | Create a finitely supported function from a total function by taking the default value to
zero. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
finsupp.sampleable_ext [has_repr α] [has_repr β] : sampleable_ext (α →₀ β) | { proxy_repr := total_function α β,
interp := total_function.apply_finsupp,
sample := (do
xs ← (sampleable.sample (list (α × β)) : gen (list (α × β))),
⟨x⟩ ← (uliftable.up $ sample β : gen (ulift.{max u v} β)),
pure $ total_function.with_default (list.to_finmap' xs) x),
shrink := total_function.shrink... | instance | slim_check.total_function.finsupp.sampleable_ext | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"shrink",
"uliftable.up"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
dfinsupp.sampleable_ext [has_repr α] [has_repr β] : sampleable_ext (Π₀ a : α, β) | { proxy_repr := total_function α β,
interp := finsupp.to_dfinsupp ∘ total_function.apply_finsupp,
sample := (do
xs ← (sampleable.sample (list (α × β)) : gen (list (α × β))),
⟨x⟩ ← (uliftable.up $ sample β : gen (ulift.{max u v} β)),
pure $ total_function.with_default (list.to_finmap' xs) x),
shrink :=... | instance | slim_check.total_function.dfinsupp.sampleable_ext | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"finsupp.to_dfinsupp",
"shrink",
"uliftable.up"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pi_pred.sampleable_ext [sampleable_ext (α → bool)] :
sampleable_ext.{u+1} (α → Prop) | { proxy_repr := proxy_repr (α → bool),
interp := λ m x, interp (α → bool) m x,
sample := sample (α → bool),
shrink := shrink } | instance | slim_check.total_function.pi_pred.sampleable_ext | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"shrink"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pi_uncurry.sampleable_ext
[sampleable_ext (α × β → γ)] : sampleable_ext.{imax (u+1) (v+1) w} (α → β → γ) | { proxy_repr := proxy_repr (α × β → γ),
interp := λ m x y, interp (α × β → γ) m (x, y),
sample := sample (α × β → γ),
shrink := shrink } | instance | slim_check.total_function.pi_uncurry.sampleable_ext | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"shrink"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
injective_function (α : Type u) : Type u
| map_to_self (xs : list (Σ _ : α, α)) :
xs.map sigma.fst ~ xs.map sigma.snd → list.nodup (xs.map sigma.snd) → injective_function | inductive | slim_check.injective_function | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"list.nodup"
] | Data structure specifying a total function using a list of pairs
and a default value returned when the input is not in the domain of
the partial function.
`map_to_self f` encodes `x ↦ f x` when `x ∈ f` and `x ↦ x`,
i.e. `x` to itself, otherwise.
We use `Σ` to encode mappings instead of `×` because we
rely on the asso... | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
apply [decidable_eq α] : injective_function α → α → α | | (injective_function.map_to_self m _ _) x := (m.lookup x).get_or_else x | def | slim_check.injective_function.apply | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Apply a total function to an argument. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
repr [has_repr α] : injective_function α → string | | (injective_function.map_to_self m _ _) := sformat!"[{total_function.repr_aux m}x ↦ x]" | def | slim_check.injective_function.repr | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | Produce a string for a given `total_function`.
The output is of the form `[x₀ ↦ f x₀, .. xₙ ↦ f xₙ, x ↦ x]`.
Unlike for `total_function`, the default value is not a constant
but the identity function. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
list.apply_id [decidable_eq α] (xs : list (α × α)) (x : α) : α | ((xs.map prod.to_sigma).lookup x).get_or_else x | def | slim_check.injective_function.list.apply_id | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"prod.to_sigma"
] | Interpret a list of pairs as a total function, defaulting to
the identity function when no entries are found for a given function | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
list.apply_id_cons [decidable_eq α] (xs : list (α × α)) (x y z : α) :
list.apply_id ((y, z) :: xs) x = if y = x then z else list.apply_id xs x | by simp only [list.apply_id, list.lookup, eq_rec_constant, prod.to_sigma, list.map]; split_ifs; refl | lemma | slim_check.injective_function.list.apply_id_cons | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"eq_rec_constant",
"list.lookup",
"prod.to_sigma"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
list.apply_id_zip_eq [decidable_eq α] {xs ys : list α} (h₀ : list.nodup xs)
(h₁ : xs.length = ys.length) (x y : α) (i : ℕ)
(h₂ : xs.nth i = some x) :
list.apply_id.{u} (xs.zip ys) x = y ↔ ys.nth i = some y | begin
induction xs generalizing ys i,
case list.nil : ys i h₁ h₂
{ cases h₂ },
case list.cons : x' xs xs_ih ys i h₁ h₂
{ cases i,
{ injection h₂ with h₀ h₁, subst h₀,
cases ys,
{ cases h₁ },
{ simp only [list.apply_id, to_sigma, option.get_or_else_some, nth, lookup_cons_eq,
... | lemma | slim_check.injective_function.list.apply_id_zip_eq | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"list.nodup",
"nth_mem",
"option.get_or_else_some"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
apply_id_mem_iff [decidable_eq α] {xs ys : list α} (h₀ : list.nodup xs)
(h₁ : xs ~ ys)
(x : α) :
list.apply_id.{u} (xs.zip ys) x ∈ ys ↔ x ∈ xs | begin
simp only [list.apply_id],
cases h₃ : (lookup x (map prod.to_sigma (xs.zip ys))),
{ dsimp [option.get_or_else],
rw h₁.mem_iff },
{ have h₂ : ys.nodup := h₁.nodup_iff.1 h₀,
replace h₁ : xs.length = ys.length := h₁.length_eq,
dsimp,
induction xs generalizing ys,
case list.nil : ys h₃ h₂ ... | lemma | slim_check.injective_function.apply_id_mem_iff | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"heq_iff_eq",
"list.nodup",
"mem_cons_iff",
"mem_map",
"option.mem_def",
"prod.fst_to_sigma",
"prod.to_sigma"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
list.apply_id_eq_self [decidable_eq α] {xs ys : list α} (x : α) :
x ∉ xs → list.apply_id.{u} (xs.zip ys) x = x | begin
intro h,
dsimp [list.apply_id],
rw lookup_eq_none.2, refl,
simp only [keys, not_exists, to_sigma, exists_and_distrib_right, exists_eq_right, mem_map,
comp_app, map_map, prod.exists],
intros y hy,
exact h (mem_zip hy).1,
end | lemma | slim_check.injective_function.list.apply_id_eq_self | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"exists_and_distrib_right",
"exists_eq_right",
"mem_map",
"not_exists"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
apply_id_injective [decidable_eq α] {xs ys : list α} (h₀ : list.nodup xs)
(h₁ : xs ~ ys) : injective.{u+1 u+1} (list.apply_id (xs.zip ys)) | begin
intros x y h,
by_cases hx : x ∈ xs;
by_cases hy : y ∈ xs,
{ rw mem_iff_nth at hx hy,
cases hx with i hx,
cases hy with j hy,
suffices : some x = some y,
{ injection this },
have h₂ := h₁.length_eq,
rw [list.apply_id_zip_eq h₀ h₂ _ _ _ hx] at h,
rw [← hx, ← hy], congr,
app... | lemma | slim_check.injective_function.apply_id_injective | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"list.nodup"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
perm.slice [decidable_eq α] (n m : ℕ) :
(Σ' xs ys : list α, xs ~ ys ∧ ys.nodup) → (Σ' xs ys : list α, xs ~ ys ∧ ys.nodup) | | ⟨xs, ys, h, h'⟩ :=
let xs' := list.slice n m xs in
have h₀ : xs' ~ ys.inter xs',
from perm.slice_inter _ _ h h',
⟨xs', ys.inter xs', h₀, h'.inter _⟩ | def | slim_check.injective_function.perm.slice | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"list.slice"
] | Remove a slice of length `m` at index `n` in a list and a permutation, maintaining the property
that it is a permutation. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
slice_sizes : ℕ → lazy_list ℕ+ | | n :=
if h : 0 < n then
have n / 2 < n, from div_lt_self h dec_trivial,
lazy_list.cons ⟨_, h⟩ (slice_sizes $ n / 2)
else lazy_list.nil | def | slim_check.injective_function.slice_sizes | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"div_lt_self",
"lazy_list"
] | A lazy list, in decreasing order, of sizes that should be
sliced off a list of length `n` | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
shrink_perm {α : Type} [decidable_eq α] [has_sizeof α] :
shrink_fn (Σ' xs ys : list α, xs ~ ys ∧ ys.nodup) | | xs := do
let k := xs.1.length,
n ← slice_sizes k,
i ← lazy_list.of_list $ list.fin_range $ k / n,
have ↑i * ↑n < xs.1.length,
from nat.lt_of_div_lt_div
(lt_of_le_of_lt (by simp only [nat.mul_div_cancel, gt_iff_lt, fin.val_eq_coe, pnat.pos]) i.2),
pure ⟨perm.slice (i*n) n xs,
by rcases xs with ... | def | slim_check.injective_function.shrink_perm | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"fin.val_eq_coe",
"gt_iff_lt",
"lazy_list.of_list",
"list.fin_range",
"list.sizeof_slice_lt",
"nat.lt_of_div_lt_div",
"pnat.pos"
] | Shrink a permutation of a list, slicing a segment in the middle.
The sizes of the slice being removed start at `n` (with `n` the length
of the list) and then `n / 2`, then `n / 4`, etc down to 1. The slices
will be taken at index `0`, `n / k`, `2n / k`, `3n / k`, etc. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
shrink {α : Type} [has_sizeof α] [decidable_eq α] : shrink_fn (injective_function α) | | ⟨xs, h₀, h₁⟩ := do
⟨⟨xs', ys', h₀, h₁⟩, h₂⟩ ← injective_function.shrink_perm ⟨_, _, h₀, h₁⟩,
have h₃ : xs'.length ≤ ys'.length, from le_of_eq (perm.length_eq h₀),
have h₄ : ys'.length ≤ xs'.length, from le_of_eq (perm.length_eq h₀.symm),
pure ⟨⟨(list.zip xs' ys').map prod.to_sigma,
by simp only [comp, map... | def | slim_check.injective_function.shrink | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"prod.fst_to_sigma",
"prod.snd_to_sigma",
"prod.to_sigma",
"shrink"
] | Shrink an injective function slicing a segment in the middle of the domain and removing
the corresponding elements in the codomain, hence maintaining the property that
one is a permutation of the other. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
mk (xs ys : list α) (h : xs ~ ys) (h' : ys.nodup) : injective_function α | have h₀ : xs.length ≤ ys.length, from le_of_eq h.length_eq,
have h₁ : ys.length ≤ xs.length, from le_of_eq h.length_eq.symm,
injective_function.map_to_self (list.to_finmap' (xs.zip ys))
(by { simp only [list.to_finmap', comp, map_fst_zip, map_snd_zip, *,
prod.fst_to_sigma, prod.snd_to_sigma, map_ma... | def | slim_check.injective_function.mk | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"prod.fst_to_sigma",
"prod.snd_to_sigma"
] | Create an injective function from one list and a permutation of that list. | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 |
injective [decidable_eq α] (f : injective_function α) :
injective (apply f) | begin
cases f with xs hperm hnodup,
generalize h₀ : map sigma.fst xs = xs₀,
generalize h₁ : xs.map (@id ((Σ _ : α, α) → α) $ @sigma.snd α (λ _ : α, α)) = xs₁,
dsimp [id] at h₁,
have hxs : xs = total_function.list.to_finmap' (xs₀.zip xs₁),
{ rw [← h₀, ← h₁, list.to_finmap'], clear h₀ h₁ xs₀ xs₁ hperm hnodup,... | lemma | slim_check.injective_function.injective | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"map_nil",
"sigma.eta"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
pi_injective.sampleable_ext : sampleable_ext { f : ℤ → ℤ // function.injective f } | { proxy_repr := injective_function ℤ,
interp := λ f, ⟨ apply f, f.injective ⟩,
sample := gen.sized $ λ sz, do
{ let xs' := int.range (-(2*sz+2)) (2*sz + 2),
ys ← gen.permutation_of xs',
have Hinj : injective (λ (r : ℕ), -(2*sz + 2 : ℤ) + ↑r),
from λ x y h, int.coe_nat_inj (add_right_injective _ h),
... | instance | slim_check.injective_function.pi_injective.sampleable_ext | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"int.range",
"shrink"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
injective.testable (f : α → β)
[I : testable (named_binder "x" $
∀ x : α, named_binder "y" $ ∀ y : α, named_binder "H" $ f x = f y → x = y)] :
testable (injective f) | I | instance | slim_check.injective.testable | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
monotone.testable [preorder α] [preorder β] (f : α → β)
[I : testable (named_binder "x" $
∀ x : α, named_binder "y" $ ∀ y : α, named_binder "H" $ x ≤ y → f x ≤ f y)] :
testable (monotone f) | I | instance | slim_check.monotone.testable | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"monotone"
] | https://github.com/leanprover-community/mathlib | 65a1391a0106c9204fe45bc73a039f056558cb83 | |
antitone.testable [preorder α] [preorder β] (f : α → β)
[I : testable (named_binder "x" $
∀ x : α, named_binder "y" $ ∀ y : α, named_binder "H" $ x ≤ y → f y ≤ f x)] :
testable (antitone f) | I | instance | slim_check.antitone.testable | testing.slim_check | src/testing/slim_check/functions.lean | [
"data.list.sigma",
"data.int.range",
"data.finsupp.defs",
"data.finsupp.to_dfinsupp",
"tactic.pretty_cases",
"testing.slim_check.sampleable",
"testing.slim_check.testable"
] | [
"antitone"
] | 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.