(* Copyright 2013 IMDEA Software Institute Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. *)
(******************************************************************************)
(* This file defines pcm -- a type equipped with partial commutative          *)
(* monoid structure, several subclasses of PCMs, and important                *)
(* concrete instances.                                                        *)
(******************************************************************************)
Set Implicit Arguments.
Unset Strict Implicit.
Unset Printing Implicit Defensive.
Delimit Scope pcm_scope with pcm.
Open Scope pcm_scope.
(*******************************)
(* Partial Commutative Monoids *)
(*******************************)
Module PCM.
Record mixin_of (T : Type) := Mixin {
valid_op : T -> bool;
join_op : T -> T -> T;
unit_op : T;
_ : commutative join_op;
_ : associative join_op;
_ : left_id unit_op join_op;
(* monotonicity of valid *)
_ : forall x y, valid_op (join_op x y) -> valid_op x;
(* unit is valid *)
_ : valid_op unit_op}.
Section ClassDef.
Notation class_of := mixin_of (only parsing).
Structure type : Type := Pack {sort : Type; _ : class_of sort}.
Local Coercion sort : type >-> Sortclass.
Variables (T : Type) (cT : type).
Definition class := let: Pack _ c as cT' := cT return class_of cT' in c.
Definition pack c := @Pack T c.
Definition clone := fun c & cT -> T & phant_id (pack c) cT => pack c.
Definition valid := valid_op class.
Definition join := join_op class.
Definition unit := unit_op class.
End ClassDef.
Arguments unit [cT].
Module Exports.
Coercion sort : type >-> Sortclass.
Notation pcm := type.
Notation PCMMixin := Mixin.
Notation PCM T m := (@pack T m).
Notation "[ 'pcmMixin' 'of' T ]" := (class _ : mixin_of T)
(at level 0, format "[ 'pcmMixin'  'of'  T ]") : pcm_scope.
Notation "[ 'pcm' 'of' T 'for' C ]" := (@clone T C _ idfun id)
(at level 0, format "[ 'pcm'  'of'  T  'for'  C ]") : pcm_scope.
Notation "[ 'pcm' 'of' T ]" := (@clone T _ _ id id)
(at level 0, format "[ 'pcm'  'of'  T ]") : pcm_scope.
Notation "x \+ y" := (join x y)
(at level 43, left associativity) : pcm_scope.
Notation valid := valid.
Notation Unit := unit.
Arguments unit [cT].
Prenex Implicits valid join unit.
(* Restating the laws, with the notation. *)
(* Plus some additional derived lemmas.   *)
Section Laws.
Variable U V : pcm.

(* Specifications: *)
Lemma joinC (x y : U) : x \+ y = y \+ x.
Lemma cancPR (P : U -> Prop) s1 s2 t1 t2 :
precise P -> valid (s1 \+ t1) -> P t1 -> P t2 ->
s1 \+ t1 = s2 \+ t2 -> (s1 = s2) * (t1 = t2).