feat(library): do not using simp lemmas for sorting arguments of AC operators by default

This commit is contained in:
Leonardo de Moura 2017-12-03 15:03:07 -08:00
parent d9322b16ca
commit b7322e28c1
23 changed files with 56 additions and 40 deletions

View file

@ -42,6 +42,10 @@ master branch (aka work in progress branch)
*Changes*
- Remove `[simp]` attribute from lemmas `or.assoc`, `or.comm`, `or.left_comm`, `and.assoc`, `and.comm`, `and.left_comm`, `add_assoc`, `add_comm`, `add_left_com`, `mul_assoc`, `mul_comm` and `mul_left_comm`.
These lemmas were being used to "sort" arguments of AC operators: and, or, (+) and (*).
This was producing unstable proofs. The old behavior can be retrieved by using the commands `local attribute [simp] ...` or `attribute [simp] ...` in the affected files.
- `string` is now a list of unicode scalar values. Moreover, in the VM,
strings are implemented as an UTF-8 encoded array of bytes.

View file

@ -158,6 +158,8 @@ section conversion
theorem bits_to_nat_to_list {n : } (x : bitvec n)
: bitvec.to_nat x = bits_to_nat (vector.to_list x) := rfl
local attribute [simp] add_comm add_assoc add_left_comm mul_comm mul_assoc mul_left_comm
theorem to_nat_append {m : } (xs : bitvec m) (b : bool)
: bitvec.to_nat (xs ++ₜ b::nil) = bitvec.to_nat xs * 2 + bitvec.to_nat (b::nil) :=
begin

View file

@ -127,13 +127,13 @@ begin
existsi e, cases t; simp [find_entry] at ⊢ h₂,
{ simp [rbtree.find, rbnode.find] at h₂, cases h₂, contradiction },
{ cases h₂ with h₂₁ h₂₂, split,
{ cases e, apply eqv_keys_of_eqv_entries h₂₁ },
{ have := rbtree.find_eq_find_of_eqv ⟨rbnode.red_node lchild val rchild, p⟩ (eqv_entries k v val.snd),
rw [←this], exact h₂₂ } },
rw [←this], exact h₂₁ },
{ cases e, apply eqv_keys_of_eqv_entries h₂₂ } },
{ cases h₂ with h₂₁ h₂₂, split,
{ cases e, apply eqv_keys_of_eqv_entries h₂₁ },
{ have := rbtree.find_eq_find_of_eqv ⟨rbnode.black_node lchild val rchild, p⟩ (eqv_entries k v val.snd),
rw [←this], exact h₂₂ } } },
rw [←this], exact h₂₁ },
{ cases e, apply eqv_keys_of_eqv_entries h₂₂ } } },
{ intro h, cases h with e h,
cases h with h₁ h₂, cases t; simp [find_entry] at h₁,
{ contradiction },

View file

@ -5,9 +5,6 @@ Authors: Leonardo de Moura
-/
universe u
/- TODO(Leo): remove after we cleanup stdlib simp lemmas -/
local attribute [-simp] or.comm or.left_comm or.assoc and.comm and.left_comm and.assoc
namespace tactic
/- TODO(Leo): move blast_disjs and twice to another file. -/

View file

@ -6,9 +6,6 @@ Authors: Leonardo de Moura
import data.rbtree.basic
universe u
/- TODO(Leo): remove after we cleanup stdlib simp lemmas -/
local attribute [-simp] or.comm or.left_comm or.assoc and.comm and.left_comm and.assoc
namespace rbnode
variables {α : Type u}

View file

@ -6,9 +6,6 @@ Authors: Leonardo de Moura
import data.rbtree.find
universes u v
/- TODO(Leo): remove after we cleanup stdlib simp lemmas -/
local attribute [-simp] or.comm or.left_comm or.assoc and.comm and.left_comm and.assoc
namespace rbnode
variables {α : Type u}

View file

@ -6,9 +6,6 @@ Authors: Leonardo de Moura
import data.rbtree.find data.rbtree.insert data.rbtree.min_max
universes u
/- TODO(Leo): remove after we cleanup stdlib simp lemmas -/
local attribute [-simp] or.comm or.left_comm or.assoc and.comm and.left_comm and.assoc
namespace rbnode
variables {α : Type u} {lt : αα → Prop}

View file

@ -6,9 +6,6 @@ Authors: Leonardo de Moura
import data.rbtree.basic
universe u
/- TODO(Leo): remove after we cleanup stdlib simp lemmas -/
local attribute [-simp] or.comm or.left_comm or.assoc and.comm and.left_comm and.assoc
namespace rbnode
variables {α : Type u} {lt : αα → Prop}

View file

@ -256,6 +256,8 @@ have a * b ≠ 0, from (division_ring.mul_ne_zero ha hb),
by rw [add_comm, ← field.div_mul_left ha this, ← field.div_mul_right hb this,
division_def, division_def, division_def, ← right_distrib]
local attribute [simp] mul_assoc mul_comm mul_left_comm
lemma field.div_mul_div (a : α) {b : α} (c : α) {d : α} (hb : b ≠ 0) (hd : d ≠ 0) :
(a / b) * (c / d) = (a * c) / (b * d) :=
begin simp [division_def], rw [mul_inv_eq hd hb, mul_comm d⁻¹] end

View file

@ -438,7 +438,7 @@ sub_lt_of_abs_sub_lt_left (abs_sub a b ▸ h)
lemma abs_sub_square (a b : α) : abs (a - b) * abs (a - b) = a * a + b * b - (1 + 1) * a * b :=
begin
rw abs_mul_abs_self,
simp [left_distrib, right_distrib]
simp [left_distrib, right_distrib, add_assoc, add_comm, add_left_comm, mul_comm]
end
lemma eq_zero_of_mul_self_add_mul_self_eq_zero {x y : α} (h : x * x + y * y = 0) : x = 0 :=

View file

@ -37,21 +37,23 @@ class group (α : Type u) extends monoid α, has_inv α :=
class comm_group (α : Type u) extends group α, comm_monoid α
@[simp] lemma mul_assoc [semigroup α] : ∀ a b c : α, a * b * c = a * (b * c) :=
lemma mul_assoc [semigroup α] : ∀ a b c : α, a * b * c = a * (b * c) :=
semigroup.mul_assoc
instance semigroup_to_is_associative [semigroup α] : is_associative α (*) :=
⟨mul_assoc⟩
@[simp] lemma mul_comm [comm_semigroup α] : ∀ a b : α, a * b = b * a :=
lemma mul_comm [comm_semigroup α] : ∀ a b : α, a * b = b * a :=
comm_semigroup.mul_comm
instance comm_semigroup_to_is_commutative [comm_semigroup α] : is_commutative α (*) :=
⟨mul_comm⟩
@[simp] lemma mul_left_comm [comm_semigroup α] : ∀ a b c : α, a * (b * c) = b * (a * c) :=
lemma mul_left_comm [comm_semigroup α] : ∀ a b c : α, a * (b * c) = b * (a * c) :=
left_comm has_mul.mul mul_comm mul_assoc
local attribute [simp] mul_comm mul_assoc mul_left_comm
lemma mul_right_comm [comm_semigroup α] : ∀ a b c : α, a * b * c = a * c * b :=
right_comm has_mul.mul mul_comm mul_assoc
@ -306,6 +308,8 @@ instance add_semigroup_to_is_eq_associative [add_semigroup α] : is_associative
instance add_comm_semigroup_to_is_eq_commutative [add_comm_semigroup α] : is_commutative α (+) :=
⟨add_comm⟩
local attribute [simp] add_assoc add_comm add_left_comm
def neg_add_self := @add_left_neg
def add_neg_self := @add_right_neg
def eq_of_add_eq_add_left := @add_left_cancel
@ -405,7 +409,7 @@ lemma eq_sub_of_add_eq' [add_comm_group α] {a b c : α} (h : c + a = b) : a = b
by simp [h.symm]
lemma sub_eq_of_eq_add' [add_comm_group α] {a b c : α} (h : a = b + c) : a - b = c :=
by simp [h]
begin simp [h], rw [add_left_comm], simp end
lemma eq_add_of_sub_eq' [add_comm_group α] {a b c : α} (h : a - b = c) : a = b + c :=
by simp [h.symm]
@ -420,7 +424,7 @@ lemma add_sub_comm [add_comm_group α] (a b c d : α) : a + b - (c + d) = (a - c
by simp
lemma sub_eq_sub_add_sub [add_comm_group α] (a b c : α) : a - b = c - b + (a - c) :=
by simp
begin simp, rw [add_left_comm c], simp end
lemma neg_neg_sub_neg [add_comm_group α] (a b : α) : - (-a - -b) = a - b :=
by simp

View file

@ -112,6 +112,8 @@ section comm_semiring
@[simp] theorem dvd_refl : a a :=
dvd.intro 1 (by simp)
local attribute [simp] mul_assoc mul_comm mul_left_comm
theorem dvd_trans {a b c : α} (h₁ : a b) (h₂ : b c) : a c :=
match h₁, h₂ with
| ⟨d, (h₃ : b = a * d)⟩, ⟨e, (h₄ : c = b * e)⟩ :=
@ -220,11 +222,13 @@ instance comm_ring.to_comm_semiring [s : comm_ring α] : comm_semiring α :=
section comm_ring
variable [comm_ring α]
local attribute [simp] add_assoc add_comm add_left_comm mul_comm
lemma mul_self_sub_mul_self_eq (a b : α) : a * a - b * b = (a + b) * (a - b) :=
by simp [right_distrib, left_distrib]
begin simp [right_distrib, left_distrib], rw [add_comm (-(a*b)), add_left_comm (a*b)], simp end
lemma mul_self_sub_one_eq (a : α) : a * a - 1 = (a + 1) * (a - 1) :=
by simp [right_distrib, left_distrib]
begin simp [right_distrib, left_distrib], rw [add_left_comm, add_comm (-a), add_left_comm a], simp end
lemma add_mul_self_eq (a b : α) : (a + b) * (a + b) = a*a + 2*a*b + b*b :=
calc (a + b)*(a + b) = a*a + (1+1)*a*b + b*b : by simp [right_distrib, left_distrib]

View file

@ -393,6 +393,8 @@ protected meta def transfer (distrib := tt) : tactic unit :=
if distrib then `[int.transfer_core, simp [add_mul, mul_add]]
else `[int.transfer_core, simp]
local attribute [simp] mul_assoc mul_comm mul_left_comm
instance : comm_ring int :=
{ add := int.add,
add_assoc := by int.transfer,

View file

@ -175,9 +175,13 @@ protected lemma zero_lt_one : (0 : ) < 1 := trivial
protected lemma lt_iff_le_not_le {a b : } : a < b ↔ (a ≤ b ∧ ¬ b ≤ a) :=
begin
simp [int.lt_iff_le_and_ne], split; intro h; cases h with hneq hab; split,
{assumption}, {intro hba, apply hneq, apply int.le_antisymm; assumption},
{intro heq, apply hab, subst heq, apply int.le_refl}, {assumption}
simp [int.lt_iff_le_and_ne], split; intro h,
{ cases h with hab hn, split,
{ assumption },
{ intro hba, simp [int.le_antisymm hab hba] at *, contradiction } },
{ cases h with hab hn, split,
{ assumption },
{ intro h, simp [*] at * } }
end
instance : decidable_linear_ordered_comm_ring int :=

View file

@ -105,7 +105,7 @@ lemma eq_or_mem_of_mem_cons {a y : α} {l : list α} : a ∈ y::l → a = y
assume h, h
@[simp] lemma mem_append {a : α} {s t : list α} : a ∈ s ++ t ↔ a ∈ s a ∈ t :=
by induction s; simp *
by induction s; simp [*, or_assoc]
@[rsimp] lemma mem_append_eq (a : α) (s t : list α) : (a ∈ s ++ t) = (a ∈ s a ∈ t) :=
propext mem_append

View file

@ -61,6 +61,8 @@ end
@[simp] lemma div2_succ (n : ) : div2 (succ n) = cond (bodd n) (succ (div2 n)) (div2 n) :=
by unfold bodd div2 bodd_div2; cases bodd_div2 n; cases fst; refl
local attribute [simp] add_comm add_assoc add_left_comm mul_comm mul_assoc mul_left_comm
theorem bodd_add_div2 : ∀ n, cond (bodd n) 1 0 + 2 * div2 n = n
| 0 := rfl
| (succ n) := begin

View file

@ -1359,6 +1359,8 @@ end
/- mod / div / pow -/
local attribute [simp] mul_comm
theorem mod_pow_succ {b : } (b_pos : b > 0) (w m : )
: m % (b^succ w) = b * (m/b % b^w) + m % b :=
begin

View file

@ -52,8 +52,8 @@ by simp
@[simp] lemma cmp_using_eq_gt [is_strict_order α lt] (a b : α) : (cmp_using lt a b = ordering.gt) = lt b a :=
begin
simp, apply propext, apply iff.intro,
{ exact λ h, h.1 },
{ intro hba, split, assumption, intro hab, exact absurd (trans hab hba) (irrefl a) }
{ exact λ h, h.2 },
{ intro hba, split, { intro hab, exact absurd (trans hab hba) (irrefl a) }, { assumption } }
end
@[simp] lemma cmp_using_eq_eq (a b : α) : (cmp_using lt a b = ordering.eq) = (¬ lt a b ∧ ¬ lt b a) :=

View file

@ -374,19 +374,19 @@ iff.intro
(assume ⟨ha, hb⟩, ⟨ha, iff.elim_left (h ha) hb⟩)
(assume ⟨ha, hc⟩, ⟨ha, iff.elim_right (h ha) hc⟩)
@[simp] lemma and.comm : a ∧ b ↔ b ∧ a :=
lemma and.comm : a ∧ b ↔ b ∧ a :=
iff.intro and.swap and.swap
lemma and_comm (a b : Prop) : a ∧ b ↔ b ∧ a := and.comm
@[simp] lemma and.assoc : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) :=
lemma and.assoc : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) :=
iff.intro
(assume ⟨⟨ha, hb⟩, hc⟩, ⟨ha, ⟨hb, hc⟩⟩)
(assume ⟨ha, ⟨hb, hc⟩⟩, ⟨⟨ha, hb⟩, hc⟩)
lemma and_assoc (a b : Prop) : (a ∧ b) ∧ c ↔ a ∧ (b ∧ c) := and.assoc
@[simp] lemma and.left_comm : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) :=
lemma and.left_comm : a ∧ (b ∧ c) ↔ b ∧ (a ∧ c) :=
iff.trans (iff.symm and.assoc) (iff.trans (and_congr and.comm (iff.refl c)) and.assoc)
lemma and_iff_left {a b : Prop} (hb : b) : (a ∧ b) ↔ a :=
@ -430,11 +430,11 @@ or.imp id h
@[congr] lemma or_congr (h₁ : a ↔ c) (h₂ : b ↔ d) : (a b) ↔ (c d) :=
iff.intro (or.imp (iff.mp h₁) (iff.mp h₂)) (or.imp (iff.mpr h₁) (iff.mpr h₂))
@[simp] lemma or.comm : a b ↔ b a := iff.intro or.swap or.swap
lemma or.comm : a b ↔ b a := iff.intro or.swap or.swap
lemma or_comm (a b : Prop) : a b ↔ b a := or.comm
@[simp] lemma or.assoc : (a b) c ↔ a (b c) :=
lemma or.assoc : (a b) c ↔ a (b c) :=
iff.intro
(or.rec (or.imp_right or.inl) (λ h, or.inr (or.inr h)))
(or.rec (λ h, or.inl (or.inl h)) (or.imp_left or.inr))
@ -442,7 +442,7 @@ iff.intro
lemma or_assoc (a b : Prop) : (a b) c ↔ a (b c) :=
or.assoc
@[simp] lemma or.left_comm : a (b c) ↔ b (a c) :=
lemma or.left_comm : a (b c) ↔ b (a c) :=
iff.trans (iff.symm or.assoc) (iff.trans (or_congr or.comm (iff.refl c)) or.assoc)
theorem or_iff_right_of_imp (ha : a → b) : (a b) ↔ b :=

View file

@ -2,6 +2,8 @@ namespace test
open tactic
meta def my_tac : tactic unit := abstract (intros >> `[simp])
local attribute [simp] add_assoc mul_assoc
structure monoid (α : Type) :=
(op : ααα)
(assoc : ∀ a b c, op (op a b) c = op a (op b c) . my_tac)

View file

@ -34,7 +34,7 @@ def reassoc : exp → exp
| _ := Mult e1' e2'
end
attribute [simp] mul_add times reassoc eeval
attribute [simp] mul_add times reassoc eeval mul_comm mul_assoc mul_left_comm
theorem eeval_times (k e) : eeval (times k e) = k * eeval e :=
by induction e; simp [*]

View file

@ -6,6 +6,7 @@ def sum_has_sizeof_2 {α β} [has_sizeof α] [has_sizeof β] : has_sizeof (psum
⟨psum.alt.sizeof⟩
local attribute [instance] sum_has_sizeof_2
local attribute [simp] add_comm add_left_comm add_assoc mul_assoc mul_comm mul_left_comm
mutual def f, g
with f :

View file

@ -26,6 +26,8 @@ attribute [simp] semigroup_morphism.multiplicative
multiplicative := begin intros, simp [coe_fn] end
}
local attribute [simp] mul_comm mul_assoc mul_left_comm
@[reducible] definition semigroup_product { α β : Type u } ( s : semigroup α ) ( t: semigroup β ) : semigroup (α × β) := {
mul := λ p q, (p^.fst * q^.fst, p^.snd * q^.snd),
mul_assoc := begin