Proof by resolution - Artificial Intelligence - logic

I'm working with an exercise where I need to show that KB |= ~D.
And I know that the Knowledge Base is:
- (B v ¬C) => ¬A
- (¬A v D) => B
- A ∧ C
After converting to CNF:
A ∧ C ∧ (¬A v ¬B) ∧ (¬A v C) ∧ (A v B) ∧ (B v ¬D)
So now I have converted to CNF but from there, I don't know how to go any further. Would appreciate any help. Thanks!

The general resolution rule is that, for any two clauses
(that is, disjunctions of literals)
P_1 v ... v P_n
and
Q_1 v ... v Q_m
in your CNF such that there is i and j with P_i and Q_j being the negation of each other,
you can add a new clause
P_1 v ... v P_{i-1} v P_{i+1} ... v P_n v Q_1 v ... v Q_{j-1} v Q_{j+1} ... v Q_m
This is just a rigorous way to say that you can form a new clause by joining two of them, minus a literal with opposite "signs" in each.
For example
(A v ¬B)∧(B v ¬C)
is equivalent to
(A v ¬B)∧(B v ¬C)∧(A v ¬C),
by joining the two clauses while removing the opposites B and ¬B, obtaining A v ¬C.
Another example is
A∧(¬A v ¬C)
which is equivalent to
A∧(¬A v ¬C) ∧ ¬C.
since A counts as a clause with a single literal (A itself). So the two clauses are joined, while A and ¬A are removed, yielding a new clause ¬C.
Applying this to your problem, we can resolve A and ¬A v ¬B, obtaining ¬B.
We then resolve this new clause ¬B with B v ¬D, obtaining ¬D.
Because the CNF is a conjunction, the fact that it holds means that every clause in it holds. That is to say, the CNF implies all of its clauses. Since ¬D is one of its clauses, ¬D is implied by the CNF. Since the CNF is equivalent to the original KB, the KB implies ¬D.

Related

Express Knowledge base in CNF and resolution in prolog

I have a knowledge base as CNF and i'd like to use prolog to make a resolution, but
i can't wrap my head around how to formulate the problem in prolog.
I have
KB = { P v Q, Q => (R ^ S), (P v R) => U }
that i put in CNF as:
KB = { P v Q, not(Q) v R, not(Q) v S, not(P) v U, not(R) v U }
and i'd like to prove that KB entails U ( KB |= U ).
I can prove in manually by refutation but i'd like to know how this can be done using prolog ?
Thx
The answer is: it is impossible.
not(Q) v R, not(Q) v S, not(P) v U, not(R) v U
can be expressed by r:-q., s:-q., u:-p. and u:-r..
Questioning ? u. amounts to asking for a proof by refutation.
However,
P v Q
cannot be expressed as a fact/rule in a prolog program. Prolog is restricted to Horn clauses, i.e. disjunctions of literals that contain at most one positive literal.

Proof by contradiction

I'm trying to do a proof by contradiction, but don't quite understand how to write it down formally or how to come to an answer in this case. I'm doing a conditional statement.
The problem I'm trying to solve is "Given the premises, h ^ ~r and (h^n) --> r, show that you can conclude ~n using proof by contradiction.
I've taken the negation of both h ^ ~r and (h^n) --> r, but I'm unsure how to use these two to prove ~n
so far I've written:
(i.)~((h^n) --> r)
(ii.)~(h ^ ~r)
therefore, ~n
The hardest part I'm having is that this isn't an actual statement that I can imagine a negation of, and a step by step answer of how to do one of these proofs would be really useful, thanks!
Suppose
~(((h ^ ~r) ^ ((h^n) --> r)) --> ~n)
Then,
~(~((h ^ ~r) ^ ((h^n) --> r)) v ~n)
=> ~(~(h ^ ~r) v ~((h^n) --> r)) v ~n)
=> ~((~h v r) v ~(~(h^n) v r)) v ~n)
=> ~((~h v r) v ((h^n) ^ ~r)) v ~n)
=> ~((~h v r) v (h ^ n ^ ~r)) v ~n)
=> ~((((~h v r v h) ^ (~h v r v n) ^ ((~h v r) v ~r)) v ~n)
=> ~(((true) ^ (~h v r v n) ^ (true)) v ~n)
=> ~((~h v r v n) v ~n)
=> ~(~h v r v n v ~n)
=> ~((~h v r) v (n v ~n))
=> ~((~h v r) v (true))
=> ~(true)
=> false //contradiction
Therefore,
((h ^ ~r) ^ ((h^n) --> r)) --> ~n
Let's define:
p1 := h ^ ~r, p2 := (h ^ n) -> r and q := ~n
we want to prove that p1 ^ p2 -> q.
Assume by contradiction that q=false. Then n=true. There are two cases r=true and r=false.
Case r=true
Then p1 cannot be true because ~r=false. Contradiction.
Case r=false
From p2 we deduce that (h ^ n) must be false. And given that we have assumed n=true, it must be h=false, in contradiction with p1.
Direct proof
From p1 we get h=true and r=false. Now from p2 we deduce (h ^ n) = false. And since h=true, it must be n=false, or ~n=true.
I think the OP is probably asking about, or mis-interpretting, the structure of a proof by contradiction rather than requesting a detailed proof for the specific example.
The structure goes like this ...
We've been told to assume a set of things A1, A2, ... An
Let's also assume the negation of what we eventually hope to prove, i.e. ~C
Do some logic that ends with any contradiction, by which we mean any statement of the form X & ~X
Now we ponder what that means. Since a contradiction can never be true, there must be something wrong with at least one of our n+1 assumptions. Could be that several or all of the assumptions are false. But if any n of the assumptions are true then the remaining one cannot be true. We cannot tell at this stage which one is the problem.
In this case we have been told ahead of time to accept A1, A2, ... An, and on that basis we can select the assumption of ~C as the one to be rejected.
As a final step we conclude that if A1, A2, ... An are true then C must be true.

I can't solve the logic

I think for the logic question for a long time. It seems easy but very hard. I don't know how to prove it using equivalence.
(A->(B->C))->((A->(C->D))->(A->(B->D)))
Use the definition of A->B (that is, ~A v B) and DeMorgan's Law to come up with an equivalent expression in disjunctive normal form (all ands and ors). From there, repeatedly apply the fact that A v ~A is true to simplify the expression to True. (The latter may require the use of distribution: A v (B ^ C) = (A v B) ^ (A v C), as well as A ^ (B v C) = (A ^ B) v (A ^ C), although the former will be of more use here.)

Formal Methods, Logic and VDM past exam paper questions

I was hoping someone can help me with the following questions, answers would be best but if you can point me in the right direction that will be helpful also.
I am a final year uni student and these questions are from a previous exam on Formal Methods and I could do with knowing the answers ready for this years paper. Our lecturer does not seem the best and has not covered a lot of this and so finding the exact answer has been proving impossible. Google has not been much of a help nor has the recommended books.
1 - Given that ∃x • P (x) is logically equivalent to ¬∀x • ¬P (x) and that
∀x ∈ S • P (x) means ∀x • x ∈ S ⇒ P (x), deduce that ∃x ∈ S • P (x)
means ∃x • x ∈ S ∧ P (x)
2 - Describe the two statements that would have to be proved to show that
the definition:
max(i, j)
if i>j
then i
else j
is a correct implementation of the specification:
max(i : Z, j : Z)r : Z
pre true
post (r = i ∨ r = j) ∧ i ≤ r ∧ j ≤ r
The first is really just manipulation of symbols using the given and two other well-known logical equivalences:
(1) ∃x • P(x) is logically equivalent to ¬∀x • ¬P(x)
(2) ∀x∈S • P(x) means ∀x • x∈S ⇒ P(x)
∃x∈S • P(x)
== ¬∀x∈S • ¬P(x) (from (1))
== ¬∀x • x∈S ⇒ ¬P(x) (from (2))
== ¬∀x • ¬x∈S v ¬P(x) (from def. of ⇒)
== ¬∀x • ¬(x∈S ∧ P(x)) (from ¬A v ¬B == ¬(A ∧ B))
== ∃x • x∈S ∧ P(x) (from (1) -- the other way around)
For the second, you need to recognize that the outcome of max(i, j) will be computed along one of two paths: one, when i<j and the other when i>=j (the logical negation of i<j)
So you need to show that
if true ∧ i<j (precondition), then (r=i ∨ r=j) ∧ i≤r ∧ j≤r (post condition), and
if true ∧ i>=j (precond.) then (r=i ∨ r=j) ∧ i≤r ∧ j≤r (post cond.),
where r is the result of max(i, j)
But section 2 of your question does not make sense since any implementation that returns either i or j is correct.
The specification is wrong.
A correct postcondition is
post (i > j => r = i) v (i <= j => r = j)

Proving the Associativity of OR

I need help proving the following:
(a ∨ b) ∨ c = a ∨ (b ∨ c)
I don't want the answer... just a hint that will help me understand the process of proving this.
Thank you.
Why not just prove it by doing all possible values of a, b and c = True, False? -- there are only 2^3 = 8 different cases.
Here's a start, for a=T, b=F, c=T
(a v b) v c = a ∨ (b ∨ c)
(T v F) v T = T v (F v T)
T v T = T v T
T = T
(However, this isn't really a programming question...)
What is your axiom set?
Not knowing the set, you could build a truth table

Resources