Homework Four

out Thursday 10/26, due Tuesday 11/7

The starter repository has 3 python files in it: agent.py, logic.py, and utils.py. You'll want to run python in the directory with those files and do "import logic".

1. Checking Validity

Use the functions in logic.py to see which of the following are valid, i.e., true in every model. You will have to (i) convert these sentences to the appropriate string form that the python code uses (see the comments in the code) and (ii) use the expr() function in logic.py to turn each into an Expr object, and (iii) use the tt_true() function to check for validity. Provide text from a session that shows the result of checking the validity of each. We've done the first one as an example.

  1. P v ¬P
    >>> logic.tt_true(logic.expr('P | ~P'))
    True

  2. P → P
  3. P→ (P v Q)
  4. (P v Q) → P
  5. ((A ∧B) →C) ↔ (A → (B → C))
  6. ((A →B) →A) →A

2. Satisfiability

Use the functions in logic.py to see which of the following are are satisfiable. We've done the first one as an example.

  1. P ∧ Q
    >>> logic.dpll_satisfiable(logic.expr('P & Q'))
    {P: True, Q: True}

  2. ALIVE→ ¬DEAD ∧ ¬ALIVE ∧ ¬DEAD
  3. P → ¬ P v P
  4. ~ (P v ¬ P)

3. Propositional Consequence

For each of the following entailment relations, say whether or not it is true. The text on the left of the entailment symbol (⊨) represents one or more sentences (separated by commas) that constitute a knowledge base. We've done the first one for you.
  1. P ∧ Q ⊨ P
    true
  2. P ⊨ P ∧ Q
  3. P ⊨ P v Q
  4. P ⊨ ¬ ¬ P
  5. P → Q ⊨ ¬ P → ¬ Q
  6. ¬ P ⊨ P → Q
  7. ¬ Q ⊨ P → Q
  8. P ∧ (P → Q) ⊨ Q
  9. ( ¬ P) ∧ (Q → P) ⊨ ¬ Q

4. English to FOL

Translate the following English sentences into first order logic. Feel free to optionally provide a more direct paraphrase of the meaning of your logic expression in English. If you think a sentence is ambiguous, describe the ambiguity and give logical expressions for all interpretations. We've done the first one for you using a notation with simple ASCII characters for logical operators (e.g., A:∀, E:∃, =>:→, <=>:↔, ^:∧, v:v, ~:¬, >:>)

  1. There is no largest prime number.

    ~(Ex number(x) ^ prime(x) ^ (Ay number(y) ^ prime(y) -> x >= y))
    It is not true that there is a prime number and it is greater than or equal to all prime numbers
  2. Zombies are not alive but they are animate.
  3. No person can have two mothers.
  4. If John has a sister, she is smart.
  5. The enemy of your enemy is your friend.

5. CNF and horn clauses

For each of the following FOL sentences, (a) give a one-sentence, unambiguous paraphrase in English of what you think the FOL sentence means, (b) the say whether or not it can be rewritten as one or more horn clauses and (c) rewrite the sentence as one or more sentences in conjunctive normal form, identifying any skolem constants or functions you introduce.. Feel free to use the simple ASCII forms for logical operators described in the previous problem and to use the to_cnf() function in logic.py to check your answers. We've done the first one for you.

  1. ∀x knows(x, x) ∧ likes(x, x)
    (a) Everyone knows and likes himself;
    (b) this can be rewritten as a horn clause;
    (c) set of clauses: [knows(x, x), likes(x, x)]

  2. ∀x ∀y loves(x, y) ↔ loves(y, x)
  3. ∀x ∀y loves(x, y) → ¬ hates(x, y)
  4. ∀x ∀y ¬ knows(x, y) → ¬ likes(x, y)
  5. ¬ (∀x loves(x, x))
  6. ¬ (∃x ∀y knows(x, y))

What and how to submit

Submit a single pdf document named hw4.pdf to your 471 github account.