There is a Bear. The Bear either sleeps in its cave or hunts in the forest. If the
Bear is hungry then it does not sleep. If the Bear is tired then it does not hunt.
Question
A
Formulate the story, above, in FOPC, using your predicates and/or objects.
Attempt A
SleepsInCave(Bear) v HuntsInForest(Bear)
Hungry(Bear) -> ~SleepsInCave(Bear)
Tired(bear) -> ~HuntsInForest(Bear)
Question B
Convert your FOPC into conjunctive normal form
Attempt B
Not sure how to conver to CNF because I was unable to complete part A!
Related
As part of an assignment I've been asked to check if proofs in natural deduction are either correct or incorrect, using Prolog. An example text file called "valid.txt" containing a proof looks like this:
[imp(p, q), p].
q.
[
[1, imp(p,q), premise],
[2, p, premise],
[3, q, impel(2,1)]
].```
This would be the input into my program, which should respond "yes" or "true" to a correct proof (which the above is), and "no" or "false" to an incorrect proof.
I have no idea where to begin. So my question is if there are some resources out there where I could learn about verifying/controlling proofs in prolog. I have some small amounts of experience programming in prolog, but I feel like I need some specific instruction on how to construct a program that can verify proofs. I've looked for textbooks and websites, but been unable to find anything that could help me.
In the end my program should probably resemble something like this: Checking whether or not a logical sequence that has assumptions in it is valid
As this is my first time asking a question on here I apologize if I missed something.
In part I totally understand the close votes, comments and such, but on the other had I can totally understand your side of the story.
Realize that I do view your question just barely on the wrong side of what is allowed here, but not so much so that other newcomers don't get away with doing the same thing.
Book recommendation questions are not allowed here. Normally a book recommendation would be seen as subjective, but when there is only one or two books that meet the requirements, how can it be subjective.
"Handbook of Practical Logic and Automated Reasoning" by John Harrison (WorldCat) (Amazon) (Webpage)
Note: The book uses the programming language OCaml, but implements a subset of Prolog. Also the book uses a domain specific language and implements a parser.
The book clearly goes way beyond what you need so you won't need to get or read the entire book.
You might only need this which is found in prop.ml
let rec eval fm v =
match fm with
False -> false
| True -> true
| Atom(x) -> v(x)
| Not(p) -> not(eval p v)
| And(p,q) -> (eval p v) & (eval q v)
| Or(p,q) -> (eval p v) or (eval q v)
| Imp(p,q) -> not(eval p v) or (eval q v)
| Iff(p,q) -> (eval p v) = (eval q v);;
Example query
tautology <<p \/ q ==> q \/ (p <=> q)>>;;
The book is more of a detailed introduction to the source code of a more feature rich version HOL-Light which is a simpler version of HOL.
The links should put you in the ball park of working applications and these all fall under the broader topic of automated theorem proves which is different from proof assistants.
Usually when you have a goal beginning ∀x you can write something like
show "∀x. Px"
proof (rule allI)
but this doesn't seem to work when you have something beginning ∀x∈S. For example, I tried
show "∀x∈S. P x"
proof (rule allI)
which gives the message
Failed to apply initial proof method
This surprised me, since I thought ∀x∈S. P x was probably syntactic sugar for ∀x. x∈S --> P x, in which case it should work.
This is similar to a question I previously asked
Intro rule for "∀r>0" in Isabelle
but I think that this time the answer might be different.
It is not just syntax; it is its own constant called Ball, and the introduction rule is called ballI.
If you ctrl-click onto `∀x∈A", it should take you straight to the definition, where you can see what it is called. Additionally, you can use the ‘Find theorems’ panel in Isabelle to find lemmas related to it.
I am having problems understanding the difference between validity and satisfiability.
Given the following:
(i) For all F, F is satisfiable or ~F is satisfiable.
(ii) For all F, F is valid or ~F is valid.
How do I prove which is true and which is false?
Statement (i) is true, as for all F, F will either be satisfiable, or ~F will be satisfiable (truth table). However, how do I go about solving for statement (ii)?
Any help is highly appreciated!
Aprilrocks92,
I don't blame you for being confused, because actually logicians, mathematicians, heck even those philosopher types use the words validity differently sometimes.
Trying not to overcomplicate, I'll give you a thin definition: a conclusion if valid when it is true whenever the premises are true. We also say, given a suitably defined logic, that the conclusion follows as a "logical consequence" of the premises.
On the other hand, satisfisability means that there exists a valuation of the non logical symbols in the formula F that makes the formula true in the logic.
So I should probably mention the difference between semantics and syntax to explain. The syntax of your logic is all those logical and non logical symbols, and the deductive rules that enable you to make "steps" towards proof in the logic. My definition of satisfisability above mentioned the word "valuation"- now how does that fit? Well the answer is that you need to supply a semantics: in short this is the structure that the formula of the logic are expressions of, usually given in set theory, and a valuation of a given F is a function that maps all the non logical symbols in F to sets and members of sets, which a given semantics for the logic composes into a truth value.
Hmm. I'm not sure that's the best explanation, but I don't have much time.
Either way, that should help you understand the difference. To answer your question about the difference between (i) and (ii) without giving too much away, think: what's the relationship between the two? Well given that as above an F' is true given a valuation that sends the sentence to true. So you could "rewrite" my definition of validity as: a conclusion is valid iff whenever the premises are satisfisable the conclusion is satisfisable.
Now, with regards your requirement to prove these things, I strongly suspect you've got a lot more context about your logic you're not telling us and your teacher or text book has intimated a context in which to answer these, as actually taken in the general sense your question doesn't make complete sense.
I have a homework assignment, and i am finished other then one question (see title)
For the life of my, i cannot figure this out... so i started to think it was a trick question.
the current answer that i will submit is:
L1 = {a^n b^n: n>=1} is deterministic. And the reverse,
L2 = {b^n a^n: n>=1} is also deterministic.
However, since all deterministic languages are a subset of Non-deterministic languages, L2 can be considered non-deterministic.
On a side note, the only other example i was trying to make work is:
L3= {{a,b}a}
This seems possible because forward there is non-determinism, since the input could be either a, or b as long as its followed by an a.
and in reverse there is determinism since it will accept only an 'a'. But, it introduces new non-determinism since the second input could be either a or b.
any help / guidance would be great.
I know the deadline has passed, but somebody might find this useful in the future.
(a+b+c)*WcW^R, where W is in (a+b)+; this is non-deterministic because you don't know where the "WcW" bit starts.
W^RcW(a+b+c)*, where W is in (a+b)+; this is deterministic because you can write a deterministic PDA to accept simple palindromes of the form "W^RcW" and modify the accepting state to loop to itself on any of a, b and c.
The trick here is that PDAs have to read input from left to right.
I've written a little app that parses expressions into abstract syntax trees. Right now, I use a bunch of heuristics against the expression in order to decide how to best evaluate the query. Unfortunately, there are examples which make the query plan extremely bad.
I've found a way to provably make better guesses as to how queries should be evaluated, but I need to put my expression into CNF or DNF first in order to get provably correct answers. I know this could result in potentially exponential time and space, but for typical queries my users run this is not a problem.
Now, converting to CNF or DNF is something I do by hand all the time in order to simplify complicated expressions. (Well, maybe not all the time, but I do know how that's done using e.g. demorgan's laws, distributive laws, etc.) However, I'm not sure how to begin translating that into a method that is implementable as an algorithm. I've looked at papers on query optimization, and several start with "well first we put things into CNF" or "first we put things into DNF", and they never seem to explain their method for accomplishing that.
Where should I start?
Look at https://github.com/bastikr/boolean.py
Example:
def test(self):
expr = parse("a*(b+~c*d)")
print(expr)
dnf_expr = normalize(boolean.OR, expr)
print(list(map(str, dnf_expr)))
cnf_expr = normalize(boolean.AND, expr)
print(list(map(str, cnf_expr)))
Output is:
a*(b+(~c*d))
['a*b', 'a*~c*d']
['a', 'b+~c', 'b+d']
UPDATE: Now I prefer this sympy logic package:
>>> from sympy.logic.boolalg import to_dnf
>>> from sympy.abc import A, B, C
>>> to_dnf(B & (A | C))
Or(And(A, B), And(B, C))
>>> to_dnf((A & B) | (A & ~B) | (B & C) | (~B & C), True)
Or(A, C)
The naive vanilla algorithm, for quantifier-free formulae, is :
for CNF, convert to negation normal form with De Morgan laws then distribute OR over AND
for DNF, convert to negation normal form with De Morgan laws then distribute AND over OR
It's unclear to me if your formulae are quantified. But even if they aren't, it seems the end of the wikipedia articles on conjunctive normal form, and its - roughly equivalent in the automated theorm prover world - clausal normal form alter ego outline a usable algorithm (and point to references if you want to make this transformation a bit more clever). If you need more than that, please do tell us more about where you encounter a difficulty.
I've came across this page: How to Convert a Formula to CNF. It shows the algorithm to convert a Boolean expression to CNF in pseudo code. Helped me to get started into this topic.