(* $Id: OrdSg_ex.v,v 1.2 1999/10/05 10:35:38 boulme Exp $ *)
Set Implicit Arguments.
Unset Strict Implicit.

Require Import Records.
Require Import Build.
Require Import Setoid_ex.
Require Import Semigroups_ex.

(**** orders ****)
Definition order_on (s : setoid) :=
  ( INF -: s -> s -> Prop ;;
    INF_refl -: forall x y : s, (s @ EQ) x y -> INF x y ;;
    INF_trans -: forall x y z : s, INF x y -> INF y z -> INF x y ;;).                    

Definition order_sig : sign eqLabel_dec.
  refine (flatsign _ _ (fun s => order_on s)); simpl in |- *; auto.
Defined.

Definition order := Drecord order_sig.

Definition order_setoid : order -> setoid.
  refine (coerce (flatsign_subsign _ _ (fun s => order_on s))); simpl in |- *;
   auto.
Defined.

Coercion order_setoid : order >-> setoid.


(**** Ordered-semigroups ***)
Definition ordsem_sig : sign eqLabel_dec.
 refine
  (mergesign (eqA_dec:=eqLabel_dec) (s:=setoid_sig) (s1:=semigroup_sig)
     (s2:=order_sig) (H1:=flatsign_subsign _ _ (fun s => semigroup_on s))
     (H2:=flatsign_subsign _ _ (fun s => order_on s)) _); 
  simpl in |- *; auto.
Defined.

Definition ordsem := Drecord ordsem_sig.

Definition ordsem_semigroup : ordsem -> semigroup.
  refine
   (coerce
      (subsign_mergesign_1 (eqA_dec:=eqLabel_dec) (s:=setoid_sig)
         (s1:=semigroup_sig) (s2:=order_sig)
         (H1:=flatsign_subsign _ _ (fun s => semigroup_on s))
         (H2:=flatsign_subsign _ _ (fun s => order_on s)) _)); 
   simpl in |- *; auto.
Defined.

Coercion ordsem_semigroup : ordsem >-> semigroup.

Definition ordsem_order : ordsem -> order.
  refine
   (coerce
      (subsign_mergesign_2 (eqA_dec:=eqLabel_dec) (s:=setoid_sig)
         (s1:=semigroup_sig) (s2:=order_sig)
         (H1:=flatsign_subsign _ _ (fun s => semigroup_on s))
         (H2:=flatsign_subsign _ _ (fun s => order_on s)) _)); 
   simpl in |- *; auto.
Defined.
Coercion ordsem_order : ordsem >-> order.

(*
Definition ordsg_on:=[s:ordsem]
     ( OP_INF_l -: forall (x y z:s), 
         (s @ INF) x y
           -> (s @ INF) ((s @ OP) x z) ((s @ OP) y z) ;;
       OP_INF_r -: forall (x y z:s),
         (s @ INF) x y
         -> (s @ INF) ((s@OP) z x) ((s@OP) z y) ;;).

Definition ordsg_sig:=(flatsign I I [s](ordsg_on s)).
Definition ordsg:=(Drecord ordsg_sig).
*)



(*
Local ordsem_sem:=(subsign_mergsig_1 ordsem_aml).
Local ordsem_ord:=(subsign_mergsig_2 ordsem_aml).


(* Check (subsign_trans (presub_subsign (presub_flatsign ordsg_on))
                       ordsem_sem). *)
Local burkD:=

Definition ordsg_semigroup_subsign: (subsign burkD ordsg_sig semigroup_sig).
  Unfold order_sig burkB; Auto with sign.
Defined.
 
Definition ordsg_semigroup: ordsg -> semigroup := 
  (coerce orsg_semigroup_subsign).
Coercion ordsg_semigroup: ordsg >-> semigroup.


Section ordsg_props.

Variable s: ordsg.

Variable x:(s @ T).

Lemma powerS_n_m:(n,m:nat)(le n m)->(s @ INF (powerS s x n) (powerS s x m)).
  Intros n m H; Elim H; Simpl; Clear H m n.
Qed.


End ordsg_props.
*)








