Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for the Prop Monad #165

Open
wants to merge 43 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
b2c404a
Quick draft after discussion with Irene
YaZko Mar 6, 2020
e07d32e
Working on the prop monad with Irene
YaZko Mar 9, 2020
a7bed80
WIP class for mayreturn
YaZko Mar 17, 2020
cb451db
Monad laws for Kento
euisuny Mar 17, 2020
30bb1be
Left conjunction of left_unit proof PropTM
Mar 18, 2020
2a18bf1
WIP ITree mayret proof
euisuny Mar 18, 2020
aa93b5a
The relationship between eutt and Returns is a bit tricky
YaZko Mar 18, 2020
f90c9c7
WIP mayret_bind inversion case
euisuny Mar 19, 2020
a6e3728
bind_ret_l proof for PropTM
Mar 19, 2020
27b9aa6
started ret_bind_r
Mar 19, 2020
df9e3b2
Merge branch 'prop' of https://github.com/DeepSpec/InteractionTrees i…
Mar 19, 2020
9704520
right unit proof changes
Mar 19, 2020
2336957
ITree mayret bind inversion proved
euisuny Mar 19, 2020
fee7e1e
Merge branch 'prop' of https://github.com/DeepSpec/InteractionTrees i…
Mar 19, 2020
704f404
Generalizing a few inversion lemmas
YaZko Mar 19, 2020
01ac024
Generalized inversion lemma for bind
YaZko Mar 19, 2020
51bae6c
Inversion lemma for binding Vis nodes proved
euisuny Mar 20, 2020
627465c
ITree mayret correctness instance complete
euisuny Mar 20, 2020
077f5c5
Deleting extraneous file
euisuny Mar 20, 2020
aeaccbf
StateT transformer for MayReturn is concerning
YaZko Mar 20, 2020
0aa496d
Excluded middle in right unit PropTM
Mar 22, 2020
8a3e2c3
Proved one direction of associativity, PropT monad laws
Mar 23, 2020
a552671
monday vellvm meeting
Mar 23, 2020
3b1992d
ret_bind_r using a stronger monad law
YaZko Mar 24, 2020
3badd6b
right unit proof for PropTM with stronger monad law
Mar 24, 2020
3290b01
resolved conflict
Mar 24, 2020
270378d
Mix bag of iter stuff and monad laws stuff
YaZko Mar 24, 2020
edd556e
Merge branch 'prop' of github.com:DeepSpec/InteractionTrees into prop
YaZko Mar 24, 2020
1de7443
Comments
YaZko Mar 25, 2020
e976e74
Progress in proving Iter Laws
euisuny Mar 25, 2020
550770a
Merge branch 'prop' of https://github.com/DeepSpec/InteractionTrees i…
euisuny Mar 25, 2020
ac87b87
New definition of MonadIter instance for PropTM
euisuny Mar 26, 2020
4e1301e
Updated prop_iter and unfold_iter proof with new iter def
euisuny Mar 26, 2020
7d0e9cc
Updated IterUnfold forward case for indexed iter
euisuny Mar 27, 2020
fa3476b
Small comments on proving unfolditer
euisuny Mar 27, 2020
37b77e7
Used dinatural law to prove part of iter unfold
euisuny Mar 31, 2020
9900b54
Attempt at changing the mayret definition
Mar 31, 2020
00e3eb0
Merge branch 'prop' of https://github.com/DeepSpec/InteractionTrees i…
Mar 31, 2020
f9eefcc
Some work on using the axiom of choice to prove the missing monad law
YaZko Mar 31, 2020
299017d
Merge branch 'prop' of github.com:DeepSpec/InteractionTrees into prop
YaZko Mar 31, 2020
425f1d9
experimental generalization of eqm
Zdancewic Apr 3, 2020
b2507a9
Exploring "Run" function for tmayret
Apr 6, 2020
6b6e176
attempt to apply tmayret with run to statet
Apr 6, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
110 changes: 110 additions & 0 deletions theories/Basics/MonadProp.v
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
From ExtLib Require Import
Structures.Monad.
From ITree Require Import
Basics.Basics
Basics.Category
Basics.CategoryKleisli
Basics.CategoryKleisliFacts
Basics.Monad.

Module Foo.

(* Variable (crazy: forall (A: Type), A -> A -> Prop). *)
Definition PropM: Type -> Type := fun A => A -> Prop.

Definition ret: forall A, A -> PropM A := fun _ a b => a = b.

Definition eqm: forall A, PropM A -> PropM A -> Prop :=
fun _ P Q => forall a, P a <-> Q a.

Definition bind {A B} (PA: PropM A) (K: A -> PropM B) : PropM B :=
fun b => exists a, PA a /\ K a b.

End Foo.

(* See [PropT.v] in the Vellvm repo for the exact framework to follow with respect to typeclasses, as well as a proof of most monad laws for [PropTM (itree E)] *)
Section Transformer.

Variable (m: Type -> Type).
Context `{Monad m}.
Context {EQM : EqM m}.
Context {ITERM : MonadIter m}.

Definition PropTM : Type -> Type :=
fun A => m A -> Prop.

Definition closed_eqm {A} (P: m A -> Prop) := forall a a', eqm a a' -> (P a <-> P a').

(* Design choice 1: closed or not by construction? *)
Definition PropTM' : Type -> Type :=
fun A => {P: m A -> Prop | closed_eqm P}.

(* Design choice 2: (ma = ret a) or eqm ma (ret a)? *)
Definition ret' : forall A, A -> PropTM A :=
fun A (a: A) (ma: m A) => eqm ma (ret a).

Definition eqm1: forall A, PropTM A -> PropTM A -> Prop:=
fun A PA PA' => forall a, PA a <-> PA' a.

Definition eqm2: forall A, PropTM A -> PropTM A -> Prop :=
fun a PA PA' =>
(forall x y, eqm x y -> (PA x <-> PA' y)) /\
closed_eqm PA /\ closed_eqm PA'.

Definition eqm3: forall A, PropTM A -> PropTM A -> Prop :=
fun _ P Q => (forall a, P a -> exists a', eqm a a' /\ Q a) /\
(forall a, Q a -> exists a', eqm a a' /\ P a).

(* bind {ret 1} (fun n => if n = 0 then empty set else {ret n}) K
K 1 == {ret 1}
= empty_set
kb : nat -> m nat
kb 0 € K 0
ma = ret 1
What will be my kb?
kb := fun n =>if n = 0 then ret 0 else (ret n)) for instance
But no matter the choice, with the following definition, we get the empty_set for the bind where we kinda would like {ret 1;; ret 1 ~~ ret 1}
It feels like a solution would be to check membership to K only over values a that "ma can return". What is this notion over a monad in general?

*)

Global Instance EqM_PropTM : EqM PropTM := eqm2.

(* This should be a typeclass rather? *)
Inductive MayRet {m: Type -> Type} {M: Monad m}: forall {A}, m A -> A -> Prop :=
| mayret_ret: forall A (a: A), MayRet (ret a) a
| mayret_bind: forall A B (ma: m A) a (k: A -> m B) b,
MayRet ma a ->
MayRet (k a) b ->
MayRet (bind ma k) b.

Global Instance Monad_PropTM : Monad (PropTM) :=
{
ret:= fun A (a: A) (ma: m A) => eqm ma (ret a)
; bind := fun A B (PA : PropTM A) (K : A -> PropTM B) mb => exists (ma: m A) (kb: A -> m B),
PA ma /\
(forall a, MayRet ma a -> K a (kb a)) /\
Monad.eqm mb (bind ma kb)
}.

Global Instance MonadIter_Prop : MonadIter PropTM :=
fun R I step i r =>
exists (step': I -> m (I + R)%type),
(forall j, step j (step' j)) /\ CategoryOps.iter step' i = r.

(* What is the connection (precisely) with this continuation monad? *)
(* Definition ContM: Type -> Type := fun A => (A -> Prop) -> Prop. *)

Lemma ret_bind:
forall A B (a : A) (f : A -> PropTM B),

eqm (bind (ret a) f) (f a).
Proof.
intros. split.
- unfold bind.
unfold Monad_PropTM.
intro mb. split.
- intros (ma & kb & HRet & HBind & HEq).
rewrite HEq.

End Transformer.
Loading