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 |
|---|---|---|---|---|---|---|
ev_minus2': forall n,
ev n -> ev (pred (pred n)).
Proof.
intros n E.
destruct E as [| n' E'].
- (* E = ev_0 *) simpl. apply ev_0.
- (* E = ev_SS n' E' *) simpl. apply E'. Qed.
(** The difference between the two forms is that [inversion] is more
convenient when used on a hypothesis that consists of an in... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_minus2' | |
evSS_ev: forall n,
ev (S (S n)) -> ev n.
(** Intuitively, we know that evidence for the hypothesis cannot
consist just of the [ev_0] constructor, since [O] and [S] are
different constructors of the type [nat]; hence, [ev_SS] is the
only case that applies. Unfortunately, [destruct] is not smart
enoug... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | evSS_ev | |
evSS_ev: forall n,
ev (S (S n)) -> ev n.
Proof.
intros n E.
inversion E as [| n' E'].
apply E'.
Qed.
(** By using [inversion], we can also apply the principle of explosion
to "obviously contradictory" hypotheses involving inductive
properties. For example: *) | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | evSS_ev | |
one_not_even: ~ ev 1.
Proof.
intros H. inversion H. Qed. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | one_not_even | |
SSSSev__even: forall n,
ev (S (S (S (S n)))) -> ev n.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | SSSSev__even | |
even5_nonsense:
ev 5 -> 2 + 2 = 9.
Proof.
(* FILL IN HERE *) Admitted.
(** The way we've used [inversion] here may seem a bit
mysterious at first. Until now, we've only used [inversion] on
equality propositions, to utilize injectivity of constructors or
to discriminate between different constructors. ... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | even5_nonsense | |
ev_even_firsttry: forall n,
ev n -> exists k, n = double k.
Proof.
(** We could try to proceed by case analysis or induction on [n]. But
since [ev] is mentioned in a premise, this strategy would probably
lead to a dead end, as in the previous section. Thus, it seems
better to first try inversion on the... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_even_firsttry | |
ev_even: forall n,
ev n -> exists k, n = double k.
Proof.
intros n E.
induction E as [|n' E' IH].
- (* E = ev_0 *)
exists 0. reflexivity.
- (* E = ev_SS n' E'
with IH : exists k', n' = double k' *)
destruct IH as [k' Hk'].
rewrite Hk'. exists (S k'). reflexivity.
Qed.
(** Here, we can see ... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_even | |
ev_even_iff: forall n,
ev n <-> exists k, n = double k.
Proof.
intros n. split.
- (* -> *) apply ev_even.
- (* <- *) intros [k Hk]. rewrite Hk. apply ev_double.
Qed.
(** As we will see in later chapters, induction on evidence is a
recurring technique across many areas, and in particular when
formalizin... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_even_iff | |
ev_sum: forall n m, ev n -> ev m -> ev (n + m).
Proof.
(* FILL IN HERE *) Admitted.
(** In general, there may be multiple ways of defining a
property inductively. For example, here's a (slightly contrived)
alternative definition for [ev]: *) | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_sum | |
ev': nat -> Prop :=
| ev'_0 : ev' 0
| ev'_2 : ev' 2
| ev'_sum : forall n m, ev' n -> ev' m -> ev' (n + m).
(** Prove that this definition is logically equivalent to the old
one. (You may want to look at the previous theorem when you get
to the induction step.) *) | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev' | |
ev'_ev: forall n, ev' n <-> ev n.
Proof.
(* FILL IN HERE *) Admitted.
(** Finding the appropriate thing to do induction on is a
bit tricky here: *) | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev'_ev | |
ev_ev__ev: forall n m,
ev (n+m) -> ev n -> ev m.
Proof.
(* FILL IN HERE *) Admitted.
(** This exercise just requires applying existing lemmas. No
induction or even case analysis is needed, though some of the
rewriting may be tedious. *) | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_ev__ev | |
ev_plus_plus: forall n m p,
ev (n+m) -> ev (n+p) -> ev (m+p).
Proof.
(* FILL IN HERE *) Admitted.
(** A proposition parameterized by a number (such as [ev])
can be thought of as a _property_ -- i.e., it defines
a subset of [nat], namely those numbers for which the proposition
is provable. In the same... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | ev_plus_plus | |
le: nat -> nat -> Prop :=
| le_n : forall n, le n n
| le_S : forall n m, (le n m) -> (le n (S m)).
Notation "m <= n" := (le m n).
(** Proofs of facts about [<=] using the constructors [le_n] and
[le_S] follow the same patterns as proofs about properties, like
[ev] above. We can [apply] the constructors to... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | le | |
test_le1:
3 <= 3.
Proof.
apply le_n. Qed. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_le1 | |
test_le2:
3 <= 6.
Proof.
apply le_S. apply le_S. apply le_S. apply le_n. Qed. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_le2 | |
test_le3:
(2 <= 1) -> 2 + 2 = 5.
Proof.
intros H. inversion H. inversion H2. Qed.
(** The "strictly less than" relation [n < m] can now be defined
in terms of [le]. *) | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_le3 | |
lt(n m:nat) := le (S n) m.
Notation "m < n" := (lt m n). | Definition | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | lt | |
square_of: nat -> nat -> Prop :=
| sq : forall n:nat, square_of n (n * n). | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | square_of | |
next_nat: nat -> nat -> Prop :=
| nn : forall n:nat, next_nat n (S n). | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | next_nat | |
next_even: nat -> nat -> Prop :=
| ne_1 : forall n, ev (S n) -> next_even n (S n)
| ne_2 : forall n, ev (S (S n)) -> next_even n (S (S n)).
(** Define an inductive binary relation [total_relation] that holds
between every pair of natural numbers. *)
(** Define an inductive binary relation [empty_relation] (o... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | next_even | |
le_trans: forall m n o, m <= n -> n <= o -> m <= o.
Proof.
(* FILL IN HERE *) Admitted. | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | le_trans | |
O_le_n: forall n,
0 <= n.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | O_le_n | |
n_le_m__Sn_le_Sm: forall n m,
n <= m -> S n <= S m.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | n_le_m__Sn_le_Sm | |
Sn_le_Sm__n_le_m: forall n m,
S n <= S m -> n <= m.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | Sn_le_Sm__n_le_m | |
le_plus_l: forall a b,
a <= a + b.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | le_plus_l | |
plus_lt: forall n1 n2 m,
n1 + n2 < m ->
n1 < m /\ n2 < m.
Proof.
unfold lt.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | plus_lt | |
lt_S: forall n m,
n < m ->
n < S m.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | lt_S | |
leb_complete: forall n m,
leb n m = true -> n <= m.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | leb_complete | |
leb_correct: forall n m,
n <= m ->
leb n m = true.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | leb_correct | |
leb_true_trans: forall n m o,
leb n m = true -> leb m o = true -> leb n o = true.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | leb_true_trans | |
leb_iff: forall n m,
leb n m = true <-> n <= m.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | leb_iff | |
R: nat -> nat -> nat -> Prop :=
| c1 : R 0 0 0
| c2 : forall m n o, R m n o -> R (S m) n (S o)
| c3 : forall m n o, R m n o -> R m (S n) (S o)
| c4 : forall m n o, R (S m) (S n) (S (S o)) -> R m n o
| c5 : forall m n o, R m n o -> R n m o.
(** - Which of the following propositions are provable?
- ... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | R | |
fR: nat -> nat -> nat
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted. | Definition | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | fR | |
R_equiv_fR: forall m n o, R m n o <-> fR m n = o.
Proof.
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | R_equiv_fR | |
reg_exp(T : Type) : Type :=
| EmptySet : reg_exp T
| EmptyStr : reg_exp T
| Char : T -> reg_exp T
| App : reg_exp T -> reg_exp T -> reg_exp T
| Union : reg_exp T -> reg_exp T -> reg_exp T
| Star : reg_exp T -> reg_exp T.
Arguments EmptySet {T}.
Arguments EmptyStr {T}.
Arguments Char {T} _.
Arguments App {T} _ _.
Argum... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp | |
exp_match{T} : list T -> reg_exp T -> Prop :=
| MEmpty : exp_match [] EmptyStr
| MChar : forall x, exp_match [x] (Char x)
| MApp : forall s1 re1 s2 re2,
exp_match s1 re1 ->
exp_match s2 re2 ->
exp_match (s1 ++ s2) (App re1 re2)
| MUnionL : forall s1 re1 re2,
exp_match s1 r... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | exp_match | |
reg_exp_ex1: [1] =~ Char 1.
Proof.
apply MChar.
Qed. | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp_ex1 | |
reg_exp_ex2: [1; 2] =~ App (Char 1) (Char 2).
Proof.
apply (MApp [1] _ [2]).
- apply MChar.
- apply MChar.
Qed.
(** (Notice how the last example applies [MApp] to the strings [[1]]
and [[2]] directly. Since the goal mentions [[1; 2]] instead of
[[1] ++ [2]], Coq wouldn't be able to figure out how to spl... | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp_ex2 | |
reg_exp_ex3: ~ ([1; 2] =~ Char 1).
Proof.
intros H. inversion H.
Qed.
(** We can define helper functions to help write down regular
expressions. The [reg_exp_of_list] function constructs a regular
expression that matches exactly the list that it receives as an
argument: *) | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp_ex3 | |
reg_exp_of_list{T} (l : list T) :=
match l with
| [] => EmptyStr
| x :: l' => App (Char x) (reg_exp_of_list l')
end. | Fixpoint | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp_of_list | |
reg_exp_ex4: [1; 2; 3] =~ reg_exp_of_list [1; 2; 3].
Proof.
simpl. apply (MApp [1]).
{ apply MChar. }
apply (MApp [2]).
{ apply MChar. }
apply (MApp [3]).
{ apply MChar. }
apply MEmpty.
Qed.
(** We can also prove general facts about [exp_match]. For instance,
the following lemma shows that every str... | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp_ex4 | |
MStar1:
forall T s (re : reg_exp T) ,
s =~ re ->
s =~ Star re.
Proof.
intros T s re H.
rewrite <- (app_nil_r _ s).
apply (MStarApp s [] re).
- apply H.
- apply MStar0.
Qed.
(** (Note the use of [app_nil_r] to change the goal of the theorem to
exactly the same shape expected by [MStarApp].) *)
... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | MStar1 | |
empty_is_empty: forall T (s : list T),
~ (s =~ EmptySet).
Proof.
(* FILL IN HERE *) Admitted. | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | empty_is_empty | |
MUnion': forall T (s : list T) (re1 re2 : reg_exp T),
s =~ re1 \/ s =~ re2 ->
s =~ Union re1 re2.
Proof.
(* FILL IN HERE *) Admitted.
(** The next lemma is stated in terms of the [fold] function from the
[Poly] chapter: If [ss : list (list T)] represents a sequence of
strings [s1, ..., sn], then [fold ap... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | MUnion' | |
MStar': forall T (ss : list (list T)) (re : reg_exp T),
(forall s, In s ss -> s =~ re) ->
fold app ss [] =~ Star re.
Proof.
(* FILL IN HERE *) Admitted.
(** Prove that [reg_exp_of_list] satisfies the following
specification: *) | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | MStar' | |
reg_exp_of_list_spec: forall T (s1 s2 : list T),
s1 =~ reg_exp_of_list s2 <-> s1 = s2.
Proof.
(* FILL IN HERE *) Admitted.
(** Since the definition of [exp_match] has a recursive
structure, we might expect that proofs involving regular
expressions will often require induction on evidence. For
example,... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reg_exp_of_list_spec | |
re_chars{T} (re : reg_exp T) : list T :=
match re with
| EmptySet => []
| EmptyStr => []
| Char x => [x]
| App re1 re2 => re_chars re1 ++ re_chars re2
| Union re1 re2 => re_chars re1 ++ re_chars re2
| Star re => re_chars re
end. | Fixpoint | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | re_chars | |
in_re_match: forall T (s : list T) (re : reg_exp T) (x : T),
s =~ re ->
In x s ->
In x (re_chars re).
Proof.
intros T s re x Hmatch Hin.
induction Hmatch
as [
|x'
|s1 re1 s2 re2 Hmatch1 IH1 Hmatch2 IH2
|s1 re1 re2 Hmatch IH|re1 s2 re2 Hmatch IH
|re|s1 s2 re Hmatch1 IH1 Hmat... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | in_re_match | |
re_not_empty{T : Type} (re : reg_exp T) : bool
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *). Admitted. | Fixpoint | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | re_not_empty | |
re_not_empty_correct: forall T (re : reg_exp T),
(exists s, s =~ re) <-> re_not_empty re = true.
Proof.
(* FILL IN HERE *) Admitted.
(** One potentially confusing feature of the [induction] tactic is
that it happily lets you try to set up an induction over a term
that isn't sufficiently general. The effe... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | re_not_empty_correct | |
star_app: forall T (s1 s2 : list T) (re : reg_exp T),
s1 =~ Star re ->
s2 =~ Star re ->
s1 ++ s2 =~ Star re.
Proof.
intros T s1 s2 re H1.
(** Just doing an [inversion] on [H1] won't get us very far in the
recursive cases. (Try it!). So we need induction. Here is a naive
first attempt: *)
induction H... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | star_app | |
star_app: forall T (s1 s2 : list T) (re re' : reg_exp T),
s1 =~ re' ->
re' = Star re ->
s2 =~ Star re ->
s1 ++ s2 =~ Star re.
(** We can now proceed by performing induction over evidence directly,
because the argument to the first hypothesis is sufficiently
general, which means that we can discharge mo... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | star_app | |
star_app: forall T (s1 s2 : list T) (re : reg_exp T),
s1 =~ Star re ->
s2 =~ Star re ->
s1 ++ s2 =~ Star re.
Proof.
intros T s1 s2 re H1.
remember (Star re) as re'.
generalize dependent s2.
induction H1
as [|x'|s1 re1 s2' re2 Hmatch1 IH1 Hmatch2 IH2
|s1 re1 re2 Hmatch IH|re1 s2' re2 Hmatch I... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | star_app | |
MStar'': forall T (s : list T) (re : reg_exp T),
s =~ Star re ->
exists ss : list (list T),
s = fold app ss []
/\ forall s', In s' ss -> s' =~ re.
Proof.
(* FILL IN HERE *) Admitted.
(** One of the first really interesting theorems in the theory of
regular expressions is the so-called _pumping lemma_... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | MStar'' | |
pumping_constant{T} (re : reg_exp T) : nat :=
match re with
| EmptySet => 0
| EmptyStr => 1
| Char _ => 2
| App re1 re2 =>
pumping_constant re1 + pumping_constant re2
| Union re1 re2 =>
pumping_constant re1 + pumping_constant re2
| Star _ => 1
end.
(** Next, it is useful to define an auxili... | Fixpoint | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | pumping_constant | |
napp{T} (n : nat) (l : list T) : list T :=
match n with
| 0 => []
| S n' => l ++ napp n' l
end. | Fixpoint | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | napp | |
napp_plus: forall T (n m : nat) (l : list T),
napp (n + m) l = napp n l ++ napp m l.
Proof.
intros T n m l.
induction n as [|n IHn].
- reflexivity.
- simpl. rewrite IHn, app_assoc. reflexivity.
Qed.
(** Now, the pumping lemma itself says that, if [s =~ re] and if the
length of [s] is at least the pumping... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | napp_plus | |
pumping: forall T (re : reg_exp T) s,
s =~ re ->
pumping_constant re <= length s ->
exists s1 s2 s3,
s = s1 ++ s2 ++ s3 /\
s2 <> [] /\
forall m, s1 ++ napp m s2 ++ s3 =~ re.
(** To streamline the proof (which you are to fill in), the [omega]
tactic, which is enabled by the following [Require], is... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | pumping | |
filter_not_empty_In: forall n l,
filter (beq_nat n) l <> [] ->
In n l.
Proof.
intros n l. induction l as [|m l' IHl'].
- (* l = [] *)
simpl. intros H. apply H. reflexivity.
- (* l = m :: l' *)
simpl. destruct (beq_nat n m) eqn:H.
+ (* beq_nat n m = true *)
intros _. rewrite beq_nat_true_iff ... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | filter_not_empty_In | |
reflect: Prop -> bool -> Prop :=
| ReflectT : forall (P:Prop), P -> reflect P true
| ReflectF : forall (P:Prop), ~ P -> reflect P false.
(** Before explaining this, let's rearrange it a little: Since the
types of both [ReflectT] and [ReflectF] begin with
[forall (P:Prop)], we can make the definition a bit more... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reflect | |
reflect(P : Prop) : bool -> Prop :=
| ReflectT : P -> reflect P true
| ReflectF : ~ P -> reflect P false.
(** The [reflect] property takes two arguments: a proposition
[P] and a boolean [b]. Intuitively, it states that the property
[P] is _reflected_ in (i.e., equivalent to) the boolean [b]: [P]
holds if ... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reflect | |
iff_reflect: forall P b, (P <-> b = true) -> reflect P b.
Proof.
intros P b H. destruct b.
- apply ReflectT. rewrite H. reflexivity.
- apply ReflectF. rewrite H. intros H'. inversion H'.
Qed. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | iff_reflect | |
reflect_iff: forall P b, reflect P b -> (P <-> b = true).
Proof.
(* FILL IN HERE *) Admitted.
(** The advantage of [reflect] over the normal "if and only if"
connective is that, by destructing a hypothesis or lemma of the
form [reflect P b], we can perform case analysis on [b] while at
the same time gene... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | reflect_iff | |
beq_natP: forall n m, reflect (n = m) (beq_nat n m).
Proof.
intros n m.
apply iff_reflect. rewrite beq_nat_true_iff. reflexivity.
Qed.
(** The new proof of [filter_not_empty_In] now goes as follows.
Notice how the calls to [destruct] and [apply] are combined into a
single call to [destruct]. *)
(** (To se... | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | beq_natP | |
filter_not_empty_In': forall n l,
filter (beq_nat n) l <> [] ->
In n l.
Proof.
intros n l. induction l as [|m l' IHl'].
- (* l = [] *)
simpl. intros H. apply H. reflexivity.
- (* l = m :: l' *)
simpl. destruct (beq_natP n m) as [H | H].
+ (* n = m *)
intros _. rewrite H. left. reflexivity.
... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | filter_not_empty_In' | |
countn l :=
match l with
| [] => 0
| m :: l' => (if beq_nat n m then 1 else 0) + count n l'
end. | Fixpoint | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | count | |
beq_natP_practice: forall n l,
count n l = 0 -> ~(In n l).
Proof.
(* FILL IN HERE *) Admitted.
(** This technique gives us only a small gain in convenience for
the proofs we've seen here, but using [reflect] consistently often
leads to noticeably shorter and clearer scripts as proofs get
larger. We'll... | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | beq_natP_practice | |
nostutter{X:Type} : list X -> Prop :=
.
(** Make sure each of these tests succeeds, but feel free to change
the suggested proof (in comments) if the given one doesn't work
for you. Your definition might be different from ours and still
be correct, in which case the examples might need a different
proof... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | nostutter | |
test_nostutter_1: nostutter [3;1;4;1;5;6].
(* FILL IN HERE *) Admitted.
(*
Proof. repeat constructor; apply beq_nat_false_iff; auto.
Qed.
*) | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_nostutter_1 | |
test_nostutter_2: nostutter (@nil nat).
(* FILL IN HERE *) Admitted.
(*
Proof. repeat constructor; apply beq_nat_false_iff; auto.
Qed.
*) | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_nostutter_2 | |
test_nostutter_3: nostutter [5].
(* FILL IN HERE *) Admitted.
(*
Proof. repeat constructor; apply beq_nat_false; auto. Qed.
*) | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_nostutter_3 | |
test_nostutter_4: not (nostutter [3;1;1;4]).
(* FILL IN HERE *) Admitted.
(*
Proof. intro.
repeat match goal with
h: nostutter _ |- _ => inversion h; clear h; subst
end.
contradiction H1; auto. Qed.
*)
(** Let's prove that our definition of [filter] from the [Poly]
chapter matches an abstract spe... | Example | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | test_nostutter_4 | |
in_split: forall (X:Type) (x:X) (l:list X),
In x l ->
exists l1 l2, l = l1 ++ x :: l2.
Proof.
(* FILL IN HERE *) Admitted.
(** Now define a property [repeats] such that [repeats X l] asserts
that [l] contains at least one repeated element (of type [X]). *) | Lemma | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | in_split | |
repeats{X:Type} : list X -> Prop :=
.
(** Now, here's a way to formalize the pigeonhole principle. Suppose
list [l2] represents a list of pigeonhole labels, and list [l1]
represents the labels assigned to a list of items. If there are
more items than labels, at least two items must have the same
labe... | Inductive | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | repeats | |
pigeonhole_principle: forall (X:Type) (l1 l2:list X),
excluded_middle ->
(forall x, In x l1 -> In x l2) ->
length l2 < length l1 ->
repeats l1.
Proof.
intros X l1. induction l1 as [|x l1' IHl1'].
(* FILL IN HERE *) Admitted. | Theorem | sf-experiment | [
"Require Export Logic"
] | sf-experiment/IndProp.v | pigeonhole_principle | |
plus_n_O(n:nat) :=
n =? n + 0. | Definition | sf-experiment | [
"Require Export Basics",
"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/Induction.v | plus_n_O | |
natprod: Type :=
| pair : nat -> nat -> natprod.
Derive Arbitrary for natprod.
Derive Show for natprod. | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | natprod | |
natprod_eq(x y : natprod) : 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",
"Require Export Induction"
] | sf-experiment/Lists.v | natprod_eq | |
fst(p : natprod) : nat :=
match p with
| pair x y => x
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",
"Require Export Induction"
] | sf-experiment/Lists.v | fst | |
snd(p : natprod) : nat :=
match p with
| pair x y => y
end.
Notation "( x , y )" := (pair x y). | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | snd | |
swap_pair(p : natprod) : natprod :=
match p with
| (x,y) => (y,x)
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",
"Require Export Induction"
] | sf-experiment/Lists.v | swap_pair | |
equal_pair(p : natprod) (q : natprod) : bool :=
match p,q with
| (p1,p2),(q1,q2) => andb (p1 =? q1) (p2 =? q2)
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",
"Require Export Induction"
] | sf-experiment/Lists.v | equal_pair | |
surjective_pairing(p : natprod) :=
equal_pair p (fst p, snd p). | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | surjective_pairing | |
natlist: Type :=
| nil : natlist
| cons : nat -> natlist -> natlist.
Derive Arbitrary for natlist.
Derive Show for natlist. | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | natlist | |
natlist_eq(x y : natlist) : Dec (x = y).
constructor. unfold ssrbool.decidable. repeat (decide equality). Defined.
Notation "x :: l" := (cons x l)
(at level 60, right associativity).
Notation "[ ]" := nil.
Notation "[ x ; .. ; y ]" := (cons x .. (cons y nil) ..). | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | natlist_eq | |
repeat(n count : nat) : natlist :=
match count with
| O => nil
| S count' => n :: (repeat n count')
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",
"Require Export Induction"
] | sf-experiment/Lists.v | repeat | |
length(l:natlist) : nat :=
match l with
| nil => O
| h :: t => S (length t)
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",
"Require Export Induction"
] | sf-experiment/Lists.v | length | |
app(l1 l2 : natlist) : natlist :=
match l1 with
| nil => l2
| h :: t => h :: (app t l2)
end.
Notation "x ++ y" := (app x y)
(right associativity, at level 60). | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | app | |
test_app1: [1;2;3] ++ [4;5] = [1;2;3;4;5].
Proof. reflexivity. Qed. | Example | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | test_app1 | |
test_app2: nil ++ [4;5] = [4;5].
Proof. reflexivity. Qed. | Example | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | test_app2 | |
test_app3: [1;2;3] ++ nil = [1;2;3].
Proof. reflexivity. Qed. | Example | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | test_app3 | |
hd(default:nat) (l:natlist) : nat :=
match l with
| nil => default
| h :: t => h
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",
"Require Export Induction"
] | sf-experiment/Lists.v | hd | |
tl(l:natlist) : natlist :=
match l with
| nil => nil
| h :: t => t
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",
"Require Export Induction"
] | sf-experiment/Lists.v | tl | |
test_hd1:= hd 0 [1;2;3] =? 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",
"Require Export Induction"
] | sf-experiment/Lists.v | test_hd1 | |
equal_listl1 l2 :=
match l1,l2 with
| [],[] => true
| h1::t1,h2::t2 => andb (h1=?h2) (equal_list t1 t2)
| _,_ => false
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",
"Require Export Induction"
] | sf-experiment/Lists.v | equal_list | |
test_tl:= equal_list (tl [1;2;3]) [2;3]. | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | test_tl | |
alternate(l1 l2 : natlist) : natlist
(* REPLACE THIS LINE WITH ":= _your_definition_ ." *) := []. | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | alternate | |
bag:= natlist. | 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",
"Require Export Induction"
] | sf-experiment/Lists.v | bag |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.