fact
stringlengths
17
6.18k
type
stringclasses
17 values
library
stringclasses
3 values
imports
listlengths
0
12
filename
stringclasses
115 values
symbolic_name
stringlengths
1
30
docstring
stringclasses
1 value
uip_prop_trans (dec : forall x y : A, x = y \/ x <> y) {x : A} : forall {y : A} (pf pf' : x = y), pf = pf' := let comp := fun (x y y' : A) (eq1 : x = y) (eq2 : x = y') => eq_ind x (fun a : A => a = y') eq2 y eq1 in let eq_dec := dec x in let nu := fun (y : A) (u : x = y) => match eq_dec y with | or_introl eqxy => eqxy | or_intror neqxy => False_ind (x = y) (neqxy u) end in let nu_constant := fun (y : A) (u v : x = y) => let o := eq_dec y in match o as o0 return (match o0 with | or_introl eqxy => eqxy | or_intror neqxy => False_ind (x = y) (neqxy u) end = match o0 with | or_introl eqxy => eqxy | or_intror neqxy => False_ind (x = y) (neqxy v) end) with | or_introl Heq => eq_refl | or_intror Hneq => match Hneq u as f return (False_ind (x = y) f = False_ind (x = y) (Hneq v)) with end end in let nu_inv := fun (y : A) (v : x = y) => comp x x y (nu x eq_refl) v in let trans_sym_eq := fun (x y : A) (u : x = y) => match u as e in (_ = y0) return (comp x y0 y0 e e = eq_refl) with | eq_refl => eq_refl end in let nu_left_inv_on := fun (y : A) (u : x = y) => match u as e in (_ = y0) return (nu_inv y0 (nu y0 e) = e) with | eq_refl => trans_sym_eq _ _ (nu _ eq_refl) end in fun (y : A) (p1 p2 : x = y) => eq_ind (nu_inv y (nu y p1)) (fun p3 : x = y => p3 = p2) (eq_ind (nu_inv y (nu y p2)) (fun p3 : x = y => nu_inv y (nu y p1) = p3) (eq_ind (nu y p1) (fun e : x = y => nu_inv y (nu y p1) = nu_inv y e) eq_refl (nu y p2) (nu_constant y p1 p2)) p2 (nu_left_inv_on _ p2)) p1 (nu_left_inv_on _ p1).
Definition
theories
[]
theories/Data/Eq/UIP_trans.v
uip_prop_trans
uip_trans (dec : forall x y : A, {x = y} + {x <> y}) := @uip_prop_trans (fun a b => match dec a b with | left pf => or_introl pf | right pf' => or_intror pf' end).
Definition
theories
[]
theories/Data/Eq/UIP_trans.v
uip_trans
BuildGraph : Type := { emptyGraph : G ; addVertex : V -> G -> G ; addEdge : V -> V -> G -> G }.
Class
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/BuildGraph.v
BuildGraph
GraphBuilderT (T : Type) : Type := stateT G m T. Global Instance Monad_GraphBuilder : Monad GraphBuilderT := Monad_stateT _ _. Global Instance MonadT_GraphBuilder : MonadT GraphBuilderT m := MonadT_stateT _ _.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/BuildGraph.v
GraphBuilderT
State_GraphBuilder : MonadState G GraphBuilderT := MonadState_stateT _ _. Import MonadNotation. Local Open Scope monad_scope.
Instance
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/BuildGraph.v
State_GraphBuilder
newEdge (f t : V) : GraphBuilderT unit := g <- get ;; put (addEdge f t g).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/BuildGraph.v
newEdge
newVertex (v : V) : GraphBuilderT unit := g <- get ;; put (addVertex v g).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/BuildGraph.v
newVertex
buildGraph {v} (c : GraphBuilderT v) (g : G) : m G := execStateT c g.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/BuildGraph.v
buildGraph
Graph : Type := { verticies : G -> list V ; successors : G -> V -> list V }.
Class
theories
[]
theories/Data/Graph/Graph.v
Graph
adj_graph : Type := map.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAdjList.v
adj_graph
verts (g : adj_graph) : list V := let c := foldM (m := writerT (Monoid_list_app) ident) (fun k_v _ => let k := fst k_v in tell (k :: nil)) (ret tt) g in psnd (unIdent (runWriterT c)).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAdjList.v
verts
succs (g : adj_graph) (v : V) : list V := match lookup v g with | None => nil | Some vs => vs end. Global Instance Graph_adj_graph : Graph V adj_graph := { verticies := verts ; successors := succs }.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAdjList.v
succs
add_vertex (v : V) (g : adj_graph) : adj_graph := if contains v g then g else add v nil g. (** TODO: Move this **)
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAdjList.v
add_vertex
list_in_dec v (ls : list V) : bool := match ls with | nil => false | l :: ls => if eq_dec l v then true else list_in_dec v ls end.
Fixpoint
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAdjList.v
list_in_dec
add_edge (f t : V) (g : adj_graph) : adj_graph := match lookup f g with | None => add f (t :: nil) g | Some vs => if list_in_dec t vs then g else add f (t :: vs) g end. Global Instance GraphBuilder_adj_graph : BuildGraph V adj_graph := { emptyGraph := empty ; addVertex := add_vertex ; addEdge := add_edge }.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAdjList.v
add_edge
list_in_dec v (ls : list V) : bool := match ls with | nil => false | l :: ls => if eq_dec l v then true else list_in_dec v ls end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAlgos.v
list_in_dec
dfs' : V -> list V -> m (list V) := mfix_multi (V :: list V :: nil) (list V) (fun rec from seen => if list_in_dec from seen then ret (m:=m) seen else foldM (fun v acc => if list_in_dec v acc then ret (m:=m) acc else rec v acc) (ret (m:=m) seen) (successors g from)).
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAlgos.v
dfs'
dfs (from : V) : list V := let count := Npos (List.fold_left (fun acc _ => Pos.succ acc) (verticies g) 1%positive) in let res := runGFix (dfs' from nil) count in match res with | Diverge => (** This should never happen! **) verticies g | Term v => v end.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Graph/GraphAlgos.v
dfs
alist : Type := list (K * V).
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist
alist_remove (k : K) (m : alist) : alist := List.filter (fun x => negb (k ?[ R ] (fst x))) m.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist_remove
alist_add (k : K) (v : V) (m : alist) : alist := (k, v) :: alist_remove k m.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist_add
alist_find (k : K) (m : alist) : option V := match m with | nil => None | (k',v) :: ms => if k ?[ R ] k' then Some v else alist_find k ms end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist_find
alist_find' (k: K) : alist -> option V := fmap snd ∘ find (rel_dec k ∘ fst).
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist_find'
alist_find_alt (m: alist) : forall k: K, alist_find k m = alist_find' k m. Proof. induction m; intuition. unfold alist_find', compose. simpl. destruct (k ?[ R ] a0) eqn:Heq; [intuition|]. rewrite IHm. reflexivity. Qed.
Lemma
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist_find_alt
fold_alist (acc : T) (map : alist) : T := match map with | nil => acc | (k,v) :: m => let acc := f k v acc in fold_alist acc m end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
fold_alist
fold_alist' : T -> alist -> T := flip $ fold_left (flip $ uncurry f).
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
fold_alist'
fold_alist_alt (map: alist) : forall acc: T, fold_alist acc map = fold_alist' acc map. Proof. induction map; intuition. simpl. rewrite IHmap. reflexivity. Qed.
Lemma
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
fold_alist_alt
alist_union (m1 m2 : alist) : alist := fold_alist alist_add m2 m1. Global Instance Map_alist : Map K V alist := { empty := nil ; add := @alist_add ; remove := alist_remove ; lookup := alist_find ; union := @alist_union }.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
alist_union
mapsto_alist (m : alist) k v : Prop := alist_find k m = Some v.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_alist
mapsto_alist_cons : forall k v m k' v', mapsto_alist ((k',v') :: m) k v <-> ( (mapsto_alist m k v /\ ~R k k') \/ (R k k' /\ v = v')). Proof. unfold mapsto_alist; intuition; simpl in *. { consider (k ?[ R ] k'); intros. { right. inversion H0; auto. } { left. auto. } } { consider (k ?[ R ] k'); intros; intuition. } { consider (k ?[ R ] k'); intros; intuition. congruence. } Qed.
Lemma
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_alist_cons
mapsto_lookup_alist : forall (k : K) (v : V) (m : list (K * V)), lookup k m = Some v <-> mapsto_alist m k v. Proof. reflexivity. Qed.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_lookup_alist
mapsto_remove_eq_alist : forall (m : list (K * V)) (k : K) (v : V), ~mapsto_alist (remove k m) k v. Proof. unfold mapsto_alist, remove, alist_remove; simpl. intros. induction m; simpl; auto. { congruence. } { destruct a; simpl in *. consider (k ?[ R ] k0); auto; intros. simpl. consider (k ?[ R ] k0); auto. } Qed.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_remove_eq_alist
mapsto_remove_neq_alist : forall (m : list (K * V)) (k : K), forall k', ~ R k k' -> forall v', (mapsto_alist m k' v' <-> mapsto_alist (remove k m) k' v'). Proof. unfold mapsto_alist, add; simpl. intros. induction m; simpl in *. { intuition. } { destruct a. simpl in *. consider (k' ?[ R ] k0); intros. { consider (k ?[ R ] k0); intros. { exfalso. eauto. } { simpl. consider (k' ?[ R ] k0); intros. { intuition. } { exfalso; auto. } } } { rewrite IHm. consider (k ?[ R ] k0); simpl; intros. { intuition. } { consider (k' ?[ R ] k0); intros. { exfalso; auto. } { intuition. } } } } Qed.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_remove_neq_alist
mapsto_add_eq_alist : forall (m : list (K * V)) (k : K) (v : V), mapsto_alist (add k v m) k v. Proof. unfold mapsto_alist, add, alist_add; simpl. intros. consider (k ?[ R ] k); auto. intro. exfalso. apply H. reflexivity. Qed.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_add_eq_alist
mapsto_add_neq_alist : forall (m : list (K * V)) (k : K) (v : V), forall k', ~ R k k' -> forall v', (mapsto_alist m k' v' <-> mapsto_alist (add k v m) k' v'). Proof. unfold mapsto_alist, add; simpl. intros. consider (k' ?[ R ] k); try solve [ intros; exfalso; auto ]. intros. eapply mapsto_remove_neq_alist in H. eapply H. Qed.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
mapsto_add_neq_alist
remove_eq_alist : forall (m : alist) (k : K), alist_find k (alist_remove k m) = None. Proof. unfold mapsto_alist. induction m; simpl; eauto; try congruence. intros; consider (k ?[ R ] fst a); simpl; intros; eauto. destruct a; simpl in *. consider (k ?[ R ] k0); eauto. tauto. Qed.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
remove_eq_alist
remove_neq_alist : forall (m : alist) (k k' : K), ~R k' k -> alist_find k (alist_remove k' m) = alist_find k m. Proof. unfold mapsto_alist. induction m; simpl; eauto; try congruence. destruct a; simpl. intros; consider (k' ?[ R ] k); simpl; intros; eauto. { consider (k0 ?[ R ] k); intros; eauto. exfalso. eapply H. etransitivity; eauto. } { consider (k0 ?[ R ] k); eauto. } Qed. Global Instance MapLaws_alist : MapOk R Map_alist. Proof. refine {| mapsto := fun k v m => mapsto_alist m k v |}; eauto using mapsto_lookup_alist, mapsto_add_eq_alist, mapsto_add_neq_alist. { intros; intro. inversion H. } { unfold mapsto_alist; simpl. intros. rewrite remove_eq_alist. congruence. } { unfold mapsto_alist. simpl; intros. erewrite (@remove_neq_alist m _ _ H). reflexivity. } Defined.
Theorem
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
remove_neq_alist
m := alist nat nat.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
m
Map_m : Map nat (alist nat). apply Map_alist. eauto with typeclass_instances. Defined.
Instance
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
Map_m
z : m := (fix fill n acc : m := let acc := add n n acc in match n with | 0 => acc | S n => fill n acc end) 500 empty. Time Eval compute in let z := z in (fix find_all n : unit := let _ := lookup n z in match n with | 0 => tt | S n => find_all n end) 500.
Definition
theories
[ "Require Import Coq.", "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "From Coq Require Import\n Basics." ]
theories/Data/Map/FMapAList.v
z
pmap : Type := | Empty | Branch : option T -> pmap -> pmap -> pmap.
Inductive
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap
pmap_here (m : pmap) : option T := match m with | Empty => None | Branch d _ _ => d end.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_here
pmap_left (m : pmap) : pmap := match m with | Empty => Empty | Branch _ l _ => l end.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_left
pmap_right (m : pmap) : pmap := match m with | Empty => Empty | Branch _ _ r => r end.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_right
pmap_lookup (p : positive) (m : pmap) {struct p} : option T := match m with | Empty => None | Branch d l r => match p with | xH => d | xO p => pmap_lookup p l | xI p => pmap_lookup p r end end.
Fixpoint
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup
pmap_insert (p : positive) (v : T) (m : pmap) {struct p} : pmap := match p with | xH => Branch (Some v) (pmap_left m) (pmap_right m) | xO p => Branch (pmap_here m) (pmap_insert p v (pmap_left m)) (pmap_right m) | xI p => Branch (pmap_here m) (pmap_left m) (pmap_insert p v (pmap_right m)) end.
Fixpoint
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_insert
branch (o : option T) (l r : pmap) : pmap := match o , l , r with | None , Empty , Empty => Empty | _ , _ , _ => Branch o l r end.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
branch
pmap_remove (p : positive) (m : pmap) {struct p} : pmap := match m with | Empty => Empty | Branch d l r => match p with | xH => branch None l r | xO p => branch d (pmap_remove p l) r | xI p => branch d l (pmap_remove p r) end end.
Fixpoint
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_remove
pmap_empty : pmap := Empty.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_empty
pmap_union (f m : pmap) : pmap := match f with | Empty => m | Branch d l r => Branch (match d with | Some x => Some x | None => pmap_here m end) (pmap_union l (pmap_left m)) (pmap_union r (pmap_right m)) end. Global Instance Map_pmap : Map positive T pmap := { empty := pmap_empty ; add := pmap_insert ; remove := pmap_remove ; lookup := pmap_lookup ; union := pmap_union }.
Fixpoint
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_union
tilde_1_inj_neg : forall k k', (k~1)%positive <> (k'~1)%positive -> k <> k'. Proof. induction k; destruct k'; intuition; try match goal with | H : _ = _ |- _ => inversion H; clear H; subst end; intuition eauto. Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
tilde_1_inj_neg
tilde_0_inj_neg : forall k k', (k~0)%positive <> (k'~0)%positive -> k <> k'. Proof. induction k; destruct k'; intuition; try match goal with | H : _ = _ |- _ => inversion H; clear H; subst end; intuition eauto. Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
tilde_0_inj_neg
pmap_lookup_insert_empty : forall k k' v, k <> k' -> pmap_lookup k' (pmap_insert k v Empty) = None. Proof. induction k; destruct k'; simpl; intros; eauto using tilde_0_inj_neg, tilde_1_inj_neg. destruct k'; simpl; auto. destruct k'; simpl; auto. destruct k'; simpl; auto. destruct k'; simpl; auto. congruence. Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_insert_empty
lookup_empty : forall k, pmap_lookup k Empty = None. Proof. destruct k; reflexivity. Qed. Hint Rewrite lookup_empty pmap_lookup_insert_empty using (eauto using tilde_1_inj_neg, tilde_1_inj_neg) : pmap_rw.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
lookup_empty
pmap_lookup_insert_eq : forall (m : pmap) (k : positive) (v : T), pmap_lookup k (pmap_insert k v m) = Some v. Proof. intros m k; revert m. induction k; simpl; intros; forward; Cases.rewrite_all_goal; eauto. Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_insert_eq
pmap_lookup_insert_Some_neq : forall (m : pmap) (k : positive) (v : T) (k' : positive), k <> k' -> forall v' : T, pmap_lookup k' m = Some v' <-> pmap_lookup k' (pmap_insert k v m) = Some v'. Proof. intros m k; revert m. induction k; simpl; intros; forward; Cases.rewrite_all_goal; autorewrite with pmap_rw; eauto. { destruct k'; simpl; destruct m; simpl; autorewrite with pmap_rw; Cases.rewrite_all_goal; try reflexivity. erewrite IHk; eauto using tilde_1_inj_neg. reflexivity. } { destruct k'; simpl; destruct m; simpl; autorewrite with pmap_rw; Cases.rewrite_all_goal; try reflexivity; try congruence. erewrite IHk. reflexivity. eauto using tilde_0_inj_neg. } { destruct k'; simpl; destruct m; simpl; autorewrite with pmap_rw; Cases.rewrite_all_goal; try reflexivity; try congruence. } Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_insert_Some_neq
pmap_lookup_insert_None_neq : forall (m : pmap) (k : positive) (v : T) (k' : positive), k <> k' -> pmap_lookup k' m = None <-> pmap_lookup k' (pmap_insert k v m) = None. Proof. intros m k; revert m. induction k; simpl; intros; forward; Cases.rewrite_all_goal; autorewrite with pmap_rw; eauto. { destruct k'; simpl; destruct m; simpl; autorewrite with pmap_rw; Cases.rewrite_all_goal; try reflexivity. erewrite IHk; eauto using tilde_1_inj_neg. reflexivity. } { destruct k'; simpl; destruct m; simpl; autorewrite with pmap_rw; Cases.rewrite_all_goal; try reflexivity; try congruence. erewrite IHk. reflexivity. eauto using tilde_0_inj_neg. } { destruct k'; simpl; destruct m; simpl; autorewrite with pmap_rw; Cases.rewrite_all_goal; try reflexivity; try congruence. } Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_insert_None_neq
pmap_lookup_insert_neq : forall (m : pmap) (k : positive) (v : T) (k' : positive), k <> k' -> forall v' : T, pmap_lookup k' (pmap_insert k v m) = pmap_lookup k' m. Proof. intros. remember (pmap_lookup k' m). destruct o; [ apply pmap_lookup_insert_Some_neq; intuition | apply pmap_lookup_insert_None_neq; intuition]. Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_insert_neq
pmap_lookup_remove_eq : forall (m : pmap) (k : positive) (v : T), pmap_lookup k (pmap_remove k m) <> Some v. Proof. induction m; destruct k; simpl; intros; try congruence. { destruct o; simpl; eauto. destruct m1; simpl; eauto. destruct (pmap_remove k m2) eqn:?; try congruence. rewrite <- Heqp. eauto. } { destruct o; simpl; eauto. destruct (pmap_remove k m1) eqn:?; try congruence. - destruct m2; try congruence; eauto. destruct k; simpl; congruence. - rewrite <- Heqp. eauto. } { destruct m1; try congruence. destruct m2; try congruence. } Qed.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_remove_eq
pmap_lookup_remove_neq : forall (m : pmap) (k k' : positive), k <> k' -> forall v' : T, pmap_lookup k' m = Some v' <-> pmap_lookup k' (pmap_remove k m) = Some v'. Proof. induction m. Local Ltac t := unfold branch; repeat match goal with | |- context [ match ?X with _ => _ end ] => lazymatch X with | match _ with _ => _ end => fail | _ => destruct X eqn:?; subst; try tauto end end. { destruct k; simpl; split; try congruence. } { destruct k', k; simpl; intros; try solve [ t; rewrite lookup_empty; tauto ]. { assert (k <> k') by congruence. rewrite IHm2; eauto. simpl. t. rewrite lookup_empty. tauto. } { assert (k <> k') by congruence. rewrite IHm1; eauto. simpl. t. rewrite lookup_empty. tauto. } } Qed. Global Instance MapOk_pmap : MapOk (@eq _) Map_pmap. Proof. refine {| mapsto := fun k v m => pmap_lookup k m = Some v |}. { abstract (induction k; simpl; congruence). } { abstract (induction k; simpl; intros; forward). } { eauto using pmap_lookup_insert_eq. } { eauto using pmap_lookup_insert_Some_neq. } { eauto using pmap_lookup_remove_eq. } { eauto using pmap_lookup_remove_neq. } Defined.
Lemma
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
pmap_lookup_remove_neq
from_list : list T -> pmap := (fix from_list acc i ls {struct ls} := match ls with | nil => acc | List.cons l ls => from_list (pmap_insert i l acc) (Pos.succ i) ls end) Empty 1%positive.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
from_list
fmap_pmap (m : pmap T) : pmap U := match m with | Empty => Empty | Branch h l r => Branch (fmap f h) (fmap_pmap l) (fmap_pmap r) end.
Fixpoint
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
fmap_pmap
fmap_lookup : forall a b m, mapsto a b m -> mapsto a (f b) (fmap_pmap m). Proof. induction a; destruct m; simpl; intros; try congruence. { eapply IHa. eapply H. } { eapply IHa; eapply H. } { subst. auto. } Qed.
Theorem
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
fmap_lookup
fmap_lookup_bk : forall a b m, mapsto a b (fmap_pmap m) -> exists b', mapsto a b' m /\ f b' = b. Proof. induction a; destruct m; simpl; intros; try congruence. { eapply IHa. eapply H. } { eapply IHa. eapply H. } { destruct o; try congruence. eexists; split; eauto. inversion H; auto. } Qed.
Theorem
theories
[ "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapPositive.v
fmap_lookup_bk
twothree (T : Type) : Type := | Leaf | Two : twothree T -> K -> T -> twothree T -> twothree T | Three : twothree T -> K -> T -> twothree T -> K -> T -> twothree T -> twothree T. Arguments Leaf {T}. Arguments Two {T} _ _ _ _. Arguments Three {T} _ _ _ _ _ _ _.
Inductive
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree
remove_greatest (m : twothree V) {T} (k_oops : unit -> T) (k_ok : K -> V -> twothree V -> T) : T := match m with | Leaf => k_oops tt | Two l k v r => remove_greatest r (fun _ => k_ok k v l) (fun k' v' r' => k_ok k' v' (Two l k v r')) | Three l k v m k' v' r => remove_greatest r (fun _ => k_ok k' v' (Two l k v m)) (fun k'' v'' r'' => k_ok k'' v'' (Three l k v m k' v' r'')) end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
remove_greatest
twothree_modify (m : twothree V) {T} (k_ok : twothree V -> T) (k_splice_up : twothree V -> K -> V -> twothree V -> T) {struct m} : T := match m with | Leaf => match def with | Some v => k_splice_up Leaf k v Leaf | None => k_ok Leaf end | Two l k' v' r => match RD_K k k' with | Eq => match upd v' with | Some v' => k_ok (Two l k v' r) | None => remove_greatest l (fun _ => k_ok r) (fun k v l => k_ok (Two l k v r)) end | Lt => twothree_modify l (fun l => k_ok (Two l k' v' r)) (fun l'' k'' v'' r'' => k_ok (Three l'' k'' v'' r'' k' v' r)) | Gt => twothree_modify r (fun r => k_ok (Two l k' v' r)) (fun l'' k'' v'' r'' => k_ok (Three l k' v' l'' k'' v'' r'')) end | Three l k1 v1 m k2 v2 r => match RD_K k k1 with | Eq => match upd v1 with | Some v' => k_ok (Three l k v' m k2 v2 r) | None => remove_greatest l (fun _ => k_ok (Two m k2 v2 r)) (fun k1 v1 l => k_ok (Three l k1 v2 m k2 v2 r)) end | Lt => twothree_modify l (fun l' => k_ok (Three l' k1 v1 m k2 v2 r)) (fun l' k' v' r' => k_splice_up (Two l' k' v' r') k1 v1 (Two m k2 v2 r)) | Gt => match RD_K k k2 with | Eq => match upd v2 with | Some v2 => k_ok (Three l k1 v1 m k v2 r) | None => remove_greatest m (fun _ => k_ok (Two l k1 v1 r)) (fun k' v' m' => k_ok (Three l k1 v1 m' k' v' r)) end | Lt => twothree_modify m (fun m' => k_ok (Three l k1 v1 m' k2 v2 r)) (fun l' k' v' r' => k_splice_up (Two l k1 v1 l') k' v' (Two r' k2 v2 r)) | Gt => twothree_modify r (fun r' => k_ok (Three l k1 v1 m k2 v2 r')) (fun l' k' v' r' => k_splice_up (Two l k1 v1 m) k2 v2 (Two l' k' v' r')) end end end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree_modify
twothree_add {V} (k : K) (v : V) (m : twothree V) : twothree V := twothree_modify k (fun _ => Some v) (Some v) m (fun m => m) Two.
Definition
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree_add
twothree_remove {V} (k : K) (m : twothree V) : twothree V := twothree_modify k (fun _ => None) None m (fun m => m) Two.
Definition
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree_remove
twothree_find {V} (k : K) (m : twothree V) : option V := match m with | Leaf => None | Two l k' v' r => match RD_K k k' with | Eq => Some v' | Lt => twothree_find k l | Gt => twothree_find k r end | Three l k1 v1 m k2 v2 r => match RD_K k k1 with | Eq => Some v1 | Lt => twothree_find k l | Gt => match RD_K k k2 with | Eq => Some v2 | Lt => twothree_find k m | Gt => twothree_find k r end end end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree_find
twothree_fold (acc : T) (map : twothree V) : T := match map with | Leaf => acc | Two l k v r => let acc := twothree_fold acc l in let acc := f k v acc in twothree_fold acc r | Three l k1 v1 m k2 v2 r => let acc := twothree_fold acc l in let acc := f k1 v1 acc in let acc := twothree_fold acc m in let acc := f k2 v2 acc in twothree_fold acc r end.
Fixpoint
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree_fold
twothree_union {V} (m1 m2 : twothree V) : twothree V := twothree_fold twothree_add m2 m1. Global Instance Map_twothree V : Map K V (twothree V) := { empty := Leaf ; add := twothree_add ; remove := twothree_remove ; lookup := twothree_find ; union := twothree_union }. Global Instance Foldable_twothree V : Foldable (twothree V) (K * V) := fun _ f b x => twothree_fold (fun k v => f (k,v)) b x.
Definition
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
twothree_union
m := twothree nat nat.
Definition
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
m
Map_m : Map nat (twothree nat). apply Map_twothree. apply Compare_dec.nat_compare. Defined.
Instance
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
Map_m
z : m := (fix fill n acc : m := let acc := add n n acc in match n with | 0 => acc | S n => fill n acc end) 500 empty. Time Eval vm_compute in let z := z in (fix find_all n : unit := let _ := lookup n z in match n with | 0 => tt | S n => find_all n end) 500.
Definition
theories
[ "Require Import Coq.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Map/FMapTwoThreeK.v
z
cont (t : Type) : Type := mkCont { runCont : (t -> Ans) -> Ans }. Global Instance Monad_cont : Monad cont := { ret := fun _ v => mkCont (fun k => k v) ; bind := fun _ c1 _ c2 => mkCont (fun k => runCont c1 (fun t => runCont (c2 t) k)) }. Global Instance Cont_cont : Cont cont := { callCC := fun _ _ f => mkCont (fun c => runCont (f (fun x => mkCont (fun _ => c x))) c) }.
Record
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
cont
mapCont (f : Ans -> Ans) {a} (c : cont a) : cont a := mkCont (fun x => f (runCont c x)).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
mapCont
withCont {a b} (f : (b -> Ans) -> (a -> Ans)) (c : cont a) : cont b := mkCont (fun x => runCont c (f x)). *) Variable M : Type -> Type.
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
withCont
contT (A : Type) : Type := mkContT { runContT : (A -> M R) -> M R }. Global Instance Monad_contT : Monad contT := { ret := fun _ x => mkContT (fun k => k x) ; bind := fun _ _ c1 c2 => mkContT (fun c => runContT c1 (fun a => runContT (c2 a) c)) }. Global Instance MonadT_contT {Monad_M : Monad M} : MonadT contT M := { lift := fun _ c => mkContT (bind c) }. (*
Record
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
contT
mapContT (f : m Ans -> m Ans) {a} (c : contT a) : contT a := mkContT (fun x => f (runContT c x)).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
mapContT
withContT {a b} (f : (b -> m Ans) -> (a -> m Ans)) (c : contT a) : contT b := mkContT (fun x => runContT c (f x)). *)
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
withContT
resetT {M} {Monad_M : Monad M} {R R'} (u : contT R M R) : contT R' M R := mkContT (fun k => bind (runContT u ret) k).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
resetT
shiftT {M} {Monad_M : Monad M} {R A} (f : (A -> M R) -> contT R M R) : contT R M A := mkContT (fun k => runContT (f k) ret).
Definition
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/ContMonad.v
shiftT
eitherT A := mkEitherT { unEitherT : m (sum T A) }. Variable M : Monad m. Global Instance Monad_eitherT : Monad eitherT := { ret := fun _ x => mkEitherT (ret (inr x)) ; bind := fun _ _ c f => mkEitherT ( xM <- unEitherT c ;; match xM with | inl x => ret (inl x) | inr x => unEitherT (f x) end ) }. Global Instance Exception_eitherT : MonadExc T eitherT := { raise := fun _ v => mkEitherT (ret (inl v)) ; catch := fun _ c h => mkEitherT ( xM <- unEitherT c ;; match xM with | inl x => unEitherT (h x) | inr x => ret (inr x) end ) }. Global Instance MonadPlus_eitherT : MonadPlus eitherT := { mplus _A _B mA mB := mkEitherT ( x <- unEitherT mA ;; match x with | inl _ => y <- unEitherT mB ;; match y with | inl t => ret (inl t) | inr b => ret (inr (inr b)) end | inr a => ret (inr (inl a)) end ) }. Global Instance MonadT_eitherT : MonadT eitherT m := { lift := fun _ c => mkEitherT (liftM inr c) }. Global Instance MonadState_eitherT {T} (MS : MonadState T m) : MonadState T eitherT := { get := lift get ; put := fun v => lift (put v) }. Global Instance MonadReader_eitherT {T} (MR : MonadReader T m) : MonadReader T eitherT := { ask := lift ask ; local := fun _ f cmd => mkEitherT (local f (unEitherT cmd)) }. Global Instance MonadWriter_eitherT {T} (Mon : Monoid T) (MW : MonadWriter Mon m) : MonadWriter Mon eitherT := { tell := fun x => lift (tell x) ; listen := fun _ c => mkEitherT ( x <- listen (unEitherT c) ;; match x with | (inl l, _) => ret (inl l) | (inr a, t) => ret (inr (a, t)) end) ; pass := fun _ c => mkEitherT ( x <- unEitherT c ;; match x with | inl s => ret (inl s) | inr (a,f) => pass (ret (inr a, f)) end) }. Global Instance MonadFix_eitherT (MF : MonadFix m) : MonadFix eitherT := { mfix := fun _ _ r v => mkEitherT (mfix (fun f x => unEitherT (r (fun x => mkEitherT (f x)) x)) v) }.
Inductive
theories
[ "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/EitherMonad.v
eitherT
FixResult (T : Type) := | Term : T -> FixResult T | Diverge : FixResult T. Arguments Diverge {_}. Arguments Term {_} _. (** The GFix monad is like monad fix except that it encapsulates the "gas" that is used as the measure **)
Inductive
theories
[ "Require Import ExtLib.", "Require Import BinPos.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonad.v
FixResult
GFix (T : Type) : Type := mkGFix { runGFix : N -> FixResult T }. Global Instance MonadFix_GFix : MonadFix GFix := { mfix := fun T U f v => mkGFix (fun n : N => match n with | N0 => Diverge | Npos g => let F := fix rec (acc : T -> FixResult U) (gas : positive) (x : T) : FixResult U := match gas return FixResult U with | xI p => runGFix (f (fun x => mkGFix (fun n => rec (fun x => rec acc p x) p x)) x) n | xO p => rec (fun x => rec acc p x) p x | xH => runGFix (f (fun x => mkGFix (fun _ => acc x)) x) n end in F (fun x => runGFix (f (fun _ => mkGFix (fun _ => Diverge)) x) n) g v end) }. Global Instance Monad_GFix : Monad GFix := { ret := fun _ v => mkGFix (fun _ => Term v) ; bind := fun _ _ c1 c2 => mkGFix (fun gas => match runGFix c1 gas with | Diverge => Diverge | Term v => runGFix (c2 v) gas end) }.
Inductive
theories
[ "Require Import ExtLib.", "Require Import BinPos.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonad.v
GFix
foo : nat -> GFix ident nat := mfix (fun recur n => match n with | 0 => ret 0 | S n => recur n end). Eval compute in runGFix (foo 10) 100000000000000000000000. **)
Definition
theories
[ "Require Import ExtLib.", "Require Import BinPos.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonad.v
foo
FixResult_eq (a b : FixResult T) : Prop := match a , b with | Diverge , Diverge => True | Term a , Term b => equal a b | _ , _ => False end. Global Instance type_FixResult : type (FixResult T) := type_from_equal FixResult_eq. Variable tokE : typeOk e. Global Instance typeOk_FixResult : typeOk type_FixResult. Proof. eapply typeOk_from_equal. { unfold proper; simpl. destruct x; destruct y; simpl; intros; auto; try contradiction. apply only_proper in H; auto. destruct H; split; apply tokE; assumption. } { red. destruct x; destruct y; simpl; auto; simpl. symmetry; auto. } { red. destruct x; destruct y; destruct z; simpl; intros; auto; try contradiction. etransitivity; eauto. } Qed.
Definition
theories
[ "Require Import RelationClasses.", "Require Import Setoid.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonadLaws.v
FixResult_eq
fix_meq (l r : GFix T) : Prop := equal (runGFix l) (runGFix r). Global Instance type_GFix : type (GFix T) := type_from_equal fix_meq. Global Instance typeOk_GFix : typeOk type_GFix. Proof. eapply typeOk_from_equal. { destruct x; destruct y; simpl. intros; split; intros. { red; simpl. red in H; red. simpl FuelMonad.runGFix in *. eapply only_proper in H; eauto with typeclass_instances. intros; subst. eapply preflexive with (wf := proper); eauto with typeclass_instances. eapply equiv_prefl; eauto with typeclass_instances. solve_proper; intuition. } { red; simpl. red in H; red; simpl FuelMonad.runGFix in *. eapply only_proper in H; eauto with typeclass_instances. intros; subst. eapply preflexive with (wf := proper); eauto with typeclass_instances. eapply equiv_prefl; eauto with typeclass_instances. solve_proper. intuition. } } { red. destruct x; destruct y; simpl; unfold fix_meq. simpl FuelMonad.runGFix in *. intros. symmetry; auto. } { red; destruct x; destruct y; destruct z; simpl; unfold fix_meq; simpl FuelMonad.runGFix in *. intros. etransitivity; eauto. } Qed. Global Instance proper_runGFix : proper (@runGFix T). Proof. repeat red; simpl; intros. eapply H. subst. reflexivity. Qed. Global Instance proper_mkGFix : proper (@mkGFix T). Proof. repeat red; simpl; intros. eapply H. subst. reflexivity. Qed.
Definition
theories
[ "Require Import RelationClasses.", "Require Import Setoid.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonadLaws.v
fix_meq
Diverge_minimal : forall C (eC : relation C) x, FixResult_leq eC Diverge x. Proof. destruct x; compute; auto. Qed.
Theorem
theories
[ "Require Import RelationClasses.", "Require Import Setoid.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonadLaws.v
Diverge_minimal
Term_maximal : forall C (eC : relation C) x y, FixResult_leq eC (Term x) y -> exists z, y = Term z /\ eC x z. Proof. destruct y; simpl; intros; try contradiction; eauto. Qed.
Theorem
theories
[ "Require Import RelationClasses.", "Require Import Setoid.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonadLaws.v
Term_maximal
leq_app : forall B C (eB : relation B) (eC : relation C) (pB : Proper eB) (pC : Proper eC) g (b b' : B) n n', proper g -> proper b -> proper b' -> eB b b' -> BinNat.N.le n n' -> FixResult_leq eC (runGFix (g b) n) (runGFix (g b') n'). Proof. intros. destruct H. specialize (H4 _ _ H0 H1 H2 _ _ H3). auto. Qed. *)
Lemma
theories
[ "Require Import RelationClasses.", "Require Import Setoid.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/FuelMonadLaws.v
leq_app
ident A := mkIdent { unIdent : A }. Global Instance Monad_ident : Monad ident := { ret := fun _ v => mkIdent v ; bind := fun _ _ c f => f (unIdent c) }.
Inductive
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IdentityMonad.v
ident
equal_ident (a b : ident T) : Prop := equal (unIdent a) (unIdent b). Global Instance type_ident : type (ident T) := { equal := equal_ident ; proper := fun x => proper (unIdent x) }. Global Instance typeOk_ident (tT : typeOk e) : typeOk type_ident. Proof. constructor. { unfold equal, proper, type_ident, equal_ident; simpl; intros. apply only_proper; auto. } { red. destruct x. intros. red; simpl. red; simpl. eapply preflexive with (wf := proper); eauto with typeclass_instances. } { red. simpl. unfold equal_ident. intros. symmetry. assumption. } { red; simpl. unfold equal_ident. intros. etransitivity; eassumption. } Qed. Global Instance proper_unIdent : proper unIdent. Proof. red; simpl; red; simpl. destruct x; compute; auto. Qed. Global Instance proper_mkIdent : proper mkIdent. Proof. do 7 red. compute; auto. Qed.
Definition
theories
[ "Require Import Coq.", "Require Import Setoid.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib.", "Require Import ExtLib." ]
theories/Data/Monads/IdentityMonadLaws.v
equal_ident
istate (i s t: Type) : Type := mkIState { runIState : i -> t * s }.
Record
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IStateMonad.v
istate
evalState {i s t} (c : istate i s t) (s : i) : t := fst (runIState c s).
Definition
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IStateMonad.v
evalState
execState {i s t} (c : istate i s t) (st : i) : s := snd (runIState c st). Global Instance IMonad_Ixstate : IxMonad istate := { ret := fun _ _ v => mkIState (fun s => (v, s)) ; bind := fun _ _ _ _ _ c1 c2 => mkIState (fun s => let (v,s) := runIState c1 s in runIState (c2 v) s) }.
Definition
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IStateMonad.v
execState
get {i : Type} := @mkIState i i i (fun s => (s,s)).
Definition
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IStateMonad.v
get
put {i o : Type} := (fun v => @mkIState i o unit (fun _ => (tt, v))).
Definition
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IStateMonad.v
put
put_ {i o : Type} (s : o) : istate i o unit := (bind (put s) (fun _ => ret tt)).
Definition
theories
[ "Require Import ExtLib." ]
theories/Data/Monads/IStateMonad.v
put_