Proving two propositions are logically equivalent (without truth table) - logic

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.

Related

How to build a proof of correctness in coq for elements_tr

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.

Proposition Logic : CNF Conversion

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.

Propositional Logic Identity

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)

How sorting list of string by length

Hi i having a problem with sort list like:
sort([p v q v r, p, p v q], R).
expected result is
R = [p, p v q, p v q v r]
Is any built in sort in swi-prolog which allow me that or i have to write it myself.

How to use apply to "extract" a implication in Coq

I'll illustrate using an example.
H : R -> P -> Q
H0 : R
Subgoal:
(Q -> P) \ / (P -> Q)
so my question is how do I extract out (P->Q). I have R already, but when I do
'apply H in H0', it evaluates everything and gives me Q.
You can do any of:
specialize (H H0).
to replace H with H: P -> Q, or:
pose proof (H H0) as H1
to introduce H1: P -> Q
You can also go forward:
right. exact (H H0).

Resources