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 |
|---|---|---|---|---|---|---|
modify {i o : Type} (f : i -> o) : istate i o i := bind get (fun x : i => bind (put (f x)) (fun _ : unit => ret x)). | Definition | theories | [
"Require Import ExtLib."
] | theories/Data/Monads/IStateMonad.v | modify | |
modify_ {i o : Type} (f : i -> o) : istate i o unit := bind (modify f) (fun _ => ret tt). | Definition | theories | [
"Require Import ExtLib."
] | theories/Data/Monads/IStateMonad.v | modify_ | |
optionT a := mkOptionT { unOptionT : m (option a) }. Context {M : Monad m}. Global Instance Monad_optionT : Monad optionT := { ret _A := fun x => mkOptionT (ret (Some x)) ; bind _A _B aMM f := mkOptionT (aM <- unOptionT aMM ;; match aM with | None => ret None | Some a => unOptionT (f a) end) }. Global Instance Zero_optionT : MonadZero optionT := { mzero _A := mkOptionT (ret None) }. Global Instance MonadT_optionT : MonadT optionT m := { lift _A aM := mkOptionT (liftM Some aM) }. Global Instance State_optionT {T} (SM : MonadState T m) : MonadState T optionT := { get := lift get ; put v := lift (put v) }. | Inductive | theories | [
"Require Import ExtLib."
] | theories/Data/Monads/OptionMonad.v | optionT | |
Plus_optionT_right : MonadPlus optionT := { mplus _A _B a b := mkOptionT (bind (unOptionT b) (fun b => match b with | None => bind (unOptionT a) (fun a => match a with | None => ret None | Some a => ret (Some (inl a)) end) | Some b => ret (Some (inr b)) end)) }. | Instance | theories | [
"Require Import ExtLib."
] | theories/Data/Monads/OptionMonad.v | Plus_optionT_right | |
Plus_optionT_left : MonadPlus optionT := { mplus _A _B a b := mkOptionT (bind (unOptionT a) (fun a => match a with | None => bind (unOptionT b) (fun b => match b with | None => ret None | Some b => ret (Some (inr b)) end) | Some a => ret (Some (inl a)) end)) }. Global Instance Plus_optionT : MonadPlus optionT := Plus_optionT_left. Global Instance Reader_optionT {T} (SM : MonadReader T m) : MonadReader T optionT := { ask := lift ask ; local _T v cmd := mkOptionT (local v (unOptionT cmd)) }. | Instance | theories | [
"Require Import ExtLib."
] | theories/Data/Monads/OptionMonad.v | Plus_optionT_left | |
OptionTError : MonadExc unit optionT := { raise _u _A := mzero ; catch _A aMM f := mkOptionT (aM <- unOptionT aMM ;; match aM with | None => unOptionT (f tt) | Some x => ret (Some x) end) }. | Instance | theories | [
"Require Import ExtLib."
] | theories/Data/Monads/OptionMonad.v | OptionTError | |
optionT_eq (a b : optionT m T) : Prop := equal (unOptionT a) (unOptionT b). Global Instance type_optionT : type (optionT m T) := type_from_equal optionT_eq. Variable tokT : typeOk tT. Global Instance typeOk_readerT : typeOk type_optionT. Proof. eapply typeOk_from_equal. { simpl. unfold optionT_eq. intros. generalize (only_proper _ _ _ H); intros. split; solve_equal. } { red. unfold equal; simpl. unfold optionT_eq; simpl. unfold Morphisms.respectful; simpl. symmetry. auto. } { red. unfold equal; simpl. unfold optionT_eq; simpl. unfold Morphisms.respectful; simpl. intros. etransitivity; eauto. } Qed. Global Instance proper_unOptionT : proper (@unOptionT m T). Proof. do 3 red; eauto. Qed. Global Instance proper_mkOptionT : proper (@mkOptionT m T). Proof. do 5 red; 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/OptionMonadLaws.v | optionT_eq | |
equal_match : forall (A B : Type) (eA : type A) (eB : type B), typeOk eA -> typeOk eB -> forall (x y : option A) (a b : B) (f g : A -> B), equal x y -> equal a b -> equal f g -> equal match x with | Some a => f a | None => a end match y with | Some a => g a | None => b end. Proof. destruct x; destruct y; intros; eauto with typeclass_instances; type_tac. { inversion H1. assumption. } { inversion H1. } { inversion H1. } 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/OptionMonadLaws.v | equal_match | |
proper_match : forall (A B : Type) (eA : type A) (eB : type B), typeOk eA -> typeOk eB -> forall (x : option A), proper x -> forall f : A -> optionT m B, proper f -> proper match x with | Some a => unOptionT (f a) | None => ret None end. Proof. destruct x; intros; eauto with typeclass_instances; type_tac. Qed. Global Instance MonadLaws_optionT : MonadLaws (@Monad_optionT _ Monad_m) type_optionT. Proof. constructor. { (* bind_of_return *) intros. do 3 red. unfold bind, optionT_eq; simpl. rewrite bind_of_return; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. } { (* return_of_bind *) simpl; unfold optionT_eq; simpl; intros. rewrite return_of_bind; eauto with typeclass_instances; intros; type_tac. destruct x; type_tac. } { (* bind_associativity *) simpl; unfold optionT_eq; simpl; intros. rewrite bind_associativity; eauto with typeclass_instances; intros; type_tac. destruct x; destruct y; try solve [ inversion H5 ]; type_tac. inversion H5; assumption. eapply equal_match; eauto with typeclass_instances; type_tac. rewrite bind_of_return; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. } { simpl; unfold optionT_eq; simpl; intros. red; simpl; intros. type_tac. } { simpl; unfold optionT_eq; simpl; intros. red; simpl; intros. red; simpl; intros. type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. } Qed. (* Theorem equal_match_option : forall T U (tT : type T) (tU : type U), typeOk tT -> typeOk tU -> forall (a b : option T) (f g : T -> U) (x y : U), equal a b -> equal f g -> equal x y -> equal match a with | Some a => f a | None => x end match b with | Some b => g b | None => y end. Proof. clear. destruct a; destruct b; simpl; intros; try contradiction; auto. Qed. *) Global Instance MonadTLaws_optionT : MonadTLaws _ _ _ _ (@MonadT_optionT _ Monad_m). Proof. constructor. { simpl. unfold optionT_eq; simpl; intros. unfold liftM. rewrite bind_of_return; eauto with typeclass_instances; type_tac. } { simpl; unfold lift, optionT_eq; simpl; intros. unfold liftM. rewrite bind_associativity; eauto with typeclass_instances; type_tac. rewrite bind_associativity; eauto with typeclass_instances; type_tac. rewrite bind_of_return; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. } { unfold lift, liftM; simpl; intros. unfold liftM. red; simpl; intros. unfold optionT_eq; simpl. type_tac. } Qed. Global Instance MonadReaderLaws_optionT (s : Type) (t : type s) (tT : typeOk t) (Mr : MonadReader s m) (MLr : MonadReaderLaws Monad_m _ _ Mr) : MonadReaderLaws _ _ _ (@Reader_optionT _ _ _ Mr). Proof. constructor. { simpl. unfold optionT_eq; simpl; intros; unfold liftM. rewrite local_bind; eauto with typeclass_instances. (erewrite bind_proper; [ | | | | eapply ask_local | ]); eauto with typeclass_instances. rewrite bind_associativity; eauto with typeclass_instances. rewrite bind_associativity; eauto with typeclass_instances. type_tac. 6: eapply preflexive. repeat rewrite bind_of_return; eauto with typeclass_instances. rewrite local_ret; eauto with typeclass_instances. type_tac. type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. apply proper_fun; intros. repeat rewrite local_ret; eauto with typeclass_instances. type_tac; eauto with typeclass_instances. type_tac. type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. type_tac. apply proper_fun; intros. repeat rewrite local_ret; eauto with typeclass_instances. type_tac. eauto with typeclass_instances. type_tac. type_tac. } { simpl. unfold optionT_eq; simpl; intros; unfold liftM. rewrite local_bind; eauto with typeclass_instances. type_tac. destruct x; destruct y; try solve [ inversion H4 ]; type_tac. inversion H4; assumption. rewrite local_ret; eauto with typeclass_instances; type_tac. type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. } { simpl. unfold optionT_eq; simpl; intros; unfold liftM. rewrite local_ret; eauto with typeclass_instances; type_tac. } { simpl. unfold optionT_eq; simpl; intros; unfold liftM. rewrite local_local; eauto with typeclass_instances; type_tac. } { unfold local; simpl; intros. red. red. intros. red in H0. red; simpl. type_tac. } { Opaque lift. unfold ask; simpl; intros. red. type_tac. eapply lift_proper; eauto with typeclass_instances. Transparent lift. } Qed. (* Global Instance MonadStateLaws_optionT (s : Type) (t : type s) (tT : typeOk t) (Ms : MonadState s m) (MLs : MonadStateLaws Monad_m _ _ Ms) : MonadStateLaws _ _ _ (@State_optionT _ _ _ Ms). Proof. constructor. { simpl; unfold optionT_eq; simpl; intros; unfold liftM; simpl. rewrite bind_associativity; eauto with typeclass_instances; type_tac. erewrite bind_proper; eauto with typeclass_instances. 2: instantiate (1 := get); type_tac. instantiate (1 := fun a => bind (put a) (fun x : unit => ret (Some x))). { rewrite <- bind_associativity; eauto with typeclass_instances; type_tac. erewrite bind_proper; eauto with typeclass_instances. 2: eapply get_put; eauto with typeclass_instances. rewrite bind_of_return; eauto with typeclass_instances. instantiate (1 := fun x => ret (Some x)). simpl. type_tac. type_tac. type_tac. } { type_tac. rewrite bind_of_return; eauto with typeclass_instances. type_tac. type_tac. eapply equal_match_option; eauto with typeclass_instances; type_tac. } { eapply equal_match_option; eauto with typeclass_instances; type_tac. } } { simpl; unfold optionT_eq; simpl; intros; unfold liftM; simpl. repeat rewrite bind_associativity; eauto with typeclass_instances; try solve [ type_tac; eapply equal_match_option; eauto with typeclass_instances; type_tac ]. rewrite bind_proper; eauto with typeclass_instances. 2: eapply preflexive; eauto with typeclass_instances; type_tac. instantiate (1 := fun a : unit => bind get (fun x0 : s => ret (Some x0))). { rewrite <- bind_associativity; eauto with typeclass_instances. Require Import MonadTac. { | Instance | 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/OptionMonadLaws.v | proper_match | |
cl := eauto with typeclass_instances. | Ltac | 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/OptionMonadLaws.v | cl | |
tcl := solve [ cl ]. | Ltac | 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/OptionMonadLaws.v | tcl | |
monad_rewrite t := first [ t | rewrite bind_rw_0; [ | tcl | tcl | tcl | t | type_tac ] | rewrite bind_rw_1 ]. monad_rewrite ltac:(eapply put_get; eauto with typeclass_instances). rewrite bind_associativity; cl; try solve_proper. rewrite bind_rw_1; [ | tcl | tcl | tcl | intros | type_tac ]. Focus 2. etransitivity. eapply bind_of_return; cl; type_tac. instantiate (1 := fun _ => ret (Some x)). simpl. type_tac. | Ltac | 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/OptionMonadLaws.v | monad_rewrite | |
Parametric Morphism (T : Type) (tT : type T) (tokT : typeOk tT) : (@equal _ tT) with signature (equal ==> equal ==> iff) as equal_mor. Proof. clear - tokT. intros. split; intros. { etransitivity. symmetry; eassumption. etransitivity; eassumption. } { etransitivity; eauto. etransitivity; eauto. symmetry; auto. } Qed. | Add | 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/OptionMonadLaws.v | Parametric | |
Parametric Morphism (T : Type) (tT : type T) (tokT : typeOk tT) : (@equal _ tT) with signature (equal ==> eq ==> iff) as equal_left_mor. Proof. clear - tokT. intros. split; intros. { etransitivity. symmetry; eassumption. eassumption. } { etransitivity; eauto. } Qed. | Add | 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/OptionMonadLaws.v | Parametric | |
Parametric Morphism (T : Type) (tT : type T) (tokT : typeOk tT) : (@equal _ tT) with signature (eq ==> equal ==> iff) as equal_right_mor. Proof. clear - tokT. intros. split; intros. { etransitivity. eassumption. eassumption. } { etransitivity; eauto. symmetry; auto. } Qed. assert (Morphisms.Proper (equal ==> Basics.flip Basics.impl) (equal (bind (put x) (fun _ : unit => ret (Some x))))) by cl. assert (Morphisms.Proper (Morphisms.pointwise_relation unit equal ==> equal) (bind (@put _ _ Ms x))). { red. red. intros. eapply bind_proper; cl. solve_proper. red; simpl. red in H1. red. assert bind_proper. debug eauto with typeclass_instances. setoid_rewrite bind_of_return. 2: rewrite bind_of_return; eauto with typeclass_instances; type_tac. rewrite bind_rw_0 3: instantiate (1 := (bind (put x) (fun _ : unit => get))). | Add | 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/OptionMonadLaws.v | Parametric | |
bind_rw_0 : forall A B (tA : type A) (tB : type B), typeOk tA -> typeOk tB -> forall (x z : m A) (y : A -> m B)z, equal x z -> proper y -> equal (bind x y) (bind z y). Proof. } { type_tac. rewrite bind_of_return; eauto with typeclass_instances; type_tac. eapply equal_match_option; eauto with typeclass_instances; type_tac. } } Print MonadStateLaws. *) Global Instance MonadZeroLaws_optionT : MonadZeroLaws (@Monad_optionT _ Monad_m) type_optionT _. Proof. constructor. { simpl; unfold optionT_eq; simpl; intros. rewrite bind_of_return; eauto with typeclass_instances; type_tac. eapply equal_match; eauto with typeclass_instances; type_tac. } { unfold mzero; simpl; intros. red; simpl. type_tac. } 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/OptionMonadLaws.v | bind_rw_0 | |
reader (t : Type) : Type := mkReader { runReader : S -> t }. Global Instance Monad_reader : Monad reader := { ret := fun _ v => mkReader (fun _ => v) ; bind := fun _ _ c1 c2 => mkReader (fun s => let v := runReader c1 s in runReader (c2 v) s) }. Global Instance MonadReader_reader : MonadReader S reader := { ask := mkReader (fun x => x) ; local := fun _ f cmd => mkReader (fun x => runReader cmd (f x)) }. Variable m : Type -> Type. | Record | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/ReaderMonad.v | reader | |
readerT (t : Type) : Type := mkReaderT { runReaderT : S -> m t }. Variable M : Monad m. Global Instance Monad_readerT : Monad readerT := { ret := fun _ x => mkReaderT (fun s => @ret _ M _ x) ; bind := fun _ _ c1 c2 => mkReaderT (fun s => @bind _ M _ _ (runReaderT c1 s) (fun v => runReaderT (c2 v) s)) }. Global Instance MonadReader_readerT : MonadReader S readerT := { ask := mkReaderT (fun x => ret x) ; local := fun _ f cmd => mkReaderT (fun x => runReaderT cmd (f x)) }. Global Instance MonadT_readerT : MonadT readerT m := { lift := fun _ c => mkReaderT (fun _ => c) }. Global Instance MonadZero_readerT (MZ : MonadZero m) : MonadZero readerT := { mzero := fun _ => lift mzero }. Global Instance MonadState_readerT T (MS : MonadState T m) : MonadState T readerT := { get := lift get ; put := fun x => lift (put x) }. Global Instance MonadWriter_readerT T (Mon : Monoid T) (MW : MonadWriter Mon m) : MonadWriter Mon readerT := { tell := fun v => lift (tell v) ; listen := fun _ c => mkReaderT (fun s => listen (runReaderT c s)) ; pass := fun _ c => mkReaderT (fun s => pass (runReaderT c s)) }. Global Instance MonadExc_readerT {E} (ME : MonadExc E m) : MonadExc E readerT := { raise := fun _ v => lift (raise v) ; catch := fun _ c h => mkReaderT (fun s => catch (runReaderT c s) (fun x => runReaderT (h x) s)) }. Global Instance MonadPlus_readerT {MP:MonadPlus m} : MonadPlus readerT := { mplus _A _B mA mB := mkReaderT (fun r => mplus (runReaderT mA r) (runReaderT mB r)) }. Global Instance MonadFix_readerT (MF : MonadFix m) : MonadFix readerT := { mfix := fun _ _ r x => mkReaderT (fun s => mfix2 _ (fun f x => runReaderT (r (fun x => mkReaderT (f x)) x)) x s) }. | Record | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/ReaderMonad.v | readerT | |
readerT_eq T (tT : type T) (a b : readerT S m T) : Prop := equal (runReaderT a) (runReaderT b). Global Instance type_readerT (T : Type) (tT : type T) : type (readerT S m T) := type_from_equal (readerT_eq tT). Global Instance typeOk_readerT (T : Type) (tT : type T) (tOkT : typeOk tT) : typeOk (type_readerT tT). Proof. eapply typeOk_from_equal. { simpl. unfold readerT_eq. intros. generalize (only_proper _ _ _ H); intros. split; do 4 red; intuition. } { red. unfold equal; simpl. unfold readerT_eq; simpl. unfold Morphisms.respectful; simpl. firstorder. } { red. unfold equal; simpl. unfold readerT_eq; simpl. unfold Morphisms.respectful; simpl. intros. etransitivity. eapply H; eauto. destruct (only_proper _ _ _ H1). eapply H0. eapply preflexive; eauto with typeclass_instances. } Qed. | Definition | theories | [
"Require Import RelationClasses.",
"Require Import Setoid.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/ReaderMonadLaws.v | readerT_eq | |
mproper_red : forall (C : Type) (tC : type C) (o : readerT S m C), proper o -> proper (runReaderT o). Proof. clear. intros. apply H. Qed. Global Instance proper_runReaderT T (tT : type T) : proper (@runReaderT S m T). Proof. repeat red; intros. apply H in H0. apply H0. Qed. Global Instance proper_mkReaderT T (tT : type T) : proper (@mkReaderT S m T). Proof. repeat red; intros. apply H in H0. apply H0. Qed. | Theorem | theories | [
"Require Import RelationClasses.",
"Require Import Setoid.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/ReaderMonadLaws.v | mproper_red | |
unfold_readerT := red; simpl; intros; do 2 (red; simpl); intros. Global Instance MonadLaws_readerT : MonadLaws (@Monad_readerT S _ Monad_m) _. Proof. constructor. { (* bind_of_return *) unfold_readerT. erewrite bind_of_return; eauto with typeclass_instances; type_tac. } { (* return_of_bind *) unfold_readerT. rewrite return_of_bind; intros; eauto with typeclass_instances. intros. eapply H0. eassumption. } { (* bind_associativity *) unfold_readerT. rewrite bind_associativity; eauto with typeclass_instances; type_tac. } { unfold_readerT. red; intros. type_tac. } { intros. unfold bind; simpl. red; intros. red; intros. red; simpl. red; simpl; intros. solve_equal. } Qed. (* Global Instance MonadTLaws_readerT : @MonadTLaws (readerT S m) (@Monad_readerT S m _) r_mleq m Monad_m (@MonadT_readerT _ m). Proof. constructor; intros; simpl; eapply lower_meq; unfold liftM; simpl; monad_norm; reflexivity. Qed. *) | Ltac | theories | [
"Require Import RelationClasses.",
"Require Import Setoid.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/ReaderMonadLaws.v | unfold_readerT | |
state (t : Type) : Type := mkState { runState : S -> t * S }. | Record | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | state | |
evalState {t} (c : state t) (s : S) : t := fst (runState c s). | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | evalState | |
execState {t} (c : state t) (s : S) : S := snd (runState c s). Global Instance Monad_state : Monad state := { ret := fun _ v => mkState (fun s => (v, s)) ; bind := fun _ _ c1 c2 => mkState (fun s => let (v,s) := runState c1 s in runState (c2 v) s) }. Global Instance MonadState_state : MonadState S state := { get := mkState (fun x => (x,x)) ; put := fun v => mkState (fun _ => (tt, v)) }. Variable m : Type -> Type. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | execState | |
stateT (t : Type) : Type := mkStateT { runStateT : S -> m (t * S)%type }. Variable M : Monad m. | Record | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | stateT | |
evalStateT {t} (c : stateT t) (s : S) : m t := bind (runStateT c s) (fun x => ret (fst x)). | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | evalStateT | |
execStateT {t} (c : stateT t) (s : S) : m S := bind (runStateT c s) (fun x => ret (snd x)). (** [Monad_stateT] is not a Global Instance because it can cause an infinite loop in typeclass inference under certain circumstances. Use [Existing Instance Monad_stateT.] to bring the instance into context. *) | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | execStateT | |
Monad_stateT : Monad stateT := { ret := fun _ x => mkStateT (fun s => @ret _ M _ (x,s)) ; bind := fun _ _ c1 c2 => mkStateT (fun s => @bind _ M _ _ (runStateT c1 s) (fun vs => let (v,s) := vs in runStateT (c2 v) s)) }. Global Instance MonadState_stateT : MonadState S stateT := { get := mkStateT (fun x => ret (x,x)) ; put := fun v => mkStateT (fun _ => ret (tt, v)) }. Global Instance MonadT_stateT : MonadT stateT m := { lift := fun _ c => mkStateT (fun s => bind c (fun t => ret (t, s))) }. Global Instance State_State_stateT T (MS : MonadState T m) : MonadState T stateT := { get := lift get ; put := fun x => lift (put x) }. Global Instance MonadReader_stateT T (MR : MonadReader T m) : MonadReader T stateT := { ask := mkStateT (fun s => bind ask (fun t => ret (t, s))) ; local := fun _ f c => mkStateT (fun s => local f (runStateT c s)) }. Global Instance MonadWriter_stateT T (Mon : Monoid T) (MR : MonadWriter Mon m) : MonadWriter Mon stateT := { tell := fun x => mkStateT (fun s => bind (tell x) (fun v => ret (v, s))) ; listen := fun _ c => mkStateT (fun s => bind (listen (runStateT c s)) (fun x => let '(a,s,t) := x in ret (a,t,s))) ; pass := fun _ c => mkStateT (fun s => bind (runStateT c s) (fun x => let '(a,t,s) := x in pass (ret ((a,s),t)))) }. Global Instance Exc_stateT T (MR : MonadExc T m) : MonadExc T stateT := { raise := fun _ e => lift (raise e) ; catch := fun _ body hnd => mkStateT (fun s => catch (runStateT body s) (fun e => runStateT (hnd e) s)) }. Global Instance MonadZero_stateT (MR : MonadZero m) : MonadZero stateT := { mzero _A := lift mzero }. Global Instance MonadFix_stateT (MF : MonadFix m) : MonadFix stateT := { mfix := fun _ _ r v => mkStateT (fun s => mfix2 _ (fun r v s => runStateT (mkStateT (r v)) s) v s) }. Global Instance MonadPlus_stateT (MP : MonadPlus m) : MonadPlus stateT := { mplus _A _B a b := mkStateT (fun s => bind (mplus (runStateT a s) (runStateT b s)) (fun res => match res with | inl (a,s) => ret (inl a, s) | inr (b,s) => ret (inr b, s) end)) }. | Instance | theories | [
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Monads/StateMonad.v | Monad_stateT | |
writerT (Monoid_S : Monoid@{s} S) (m : Type@{d} -> Type@{c}) (t : Type@{d}) : Type := mkWriterT { runWriterT : m (pprod t S)%type }. Variable Monoid_S : Monoid S. Variable m : Type@{d} -> Type@{c}. Context {M : Monad m}. Arguments mkWriterT _ [_ _] _. | Record | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | writerT | |
execWriterT {T} (c : writerT Monoid_S m T) : m S := bind (runWriterT c) (fun (x : pprod T S) => ret (psnd x)). | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | execWriterT | |
evalWriterT {T} (c : writerT Monoid_S m T) : m T := bind (runWriterT c) (fun (x : pprod T S) => ret (pfst x)). Local Notation "( x , y )" := (ppair x y). Global Instance Monad_writerT : Monad (writerT Monoid_S m) := { ret := fun _ x => mkWriterT _ (@ret _ M _ (x, monoid_unit Monoid_S)) ; bind := fun _ _ c1 c2 => mkWriterT _ ( @bind _ M _ _ (runWriterT c1) (fun v => bind (runWriterT (c2 (pfst v))) (fun v' => ret (pfst v', monoid_plus Monoid_S (psnd v) (psnd v'))))) }. Global Instance Writer_writerT : MonadWriter Monoid_S (writerT Monoid_S m) := { tell := fun x => mkWriterT _ (ret (tt, x)) ; listen := fun _ c => mkWriterT _ (bind (runWriterT c) (fun x => ret (pair (pfst x) (psnd x), psnd x))) ; pass := fun _ c => mkWriterT _ (bind (runWriterT c) (fun x => ret (let '(ppair (pair x ss) s) := x in (x, ss s)))) }. Global Instance MonadT_writerT : MonadT (writerT Monoid_S m) m := { lift := fun _ c => mkWriterT _ (bind c (fun x => ret (x, monoid_unit Monoid_S))) }. Global Instance Reader_writerT {S'} (MR : MonadReader S' m) : MonadReader S' (writerT Monoid_S m) := { ask := mkWriterT _ (bind ask (fun v => @ret _ M _ (v, monoid_unit Monoid_S))) ; local := fun _ f c => mkWriterT _ (local f (runWriterT c)) }. Global Instance State_writerT {S'} (MR : MonadState S' m) : MonadState S' (writerT Monoid_S m) := { get := lift get ; put := fun v => lift (put v) }. Global Instance Zero_writerT (MZ : MonadZero m) : MonadZero (writerT Monoid_S m) := { mzero := fun _ => lift mzero }. Global Instance Exception_writerT {E} (ME : MonadExc E m) : MonadExc E (writerT Monoid_S m) := { raise := fun _ v => lift (raise v) ; catch := fun _ c h => mkWriterT _ (catch (runWriterT c) (fun x => runWriterT (h x))) }. Global Instance Writer_writerT_pass {T} {MonT : Monoid T} {M : Monad m} {MW : MonadWriter MonT m} : MonadWriter MonT (writerT Monoid_S m) := { tell := fun x => mkWriterT _ (bind (tell x) (fun x => ret (x, monoid_unit Monoid_S))) ; listen := fun _ c => mkWriterT _ (bind (m:=m) (@listen _ _ _ MW _ (runWriterT c)) (fun x => let '(pair (ppair a t) s) := x in ret (m:=m) (pair a s,t))) ; pass := fun _ c => mkWriterT _ (@pass _ _ _ MW _ (bind (m:=m) (runWriterT c) (fun x => let '(ppair (pair a t) s) := x in ret (m:=m) (pair (ppair a s) t)))) }. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | evalWriterT | |
mapWriterT (f: m (pprod A W) -> n (pprod B W')) : writerT Monoid_W m A -> writerT Monoid_W' n B := mkWriterT Monoid_W' ∘ f ∘ runWriterT. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | mapWriterT | |
castWriterT : writerT Monoid_W m A -> writerT Monoid_W' m A := mkWriterT Monoid_W' ∘ runWriterT. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | castWriterT | |
writer : Type -> Type := writerT Monoid_W ident. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | writer | |
runWriter : writer A -> pprod A W := unIdent ∘ (@runWriterT W Monoid_W ident A). | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | runWriter | |
execWriter : writer A -> W := psnd ∘ runWriter. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | execWriter | |
evalWriter : writer A -> A := pfst ∘ runWriter. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | evalWriter | |
mapWriter (f: pprod A W -> pprod B W') : writer Monoid_W A -> writer Monoid_W' B := mapWriterT Monoid_W' ident B (mkIdent ∘ f ∘ unIdent). | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | mapWriter | |
castWriter : writer Monoid_W A -> writer Monoid_W' A := castWriterT Monoid_W' (m:=ident). | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import Coq."
] | theories/Data/Monads/WriterMonad.v | castWriter | |
lset (T : Type) : Type := list T. Variable T : Type. Variable R_dec : T -> T -> bool. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset | |
lset_contains (v : T) (ls : lset T) : bool := match ls with | nil => false | l :: ls => if R_dec v l then true else lset_contains v ls end. | Fixpoint | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_contains | |
lset_empty : lset T := nil. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_empty | |
lset_add (v : T) (ls : lset T) : lset T := if lset_contains v ls then ls else v :: ls. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_add | |
lset_remove (v : T) : lset T -> lset T := List.filter (fun x => negb (R_dec v x)). | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_remove | |
lset_union (l r : lset T) : lset T := fold_left (fun x y => lset_add y x) l r. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_union | |
lset_difference (l r : lset T) : lset T := List.filter (fun x => negb (lset_contains x r)) l. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_difference | |
lset_intersect (l r : lset T) : lset T := List.filter (fun x => lset_contains x r) l. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_intersect | |
lset_subset (l r : lset T) : bool := allb (fun x => lset_contains x r) l. | Definition | theories | [
"Require Import List.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/ListSet.v | lset_subset | |
tree := (* Null_t = _ *) | Null_t : tree (* [a] * Two_t X a Y = / \ * X Y * Invariant: x in X => x < a; y in Y => y > a *) | Two_t : tree -> E -> tree -> tree (* [a][b] * Three_t X a Y b Z = / | \ * X Y Z * Invariant: x in X => x < a; y in Y => a < y < b; z in Z => z > b *) | Three_t : tree -> E -> tree -> E -> tree -> tree . | Inductive | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | tree | |
height_t (t:tree) : nat := match t with | Null_t => O | Two_t tl _ tr => max (height_t tl) (height_t tr) | Three_t tl _ tm _ tr => max (max (height_t tl) (height_t tm)) (height_t tr) end. (* a context of a two-three tree. this is the type of taking a tree and * replacing a sub-tree with a hole. *) | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | height_t | |
context := (* Top_c = _ *) | Top_c : context (* C * TwoLeftHole_c a Y C = | * [a] * / \ * ? Y *) | TwoLeftHole_c : E -> tree -> context -> context (* C * TwoRightHole_c X a C = | * [a] * / \ * X ? *) | TwoRightHole_c : tree -> E -> context -> context (* C * ThreeLeftHole a Y b Z C = | * [a][b] * / | \ * ? Y Z *) | ThreeLeftHole_c : E -> tree -> E -> tree -> context -> context (* C * ThreeMiddleHole X a b Z C = | * [a][b] * / | \ * X ? Z *) | ThreeMiddleHole_c : tree -> E -> E -> tree -> context -> context (* C * ThreeRightHole_c X a Y b C = | * [a][b] * / | \ * X Y ? *) | ThreeRightHole_c : tree -> E -> tree -> E -> context -> context . (* zip takes a context (which can be thought of as a tree with a hole), and a * subtree, and fills the hole with the subtree *) | Inductive | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | context | |
zip (t:tree) (c:context) : tree := match c with | Top_c => t | TwoLeftHole_c em tr c' => zip (Two_t t em tr) c' | TwoRightHole_c tl em c' => zip (Two_t tl em t) c' | ThreeLeftHole_c el em er tr c' => zip (Three_t t el em er tr) c' | ThreeMiddleHole_c tl el er tr c' => zip (Three_t tl el t er tr) c' | ThreeRightHole_c tl el em er c' => zip (Three_t tl el em er t) c' end. | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | zip | |
fuse (c1:context) (c2:context) : context := match c1 with | Top_c => c2 | TwoLeftHole_c em tr c1' => TwoLeftHole_c em tr (fuse c1' c2) | TwoRightHole_c tl em c1' => TwoRightHole_c tl em (fuse c1' c2) | ThreeLeftHole_c el em er tr c1' => ThreeLeftHole_c el em er tr (fuse c1' c2) | ThreeMiddleHole_c tl el er tr c1' => ThreeMiddleHole_c tl el er tr (fuse c1' c2) | ThreeRightHole_c tl el em er c1' => ThreeRightHole_c tl el em er (fuse c1' c2) end. | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | fuse | |
location := (* C * TwoHole_l X Y C = | * [?] * / \ * X Y *) | TwoHole_l : tree -> tree -> context -> location (* C * TwoHole_l X Y b Z C = | * [?][b] * / | \ * X Y Z *) | ThreeLeftHole_l : tree -> tree -> E -> tree -> context -> location (* C * TwoHole_l X a Y Z C = | * [a][?] * / | \ * X Y Z *) | ThreeRightHole_l : tree -> E -> tree -> tree -> context -> location . | Inductive | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | location | |
fillLocation (e:E) (l:location) : tree := match l with | TwoHole_l tl tr c => zip (Two_t tl e tr) c | ThreeLeftHole_l tl tm vr tr c => zip (Three_t tl e tm vr tr) c | ThreeRightHole_l tl el tm tr c => zip (Three_t tl el tm e tr) c end. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | fillLocation | |
locate (e:E) (t:tree) (c:context) : context + E * location := match t with | Null_t => inl c | Two_t tl em tr => match comp e em with | Lt => locate e tl $ TwoLeftHole_c em tr c | Eq => inr (em, TwoHole_l tl tr c) | Gt => locate e tr $ TwoRightHole_c tl em c end | Three_t tl el tm er tr => match comp e el, comp e er with | Lt, _ => locate e tl $ ThreeLeftHole_c el tm er tr c | Eq, _ => inr (el, ThreeLeftHole_l tl tm er tr c) | Gt, Lt => locate e tm $ ThreeMiddleHole_c tl el er tr c | _, Eq => inr (er, ThreeRightHole_l tl el tm tr c) | _, Gt => locate e tr $ ThreeRightHole_c tl el tm er c end end. | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | locate | |
locateGreatest (t:tree) (c:context) : option (E * (context + E * context)) := match t with | Null_t => None | Two_t tl em tr => liftM sum_tot $ locateGreatest tr (TwoRightHole_c tl em c) <+> ret (em, inl c) | Three_t tl el tm er tr => liftM sum_tot $ locateGreatest tr (ThreeRightHole_c tl el tm er c) <+> ret (er, inr (el, c)) end. | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | locateGreatest | |
single e := Two_t Null_t e Null_t. (* if insertion results in a subtree which is too tall, propegate it up into * its context. *) | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | single | |
insertUp (tet:tree * E * tree) (c:context) : tree := let '(tl,em,tr) := tet in match c with (* _ * | * [em] => [em] * // \\ / \ * tl tr tl tr *) | Top_c => Two_t tl em tr (* c' c' * | | * [em'] => [em][em'] * / \ / | \ * [em] tr' tl tr tr' * // \\ * tl tr *) | TwoLeftHole_c em' tr' c' => zip (Three_t tl em tr em' tr') c' (* c' c' * | | * [em'] => [em'][em] * / \ / | \ * tl' [em] tl' tl tr * // \\ * tl tr *) | TwoRightHole_c tl' em' c' => zip (Three_t tl' em' tl em tr ) c' (* c' c' * | | * [el][er] => [el] * / | \ // \\ * [em] tm tr' [em] [er] * // \\ / \ / \ * tl tr tl tr tm tr' *) | ThreeLeftHole_c el tm er tr' c' => insertUp (Two_t tl em tr, el, Two_t tm er tr') c' (* c' c' * | | * [el][er] => [em] * / | \ // \\ * tl' [em] tr' [el] [er] * // \\ / \ / \ * tl tr tl' tl tr tr' *) | ThreeMiddleHole_c tl' el er tr' c' => insertUp (Two_t tl' el tl, em, Two_t tr er tr') c' (* c' c' * | | * [el][er] => [er] * / | \ // \\ * tl' tm [em] [el] [em] * // \\ / \ / \ * tl tr tl' tm tl tr *) | ThreeRightHole_c tl' el tm er c' => insertUp (Two_t tl' el tm, er, Two_t tl em tr) c' end. (* insert an element into the two-three tree *) | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | insertUp | |
insert (e:E) (t:tree) : tree := match locate e t Top_c with | inl c => insertUp (Null_t, e, Null_t) c | inr (_, l) => fillLocation e l end. (* if remove results in a tree which is too short, propegate the gap into the * context *) | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | insert | |
removeUp (t:tree) (c:context) : tree := match c with (* _ * || * e => e *) | Top_c => t (* c' c' * | | * [em] => [el'] * // \ / \ * t [el'][er'] [em] [er'] * / | \ / \ / \ * tl' tm' tr' t tl' tm' tr' *) | TwoLeftHole_c em (Three_t tl' el' tm' er' tr') c' => zip (Two_t (Two_t t em tl') el' (Two_t tm' er' tr')) c' (* c' c' * | || * [em] => [em][em'] * // \ / | \ * t [em'] t tl' tr' * / \ * tl' tr' *) | TwoLeftHole_c em (Two_t tl' em' tr') c' => removeUp (Three_t t em tl' em' tr') c' (* c' c' * | | * [em] => [er'] * / \\ / \ * [el'][er'] t [el'] [em] * / | \ / \ / \ * tl' tm' tr' tl' tm' tr' t *) | TwoRightHole_c (Three_t tl' el' tm' er' tr') em c' => zip (Two_t (Two_t tl' el' tm') er' (Two_t tr' em t)) c' (* c' c' * | || * [em] => [em'][em] * / \\ / | \ * [em'] t tl' tr' t * / \ * tl' tr' *) | TwoRightHole_c (Two_t tl' em' tr') em c' => removeUp (Three_t tl' em' tr' em t) c' (* c' c' * | | * [el][er] => [el][er] * // | \ / | \ * t [el'][er'] tr [el'] [er'] tr * / | \ / \ / \ * tl' tm' tr' t tl' tm' tr' *) | ThreeLeftHole_c el (Three_t tl' el' tm' er' tr') er tr c' => zip (Three_t (Two_t t el' tl') el (Two_t tm' er' tr') er tr) c' (* c' c' * | | * [el][er] => [er] * // | \ / \ * t [em'] tr [el][em'] tr * / \ / | \ * tl' tr' t tl' tr' *) | ThreeLeftHole_c el (Two_t tl' em' tr') er tr c' => zip (Two_t (Three_t t el tl' em' tr') er tr) c' (* c' c' * | | * [el][er] => [er'][er] * / || \ / | \ * [el'][er'] t tr [el'] [el] tr * / | \ / \ / \ * tl' tm' tr' tl' tm' tr' t *) | ThreeMiddleHole_c (Three_t tl' el' tm' er' tr') el er tr c' => zip (Three_t (Two_t tl' el' tm') er' (Two_t tr' el t) er tr) c' (* c' c' * | | * [el][er] => [el][el'] * / || \ / | \ * tl t [el'][er'] tl [er] [er'] * / | \ / \ / \ * tl' tm' tr' t tl' tm' tr' *) | ThreeMiddleHole_c tl el er (Three_t tl' el' tm' er' tr') c' => zip (Three_t tl el (Two_t t er tl') el' (Two_t tm' er' tr')) c' (* c' c' * | | * [el][er] => [er] * / || \ / \ * [em'] t tr [em'][el] tr * / \ / | \ * tl' tr' tl' tr' t *) | ThreeMiddleHole_c (Two_t tl' em' tr') el er tr c' => zip (Two_t (Three_t tl' em' tr' el t) er tr) c' (* c' c' * | | * [el][er] => [el] * / || \ / \ * tl t [em'] tl [er][em'] * / \ / | \ * tl' tr' t tl' tr' *) | ThreeMiddleHole_c tl el er (Two_t tl' em' tr') c' => zip (Two_t tl el (Three_t t er tl' em' tr')) c' (* c' c' * | | * [el][er] => [el][er'] * / | \\ / | \ * tl [el'][er'] t tl [el'] [er] * / | \ / \ / \ * tl' tm' tr' tl' tm' tr' t *) | ThreeRightHole_c tl el (Three_t tl' el' tm' er' tr') er c' => zip (Three_t tl el (Two_t tl' el' tm') er' (Two_t tr' er t)) c' (* c' c' * | | * [el][er] => [el] * / | \\ / \ * tl [em'] t tl [em'][er] * / \ / | \ * tl' tr' tl' tr t *) | ThreeRightHole_c tl el (Two_t tl' em' tr') er c' => zip (Two_t tl el (Three_t tl' em' tr' er t)) c' | TwoLeftHole_c _ Null_t _ => Null_t (* not wf *) | TwoRightHole_c Null_t _ _ => Null_t (* not wf *) | ThreeLeftHole_c _ Null_t _ _ _ => Null_t (* not wf *) | ThreeMiddleHole_c Null_t _ _ _ _ => Null_t (* not wf *) | ThreeRightHole_c _ _ Null_t _ _ => Null_t (* not wf *) end. | Fixpoint | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | removeUp | |
remove (e:E) (t:tree) : tree := match locate e t Top_c with (* element doesn't exist *) | inl _ => t (* element found at location [loc] *) | inr (_, loc) => match loc with (* element found at a two-node *) | TwoHole_l tl tr c => let mkContext g c' := TwoLeftHole_c g tr c' in match locateGreatest tl Top_c with (* no children: turn into a hole and propagate *) | None => removeUp Null_t c (* greatest leaf is a two-node: replace it with a hole and propagate *) | Some (g, inl c') => removeUp Null_t $ fuse (mkContext g c') c (* greatest leaf is a three-node: turn it into a two-node *) | Some (g, inr (el, c')) => zip (single el) $ fuse (mkContext g c') c end (* element found on left side of three-node *) | ThreeLeftHole_l tl tm er tr c => let mkContext g c' := ThreeLeftHole_c g tm er tr c' in match locateGreatest tl Top_c with (* no children: turn into a two-node *) | None => zip (single er) c (* greatest leaf is a two-node: replace it with a hole and propagate *) | Some (g, inl c') => removeUp Null_t $ fuse (mkContext g c') c (* greatest leaf is a three-node: turn it into a two-node *) | Some (g, inr (el, c')) => zip (single el) $ fuse (mkContext g c') c end (* element found on right side of three-node *) | ThreeRightHole_l tl el tm tr c => let mkContext g c' := ThreeMiddleHole_c tl el g tr c' in match locateGreatest tm Top_c with (* no children: turn into a two-node *) | None => zip (single el) c (* greatest leaf is a two-node: replace it with a hole and propagate *) | Some (g, inl c') => removeUp Null_t $ fuse (mkContext g c') c (* greatest leaf is a three-node: turn it into a two-node *) | Some (g, inr (el, c')) => zip (single el) $ fuse (mkContext g c') c end end end. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | remove | |
tree_wf : tree E -> nat -> EtndTopBot E -> EtndTopBot E -> Prop := | NullTreeWf : forall eLL eRR, tree_wf Null_t O eLL eRR | TwoTreeWf : forall tl em tr h eLL eRR, eLL << IncEtndTopBot em -> IncEtndTopBot em << eRR -> tree_wf tl h eLL (IncEtndTopBot em) -> tree_wf tr h (IncEtndTopBot em) eRR -> tree_wf (Two_t tl em tr) (S h) eLL eRR | ThreeTreWf : forall tl el tm er tr eLL eRR h, eLL << IncEtndTopBot el -> el << er -> IncEtndTopBot er << eRR -> tree_wf tl h eLL (IncEtndTopBot el) -> tree_wf tm h (IncEtndTopBot el) (IncEtndTopBot er) -> tree_wf tr h (IncEtndTopBot er) eRR -> tree_wf (Three_t tl el tm er tr) (S h) eLL eRR . | Inductive | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | tree_wf | |
tree_in : E -> tree E -> Prop := | TwoTreeIn : forall e tl em tr, e ~= em \/ tree_in e tl \/ tree_in e tr -> tree_in e (Two_t tl em tr) | ThreeTreeIn : forall e tl el tm er tr, e ~= el \/ e ~= er \/ tree_in e tl \/ tree_in e tm \/ tree_in e tr -> tree_in e (Three_t tl el tm er tr) . (* | Inductive | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | tree_in | |
swapTwoWf : forall tl em tr h eLL eRR em', tree_wf (Two_t tl em tr) h eLL eRR -> em ~= em' -> tree_wf (Two_t tl em' tr) h eLL eRR. Proof. intros ; induction h. inversion H. inversion H ; subst ; clear H. constructor. repeat (ohsnap ; girlforeal). unfold ltP in H5. destruct eLL ; repeat (ohsnap ; girlforeal). ... *) | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | swapTwoWf | |
context_wf (c:context) (sth:nat) (sel:E+bool) (ser:E+bool) (th:nat) (eLL:E+bool) (eRR:E+bool) : Prop := forall t:tree, tree_wf t sth sel ser -> tree_wf (zip t c) th eLL eRR. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | context_wf | |
twoLeftHoleZipWf : forall tl em tr c h eLL eRR, tree_wf (zip (Two_t tl em tr) c) h eLL eRR -> tree_wf (zip tl (TwoLeftHole_c em tr c)) h eLL eRR. Proof. intros. induction tl ; intros ; simpl ; auto. Qed. Hint Immediate twoLeftHoleZipWf : twoThreeDb. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | twoLeftHoleZipWf | |
twoRightHoleZipWf : forall tl em tr c h eLL eRR, tree_wf (zip (Two_t tl em tr) c) h eLL eRR -> tree_wf (zip tr (TwoRightHole_c tl em c)) h eLL eRR. Proof. intros. induction tl ; intros ; simpl ; auto. Qed. Hint Immediate twoRightHoleZipWf : twoThreeDb. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | twoRightHoleZipWf | |
threeLeftHoleZipWf : forall tl el tm er tr c h eLL eRR, tree_wf (zip (Three_t tl el tm er tr) c) h eLL eRR-> tree_wf (zip tl (ThreeLeftHole_c el tm er tr c)) h eLL eRR. Proof. intros. induction tl ; intros ; simpl ; auto. Qed. Hint Immediate threeLeftHoleZipWf : twoThreeDb. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | threeLeftHoleZipWf | |
threeMiddleHoleZipWf : forall tl el tm er tr c h eLL eRR, tree_wf (zip (Three_t tl el tm er tr) c) h eLL eRR -> tree_wf (zip tm (ThreeMiddleHole_c tl el er tr c)) h eLL eRR. Proof. intros. induction tl ; intros ; simpl ; auto. Qed. Hint Immediate threeMiddleHoleZipWf : twoThreeDb. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | threeMiddleHoleZipWf | |
threeRightHoleZipWf : forall tl el tm er tr c h eLL eRR, tree_wf (zip (Three_t tl el tm er tr) c) h eLL eRR -> tree_wf (zip tr (ThreeRightHole_c tl el tm er c)) h eLL eRR. Proof. intros. induction tl ; intros ; simpl ; auto. Qed. Hint Immediate threeRightHoleZipWf : twoThreeDb. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | threeRightHoleZipWf | |
location_wf (l:location) h eLL eRR : Prop := forall e:E, tree_wf (fillLocation e l) h eLL eRR. | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | location_wf | |
zipLocationWf : forall tl em tr c, tree_wf (zip (Two_t tl em tr) c) -> location_wf (TwoHole_l tl tr c). Proof. intros. unfold location_wf. intros. simpl. exists em. auto. Qed. Hint Immediate zipLocationWf : twoThreeDb. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | zipLocationWf | |
locate_wf : forall e t c, tree_wf (zip t c) -> match locate e t c with inl c => tree_wf (zip Null_t c) | inr (_,l) => location_wf l end. Proof. intros. gd c. gd e. induction t ; intros ; simpl ; auto. destruct (compareo e0 e). pose (twoLeftHoleZipWf _ _ _ _ H). specialize (IHt1 e0 _ t). apply IHt1. eauto with twoThreeDb. pose (twoRightHoleZipWf _ _ _ _ H). specialize (IHt2 e0 _ t). apply IHt2. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | locate_wf | |
single_wf : forall e, tree_wf (single e). Proof. intros. simpl. auto. Qed. | Lemma | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | single_wf | |
insert_wf : forall e t, tree_wf t -> tree_wf (insert e t). Proof. intros. destruct t. simpl. auto. unfold insert. simpl. destruct (compareo e e0). unfold insert. destruct (locate e t Top_c). simpl. *) *) | Definition | theories | [
"Require Import ExtLib.",
"Require Import ExtLib.",
"Require Import ExtLib."
] | theories/Data/Set/TwoThreeTrees.v | insert_wf |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.