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.
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 have the following inductive definition for sortedness of a list:
Class DecTotalOrder (A : Type) := {
leb : A -> A -> bool;
leb_total_dec : forall x y, {leb x y}+{leb y x};
leb_antisym : forall x y, leb x y -> leb y x -> x = y;
leb_trans : forall x y z, leb x y -> leb y z -> leb x z }.
Inductive Sorted {A} {dto : DecTotalOrder A} : list A -> Prop :=
| Sorted_0 : Sorted []
| Sorted_1 : forall x, Sorted [x]
| Sorted_2 : forall x y, leb x y ->
forall l, Sorted (y :: l) ->
Sorted (x :: y :: l).
And the following two definitions to declare that an element x is smaller or equal than each element of the list (LeLst) and bigger or equal than each element of the list (LstLe) :
Definition LeLst {A} {dto : DecTotalOrder A} (x : A) (l : list A) :=
List.Forall (leb x) l.
Definition LstLe {A} {dto : DecTotalOrder A} (x : A) (l : list A) :=
List.Forall (fun y => leb y x) l.
I am trying to prove the following lemma about sortedness which basically states that if we know that h is greater or equal to each element in l and h is smaller or equal than each element in l' we can put it in between the two:
Lemma lem_lstle_lelst {A} {dto: DecTotalOrder A} : forall h l l',
LstLe h l -> LeLst h l' -> Sorted (l ++ h :: l').
It seems very intuitiv but i get stuck every time in the proof. This is my current attempt:
Lemma lem_lstle_lelst {A} {dto: DecTotalOrder A} : forall h l l',
LstLe h l -> LeLst h l' -> Sorted (l ++ h :: l').
Proof.
intros h l l' H_LstLe.
induction H_LstLe.
- intros. simpl. Search (Sorted (_ :: _)).
unfold LeLst in H. Search (List.Forall _ _).
induction l'.
+ constructor.
+ Search (List.Forall _ _).
constructor.
{ hauto use: List.Forall_inv. }
{ generalize (List.Forall_inv_tail H).
intros.
generalize (List.Forall_inv H).
intros.
generalize (IHl' H0).
intros.
generalize (lem_sorted_tail H2).
intros.
However I get stuck here, because the hypotheses just don't seem strong enough:
1 subgoal
A : Type
dto : DecTotalOrder A
h, a : A
l' : list A
H : List.Forall (fun x : A => leb h x) (a :: l')
IHl' : List.Forall (fun x : A => leb h x) l' -> Sorted (h :: l')
H0 : List.Forall (fun x : A => leb h x) l'
H1 : leb h a
H2 : Sorted (h :: l')
H3 : Sorted l'
______________________________________(1/1)
Sorted (a :: l')
I'd be really glad if someone could give me a hint, maybe something is wrong with my definitions and that is why i can't get on with the proof? Or am I just missing out on some tactics that I could use?
Here is a list of lemmata allready proven about sortedness:
Lemma lem_sorted_tail {A} {dto : DecTotalOrder A}{l x} :
Sorted (x :: l) -> Sorted l.
Lemma lem_sorted_prepend {A} {dto: DecTotalOrder A} : forall x l l',
Sorted((x :: l) ++ l') -> Sorted(l ++ l').
Lemma lem_sort_conc_mid {A} {dto: DecTotalOrder A} : forall x y l,
Sorted (x :: y :: l) -> Sorted (x :: l).
As stated in a comment the Lemma is not provable.
Instead its defintion has to be expanded by adding properties about the sortedness of l
and l':
Lemma lem_lstle_lelst {A} {dto: DecTotalOrder A} : forall h l l',
LstLe h l -> LeLst h l' -> Sorted l -> Sorted l' -> Sorted (l ++ h :: l').
This is possible to prove with the following:
Proof.
intros h l l' H_Lstle_h_l.
induction H_Lstle_h_l.
- intros H_Lelst_h_l' H_Sort_1 H_Sort_2.
simpl;inversion H_Lelst_h_l';sauto.
- intros H_Lelst_h_l' H_Sort_1 H_Sort_2.
generalize (lem_sorted_tail H_Sort_1).
intros H_Sort_l.
generalize (IHH_Lstle_h_l H_Lelst_h_l' H_Sort_l H_Sort_2).
intros H_Sort_l_h_l'.
generalize (lem_sorted_lelst x l H_Sort_1).
intros H_Lelst_x_l.
hauto use: lem_Sorted_prepend_inv.
Qed.
introducing new helper lemmata:
Lemma lem_Sorted_prepend_inv {A} {dto: DecTotalOrder A} :
forall x h l l', leb x h -> Sorted(l ++ h :: l') -> LeLst x l -> Sorted(x::l++ h::l').
Lemma lem_sorted_lelst {A} {dto: DecTotalOrder A} :
forall x l, Sorted(x :: l) -> LeLst x l.
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.
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)
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).