fact
stringlengths
9
10.6k
type
stringclasses
19 values
library
stringclasses
6 values
imports
listlengths
0
12
filename
stringclasses
101 values
symbolic_name
stringlengths
1
48
docstring
stringclasses
1 value
invH := inversion H; subst; clear H.
Ltac
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
inv
ceval_deterministic: forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2; generalize dependent st2; induction E1; intros st2 E2; inv E2. - (* E_Skip *) reflexivity. - (* E_Ass *) reflexivity. - (* E_Seq *) assert (st' = st'0) as EQ1. { (...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic
auto_example_1: forall (P Q R: Prop), (P -> Q) -> (Q -> R) -> P -> R. Proof. intros P Q R H1 H2 H3. apply H2. apply H1. assumption. Qed. (** The [auto] tactic frees us from this drudgery by _searching_ for a sequence of applications that will prove the goal *)
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_1
auto_example_1': forall (P Q R: Prop), (P -> Q) -> (Q -> R) -> P -> R. Proof. intros P Q R H1 H2 H3. auto. Qed. (** The [auto] tactic solves goals that are solvable by any combination of - [intros] and - [apply] (of hypotheses from the local context, by default). *) (** Using [auto] is always "safe" i...
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_1'
auto_example_2: forall P Q R S T U : Prop, (P -> Q) -> (P -> R) -> (T -> R) -> (S -> T -> U) -> ((P->Q) -> (P->S)) -> T -> P -> U. Proof. auto. Qed. (** Proof search could, in principle, take an arbitrarily long time, so there are limits to how far [auto] will search by default. *)
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_2
auto_example_3: forall (P Q R S T U: Prop), (P -> Q) -> (Q -> R) -> (R -> S) -> (S -> T) -> (T -> U) -> P -> U. Proof. auto. auto 6. Qed. (** When searching for potential proofs of the current goal, [auto] considers the hypotheses in the current context together with a _hint database_ of oth...
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_3
auto_example_4: forall P Q R : Prop, Q -> (Q -> R) -> P \/ (Q /\ R). Proof. auto. Qed. (** We can extend the hint database just for the purposes of one application of [auto] by writing [auto using ...]. *)
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_4
le_antisym: forall n m: nat, (n <= m /\ m <= n) -> n = m. Proof. intros. omega. Qed.
Lemma
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
le_antisym
auto_example_6: forall n m p : nat, (n <= p -> (n <= m /\ m <= n)) -> n <= p -> n = m. Proof. intros. auto. (* does nothing: auto doesn't destruct hypotheses! *) auto using le_antisym. Qed. (** Of course, in any given development there will probably be some specific constructors and lemmas that are use...
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_6
auto_example_6': forall n m p : nat, (n<= p -> (n <= m /\ m <= n)) -> n <= p -> n = m. Proof. intros. auto. (* picks up hint from database *) Qed.
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_6'
is_fortytwox := x = 42.
Definition
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
is_fortytwo
auto_example_7: forall x, (x <= 42 /\ 42 <= x) -> is_fortytwo x. Proof. auto. (* does nothing *) Abort. Hint Unfold is_fortytwo.
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_7
auto_example_7': forall x, (x <= 42 /\ 42 <= x) -> is_fortytwo x. Proof. auto. Qed. (** Now let's take a first pass over [ceval_deterministic] to simplify the proof script. *)
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_7'
ceval_deterministic': forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; auto. - (* E_Seq *) assert (st' = st'0) as EQ1 by auto. subst st'0. auto. - (* E_IfTrue *) ...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic'
ceval_deterministic'_alt: forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof with auto. intros c st st1 st2 E1 E2; generalize dependent st2; induction E1; intros st2 E2; inv E2... - (* E_Seq *) assert (st' = st'0) as EQ1... subst st'0... - (* E_IfTrue *)...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic'_alt
rwinvH1 H2 := rewrite H1 in H2; inv H2.
Ltac
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
rwinv
ceval_deterministic'': forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; auto. - (* E_Seq *) assert (st' = st'0) as EQ1 by auto. subst st'0. auto. - (* E_IfTrue *) +...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic''
find_rwinv:= match goal with H1: ?E = true, H2: ?E = false |- _ => rwinv H1 H2 end. (** The [match goal] tactic looks for two distinct hypotheses that have the form of equalities, with the same arbitrary expression [E] on the left and with conflicting boolean values on the right. If such hy...
Ltac
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
find_rwinv
ceval_deterministic''': forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; try find_rwinv; auto. - (* E_Seq *) assert (st' = st'0) as EQ1 by auto. subst st'0. auto. - (* ...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic'''
ceval_deterministic'''': forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; try find_rwinv; auto. - (* E_Seq *) rewrite (IHE1_1 st'0 H1) in *. auto. - (* E_WhileTrue *) + (* ...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic''''
find_eqn:= match goal with H1: forall x, ?P x -> ?L = ?R, H2: ?P ?X |- _ => rewrite (H1 X H2) in * end. (** The pattern [forall x, ?P x -> ?L = ?R] matches any hypothesis of the form "for all [x], _some property of [x]_ implies _some equality_." The property of [x] is bound to the pattern vari...
Ltac
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
find_eqn
ceval_deterministic''''': forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; try find_rwinv; repeat find_eqn; auto. Qed. (** The big payoff in this approach is that our proof script...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic'''''
com: Type := | CSkip : com | CAsgn : id -> aexp -> com | CSeq : com -> com -> com | CIf : bexp -> com -> com -> com | CWhile : bexp -> com -> com | CRepeat : com -> bexp -> com. (** [REPEAT] behaves like [WHILE], except that the loop guard is checked _after_ each execution of the body, with the loop ...
Inductive
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
com
ceval: state -> com -> state -> Prop := | E_Skip : forall st, ceval st SKIP st | E_Ass : forall st a1 n X, aeval st a1 = n -> ceval st (X ::= a1) (t_update st X n) | E_Seq : forall c1 c2 st st' st'', ceval st c1 st' -> ceval st' c2 st'' -> ceval st (c1 ; c2) st'' | E_IfTrue ...
Inductive
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval
ceval_deterministic: forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; try find_rwinv; repeat find_eqn; auto. - (* E_RepeatEnd *) + (* b evaluates to false (contradiction) *) ...
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic
ceval_deterministic': forall c st st1 st2, c / st \\ st1 -> c / st \\ st2 -> st1 = st2. Proof. intros c st st1 st2 E1 E2. generalize dependent st2; induction E1; intros st2 E2; inv E2; repeat find_eqn; try find_rwinv; auto. Qed.
Theorem
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_deterministic'
ceval_example1: (X ::= ANum 2;; IFB BLe (AId X) (ANum 1) THEN Y ::= ANum 3 ELSE Z ::= ANum 4 FI) / empty_state \\ (t_update (t_update empty_state X 2) Z 4). Proof. apply E_Seq with (t_update empty_state X 2). - apply E_Ass. reflexivity. - apply E_IfFalse. reflexivity. apply E_Ass...
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval_example1
ceval'_example1: (X ::= ANum 2;; IFB BLe (AId X) (ANum 1) THEN Y ::= ANum 3 ELSE Z ::= ANum 4 FI) / empty_state \\ (t_update (t_update empty_state X 2) Z 4). Proof. eapply E_Seq. (* 1 *) - apply E_Ass. (* 2 *) reflexivity. (* 3 *) - (* 4 *) apply E_IfFalse. reflexivity. apply...
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
ceval'_example1
st12:= t_update (t_update empty_state X 1) Y 2.
Definition
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
st12
st21:= t_update (t_update empty_state X 2) Y 1.
Definition
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
st21
auto_example_8: exists s', (IFB (BLe (AId X) (AId Y)) THEN (Z ::= AMinus (AId Y) (AId X)) ELSE (Y ::= APlus (AId X) (AId Z)) FI) / st21 \\ s'. Proof. eauto. Qed. (** The [eauto] tactic works just like [auto], except that it uses [eapply] instead of [apply]. *)
Example
sf-experiment
[ "Require Import Coq.omega.Omega", "Require Import Maps", "Require Import Imp" ]
sf-experiment/Auto.v
auto_example_8
day: Type := | monday : day | tuesday : day | wednesday : day | thursday : day | friday : day | saturday : day | sunday : day.
Inductive
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
day
next_weekday(d:day) : day := match d with | monday => tuesday | tuesday => wednesday | wednesday => thursday | thursday => friday | friday => monday | saturday => monday | sunday => monday end.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
next_weekday
test_next_weekday:= (next_weekday (next_weekday saturday)) = tuesday. (* BCP: Needs an equality test. QuickCheck test_next_weekday. *) (* BCP: QC needs the native one. (Unless we make this Checkable somehow.)
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
test_next_weekday
bool: Type := | true : bool | false : bool. *)
Inductive
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
bool
negb(b:bool) : bool := match b with | true => false | false => true end.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
negb
andb(b1:bool) (b2:bool) : bool := match b1 with | true => b2 | false => false end.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
andb
orb(b1:bool) (b2:bool) : bool := match b1 with | true => true | false => b2 end.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
orb
nandb(b1:bool) (b2:bool) : bool (* REPLACE THIS LINE WITH ":= _your_definition_ ." *) := false.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
nandb
test_nandb1:= (nandb true false).
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
test_nandb1
minustwo(n : nat) : nat := match n with | O => O | S O => O | S (S n') => n' end.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
minustwo
evenb(n:nat) : bool := match n with | O => true | S O => false | S (S n') => evenb n' end.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
evenb
oddb(n:nat) : bool := negb (evenb n).
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
oddb
test_oddb1:= oddb 1.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
test_oddb1
plus(n : nat) (m : nat) : nat := match n with | O => m | S n' => S (plus n' m) end.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
plus
mult(n m : nat) : nat := match n with | O => O | S n' => plus m (mult n' m) end.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
mult
test_mult1:= (mult 3 3) =? 9.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
test_mult1
minus(n m:nat) : nat := match n, m with | O , _ => O | S _ , O => n | S n', S m' => minus n' m' end.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
minus
exp(base power : nat) : nat := match power with | O => S O | S p => mult base (exp base p) end.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
exp
factorial(n:nat) : nat (* REPLACE THIS LINE WITH ":= _your_definition_ ." *) := 0.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
factorial
test_factorial1:= (factorial 3) =? 6. Notation "x + y" := (plus x y) (at level 50, left associativity) : nat_scope. Notation "x - y" := (minus x y) (at level 50, left associativity) : nat_scope. Notation "x * y" := (mu...
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
test_factorial1
beq_nat(n m : nat) : bool := match n with | O => match m with | O => true | S m' => false end | S n' => match m with | O => false | S m' => beq_nat n' m' end end.
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
beq_nat
leb(n m : nat) : bool := match n with | O => true | S n' => match m with | O => false | S m' => leb n' m' end end. Notation "'FORALLX' x : T , c" := (forAllShrink (@arbitrary T _) shrink (fun x => c)) (at level 200, x ident, T at level 200, c at level 200, right associativity (* ...
Fixpoint
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
leb
plus_O_n:= FORALL n:nat, 0 + n =? n.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
plus_O_n
bool_eq(x y : bool) : Dec (x = y). constructor. unfold ssrbool.decidable. repeat (decide equality). Defined.
Instance
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
bool_eq
negb_involutive(b: bool) := (negb (negb b) = b)?. Check negb_involutive. QuickChick negb_involutive.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
negb_involutive
negb_involutive2(b: bool) := Bool.eqb (negb (negb b)) b.
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
negb_involutive2
andb_commutative:= fun b c => Bool.eqb (andb b c) (andb c b). (* BCP: Don't know what to do with this one!
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
andb_commutative
identity_fn_applied_twice: forall (f : bool -> bool), (forall (x : bool), f x = x) -> forall (b : bool), f (f b) = b. *)
Theorem
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
identity_fn_applied_twice
andb_eq_orb:= fun (b c : bool) => (Bool.eqb (andb b c) (orb b c)) ==> (Bool.eqb b c).
Definition
sf-experiment
[ "From QuickChick Require Import QuickChick", "Require Import List ZArith", "From mathcomp Require Import ssreflect ssrfun ssrbool", "From mathcomp Require Import seq ssrnat eqtype" ]
sf-experiment/Basics.v
andb_eq_orb
aexp: Type := | ANum : nat -> aexp | APlus : aexp -> aexp -> aexp | AMinus : aexp -> aexp -> aexp | AMult : aexp -> aexp -> aexp.
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aexp
bexp: Type := | BTrue : bexp | BFalse : bexp | BEq : aexp -> aexp -> bexp | BLe : aexp -> aexp -> bexp | BNot : bexp -> bexp | BAnd : bexp -> bexp -> bexp. (** In this chapter, we'll elide the translation from the concrete syntax that a programmer would actually write to these abstract syntax trees...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
bexp
aeval(a : aexp) : nat := match a with | ANum n => n | APlus a1 a2 => (aeval a1) + (aeval a2) | AMinus a1 a2 => (aeval a1) - (aeval a2) | AMult a1 a2 => (aeval a1) * (aeval a2) end.
Fixpoint
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aeval
test_aeval1: aeval (APlus (ANum 2) (ANum 2)) = 4. Proof. reflexivity. Qed.
Example
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
test_aeval1
beval(b : bexp) : bool := match b with | BTrue => true | BFalse => false | BEq a1 a2 => beq_nat (aeval a1) (aeval a2) | BLe a1 a2 => leb (aeval a1) (aeval a2) | BNot b1 => negb (beval b1) | BAnd b1 b2 => andb (beval b1) (beval b2) end. (** We haven't defined very much yet, but we c...
Fixpoint
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
beval
optimize_0plus(a:aexp) : aexp := match a with | ANum n => ANum n | APlus (ANum 0) e2 => optimize_0plus e2 | APlus e1 e2 => APlus (optimize_0plus e1) (optimize_0plus e2) | AMinus e1 e2 => AMinus (optimize_0plus e1) (optimize_0plus e2) | AMult e1 e2 => AMult (optimize_0plus e1) (...
Fixpoint
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
optimize_0plus
test_optimize_0plus: optimize_0plus (APlus (ANum 2) (APlus (ANum 0) (APlus (ANum 0) (ANum 1)))) = APlus (ANum 2) (ANum 1). Proof. reflexivity. Qed. (** But if we want to be sure the optimization is correct -- i.e., that evaluating an optimized expression g...
Example
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
test_optimize_0plus
optimize_0plus_sound: forall a, aeval (optimize_0plus a) = aeval a. Proof. intros a. induction a. - (* ANum *) reflexivity. - (* APlus *) destruct a1. + (* a1 = ANum n *) destruct n. * (* n = 0 *) simpl. apply IHa2. * (* n <> 0 *) simpl. rewrite IHa2. reflexivity. + (* a1 = APlus a1_1 a1_2 ...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
optimize_0plus_sound
silly1: forall ae, aeval ae = aeval ae. Proof. try reflexivity. (* this just does [reflexivity] *) Qed.
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
silly1
silly2: forall (P : Prop), P -> P. Proof. intros P HP. try reflexivity. (* just [reflexivity] would have failed *) apply HP. (* we can still finish the proof in some other way *) Qed. (** There is no real reason to use [try] in completely manual proofs like these, but it is very useful for doing automated ...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
silly2
foo: forall n, leb 0 n = true. Proof. intros. destruct n. - (* n=0 *) simpl. reflexivity. - (* n=Sn' *) simpl. reflexivity. Qed.
Lemma
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
foo
foo': forall n, leb 0 n = true. Proof. intros. destruct n; simpl; reflexivity. Qed. (** Using [try] and [;] together, we can get rid of the repetition in the proof that was bothering us a little while ago. *)
Lemma
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
foo'
optimize_0plus_sound': forall a, aeval (optimize_0plus a) = aeval a. Proof. intros a. induction a; try (simpl; rewrite IHa1; rewrite IHa2; reflexivity). (* ... but the remaining cases -- ANum and APlus -- are different: *) - (* ANum *) reflexivity. - (* APlus *) destruct a1; try (simp...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
optimize_0plus_sound'
optimize_0plus_sound'': forall a, aeval (optimize_0plus a) = aeval a. Proof. intros a. induction a; try (simpl; rewrite IHa1; rewrite IHa2; reflexivity); try reflexivity. - (* APlus *) destruct a1; try (simpl; simpl in IHa1; rewrite IHa1; rewrite IHa2; reflexivity). + (* a1...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
optimize_0plus_sound''
In10: In 10 [1;2;3;4;5;6;7;8;9;10]. Proof. repeat (try (left; reflexivity); right). Qed. (** The tactic [repeat T] never fails: if the tactic [T] doesn't apply to the original goal, then repeat still succeeds without changing the original goal (i.e., it repeats zero times). *)
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
In10
In10': In 10 [1;2;3;4;5;6;7;8;9;10]. Proof. repeat (left; reflexivity). repeat (right; try (left; reflexivity)). Qed. (** The tactic [repeat T] also does not have any upper bound on the number of times it applies [T]. If [T] is a tactic that always succeeds, then repeat [T] will loop forever (e.g., [repea...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
In10'
optimize_0plus_b(b : bexp) : bexp (* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted.
Fixpoint
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
optimize_0plus_b
optimize_0plus_b_sound: forall b, beval (optimize_0plus_b b) = beval b. Proof. (* FILL IN HERE *) Admitted. (** _Design exercise_: The optimization implemented by our [optimize_0plus] function is only one of many possible optimizations on arithmetic and boolean expressions. Write a more sophisticated ...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
optimize_0plus_b_sound
silly_presburger_example: forall m n o p, m + n <= n + o /\ o + 3 = p + 3 -> m <= p. Proof. intros. omega. Qed. (** Finally, here are some miscellaneous tactics that you may find convenient. - [clear H]: Delete hypothesis [H] from the context. - [subst x]: Find an assumption [x = e] or [e = x] ...
Example
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
silly_presburger_example
aevalR: aexp -> nat -> Prop := | E_ANum : forall (n: nat), aevalR (ANum n) n | E_APlus : forall (e1 e2: aexp) (n1 n2: nat), aevalR e1 n1 -> aevalR e2 n2 -> aevalR (APlus e1 e2) (n1 + n2) | E_AMinus: forall (e1 e2: aexp) (n1 n2: nat), aevalR e1 n1 -> aevalR e2 n2 -> aeval...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aevalR
aevalR: aexp -> nat -> Prop := | E_ANum : forall (n:nat), (ANum n) \\ n | E_APlus : forall (e1 e2: aexp) (n1 n2 : nat), (e1 \\ n1) -> (e2 \\ n2) -> (APlus e1 e2) \\ (n1 + n2) | E_AMinus : forall (e1 e2: aexp) (n1 n2 : nat), (e1 \\ n1) -> (e2 \\ n2) -> (AMinus e1 e2) \\ (n1 - n2) | E_AMult : f...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aevalR
aeval_iff_aevalR: forall a n, (a \\ n) <-> aeval a = n. Proof. split. - (* -> *) intros H. induction H; simpl. + (* E_ANum *) reflexivity. + (* E_APlus *) rewrite IHaevalR1. rewrite IHaevalR2. reflexivity. + (* E_AMinus *) rewrite IHaevalR1. rewrite IHaevalR2. reflexivity. + (* ...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aeval_iff_aevalR
aeval_iff_aevalR': forall a n, (a \\ n) <-> aeval a = n. Proof. split. - (* -> *) intros H; induction H; subst; reflexivity. - (* <- *) generalize dependent n. induction a; simpl; intros; subst; constructor; try apply IHa1; try apply IHa2; reflexivity. Qed. (** Write a relation [bevalR] in t...
Theorem
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aeval_iff_aevalR'
bevalR: bexp -> bool -> Prop := .
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
bevalR
beval_iff_bevalR: forall b bv, bevalR b bv <-> beval b = bv. Proof. (* FILL IN HERE *) Admitted.
Lemma
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
beval_iff_bevalR
aexp: Type := | ANum : nat -> aexp | APlus : aexp -> aexp -> aexp | AMinus : aexp -> aexp -> aexp | AMult : aexp -> aexp -> aexp | ADiv : aexp -> aexp -> aexp. (* <--- new *) (** Extending the definition of [aeval] to handle this new operation would not be straightforward (what should we return as the ...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aexp
aevalR: aexp -> nat -> Prop := | E_ANum : forall (n:nat), (ANum n) \\ n | E_APlus : forall (a1 a2: aexp) (n1 n2 : nat), (a1 \\ n1) -> (a2 \\ n2) -> (APlus a1 a2) \\ (n1 + n2) | E_AMinus : forall (a1 a2: aexp) (n1 n2 : nat), (a1 \\ n1) -> (a2 \\ n2) -> (AMinus a1 a2) \\ (n1 - n2) | E_AMult : f...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aevalR
aexp: Type := | AAny : aexp (* <--- NEW *) | ANum : nat -> aexp | APlus : aexp -> aexp -> aexp | AMinus : aexp -> aexp -> aexp | AMult : aexp -> aexp -> aexp. (** Again, extending [aeval] would be tricky, since now evaluation is _not_ a deterministic function from expressions to number...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aexp
aevalR: aexp -> nat -> Prop := | E_Any : forall (n:nat), AAny \\ n (* <--- new *) | E_ANum : forall (n:nat), (ANum n) \\ n | E_APlus : forall (a1 a2: aexp) (n1 n2 : nat), (a1 \\ n1) -> (a2 \\ n2) -> (APlus a1 a2) \\ (n1 + n2) | E_AMinus : forall (a1 a2: aexp) (n1 n2 : nat), ...
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aevalR
state:= total_map nat.
Definition
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
state
empty_state: state := t_empty 0. (** We can add variables to the arithmetic expressions we had before by simply adding one more constructor: *)
Definition
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
empty_state
aexp: Type := | ANum : nat -> aexp | AId : id -> aexp (* <----- NEW *) | APlus : aexp -> aexp -> aexp | AMinus : aexp -> aexp -> aexp | AMult : aexp -> aexp -> aexp. (** Defining a few variable names as notational shorthands will make examples easier to read: *)
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aexp
W: id := Id "W".
Definition
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
W
X: id := Id "X".
Definition
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
X
Y: id := Id "Y".
Definition
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
Y
Z: id := Id "Z". (** (This convention for naming program variables ([X], [Y], [Z]) clashes a bit with our earlier use of uppercase letters for types. Since we're not using polymorphism heavily in the chapters devoped to Imp, this overloading should not cause confusion.) *) (** The definition of [bexp]s i...
Definition
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
Z
bexp: Type := | BTrue : bexp | BFalse : bexp | BEq : aexp -> aexp -> bexp | BLe : aexp -> aexp -> bexp | BNot : bexp -> bexp | BAnd : bexp -> bexp -> bexp. (** The arith and boolean evaluators are extended to handle variables in the obvious way, taking a state as an extra argument: *)
Inductive
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
bexp
aeval(st : state) (a : aexp) : nat := match a with | ANum n => n | AId x => st x (* <----- NEW *) | APlus a1 a2 => (aeval st a1) + (aeval st a2) | AMinus a1 a2 => (aeval st a1) - (aeval st a2) | AMult a1 a2 => (aeval st a1) * (aeval st a2) end.
Fixpoint
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aeval
beval(st : state) (b : bexp) : bool := match b with | BTrue => true | BFalse => false | BEq a1 a2 => beq_nat (aeval st a1) (aeval st a2) | BLe a1 a2 => leb (aeval st a1) (aeval st a2) | BNot b1 => negb (beval st b1) | BAnd b1 b2 => andb (beval st b1) (beval st b2) end.
Fixpoint
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
beval
aexp1: aeval (t_update empty_state X 5) (APlus (ANum 3) (AMult (AId X) (ANum 2))) = 13. Proof. reflexivity. Qed.
Example
sf-experiment
[ "Require Import Coq.Bool.Bool", "Require Import Coq.Arith.Arith", "Require Import Coq.Arith.EqNat", "Require Import Coq.omega.Omega", "Require Import Coq.Lists.List", "Require Import Maps" ]
sf-experiment/Imp.v
aexp1