Dataset Viewer
Auto-converted to Parquet Duplicate
statement
stringlengths
1
1.39k
proof
stringlengths
0
13.6k
type
stringclasses
20 values
symbolic_name
stringlengths
1
39
library
stringclasses
19 values
filename
stringclasses
133 values
imports
listlengths
0
32
deps
listlengths
0
64
docstring
stringlengths
0
2.93k
source_url
stringclasses
1 value
commit
stringclasses
1 value
ioE : Type -> Type
:= | Input : ioE (list nat) (** Ask for a list of [nat] from the environment. *) | Output : list nat -> ioE unit (** Send a list of [nat]. *) .
Inductive
ioE
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[]
We first show how to represent effectful computations as interaction trees. The [itree] type is parameterized by an _event type_, which is typically an indexed type with constructors describing the possible interactions with the environment. For instance, [ioE] below is a type of simple input/outpu...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
write_one : itree ioE unit
:= xs <- ITree.trigger Input;; ITree.trigger (Output (xs ++ [1])).
Definition
write_one
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "ioE", "itree", "trigger" ]
Read some input, and echo it back, appending [1] to it.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
handle_io : forall R, ioE R -> Monads.stateT (list nat) (itree void1) R
:= fun R e log => match e with | Input => ret (log, [0]) | Output o => ret (log ++ o, tt) end.
Definition
handle_io
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "ioE", "itree", "log", "stateT", "void1" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
interp_io : forall R, itree ioE R -> itree void1 (list nat * R)
:= fun R t => Monads.run_stateT (interp handle_io t) [].
Definition
interp_io
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "handle_io", "interp", "ioE", "itree", "run_stateT", "void1" ]
[interp] lifts any handler into an _interpreter_, of type [forall R, itree ioE R -> M R].
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
interpreted_write_one : itree void1 (list nat * unit)
:= interp_io _ write_one.
Definition
interpreted_write_one
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "interp_io", "itree", "void1", "write_one" ]
We can now interpret [write_one].
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
interp_write_one F (handle_io : forall R, ioE R -> itree F R) : interp handle_io write_one ≈ (xs <- handle_io _ Input;; handle_io _ (Output (xs ++ [1]))).
Proof. unfold write_one. (* Use lemmas from [ITree.Simple] ([theories/Simple.v]). *) (* ADMITTED *) rewrite interp_bind. rewrite interp_trigger. setoid_rewrite interp_trigger. reflexivity. Qed.
Lemma
interp_write_one
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "handle_io", "interp", "interp_bind", "interp_trigger", "ioE", "itree", "write_one" ]
Intuitively, [interp_io] replaces every [ITree.trigger] in the definition of [write_one] with [handle_io]: [[ interpreted_write_one = xs <- handle_io _ Input;; handle_io _ (Output (xs ++ [1])) ]] We can prove such a lemma in a more restricted setting, where [handle_io] targets some monad of the f...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
E
:= void1.
Definition
E
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "void1" ]
In this file, we won't use external events, so we will use this empty event type [void1].
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
factorial_spec (n : nat) : nat
:= match n with | 0 => 1 | S m => n * factorial_spec m end.
Fixpoint
factorial_spec
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[]
This is the Coq specification -- the usual mathematical definition.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fact_body (x : nat) : itree (callE nat nat +' E) nat
:= match x with | 0 => Ret 1 | S m => y <- call m ;; (* Recursively compute [y := m!] *) Ret (x * y) end.
Definition
fact_body
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "call", "callE", "itree" ]
The generic [rec] interface of the library's [Interp] module can be used to define a single recursive function. The more general [mrec] (from which [rec] is defined) allows multiple, mutually recursive definitions. The argument of [rec] is an interaction tree with an event type [callE A B] to repr...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
factorial (n : nat) : itree E nat
:= rec fact_body n.
Definition
factorial
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "fact_body", "itree", "rec" ]
The factorial function itself is defined as an ITree by "tying the knot" using [rec].
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fact_5 : factorial 5 ≈ Ret 120.
Proof. tau_steps. reflexivity. Qed.
Example
fact_5
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "factorial", "tau_steps" ]
... or with tactics, such as [tau_steps], which removes all taus from the left-hand side of an [≈] equation.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
factorial' : nat -> itree E nat
:= rec-fix fact x := match x with | 0 => Ret 1 | S m => y <- fact m ;; Ret (x * y) end.
Definition
factorial'
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "fact", "itree", "rec" ]
An equivalent definition with a [rec-fix] notation looking like [fix], where the recursive call can be given a more specific name.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
factorial_same : factorial = factorial'.
Proof. reflexivity. Qed.
Lemma
factorial_same
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "factorial", "factorial'" ]
These two definitions are definitionally equal.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
unfold_factorial : forall x, factorial x ≈ match x with | 0 => Ret 1 | S m => y <- factorial m ;; Ret (x * y) end.
Proof. intros x. unfold factorial. (* ADMITTED *) rewrite rec_as_interp; unfold fact_body at 2. destruct x. - rewrite interp_ret. reflexivity. - rewrite interp_bind. rewrite interp_recursive_call. setoid_rewrite interp_ret. reflexivity. Qed.
Lemma
unfold_factorial
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "fact_body", "factorial", "interp_bind", "interp_recursive_call", "interp_ret", "rec_as_interp" ]
[rec] is actually a special version of [interp], which replaces every [call] in [fact_body] with [factorial] itself.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
factorial_correct : forall n, factorial n ≈ Ret (factorial_spec n).
Proof. intros n. (* ADMITTED *) induction n as [ | n' IH ]. - (* n = 0 *) rewrite unfold_factorial. reflexivity. - (* n = S n' *) rewrite unfold_factorial. rewrite IH. (* Induction hypothesis *) rewrite bind_ret. simpl. reflexivity. Qed.
Lemma
factorial_correct
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "bind_ret", "factorial", "factorial_spec", "unfold_factorial" ]
We can prove that the ITrees version [factorial] is "equivalent" to the [factorial_spec] version. The proof goes by induction on [n] and uses only rewriting -- no coinduction necessary. Here, we detail each step of rewriting to illustrate the use of the equational theory, which is mostly applications ...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
factorial_correct' : forall n, factorial n ≈ Ret (factorial_spec n).
Proof. intros n. unfold factorial. induction n as [ | n' IH ]. - (* n = 0 *) tau_steps. (* Just compute away. *) reflexivity. - (* n = S n' *) rewrite rec_as_interp. unfold fact_body at 2. autorewrite with itree. rewrite IH. (* Induction hypothesis *) autorewrite with i...
Lemma
factorial_correct'
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "fact_body", "factorial", "factorial_spec", "itree", "rec_as_interp", "tau_steps" ]
The tactics [tau_steps] and [autorewrite with itree] offer a little automation to simplify monadic expressions.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fib_spec (n : nat) : nat
:= match n with | 0 => 0 | S n' => match n' with | 0 => 1 | S n'' => fib_spec n'' + fib_spec n' end end.
Fixpoint
fib_spec
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[]
Carry out the analogous proof of correctness for the Fibonacci function, whose naturally recursive coq definition is given below.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fib_body : nat -> itree (callE nat nat +' E) nat (* ADMITDEF *)
:= fun n => match n with | 0 => Ret 0 | S n' => match n' with | 0 => Ret 1 | S n'' => y1 <- call n'' ;; y2 <- call n' ;; Ret (y1 + y2) end end.
Definition
fib_body
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "call", "callE", "itree" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fib n : itree E nat
:= rec fib_body n.
Definition
fib
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "fib_body", "itree", "rec" ]
/ADMITDEF
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fib_3_6 : mapT fib [4;5;6] ≈ Ret [3; 5; 8].
Proof. (* Use [tau_steps] to compute. *) (* ADMITTED *) tau_steps. reflexivity. Qed.
Example
fib_3_6
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "fib", "tau_steps" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fib_correct_aux : forall n m, m <= n -> fib m ≈ Ret (fib_spec m).
Proof. intros n. unfold fib. induction n as [ | n' IH ]; intros. - (* n = 0 *) apply Nat.le_0_r in H. subst m. (* ADMIT *) rewrite rec_as_interp. simpl. rewrite interp_ret. (* alternatively, [tau_steps], or [autorewrite with itree] *) reflexivity. (* /ADMIT *) - (* n = S n' *) ...
Lemma
fib_correct_aux
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "fib", "fib_spec", "interp_ret", "itree", "rec_as_interp", "subst" ]
Since fib uses two recursive calls, we need to strengthen the induction hypothesis. One way to do that is to prove the property for all [m <= n]. You may find the following two lemmas useful at the start of each case. [[ Nat.le_0_r : forall n : nat, n <= 0 <-> n = 0 Nat.le_succ_r : forall n m : nat, n...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
fib_correct : forall n, fib n ≈ Ret (fib_spec n).
Proof. (* ADMITTED *) intros n. eapply fib_correct_aux. reflexivity. Qed.
Lemma
fib_correct
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "fib", "fib_correct_aux", "fib_spec" ]
The final correctness result follows.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
log (b : nat) : nat -> itree E nat (* ADMITDEF *)
:= rec-fix log_b n := if n <=? 1 then Ret O else y <- log_b (n / b) ;; Ret (S y).
Definition
log
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "itree", "rec" ]
An example of a function which is not structurally recursive. [log_ b n]: logarithm of [n] in base [b]. Specification: [log_ b (b ^ y) ≈ Ret y] when [1 < b]. (Note that this only constrains a very small subset of inputs, and in fact our solution diverges for some of them.)
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
log_2_64 : log 2 (2 ^ 6) ≈ Ret 6.
Proof. (* ADMITTED *) tau_steps. reflexivity. Qed.
Example
log_2_64
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "log", "tau_steps" ]
/ADMITDEF
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
log_correct_helper : forall b y, 1 < b -> (b * b ^ y <=? 1) = false.
Proof. intros. apply Nat.leb_gt. apply Nat.lt_1_mul_pos; auto. apply Nat.neq_0_lt_0. intro. apply (Nat.pow_nonzero b y); lia. Qed.
Lemma
log_correct_helper
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[]
These lemmas take care of the boring arithmetic.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
log_correct_helper2 : forall b y, 1 < b -> (b * b ^ y / b) = (b ^ y).
Proof. intros; rewrite Nat.mul_comm, Nat.div_mul; lia. Qed.
Lemma
log_correct_helper2
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
log_correct : forall b y, 1 < b -> log b (b ^ y) ≈ Ret y.
Proof. intros b y H. (* ADMITTED *) unfold log, rec_fix. induction y. - rewrite rec_as_interp; cbn. autorewrite with itree. reflexivity. - rewrite rec_as_interp; cbn. (* (b * b ^ y <=? 1) = false *) rewrite log_correct_helper by auto. autorewrite with itree. (* (b * b ^ y / b) = (b ^...
Lemma
log_correct
examples
examples/IntroductionSolutions.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "Simple", "ListNotations", "ITreeNotations", "MonadNotation" ]
[ "Ret", "itree", "log", "log_correct_helper", "log_correct_helper2", "rec_as_interp", "rec_fix" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
stateE (S:Type) : Type -> Type
:= | Get : stateE S S | Put : S -> stateE S unit.
Variant
stateE
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[]
Suppose that we have an ITree whose event type admits certain kinds of operations. For this example, we take a simplified version of the [stateE] event, which defines [get] and [put] operations on states.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
stateT (S:Type) (M:Type -> Type) (R:Type)
:= S -> M (S * R)%type.
Definition
stateT
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[]
We can define an interpretation of [stateE] events into itrees with no events as follows. Note that we split out the "node functor", which is parameterized by the interpreter on the recursive calls, separating it from the CoFixpoint. This structure mirrors the way that we define predicates below. The I...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
interpret_stateF (S:Type) {R} (rec : itree (stateE S) R -> stateT S (itree void1) R) (t : itree (stateE S) R) : stateT S (itree void1) R
:= fun s => match observe t with | RetF r => ret (s, r) | TauF t => Tau (rec t s) | VisF Get k => Tau (rec (k s) s) | VisF (Put s') k => Tau (rec (k tt) s') end.
Definition
interpret_stateF
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "Tau", "itree", "observe", "rec", "stateE", "stateT", "void1" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
interpret_state {S R:Type} (t:itree (stateE S) R) : stateT S (itree void1) R
:= interpret_stateF interpret_state t.
CoFixpoint
interpret_state
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "interpret_stateF", "itree", "stateE", "stateT", "void1" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
unfold_interpret_state : forall {S R} (t : itree (stateE S) R) (s:S), observe (interpret_state t s) = observe (interpret_stateF interpret_state t s).
Proof. reflexivity. Qed.
Lemma
unfold_interpret_state
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "interpret_state", "interpret_stateF", "itree", "observe", "stateE" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
proper_interpret_state {S R} : Proper ((@eq_itree (stateE S) R _ eq) ==> (@eq S) ==> (@eq_itree void1 (S * R) _ eq)) interpret_state.
Proof. ginit. gcofix CIH. intros x y H0 x2 y0 H1. rewrite (itree_eta (interpret_state x x2)). rewrite (itree_eta (interpret_state y y0)). rewrite !unfold_interpret_state. subst. punfold H0. repeat red in H0. unfold interpret_stateF. destruct (observe x); inv H0; try discriminate; pclearbot; ...
Instance
proper_interpret_state
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "ddestruction", "eq_itree", "fail", "interpret_state", "interpret_stateF", "inv", "itree", "itree_eta", "observe", "stateE", "subst", "unfold_interpret_state", "void1" ]
SAZ: This proof is a bit annoying. We can only rewrite under the "upto" paco2 predicate (see the eq_itree_paco instance in Eq), which means we have to introduce names, start the upto proof, do the rewrite, and then regeneralize for the CIH. It would be nicer if we could rewrite under (paco2 _ r).
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
NoGetsF {S R} (rec : itree (stateE S) R -> Prop) : itreeF (stateE S) R (itree (stateE S) R) -> Prop
:= | isRet : forall (r:R), NoGetsF rec (RetF r) | isTau : forall t, rec t -> NoGetsF rec (TauF t) | isPut : forall (k : unit -> itree (stateE S) R), forall (s:S), rec (k tt) -> NoGetsF rec (VisF (Put s) k).
Variant
NoGetsF
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "itree", "itreeF", "rec", "stateE" ]
First, we define [NoGetsF]. It takes as input [rec], which will be instantiated to the [NoGets] predicate for subtrees. It yields a predicate on [itreeF] nodes.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
NoGets_ {S R} (rec : itree (stateE S) R -> Prop) (t : itree (stateE S) R) : Prop
:= NoGetsF rec (observe t).
Definition
NoGets_
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGetsF", "itree", "observe", "rec", "stateE" ]
SAZ: n.b. for some reason, we have adopted the [Foo_] notational convention for the predicate transformer whose greatest fixpoint is [Foo]. Is this good? SAZ: Actually, I see that we're inconsistent between [eq_itree] and [eutt] with these naming conventions.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
monotone_NoGetsF : forall {S R} t (r r' : itree (stateE S) R -> Prop) (IN: NoGetsF r t) (LE: forall y, r y -> r' y), NoGetsF r' t.
Proof. pmonauto. Qed.
Lemma
monotone_NoGetsF
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGetsF", "itree", "stateE" ]
SAZ: Arguably, the LE fact should be defined via some named property. In the Coq Relationclasses library, there is a definition of subrelation, which is the binary version of this. It might be more uniform to have subrelation1, subrelation2, subrelation3, etc. for different arities. SAZ: It's a bit of a ...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
monotone_NoGets_ : forall {S R}, monotone1 (@NoGets_ S R).
Proof. do 2 red. pmonauto. Qed.
Lemma
monotone_NoGets_
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGets_" ]
SAZ: we need to do a couple of reductions to expose the structure of the lemma so that pmonauto can work. Note that [cbn] and [simple] don't work here because they don't unfold the definitions.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
NoGets {S R} : itree (stateE S) R -> Prop
:= paco1 NoGets_ bot1.
Definition
NoGets
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGets_", "itree", "stateE" ]
Finally, we can define the [NoGets] predicate by simply applying paco1 starting from bot1 (the least prediate). We would use paco2 and bot2 for a binary relation, paco3 and bot3 for ternary, etc.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
state_independent : forall {S R} (t:itree (stateE S) R) (H: NoGets t), forall s s', ('(s,x) <- interpret_state t s ;; ret x) ≅ ('(s,x) <- interpret_state t s' ;; ret x).
Proof. intros S R. ginit. gcofix CIH. intros t H0 s s'. rewrite (itree_eta (interpret_state t s)). rewrite (itree_eta (interpret_state t s')). rewrite !unfold_interpret_state. unfold interpret_stateF. punfold H0. repeat red in H0. destruct (observe t); cbn. - rewrite !bind_ret_l. gstep. econstructor...
Lemma
state_independent
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGets", "bind_ret_l", "bind_tau", "ddestruction", "interpret_state", "interpret_stateF", "itree", "itree_eta", "observe", "stateE", "subst", "unfold_interpret_state" ]
Now that we have defined [NoGets], we can use that predicate to do a coinductive proof. Intuitively, if we interpret an itree of type [itree (stateE S) R] that satisfies the [NoGets] predicate, it does not matter what initial state it runs in. To state this correctly, we have to "project away" the final s...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
state_independent_k : forall {S R U} (t:itree (stateE S) R) (H: NoGets t) (k: (S * R) -> itree void1 U) (INV: forall s s' x, k (s, x) ≅ k (s', x)), forall s s', (sx <- interpret_state t s ;; (k sx)) ≅ (sx <- interpret_state t s' ;; (k sx)).
Proof. intros S R U. ginit. gcofix CIH. intros t H0 k INV s s'. rewrite (itree_eta (interpret_state t s)). rewrite (itree_eta (interpret_state t s')). rewrite !unfold_interpret_state. unfold interpret_stateF. punfold H0. repeat red in H0. destruct (observe t); cbn. - rewrite !bind_ret_l. gfinal. rig...
Lemma
state_independent_k
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGets", "bind_ret_l", "bind_tau", "ddestruction", "interpret_state", "interpret_stateF", "itree", "itree_eta", "observe", "stateE", "subst", "unfold_interpret_state", "void1" ]
More or less the same proof also works for any continuation [k] that ignores the state. This proof illustrates the use of paco2_mon -- monotonicity means that if we assume that [k (s, x) ≅ k (s', x))] then [k (s, x)] is related to [k (s', x)] at any "later" step of the cofixpoint. e.g. in the proof below we n...
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
state_independent': forall {S R} (t:itree (stateE S) R) (H: NoGets t), forall s s', ('(s,x) <- interpret_state t s ;; ret x) ≅ ('(s,x) <- interpret_state t s' ;; ret x).
Proof. intros S R t H s s'. eapply state_independent_k; eauto. intros. reflexivity. Qed.
Theorem
state_independent'
examples
examples/ITreePredicatesExample.v
[ "Coq", "Morphisms", "Paco", "paco", "ExtLib", "Monads", "ITree", "Axioms", "ITreeFacts", "Eq.Paco2", "ITreeNotations" ]
[ "NoGets", "interpret_state", "itree", "stateE", "state_independent_k" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
term : Type
:= | Var : nat -> term (* DeBruijn indexed *) | App : term -> term -> term | Lam : term -> term .
Inductive
term
examples
examples/LC.v
[ "Coq", "Arith", "ExtLib.Structures", "Monad", "MonadNotation", "ITree", "Interp.Recursion" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
headvar : Type
:= | VVar : nat -> headvar | VApp : headvar -> value -> headvar with value : Type := | VHead : headvar -> value | VLam : term -> value .
Inductive
headvar
examples
examples/LC.v
[ "Coq", "Arith", "ExtLib.Structures", "Monad", "MonadNotation", "ITree", "Interp.Recursion" ]
[ "term", "value" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
to_term (v : value) : term
:= match v with | VHead hv => hv_to_term hv | VLam t => Lam t end with hv_to_term (hv : headvar) : term := match hv with | VVar n => Var n | VApp hv v => App (hv_to_term hv) (to_term v) end.
Fixpoint
to_term
examples
examples/LC.v
[ "Coq", "Arith", "ExtLib.Structures", "Monad", "MonadNotation", "ITree", "Interp.Recursion" ]
[ "headvar", "term", "value" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
shift (n m : nat) (s : term)
:= match s with | Var p => if p <? m then Var (n + p) else Var p | App t1 t2 => App (shift n m t1) (shift n m t2) | Lam t => Lam (shift n (S m) t) end.
Fixpoint
shift
examples
examples/LC.v
[ "Coq", "Arith", "ExtLib.Structures", "Monad", "MonadNotation", "ITree", "Interp.Recursion" ]
[ "term" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
subst (n : nat) (s t : term)
:= match t with | Var m => if m <? n then Var m else if m =? n then shift n O s else Var (pred m) | App t1 t2 => App (subst n s t1) (subst n s t2) | Lam t => Lam (subst (S n) s t) end.
Fixpoint
subst
examples
examples/LC.v
[ "Coq", "Arith", "ExtLib.Structures", "Monad", "MonadNotation", "ITree", "Interp.Recursion" ]
[ "shift", "term" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
big_step : term -> itree void1 value
:= rec (fun t => match t with | Var n => ret (VHead (VVar n)) | App t1 t2 => t2' <- trigger (Call t2);; t1' <- trigger (Call t1);; match t1' with | VHead hv => ret (VHead (VApp hv t2')) | VLam t1'' => trigger (Call (subst O (to_term t2') t1'')) end | Lam t =...
Definition
big_step
examples
examples/LC.v
[ "Coq", "Arith", "ExtLib.Structures", "Monad", "MonadNotation", "ITree", "Interp.Recursion" ]
[ "itree", "rec", "subst", "term", "to_term", "trigger", "value", "void1" ]
big-step call-by-value
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
printE : Type -> Type
:= Print : string -> printE unit.
Variant
printE
examples
examples/MultiThreadedPrinting.v
[ "Coq", "String", "ITree", "Events.Concurrency", "ITreeNotations" ]
[]
An OCaml-interpreted event that just prints the given string.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
thread {E} `{printE -< E} (s:string) : itree E unit
:= ITree.forever (trigger (Print s)).
Definition
thread
examples
examples/MultiThreadedPrinting.v
[ "Coq", "String", "ITree", "Events.Concurrency", "ITreeNotations" ]
[ "forever", "itree", "printE", "trigger" ]
A thread that loops, printing [s] forever.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
main_thread : itree (spawnE printE +' printE) unit
:= spawn (thread "Thread 1") ;; spawn (thread "Thread 2") ;; spawn (thread "Thread 3").
Definition
main_thread
examples
examples/MultiThreadedPrinting.v
[ "Coq", "String", "ITree", "Events.Concurrency", "ITreeNotations" ]
[ "itree", "printE", "spawn", "spawnE", "thread" ]
Run three threads.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
scheduled_thread : itree printE unit
:= run_spawn main_thread.
Definition
scheduled_thread
examples
examples/MultiThreadedPrinting.v
[ "Coq", "String", "ITree", "Events.Concurrency", "ITreeNotations" ]
[ "itree", "main_thread", "printE", "run_spawn" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
com : Type
:= | loop : com -> com (* Nondeterministically, continue or stop. *) | choose : com -> com -> com | skip : com | seq : com -> com -> com .
Inductive
com
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "choose", "loop", "seq" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
one_loop : com
:= loop skip.
Example
one_loop
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "com", "loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
two_loops : com
:= loop (loop skip).
Example
two_loops
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "com", "loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
loop_choose : com
:= loop (choose skip skip).
Example
loop_choose
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "choose", "com", "loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
choose_loop : com
:= choose (loop skip) skip.
Example
choose_loop
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "choose", "com", "loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
step : relation com
:= | step_loop_stop c : loop c --> skip | step_loop_go c : loop c --> (c ;; loop c) | step_choose_l c1 c2 : choose c1 c2 --> c1 | step_choose_r c1 c2 : choose c1 c2 --> c2 | step_seq_go c1 c1' c2 : c1 --> c2 -> (c1 ;; c2) --> (c1' ;; c2) | step_seq_next c2 : (skip ;; c2) --> c2 where "x -->...
Inductive
step
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "choose", "com", "loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
infinite_steps (c : com) : Type
:= | more c' : step c c' -> infinite_steps c' -> infinite_steps c.
CoInductive
infinite_steps
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "com", "step" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
infinite_simple_loop : infinite_steps one_loop.
Proof. cofix self. eapply more. { eapply step_loop_go. } eapply more. { eapply step_seq_next. } apply self. Qed.
Lemma
infinite_simple_loop
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "infinite_steps", "one_loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
label
:= tau | bit (b : bool).
Variant
label
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
step : label -> relation com
:= | step_loop_stop c : loop c ! true --> skip | step_loop_go c : loop c ! false --> (c ;; loop c) | step_choose_l c1 c2 : choose c1 c2 ! true --> c1 | step_choose_r c1 c2 : choose c1 c2 ! false --> c2 | step_seq_go b c1 c1' c2 : c1 ? b --> c2 -> (c1 ;; c2) ? b --> (c1' ;; c2) | step_seq_next c2...
Inductive
step
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "choose", "com", "label", "loop" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
infinite_steps (c : com) : Type
:= | more b c' : step b c c' -> infinite_steps c' -> infinite_steps c.
CoInductive
infinite_steps
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "com", "step" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
nd : Type -> Prop
:= | Or : nd bool.
Variant
nd
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
or {R : Type} (t1 t2 : itree nd R) : itree nd R
:= Vis Or (fun b : bool => if b then t1 else t2).
Definition
or
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "Vis", "itree", "nd" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
choice {E} `{nd -< E} : itree E bool
:= trigger Or.
Definition
choice
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "itree", "nd", "trigger" ]
Flip a coin
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
eval_def : com -> itree (callE _ _ +' nd) unit
:= (fun (c : com) => match c with | loop c => (b <- choice;; if b : bool then Ret tt else (trigger (Call c);; trigger (Call (loop c))))%itree | choose c1 c2 => (b <- choice;; if b : bool then trigger (Call c1) else trigger (Call c2))%itree | (t1 ;; t2)%com...
Definition
eval_def
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "Ret", "callE", "choice", "choose", "com", "itree", "loop", "nd", "trigger" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
eval : com -> itree nd unit
:= rec eval_def.
Definition
eval
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "com", "eval_def", "itree", "nd", "rec" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
one_loop_tree : itree nd unit
:= rec (fun _ : unit => (* note: [or] is not allowed under [mfix]. *) b <- choice;; if b : bool then Ret tt else trigger (Call tt))%itree tt.
Definition
one_loop_tree
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "Ret", "choice", "itree", "nd", "rec", "trigger" ]
[itree] semantics of [one_loop].
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
eval_skip: rec eval_def skip ≈ Ret tt.
Proof. rewrite rec_as_interp. cbn. rewrite interp_ret. reflexivity. Qed.
Lemma
eval_skip
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "Ret", "eval_def", "interp_ret", "rec", "rec_as_interp" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
eval_one_loop : eval one_loop ≈ one_loop_tree.
Proof. einit. ecofix CIH. edrop. setoid_rewrite rec_as_interp. setoid_rewrite interp_bind. setoid_rewrite interp_vis. setoid_rewrite tau_eutt. setoid_rewrite interp_ret. setoid_rewrite bind_bind. setoid_rewrite bind_ret_l. setoid_rewrite bind_vis. evis. intros. setoid_rewrite bind_ret_l. destruc...
Lemma
eval_one_loop
examples
examples/Nimp.v
[ "Coq", "Relations", "ITree", "ITreeFacts", "ITreeNotations", "Paco", "paco", "Coq.Classes.Morphisms" ]
[ "bind_bind", "bind_ret_l", "bind_vis", "ecofix", "edrop", "einit", "eval", "eval_skip", "evis", "interp_bind", "interp_recursive_call", "interp_ret", "interp_vis", "one_loop", "one_loop_tree", "rec_as_interp", "tau_eutt" ]
SAZ: the [~] notation for eutt wasn't working here.
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
inputE : Type -> Prop
:= | Input : inputE nat.
Variant
inputE
examples
examples/ReadmeExample.v
[ "ITree", "ITreeFacts", "ITreeNotations" ]
[]
Custom effects
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
echo : itree inputE nat
:= x <- trigger Input ;; Ret x.
Definition
echo
examples
examples/ReadmeExample.v
[ "ITree", "ITreeFacts", "ITreeNotations" ]
[ "Ret", "inputE", "itree", "trigger" ]
Effectful programs
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
handler {E} (n : nat) : inputE ~> itree E
:= fun _ e => match e with | Input => Ret n end.
Definition
handler
examples
examples/ReadmeExample.v
[ "ITree", "ITreeFacts", "ITreeNotations" ]
[ "Ret", "inputE", "itree" ]
Effect handlers
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
echoed (n : nat) : itree void1 nat
:= interp (handler n) echo.
Definition
echoed
examples
examples/ReadmeExample.v
[ "ITree", "ITreeFacts", "ITreeNotations" ]
[ "echo", "handler", "interp", "itree", "void1" ]
Interpreters
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
echoed_id : forall n, echoed n ≈ Ret n.
Proof. intros n. (* echoed n *) unfold echoed, echo. (* ≈ interp (handler n) (x <- trigger Input ;; Ret x) *) rewrite interp_bind. (* ≈ x <- interp (handler n) Input ;; interp (handler n) (Ret x) *) rewrite interp_trigger. (* ≈ x <- handler n _ Input ;; interp (handle...
Theorem
echoed_id
examples
examples/ReadmeExample.v
[ "ITree", "ITreeFacts", "ITreeNotations" ]
[ "Ret", "bind_ret_l", "echo", "echoed", "interp_bind", "interp_ret", "interp_trigger" ]
Equational reasoning
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
typ
:= | Base | Arr (s:typ) (t:typ).
Inductive
typ
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
tm : typ -> Type
:= | Lit (n:nat) : tm Base | Var : forall (t:typ), V t -> tm t | App : forall t1 t2 (m1 : tm (Arr t1 t2)) (m2 : tm t1), tm t2 | Lam : forall t1 t2 (body : V t1 -> tm t2), tm (Arr t1 t2) | Opr : forall (m1 : tm Base) (m2 : tm Base), tm Base .
Inductive
tm
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "typ" ]
PHOAS variables
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
open_tm (G : list typ) (u:typ) : Type
:= match G with | [] => tm u | t::ts => V t -> (open_tm ts u) end.
Fixpoint
open_tm
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "tm", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
Term (G : list typ) (u:typ)
:= forall (V : typ -> Type), open_tm V G u.
Definition
Term
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "open_tm", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
denote_typ E (t:typ) : Type
:= match t with | Base => nat | Arr s t => (denote_typ E s) -> itree E (denote_typ E t) end.
Fixpoint
denote_typ
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "itree", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
denotation_tm_typ E (V:typ -> Type) (G : list typ) (u:typ)
:= match G with | [] => itree E (V u) | t::ts => (V t) -> denotation_tm_typ E V ts u end.
Fixpoint
denotation_tm_typ
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "itree", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
denote_closed_term {E} {u:typ} (m : tm (denote_typ E) u) : itree E (denote_typ E u)
:= match m with | Lit n => Ret n | Var x => Ret x | App m1 m2 => f <- (denote_closed_term m1) ;; x <- (denote_closed_term m2) ;; ans <- f x ;; ret ans | Lam body => ret (fun x => denote_closed_term (body x)) | Opr m1 m2 => x <- (denote_closed...
Fixpoint
denote_closed_term
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Ret", "denote_typ", "itree", "tm", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
denote_rec (V:typ -> Type) E (base : forall u (m : tm V u), itree E (V u)) (G: list typ) (u:typ) (m : open_tm V G u) : denotation_tm_typ E V G u := match G with | [] => base u _ | t::ts => fun (x : V t) => denote_rec V E base ts u _ end.
Next Obligation. simpl in m. exact m. Defined.
Fixpoint
denote_rec
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "denotation_tm_typ", "itree", "open_tm", "tm", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
denote E (G : list typ) (u:typ) (m : Term G u) : denotation_tm_typ E (denote_typ E) G u := denote_rec (denote_typ E) E (@denote_closed_term E) G u _.
Next Obligation. unfold Term in m. specialize (m (denote_typ E)). exact m. Defined.
Definition
denote
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term", "denotation_tm_typ", "denote_closed_term", "denote_rec", "denote_typ", "typ" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
id_tm : Term [] (Arr Base Base)
:= fun V => Lam (fun x => Var x).
Definition
id_tm
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
example : Term [] Base
:= fun V => App (id_tm V) (Lit 3).
Definition
example
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term", "id_tm" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
example_equiv E : (denote E [] Base example) ≈ Ret 3.
Proof. cbn. repeat rewrite bind_ret_l. reflexivity. Qed.
Lemma
example_equiv
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Ret", "bind_ret_l", "denote", "example" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
twice : Term [] (Arr (Arr Base Base) (Arr Base Base))
:= fun V => Lam (fun f => Lam (fun x => App (Var f) (App (Var f) (Var x)))).
Definition
twice
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
example2 : Term [] Base
:= fun V => App (App (twice V) (id_tm V)) (Lit 3).
Definition
example2
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term", "id_tm", "twice" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
big_example_equiv E : (denote E [] Base example2) ≈ Ret 3.
Proof. cbn. repeat rewrite bind_ret_l. reflexivity. Qed.
Lemma
big_example_equiv
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Ret", "bind_ret_l", "denote", "example2" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
add_2_tm : Term [] (Arr Base Base)
:= fun V => Lam (fun x => (Opr (Var x) (Lit 2))).
Definition
add_2_tm
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
example3 : Term [] Base
:= fun V => App (App (twice V) (add_2_tm V)) (Lit 3).
Definition
example3
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Term", "add_2_tm", "twice" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
big_example2_equiv E : (denote E [] Base example3) ≈ Ret 7.
Proof. cbn. repeat rewrite bind_ret_l. reflexivity. Qed.
Lemma
big_example2_equiv
examples
examples/STLC.v
[ "Coq", "Arith", "Lia", "List", "ExtLib", "Monad", "Traversable", "Data.List", "ITree", "ITreeFacts", "Basics.Basics", "Basics.Category", "Basics.CategoryKleisli", "Basics.CategoryKleisliFacts", "Basics.Basics.Monads", "ListNotations", "ITreeNotations" ]
[ "Ret", "bind_ret_l", "denote", "example3" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
IO : Type -> Type
:= | Read : IO nat | Write : nat -> IO unit.
Inductive
IO
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
read : itree IO nat
:= embed Read.
Definition
read
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[ "IO", "itree" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
write : nat -> itree IO unit
:= embed Write.
Definition
write
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[ "IO", "itree" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
example : itree IO unit
:= n <- read;; write n.
Definition
example
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[ "IO", "itree", "read", "write" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
SOME_NUMBER
:= 13.
Definition
SOME_NUMBER
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
test_interp : itree IO unit -> bool
:= fun t => match observe t with | VisF e k => match e in IO X return (X -> _) -> _ with | Read => fun id => match observe (k (id SOME_NUMBER)) with | VisF (Write n) _ => n =? SOME_NUMBER | _ => false end | _ => fun _ => false end (fun x => x) | _ => false end.
Definition
test_interp
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[ "IO", "SOME_NUMBER", "itree", "observe" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
test : test_interp example = true
:= eq_refl.
Example
test
examples.extract-io
examples/extract-io/IO.v
[ "Coq", "Arith", "ITree", "ITreeNotations", "Extraction" ]
[ "example", "test_interp" ]
https://github.com/DeepSpec/InteractionTrees
163b651faeb7f779638ffb409ef0e25ae0d6ffc3
End of preview. Expand in Data Studio

Coq-InteractionTrees

Structured dataset from Interaction Trees — Representing recursive and impure programs.

Source

Schema

Column Type Description
statement string Declaration signature/claim with the leading keyword removed (verbatim slice); the full declaration minus its proof
proof string Verbatim proof/body, empty if the declaration has none
type string Declaration keyword
symbolic_name string Declaration identifier
library string Sub-library
filename string Repository-relative source path
imports list[string] File-level Require/Import modules
deps list[string] Intra-corpus identifiers referenced
docstring string Preceding documentation comment, empty if absent
source_url string Upstream repository
commit string Upstream commit extracted

Statistics

  • Entries: 3,052
  • With proof: 3,016 (98.8%)
  • With docstring: 727 (23.8%)
  • Libraries: 19

By type

Type Count
Lemma 1,176
Definition 637
Instance 610
Notation 131
Ltac 106
Class 86
Variant 80
Inductive 69
Fixpoint 36
Parameter 28
Theorem 27
Fact 17
Example 10
CoFixpoint 9
Corollary 9
CoInductive 7
Coercion 6
Let 3
Record 3
Axiom 2

Example

ioE : Type -> Type
:=
| Input : ioE (list nat)
  (** Ask for a list of [nat] from the environment. *)

| Output : list nat -> ioE unit
  (** Send a list of [nat]. *)
.
  • type: Inductive | symbolic_name: ioE | examples/IntroductionSolutions.v

Use

Each declaration is split into a statement (signature/claim) and a proof (body) that are disjoint and together form the complete declaration, for proof modeling, autoformalization, retrieval, and dependency analysis via deps.

Citation

@misc{coq_interactiontrees_dataset,
  title  = {Coq-InteractionTrees},
  author = {Norton, Charles},
  year   = {2026},
  note   = {Extracted from https://github.com/DeepSpec/InteractionTrees, commit 163b651faeb7},
  url    = {https://huggingface.co/datasets/phanerozoic/Coq-InteractionTrees}
}
Downloads last month
62

Collection including phanerozoic/Coq-InteractionTrees