playground/coq/sf/1-lf-logic.v

195 lines
3.2 KiB
Coq

Require Import Arith.
Example and_exercise :
forall n m : nat, n + m = 0 -> n = 0 /\ m = 0.
Proof.
intros n m H.
destruct n.
- auto.
- inversion H.
Qed.
Example and_exercise':
forall n m : nat, n + m = 0 -> n = 0 /\ m = 0.
Proof.
(* https://github.com/yanhick/coq-exercises/blob/master/LF/Logic.v *)
intros n m H.
split.
- destruct n.
+ reflexivity.
+ inversion H.
- destruct m.
+ reflexivity.
+ rewrite plus_comm in H.
inversion H. (* XXX: Why rewrite helped for inversion? *)
Qed.
Lemma proj2 : forall P Q : Prop, P /\ Q -> Q.
Proof.
intros p q H.
destruct H as [Hp Hq].
exact Hq.
Qed.
Theorem and_assoc : forall P Q R : Prop,
P /\ (Q /\ R) -> (P /\ Q) /\ R.
Proof.
intros p q r H.
destruct H as [Hp [Hq Hr]].
split.
- split.
+ exact Hp.
+ exact Hq.
- exact Hr.
Qed.
Fact not_implies_our_not : forall (P:Prop),
~ P -> (forall (Q:Prop), P -> Q).
Proof.
intros p Hp' q Hp.
contradiction.
Qed.
Theorem double_not: forall P:Prop, P -> ~~P.
Proof.
intros p Hp.
(* Or just [auto] *)
unfold not.
intro pF.
apply pF.
exact Hp.
Qed.
Theorem contrapositive : forall (P Q : Prop),
(P -> Q) -> (~Q -> ~P).
Proof.
intros p q Hpq.
intro Hq'.
unfold not.
intro Hp.
destruct Hq'. (* XXX: What happened here? *)
apply Hpq.
exact Hp.
Qed.
Theorem not_both_true_and_false : forall P : Prop,
~ (P /\ ~P).
Proof.
intros p.
intro H.
destruct H as [H'].
destruct H.
exact H'.
Qed.
Theorem not_true_is_false : forall b : bool,
b <> true -> b = false.
Proof.
intros b Hb'.
unfold not in Hb'.
destruct b.
- destruct Hb'.
reflexivity.
- reflexivity.
Qed.
Theorem iff_sym : forall P Q : Prop,
(P <-> Q) -> (Q <-> P).
Proof.
intros p q Hpqiff.
destruct Hpqiff as [Hpq Hqp].
split.
- exact Hqp.
- exact Hpq.
Qed.
Lemma not_true_iff_false : forall b,
b <> true <-> b = false.
Proof.
intros b.
split.
- intro HbnqT.
apply not_true_is_false.
exact HbnqT.
- intro HbeqF.
rewrite HbeqF.
auto.
Qed.
Theorem or_distributes_over_and : forall P Q R: Prop,
P \/ (Q /\ R) <-> (P \/ Q) /\ (P \/ R).
Proof.
intros p q r.
split.
- intro H.
split.
+ destruct H.
* auto.
* destruct H; auto.
+ destruct H.
* auto.
* destruct H; auto.
- intro H.
destruct H.
left.
destruct H0.
+ exact H0.
+ destruct H.
* exact H.
*
Abort.
Lemma mul_eq_0 : forall n m, n * m = 0 <-> n = 0 \/ m = 0.
Proof.
intros n m.
split.
- intro H.
Abort.
Theorem or_assoc :
forall P Q R : Prop, P \/ (Q \/ R) <-> (P \/ Q) \/ R.
Proof.
intros p q r.
split.
- intro H.
destruct H.
+ left.
left.
exact H.
+ destruct H.
* left.
right.
exact H.
* right.
exact H.
- intros [[Hp | Hq] | Hr].
+ left.
exact Hp.
+ right.
left.
exact Hq.
+ right.
right.
exact Hr.
Qed.
Lemma mul_eq_0_ternary :
forall n m p, n * m * p = 0 <-> n = 0 \/ m = 0 \/ p = 0.
Proof.
intros n m p.
split.
- intro H.
Search (_ * _ = 0).
(*rewrite mult_is_O.*)
Abort.
Lemma apply_iff_example :
forall n m : nat, n * m = 0 -> n = 0 \/ m = 0.
Proof.
intros n m H.
induction n.
- auto.
- induction m.
+ auto.
Abort.