How to show that π β π β‘ π β¨ π β (π β§ π)
So far I've done this...
π β π β‘(p β q) β§(q β p) Law of Algebra
(p β q) β§ (q β p) β‘(~p V q) β§ (q β p) Law of Conditional Proposition
(~p V q) β§ (q β p) β‘(~p V q) β§ (~q V p) Law of Conditional Proposition
By identity laws:
p β q Given
(p β q) & (q β p) β Elimination
(~p β¨ q) & (~q β¨ p) Material implication
((~p β¨ q) & ~q) β¨ (((~p β¨ q) & p)) Distributive
~p & ~q β¨ q & ~q β¨ ~p & p β¨ q & p Distributive
~p & ~q β¨ F β¨ F β¨ q & p Complement
~p & ~q β¨ q & p Identity
~(p β¨ q) β¨ p & q De Morgan's law
(p β¨ q) β (p & q) Material implication
By natural deduction:
To prove an identity by natural deduction, you have to conduct your proof in both directions. That is, you have to prove both that:
p β q entails (p β¨ q) β (p & q), and
(p β¨ q) β (p & q) entails p β q
{1} 1. p β q Prem.
{1} 2. (p β q) & (q β p) 1 βE
{1} 3. p β q 2 &E
{1} 4. q β p 2 &E
{5} 5. p β¨ q Assum.
{6} 6. p Assum. (1st Disj.)
{1,6} 7. q 3,6 MP
{1,6} 8. p & q 6,7 &I (1st Conc.)
{9} 9. q Assum. (2nd Disj.)
{1,9} 10. p 4,9 MP
{1,9} 11. p & q 9,10 &I (2nd Conc.)
{1,5} 12. p & q 5,6,8,9,11 β¨E
{1} 14. (p β¨ q) β (p & q) 5,12 CP
Here's the proof in the opposite direction:
{1} 1. (p β¨ q) β (p & q) Prem.
{2} 2. p Assum.
{2} 3. p β¨ q 2 β¨I
{1,2} 4. p & q 1,3 MP
{1,2} 5. q 4 &E
{1} 6. p β q 2,5 CP
{7} 7. q Assum.
{7} 8. p β¨ q 7 β¨I
{1,7} 9. p & q 1,8 MP
{1,7} 10. p 9 &E
{1} 11. q β p 7,10 CP
{1} 12. (p β q) & (q β p) 6,12 &I
{1} 13. p β q 12 βI
Abbreviations:
&I = Conjunction introduction
&E = Conjunction elimination
β¨I = Disjunction introduction
β¨E = Disjunction elimination
βI = Double arrow introduction
βE = Double arrow elimination
MP = Modus ponens
CP = Conditional proof (β introduction)
Related
I want to build a proof of correctness for elements_tr...
It is actually related to some sort of reimplementation of BSTs with int keys.
Elements_tr is defined as follows:
Fixpoint elements_aux {V : Type} (t : tree V)
(acc : list (key * V)) : list (key * V) :=
match t with
| E => acc
| T l k v r => elements_aux l ((k, v) :: elements_aux r acc)
end.
Definition elements_tr {V : Type} (t : tree V) : list (key * V) :=
elements_aux t [].
However I am unable to build such proof as I continuously get false = true...
What Am I doing wrong?
Corollary elements_tr_correct :
forall (V : Type) (k : key) (v d : V) (t : tree V),
BST t ->
In (k, v) (elements_tr t) ->
bound k t = true /\ lookup d k t = v.
Proof.
intros.
split.
induction t.
- unfold elements_tr.
unfold elements. simpl.
admit.
- admit.
- admit.
Admitted.
Bellow is the full code to run...
From Coq Require Import String.
From Coq Require Export Arith.
From Coq Require Export Lia.
Notation "a >=? b" := (Nat.leb b a) (at level 70) : nat_scope.
Notation "a >? b" := (Nat.ltb b a) (at level 70) : nat_scope.
From Coq Require Export Lists.List.
Export ListNotations.
Definition key := nat.
Inductive tree (V : Type) : Type :=
| E
| T (l : tree V) (k : key) (v : V) (r : tree V).
Arguments E {V}.
Arguments T {V}.
Definition ex_tree : tree string :=
(T (T E 2 "two" E) 4 "four" (T E 5 "five" E))%string.
Definition empty_tree {V : Type} : tree V := E.
Fixpoint bound {V : Type} (x : key) (t : tree V) :=
match t with
| E => false
| T l y v r => if x <? y then bound x l
else if x >? y then bound x r
else true
end.
Fixpoint lookup {V : Type} (d : V) (x : key) (t : tree V) : V :=
match t with
| E => d
| T l y v r => if x <? y then lookup d x l
else if x >? y then lookup d x r
else v
end.
Fixpoint insert {V : Type} (x : key) (v : V) (t : tree V) : tree V :=
match t with
| E => T E x v E
| T l y v' r => if x <? y then T (insert x v l) y v' r
else if x >? y then T l y v' (insert x v r)
else T l x v r
end.
Fixpoint ForallT {V : Type} (P: key -> V -> Prop) (t: tree V) : Prop :=
match t with
| E => True
| T l k v r => P k v /\ ForallT P l /\ ForallT P r
end.
Inductive BST {V : Type} : tree V -> Prop :=
| BST_E : BST E
| BST_T : forall l x v r,
ForallT (fun y _ => y < x) l ->
ForallT (fun y _ => y > x) r ->
BST l ->
BST r ->
BST (T l x v r).
Hint Constructors BST.
Ltac inv H := inversion H; clear H; subst.
Inductive reflect (P : Prop) : bool -> Set :=
| ReflectT : P -> reflect P true
| ReflectF : ~ P -> reflect P false.
Theorem 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.
Lemma eqb_reflect : forall x y, reflect (x = y) (x =? y).
Proof.
intros x y. apply iff_reflect. symmetry.
apply Nat.eqb_eq.
Qed.
Lemma ltb_reflect : forall x y, reflect (x < y) (x <? y).
Proof.
intros x y. apply iff_reflect. symmetry.
apply Nat.ltb_lt.
Qed.
Lemma leb_reflect : forall x y, reflect (x <= y) (x <=? y).
Proof.
intros x y. apply iff_reflect. symmetry.
apply Nat.leb_le.
Qed.
Hint Resolve ltb_reflect leb_reflect eqb_reflect : bdestruct.
Ltac bdestruct X :=
let H := fresh in let e := fresh "e" in
evar (e: Prop);
assert (H: reflect e X); subst e;
[eauto with bdestruct
| destruct H as [H|H];
[ | try first [apply not_lt in H | apply not_le in H]]].
Lemma ForallT_insert : forall (V : Type) (P : key -> V -> Prop) (t : tree V),
ForallT P t -> forall (k : key) (v : V),
P k v -> ForallT P (insert k v t).
Proof.
intros V P t.
induction t; intros H k' v' Pkv.
- simpl. auto.
- simpl in *.
destruct H as [H1 [H2 H3]].
bdestruct (k >? k').
+ simpl. repeat split.
* assumption.
* apply (IHt1 H2 k' v' Pkv).
* assumption.
+ bdestruct (k' >? k).
++ simpl. repeat split.
* assumption.
* assumption.
* apply (IHt2 H3 k' v' Pkv).
++ simpl. repeat split.
* assumption.
* assumption.
* assumption.
Qed.
Fixpoint elements {V : Type} (t : tree V) : list (key * V) :=
match t with
| E => []
| T l k v r => elements l ++ [(k, v)] ++ elements r
end.
Fixpoint elements_aux {V : Type} (t : tree V)
(acc : list (key * V)) : list (key * V) :=
match t with
| E => acc
| T l k v r => elements_aux l ((k, v) :: elements_aux r acc)
end.
Definition elements_tr {V : Type} (t : tree V) : list (key * V) :=
elements_aux t [].
Corollary elements_tr_correct :
forall (V : Type) (k : key) (v d : V) (t : tree V),
BST t ->
In (k, v) (elements_tr t) ->
bound k t = true /\ lookup d k t = v.
Proof.
intros.
split.
induction t.
- unfold elements_tr.
unfold elements. simpl.
admit.
- admit.
- admit.
Admitted.
I'm trying to find a way to prove a couple of set theory-based problems in Agda, but I'm having a hard time defining the function range.
I took the definition of Subset from Proving decidability of subset in Agda and built on top of it. This is what I got so far:
open import Data.Bool as Bool using (Bool; true; false; T; _β¨_; _β§_)
open import Data.Unit using (β€; tt)
open import Level using (Level; _β_; 0β) renaming (suc to lsuc)
open import Data.Product using (_Γ_) renaming (_,_ to β¨_,_β©)
Subset : β {Ξ±} (A : Set Ξ±) -> Set _
Subset A = A β Bool
_β_ : β {Ξ±} {A : Set Ξ±} β A β Subset A β Set
a β p = T (p a)
Relation : β {Ξ± Ξ²} (A : Set Ξ±) (B : Set Ξ²) β Set (Ξ± β Ξ²)
Relation A B = Subset (A Γ B)
Range : β {A B : Set} β Relation A B β Subset B
Range = ?
_β_ : β {A : Set} β Subset A β Subset A β Set
A β B = β x β x β A β x β B
wholeSet : β (A : Set) β Subset A
wholeSet _ = Ξ» _ β true
βsubsetβset : β {A : Set} {sub : Subset A} β sub β wholeSet A
βsubsetβset = Ξ» _ _ β tt
_β©_ : β {A : Set} β Subset A β Subset A β Subset A
A β© B = Ξ» x β (A x) β§ (B x)
β-range-β© : β {A B : Set}
(F G : Relation A B)
β Range (F β© G) β (Range F β© Range G)
β-range-β© f g = ?
The problem is that Range takes as an input a function of type A Γ B β Bool and must return a function B β Bool such that a value B is true iff there exists a value A Γ B which is true in the initial function. Basically, I would need to iterate through all values of A to know whether B is in the range of the relation. Something impossible to do, isn't it?
There must be surely a better way to implement Range, doesn't it?
Here is the implementation I suggest :
open import Data.Unit
open import Data.Product renaming (_,_ to β¨_,_β©)
open import Data.Sum
open import Function
Change the definition of Subset to go to Set instead of Bool. I know this might be controversial, but in my experience this has always been the way to go, and also this is how subsets are implemented in the standard library. (By the way, if you are interested to see the implementation in the standard library, it is in the file Relation/Unary.agda). I also removed the levels of universe since you didn't use them in your later definitions, which led me to clean up the types of the module.
Subset : Set β Setβ
Subset A = A β Set
The definition of membership is changed accordingly.
_β_ : β {A} β A β Subset A β Set
a β P = P a
Relation : β A B β Setβ
Relation A B = Subset (A Γ B)
The range becomes then very natural : b is in the range of R if their exists an a such as R of a and b holds.
Range : β {A B} β Relation A B β Subset B
Range R b = β (R β β¨_, b β©) -- equivalent to β \a β R β¨ a , b β©
_β_ : β {A} β Subset A β Subset A β Set
A β B = β x β x β A β x β B
Not much to say about the wholeset
wholeSet : β A β Subset A
wholeSet _ _ = β€
βsubsetβset : β {A sub} β sub β wholeSet A
βsubsetβset _ _ = tt
_β©_ : β {A} β Subset A β Subset A β Subset A
(A β© B) x = x β A Γ x β B
The proof of range inclusion is done very naturally with this definition.
β-range-β© : β {A B} {F G : Relation A B} β Range (F β© G) β (Range F β© Range G)
β-range-β© _ β¨ a , β¨ Fab , Gab β© β© = β¨ β¨ a , Fab β© , β¨ a , Gab β© β©
I also took the liberty to add the corresponding property about union.
_β_ : β {A} β Subset A β Subset A β Subset A
(A β B) x = x β A β x β B
β-range-β : β {A B} {F G : Relation A B} β (Range F β Range G) β Range (F β G)
β-range-β _ (injβ β¨ a , Fab β©) = β¨ a , injβ Fab β©
β-range-β _ (injβ β¨ a , Gab β©) = β¨ a , injβ Gab β©
I'm trying to solve a simple exercise in which I have to convert a propositional sentence in CNF :
This is the sentence :
P => (Q <=> R)
According to the resolution rule the first thing I did is to eliminate the <=> symbol in this way :
P => (Q <=> R) ---> P => (Q V R) /\ (R V Q)
Then I removed the => symbol :
P => (Q V R) /\ (R V Q) ------> Β¬P V (Q V R) /\ (R V Q)
So my solution is : (Β¬P V Q V R) /\ (Β¬P V R V Q)
While the right one is : (Β¬P V Β¬Q V R) /\ (Β¬P V Β¬R V Q)
Can anyone help me to understand where I get wrong ?
StackOverflow is intended for programming questions, which rules this question off-topic. But since I've already typed that much let me add that your first step ...
P => (Q <=> R) ---> P => (Q V R) ^ (R V Q)
is incorrect.
You know that Q<=>R means by definition (Q=>R)^(R=>Q), right? So replacing that is the first step. Then you can use the equivalences (Q=>R) ---> (~QvR) and (R=>Q) ---> (~RvQ).
Putting that together you should get ...
P => (Q <=> R) ---> P => (~Q V R) ^ (~R V Q)
I think you can work out the rest.
I have to prove that ~pβ(qβr)β‘ qβ(pvr)
This is what I've done so far:
qβ(pvr)
β‘(qβp)v(qβr)
β‘ ~(qβp)β(qβr)
β‘ (q^~p)β(qβr)
β‘ qβ(~qvr) v ~pβ(qβr)
β‘ ~qv(~qvr) v ~pβ(qβr)
β‘ (~qvr)v ~pβ(qβr)
β‘ (qβr) v [~pβ(qβr)]
How should i solve this?
~pβ(qβr) <=> p v (qβr) <=> p v (~q v r) <=> p v ~q v r
qβ(p v r) <=> ~q v (p v r) <=> ~q v p v r <=> p v ~q v r
Here I am using the rule that pβq <=> ~p v q and the fact that disjunction is associative and commutative.
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 7 years ago.
Improve this question
I am trying to get from (pβq) and (qrβs) to (prβs), which is the same as ((not p) or q) and (not(q and r) or s) to (not(p and r) or s)
Theorem:
p β q
= Β¬p β¨ q -- 1
(q β§ r) β s
= Β¬(q β§ r) β¨ s
= Β¬q β¨ Β¬r β¨ s -- 2
Β¬p β¨ Β¬r β¨ s -- from 1 and 2, q and Β¬q cancel
= Β¬(p β§ r) β¨ s
= (p β§ r) β s
Qed.
Using Coq, we can prove this theorem as follows:
Coq < Theorem prop : forall p q r s : Prop, (p -> q) /\ (q /\ r -> s) -> p /\ r -> s.
1 subgoal
============================
forall p q r s : Prop, (p -> q) /\ (q /\ r -> s) -> p /\ r -> s
prop < intros.
1 subgoal
p : Prop
q : Prop
r : Prop
s : Prop
H : (p -> q) /\ (q /\ r -> s)
H0 : p /\ r
============================
s
prop < destruct H.
1 subgoal
p : Prop
q : Prop
r : Prop
s : Prop
H : p -> q
H1 : q /\ r -> s
H0 : p /\ r
============================
s
prop < destruct H0.
1 subgoal
p : Prop
q : Prop
r : Prop
s : Prop
H : p -> q
H1 : q /\ r -> s
H0 : p
H2 : r
============================
s
prop < apply H1.
1 subgoal
p : Prop
q : Prop
r : Prop
s : Prop
H : p -> q
H1 : q /\ r -> s
H0 : p
H2 : r
============================
q /\ r
prop < split.
2 subgoals
p : Prop
q : Prop
r : Prop
s : Prop
H : p -> q
H1 : q /\ r -> s
H0 : p
H2 : r
============================
q
subgoal 2 is:
r
prop < exact (H H0).
1 subgoal
p : Prop
q : Prop
r : Prop
s : Prop
H : p -> q
H1 : q /\ r -> s
H0 : p
H2 : r
============================
r
prop < exact H2.
No more subgoals.
prop < Qed.
intros.
destruct H.
destruct H0.
apply H1.
split.
exact (H H0).
exact H2.
prop is defined
Hope that helps.