(* This program is free software; you can redistribute it and/or      *)
(* modify it under the terms of the GNU Lesser General Public License *)
(* as published by the Free Software Foundation; either version 2.1   *)
(* of the License, or (at your option) any later version.             *)
(*                                                                    *)
(* This program is distributed in the hope that it will be useful,    *)
(* but WITHOUT ANY WARRANTY; without even the implied warranty of     *)
(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the      *)
(* GNU General Public License for more details.                       *)
(*                                                                    *)
(* You should have received a copy of the GNU Lesser General Public   *)
(* License along with this program; if not, write to the Free         *)
(* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *)
(* 02110-1301 USA                                                     *)
Set Implicit Arguments.
Unset Strict Implicit.
Require Export Cfield_facts.
Section Def.
Variable R : CFIELD.
Record Ctype : Type :=  {real :> R; imag : R}.
Definition Cadd (z z' : Ctype) : Ctype :=
Build_Ctype (sgroup_law R (real z) (real z'))
(sgroup_law R (imag z) (imag z')).
Definition Cmult (z z' : Ctype) : Ctype :=
Build_Ctype
(sgroup_law R (ring_mult (real z) (real z'))
(group_inverse R (ring_mult (imag z) (imag z'))))
(sgroup_law R (ring_mult (real z) (imag z'))
(ring_mult (imag z) (real z'))).
Definition Copp (z : Ctype) : Ctype :=
Build_Ctype (group_inverse R (real z)) (group_inverse R (imag z)).
Definition Cone : Ctype := Build_Ctype (ring_unit R) (monoid_unit R).
Definition Czero : Ctype := Build_Ctype (monoid_unit R) (monoid_unit R).
Definition Ceq (z z' : Ctype) :=
Equal (real z) (real z') /\ Equal (imag z) (imag z').
Definition Cset : Setoid.
apply (Build_Setoid (Carrier:=Ctype) (Equal:=Ceq)).
red in |- *.
split; [ red in |- * | red in |- * ].
intros x; red in |- *; red in |- *; auto with algebra.
split; [ red in |- * | red in |- * ].
unfold app_rel, Ceq in |- *.
intros x y z H' H'0; split; [ try assumption | idtac ].
apply Trans with (real y); intuition.
apply Trans with (imag y); intuition.
unfold app_rel, Ceq in |- *.
intuition.
Defined.
Require Export Ring_util.

(* Specifications: *)
Lemma Build_Ctype_comp :
forall x x' y y' : R,
Equal x x' ->
Equal y y' -> Equal (s:=Cset) (Build_Ctype x y) (Build_Ctype x' y').