Merge branch 'upgrade_proofs_coq_8_11_to_8_16' into 'master'
[why3.git] / stdlib / algebra.mlw
bloba2d5f9fa97c52085c75b128b0230b2e716f255d7
2 (** {1 Basic Algebra Theories} *)
4 (** {2 Associativity} *)
6 module Assoc
8   type t
9   function op t t : t
10   axiom Assoc : forall x y z : t. op (op x y) z = op x (op y z)
12 end
14 (** {2 Commutativity} *)
16 module Comm
18   type t
19   function op t t : t
20   axiom Comm : forall x y : t. op x y = op y x
22 end
24 (** {2 Associativity and Commutativity} *)
26 module AC
28   clone export Assoc with axiom Assoc
29   clone export Comm with type t = t, function op = op, axiom Comm
30   meta AC function op
32 end
34 (** {2 Monoids} *)
36 module Monoid
38   clone export Assoc with axiom Assoc
39   constant unit : t
40   axiom Unit_def_l : forall x:t. op unit x = x
41   axiom Unit_def_r : forall x:t. op x unit = x
43 end
45 (** {2 Commutative Monoids} *)
47 module CommutativeMonoid
49   clone export Monoid with axiom Assoc, axiom Unit_def_l, axiom Unit_def_r
50   clone export Comm with type t = t, function op = op, axiom Comm
51   meta AC function op
53 end
55 (** {2 Groups} *)
57 module Group
59   clone export Monoid with axiom Assoc, axiom Unit_def_l, axiom Unit_def_r
60   function inv t : t
61   axiom Inv_def_l : forall x:t. op (inv x) x = unit
62   axiom Inv_def_r : forall x:t. op x (inv x) = unit
64 (***
65   lemma Inv_unit : forall x y:t. op x (inv y) = unit -> x = y
68 end
70 (** {2 Commutative Groups} *)
72 module CommutativeGroup
74   clone export Group with axiom .
75   clone export Comm with type t = t, function op = op, axiom Comm
76   meta AC function op
78 end
80 (** {2 Rings} *)
82 module Ring
84   type t
85   constant zero : t
86   function (+) t t : t
87   function (-_) t : t
88   function (*) t t : t
90   clone export CommutativeGroup with type t = t,
91                                 constant unit = zero,
92                                 function op = (+),
93                                 function inv = (-_),
94                                 axiom .
96   clone Assoc as MulAssoc with type t = t, function op = (*), axiom Assoc
98   axiom Mul_distr_l : forall x y z : t. x * (y + z) = x * y + x * z
99   axiom Mul_distr_r : forall x y z : t. (y + z) * x = y * x + z * x
103 (** {2 Commutative Rings} *)
105 module CommutativeRing
107   clone export Ring with axiom .
108   clone Comm as MulComm with type t = t, function op = (*), axiom Comm
109   meta AC function (*)
113 (** {2 Commutative Rings with Unit} *)
115 module UnitaryCommutativeRing
117   clone export CommutativeRing with axiom .
118   constant one : t
119   axiom Unitary : forall x:t. one * x = x
120   axiom NonTrivialRing : zero <> one
124 (** {2 Ordered Commutative Rings} *)
126 module OrderedUnitaryCommutativeRing
128   clone export UnitaryCommutativeRing with axiom .
130   predicate (<=) t t
132   clone export relations.TotalOrder with
133     type t = t, predicate rel = (<=), axiom .
135   axiom ZeroLessOne : zero <= one
137   axiom CompatOrderAdd  :
138     forall x y z : t. x <= y -> x + z <= y + z
140   axiom CompatOrderMult :
141     forall x y z : t. x <= y -> zero <= z -> x * z <= y * z
142   meta "remove_unused:dependency" axiom CompatOrderMult, function (*)
146 (** {2 Field theory} *)
148 module Field
150   clone export UnitaryCommutativeRing with axiom .
152   function inv t : t
154   axiom Inverse : forall x:t. x <> zero -> x * inv x = one
156   function (-) (x y : t) : t = x + -y
157   function (/) (x y : t) : t = x * inv y
159   lemma add_div :
160     forall x y z : t. z <> zero -> (x+y)/z = x/z + y/z
161   meta "remove_unused:dependency" lemma add_div, function (/)
163   lemma sub_div :
164     forall x y z : t. z <> zero -> (x-y)/z = x/z - y/z
165   meta "remove_unused:dependency" lemma sub_div, function (/)
167   lemma neg_div :
168     forall x y : t. y <> zero -> (-x)/y = -(x/y)
169   meta "remove_unused:dependency" lemma neg_div, function (/)
171   lemma assoc_mul_div: forall x y z:t.
172     (* todo: discard the hypothesis ? *)
173      z <> zero -> (x*y)/z = x*(y/z)
174   meta "remove_unused:dependency" lemma assoc_mul_div, function (/)
176   lemma assoc_div_mul: forall x y z:t.
177     (* todo: discard the hypothesis ? *)
178      y <> zero /\ z <> zero -> (x/y)/z = x/(y*z)
179   meta "remove_unused:dependency" lemma assoc_div_mul, function (/)
181   lemma assoc_div_div: forall x y z:t.
182     (* todo: discard the hypothesis ? *)
183      y <> zero /\ z <> zero -> x/(y/z) = (x*z)/y
184   meta "remove_unused:dependency" lemma assoc_div_div, function (/)
188 (** {2 Ordered Fields} *)
190 module OrderedField
192   clone export Field with axiom .
194   predicate (<=) t t
196   clone export relations.TotalOrder with
197     type t = t, predicate rel = (<=), axiom .
199   axiom ZeroLessOne : zero <= one
201   axiom CompatOrderAdd  : forall x y z : t. x <= y -> x + z <= y + z
203   axiom CompatOrderMult :
204     forall x y z : t. x <= y -> zero <= z -> x * z <= y * z
208 (***
209  to be discussed: should we add the following lemmas, and where
211   lemma InvMult : forall x y : t. (-x) * y = - (x * y) = x * (-y)
212   lemma InvSquare : forall x : t. x * x = (-x) * (-x)
213   lemma ZeroMult : forall x : t. x * zero = zero = zero * x
214   lemma SquareNonNeg1 : forall x : t. x <= zero -> zero <= x * x
215   lemma SquareNonNeg : forall x : t. zero <= x * x