# mathlibdocumentation

core / init.meta.simp_tactic

Equations
Equations
meta constant mk_simp_attr_decl_name (attr_name : name) :

Prefix the given attr_name with "simp_attr".

meta constant simp_lemmas  :
Type

Simp lemmas are used by the "simplifier" family of tactics. simp_lemmas is essentially a pair of tables rb_map (expr_type × name) (priority_list simp_lemma). One of the tables is for congruences and one is for everything else. An individual simp lemma is:

• A kind which can be Refl, Simp or Congr.
• A pair of exprs l ~> r. The rb map is indexed by the name of get_app_fn(l).
• A proof that l = r or l ↔ r.
• A list of the metavariables that must be filled before the proof can be applied.
• A priority number
Instances for simp_lemmas
meta constant simp_lemmas.mk  :

Make a new table of simp lemmas

meta constant simp_lemmas.join  :

Merge the simp_lemma tables.

meta constant simp_lemmas.erase  :

Remove the given lemmas from the table. Use the names of the lemmas.

meta constant simp_lemmas.erase_simp_lemmas  :

Remove all simp lemmas from the table.

meta constant simp_lemmas.mk_default  :

Makes the default simp_lemmas table which is composed of all lemmas tagged with simp.

meta constant simp_lemmas.add (s : simp_lemmas) (e : expr) (symm : bool := ) :

Add a simplification lemma by an expression p. Some conditions on p must hold for it to be added, see list below. If your lemma is not being added, you can see the reasons by setting set_option trace.simp_lemmas true.

• p must have the type Π (h₁ : _) ... (hₙ : _), LHS ~ RHS for some reflexive, transitive relation (usually =).
• Any of the hypotheses hᵢ should either be present in LHS or otherwise a Prop or a typeclass instance.
• LHS should not occur within RHS.
• LHS should not occur within a hypothesis hᵢ.
meta constant simp_lemmas.add_simp (s : simp_lemmas) (id : name) (symm : bool := ) :

Add a simplification lemma by it's declaration name. See simp_lemmas.add for more information.

Adds a congruence simp lemma to simp_lemmas. A congruence simp lemma is a lemma that breaks the simplification down into separate problems. For example, to simplify a ∧ b to c ∧ d, we should try to simp a to c and b to d. For examples of congruence simp lemmas look for lemmas with the @[congr] attribute.

lemma if_simp_congr ... (h_c : b ↔ c) (h_t : x = u) (h_e : y = v) : ite b x y = ite c u v := ...
lemma imp_congr_right (h : a → (b ↔ c)) : (a → b) ↔ (a → c) := ...
lemma and_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a ∧ b) ↔ (c ∧ d) := ...

meta def simp_lemmas.append_with_symm (s : simp_lemmas) (hs : list ) :

Add expressions to a set of simp lemmas using simp_lemmas.add.

This is the new version of simp_lemmas.append, which also allows you to set the symm flag.

meta def simp_lemmas.append (s : simp_lemmas) (hs : list expr) :

Add expressions to a set of simp lemmas using simp_lemmas.add.

This is the backwards-compatibility version of simp_lemmas.append_with_symm, and sets all symm flags to ff.

meta constant simp_lemmas.rewrite (s : simp_lemmas) (e : expr) (prove : := tactic.failed) (r : name := )  :

simp_lemmas.rewrite s e prove R apply a simplification lemma from 's'

• 'e' is the expression to be "simplified"
• 'prove' is used to discharge proof obligations.
• 'r' is the equivalence relation being used (e.g., 'eq', 'iff')
• 'md' is the transparency; how aggresively should the simplifier perform reductions.

Result (new_e, pr) is the new expression 'new_e' and a proof (pr : e R new_e)

meta constant simp_lemmas.rewrites (s : simp_lemmas) (e : expr) (prove : := tactic.failed) (r : name := )  :
meta constant simp_lemmas.drewrite (s : simp_lemmas) (e : expr)  :

simp_lemmas.drewrite s e tries to rewrite 'e' using only refl lemmas in 's'

meta constant is_valid_simp_lemma_cnst  :
meta constant is_valid_simp_lemma  :
meta constant simp_lemmas.pp  :
@[protected, instance]
meta def tactic.revert_and_transform (transform : expr) (h : expr) :

Revert a local constant, change its type using transform.

meta def tactic.get_eqn_lemmas_for (deps : bool) (d : name) :

get_eqn_lemmas_for deps d returns the automatically generated equational lemmas for definition d. If deps is tt, then lemmas for automatically generated auxiliary declarations used to define d are also included.

structure tactic.dsimp_config  :
Type
Instances for tactic.dsimp_config
meta constant simp_lemmas.dsimplify (s : simp_lemmas) (u : := list.nil) (e : expr) (cfg : tactic.dsimp_config := ) :

(Definitional) Simplify the given expression using only reflexivity equality lemmas from the given set of lemmas. The resulting expression is definitionally equal to the input.

The list u contains defintions to be delta-reduced, and projections to be reduced.

meta constant tactic.dsimplify_core {α : Type} (a : α) (pre post : α → exprtactic × ) (e : expr) (cfg : tactic.dsimp_config := ) :
meta def tactic.dsimplify (pre post : exprtactic ) :
meta def tactic.dsimp_hyp (h : expr) (u : := list.nil) (cfg : tactic.dsimp_config := ) :
meta constant tactic.dunfold_head (e : expr)  :

Tries to unfold e if it is a constant or a constant application. Remark: this is not a recursive procedure.

structure tactic.dunfold_config  :
Type
Instances for tactic.dunfold_config
meta constant tactic.dunfold (cs : list name) (e : expr) (cfg : tactic.dunfold_config := {to_dsimp_config := ) :
structure tactic.delta_config  :
Type
• max_steps :
• visit_instances : bool
Instances for tactic.delta_config
meta def tactic.delta (cs : list name) (e : expr)  :

Delta reduce the given constant names

meta def tactic.delta_target (cs : list name)  :
meta def tactic.delta_hyp (cs : list name) (h : expr)  :
structure tactic.unfold_proj_config  :
Type
Instances for tactic.unfold_proj_config
meta constant tactic.unfold_proj (e : expr)  :

If e is a projection application, try to unfold it, otherwise fail.

structure tactic.simp_config  :
Type
Instances for tactic.simp_config
meta constant tactic.simplify (s : simp_lemmas) (to_unfold : := list.nil) (e : expr) (cfg : tactic.simp_config := ) (r : name := ) (discharger : := tactic.failed) :

simplify s e cfg r prove simplify e using s using bottom-up traversal. discharger is a tactic for dischaging new subgoals created by the simplifier. If it fails, the simplifier tries to discharge the subgoal by simplifying it to true.

The parameter to_unfold specifies definitions that should be delta-reduced, and projection applications that should be unfolded.

meta def tactic.simp_target (s : simp_lemmas) (to_unfold : := list.nil) (cfg : tactic.simp_config := ) (discharger : := tactic.failed) :
meta def tactic.simp_hyp (s : simp_lemmas) (to_unfold : := list.nil) (h : expr) (cfg : tactic.simp_config := ) (discharger : := tactic.failed) :
meta constant tactic.ext_simplify_core {α : Type} (a : α) (c : tactic.simp_config) (s : simp_lemmas) (discharger : α → ) (pre post : α → simp_lemmasnameexprtactic × ) (r : name) :
exprtactic ×

ext_simplify_core a c s discharger pre post r e:

• a : α - initial user data
• c : simp_config - simp configuration options
• s : simp_lemmas - the set of simp_lemmas to use. Remark: the simplification lemmas are not applied automatically like in the simplify tactic. The caller must use them at pre/post.
• discharger : α → tactic α - tactic for dischaging hypothesis in conditional rewriting rules. The argument 'α' is the current user data.
• pre a s r p e is invoked before visiting the children of subterm 'e'.
• arguments:
• a is the current user data
• s is the updated set of lemmas if 'contextual' is tt,
• r is the simplification relation being used,
• p is the "parent" expression (if there is one).
• e is the current subexpression in question.
• if it succeeds the result is (new_a, new_e, new_pr, flag) where
• new_a is the new value for the user data
• new_e is a new expression s.t. r e new_e
• new_pr is a proof for r e new_e, If it is none, the proof is assumed to be by reflexivity
• flag if tt new_e children should be visited, and post invoked.
• (post a s r p e) is invoked after visiting the children of subterm e, The output is similar to (pre a r s p e), but the 'flag' indicates whether the new expression should be revisited or not.
• r is the simplification relation. Usually = or ↔.
• e is the input expression to be simplified.

The method returns (a,e,pr) where

• a is the final user data
• e is the new expression
• pr is the proof that the given expression equals the input expression.

Note that ext_simplify_core will succeed even if pre and post fail, as failures are used to indicate that the method should move on to the next subterm. If it is desirable to propagate errors from pre, they can be propagated through the "user data". An easy way to do this is to call tactic.capture (do ...) in the parts of pre/post where errors matter, and then use tactic.unwrap a on the result.

Additionally, ext_simplify_core does not propagate changes made to the tactic state by pre and post. If it is desirable to propagate changes to the tactic state in addition to errors, usetactic.resumeinstead oftactic.unwrap.

meta def tactic.intro1_aux  :
bool
structure tactic.simp_intros_config  :
Type
Instances for tactic.simp_intros_config
meta def tactic.simp_intros_aux (cfg : tactic.simp_config) (use_hyps : bool) (to_unfold : list name) :
meta def tactic.mk_eq_simp_ext (simp_ext : exprtactic ) :
meta def tactic.mk_simp_attr (attr_name : name) (attr_deps : := list.nil) :
meta def tactic.get_user_simp_lemmas (attr_name : name) :

### Example usage: #

-- make a new simp attribute called "my_reduction"
run_cmd mk_simp_attr my_reduction
-- Add "my_reduction" attributes to these if-reductions
attribute [my_reduction] if_pos if_neg dif_pos dif_neg

-- will return the simp_lemmas with the my_reduction attribute.
#eval get_user_simp_lemmas my_reduction



meta def tactic.join_user_simp_lemmas (no_dflt : bool) (attrs : list name) :
meta def tactic.simplify_top_down {α : Type} (a : α) (pre : α → exprtactic × ) (e : expr) (cfg : tactic.simp_config := ) :
tactic ×
meta def tactic.simp_top_down (pre : exprtactic ) (cfg : tactic.simp_config := ) :
meta def tactic.simplify_bottom_up {α : Type} (a : α) (post : α → exprtactic × ) (e : expr) (cfg : tactic.simp_config := ) :
tactic ×
meta def tactic.simp_bottom_up (post : exprtactic ) (cfg : tactic.simp_config := ) :
meta structure tactic.simp_all_entry  :
Type
meta def tactic.simp_all (s : simp_lemmas) (to_unfold : list name) (cfg : tactic.simp_config := ) (discharger : := tactic.failed) :
meta constant tactic.trace_algebra_info  :
meta def simp_attr.norm  :