feat(library/init/algebra/ac): add helper classes for AC

This commit is contained in:
Leonardo de Moura 2016-12-27 16:54:00 -08:00
parent d3795b20dd
commit 8fcfe0bbd4
2 changed files with 31 additions and 1 deletions

View file

@ -0,0 +1,18 @@
/-
Copyright (c) 2016 Microsoft Corporation. All rights reserved.
Released under Apache 2.0 license as described in the file LICENSE.
Authors: Leonardo de Moura
-/
prelude
import init.logic
universe variables u
class is_associative (α : Type u) (r : αα → Prop) (op : ααα) :=
(assoc : ∀ a b c, r (op (op a b) c) (op a (op b c)))
class is_commutative (α : Type u) (r : αα → Prop) (op : ααα) :=
(comm : ∀ a b, r (op a b) (op b a))
class is_eq_associative (α : Type u) (op : ααα) extends is_associative α eq op
class is_eq_commutative (α : Type u) (op : ααα) extends is_commutative α eq op

View file

@ -4,7 +4,7 @@ Released under Apache 2.0 license as described in the file LICENSE.
Authors: Jeremy Avigad, Leonardo de Moura
-/
prelude
import init.logic init.meta.interactive init.meta.decl_cmds
import init.logic init.algebra.ac init.meta.interactive init.meta.decl_cmds
/- Make sure instances defined in this file have lower priority than the ones
defined for concrete structures -/
@ -38,9 +38,15 @@ class comm_group (α : Type u) extends group α, comm_monoid α
@[simp] lemma mul_assoc [semigroup α] : ∀ a b c : α, a * b * c = a * (b * c) :=
semigroup.mul_assoc
instance semigroup_to_is_eq_associative [semigroup α] : is_eq_associative α mul :=
⟨mul_assoc⟩
@[simp] lemma mul_comm [comm_semigroup α] : ∀ a b : α, a * b = b * a :=
comm_semigroup.mul_comm
instance comm_semigroup_to_is_eq_commutative [comm_semigroup α] : is_eq_commutative α mul :=
⟨mul_comm⟩
@[simp] lemma mul_left_comm [comm_semigroup α] : ∀ a b c : α, a * (b * c) = b * (a * c) :=
left_comm mul mul_comm mul_assoc
@ -278,6 +284,12 @@ run_command transport_to_additive `eq_mul_of_inv_mul_eq `eq_add_of_neg_add_eq
run_command transport_to_additive `mul_eq_of_eq_inv_mul `add_eq_of_eq_neg_add
run_command transport_to_additive `mul_eq_of_eq_mul_inv `add_eq_of_eq_add_neg
instance add_semigroup_to_is_eq_associative [add_semigroup α] : is_eq_associative α add :=
⟨add_assoc⟩
instance add_comm_semigroup_to_is_eq_commutative [add_comm_semigroup α] : is_eq_commutative α add :=
⟨add_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