CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
e1 = e2
P -> Q
forall x, P
Is this all we can do?
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
e1 = e2
P -> Q
forall x, P
Is this all we can do? No.
We encoded predicates computationally:
Basics.v
we defined Nat.eqb: nat -> nat -> bool
to compare if two naturals are equal.Basics.v
we defined even: nat -> bool
to check if a natural number is evenComputational predicates are limited in what they can describe (eg, functions in Coq have to be total), and are not very easy to reason about (ie, they are meant to compute/execute, not build logic statements).
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the type of an equality?
Check beq_nat 2 2 = true.Check forall (n m : nat), n + m = m + n.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the type of an equality?
Check beq_nat 2 2 = true.Check forall (n m : nat), n + m = m + n.
Both of these expressions have type Prop
, for proposition.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Obviously no. How do you prove this proposition:
Check 0 = 1. (* Prints: 0 = 1: Prop *)Goal 0 = 1.
We can write any proposition, even unprovable ones.
We can write proposition 0 = 1
, but we cannot prove it.
The fact that something is false is not the same as unprovable!
We can prove that something is false (by showing it leads to false), eg, 0 = 1
. .
We cannot prove the law of the excluded middle in Coq.
In Coq, we must show evidence of what holds. (This is known as a constructive logic.)
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the type of
ex0
:
Definition ex0 := beq_nat 2 2.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the type of
ex0
:
Definition ex0 := beq_nat 2 2.
What is the type of
ex1
? How can we useex1
?
Definition ex1 (n:nat) := beq_nat 2 n = true.Check ex1.
ex1
is a function that returns a proposition, a parameterized proposition.
For whichn
isex1 n
provable?
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the type of
ex0
:
Definition ex0 := beq_nat 2 2.
What is the type of
ex1
? How can we useex1
?
Definition ex1 (n:nat) := beq_nat 2 n = true.Check ex1.
ex1
is a function that returns a proposition, a parameterized proposition.
For whichn
isex1 n
provable?
Lemma easy: forall n, n = 2 -> ex1 n.Proof.
(Done in class.)
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the difference between
ex1
andex2
?
Definition ex1 (n:nat) := beq_nat 2 n = true.Theorem ex2: forall (n:nat), beq_nat 2 n = true.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the difference between
ex1
andex2
?
Definition ex1 (n:nat) := beq_nat 2 n = true.Theorem ex2: forall (n:nat), beq_nat 2 n = true.
ex1
defines a position (Prop
), ex2
is a theorem definition and is
expecting a proof.
What is the relation between
ex3
andex1
,ex2
?
Definition ex3 (n:nat) : beq_nat 2 n = true.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
What is the difference between
ex1
andex2
?
Definition ex1 (n:nat) := beq_nat 2 n = true.Theorem ex2: forall (n:nat), beq_nat 2 n = true.
ex1
defines a position (Prop
), ex2
is a theorem definition and is
expecting a proof.
What is the relation between
ex3
andex1
,ex2
?
Definition ex3 (n:nat) : beq_nat 2 n = true.
Theorem
and Definition
are synonyms!ex2
and ex3
are the sameCS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Prop
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Prop
Prop
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Prop
Prop
Prop -> Prop -> Prop
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
When a logical-and appears in the goal, use split
You need to prove both propositions
Goal 3 + 4 = 7 /\ 2 * 2 = 4.Proof. split.
(Done in class.)
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
More generally, we can show that if we have propositions A and B, we can conclude that we have A∧B.
Goal forall A B : Prop, A -> B -> A /\ B.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
A /\ B
, how many proofs? how many goals?Goal forall x y, 3 + x = y /\ 2 * 2 = x -> x = 4 /\ y = 7.Proof. intros x y Hconj. destruct Hconj as [Hleft Hright].
(Done in class.)
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Lemma correct_2 : forall A B : Prop, A /\ B -> A.Proof.
Lemma correct_3 : forall A B : Prop, A /\ B -> B.Proof.
(Done in class.)
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Prop
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Prop
Prop
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Prop
Prop
Prop -> Prop -> Prop
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
left
/right
to pick what you want to proveGoal forall n m : nat, Nat.beq n m = true \/ Nat.beq n m = false.Proof.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
A \/ B
, how many proofs? how many goals?Lemma or_example : forall n m : nat, n = 0 \/ m = 0 -> n * m = 0.Proof. intros n m Hor. destruct Hor as [Heq | Heq].
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
False
cannot be proved (we postpone how to our next lecture)discriminate
)1 = 2
is (leads to) false.Goal 1 = 2 -> False.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
False
as assumptionTheorem ex_falso_quodlibet : forall (P:Prop), False -> P.Proof.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
Definition not (P:Prop) := P -> False.Notation "~ x" := (not x) : type_scope.
~ P
in P
to reach contradictioncontradiction
Theorem contradiction_implies_anything : forall P Q : Prop, (P /\ ~ P) -> Q.Proof.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
~ P
by assuming P
and reaching contradictionGoal ~ False.
CS720: Lecture 7 𐫱 Tiago Cogumbreiro
e1 = e2
P -> Q
forall x, P
Is this all we can do?
Keyboard shortcuts
↑, ←, Pg Up, k | Go to previous slide |
↓, →, Pg Dn, Space, j | Go to next slide |
Home | Go to first slide |
End | Go to last slide |
Number + Return | Go to specific slide |
b / m / f | Toggle blackout / mirrored / fullscreen mode |
c | Clone slideshow |
p | Toggle presenter mode |
t | Restart the presentation timer |
?, h | Toggle this help |
Esc | Back to slideshow |