-
Notifications
You must be signed in to change notification settings - Fork 2
/
submission.py
36 lines (32 loc) · 1.55 KB
/
submission.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
import collections, sys, os
from logic import *
############################################################
# Problem 1: propositional logic
# Convert each of the following natural language sentences into a propositional
# logic formula. See rainWet() in examples.py for a relevant example.
# Sentence: "If it's summer and we're in California, then it doesn't rain."
def formula1a():
# Predicates to use:
Summer = Atom('Summer') # whether it's summer
California = Atom('California') # whether we're in California
Rain = Atom('Rain') # whether it's raining
# BEGIN_YOUR_CODE (our solution is 1 line of code, but don't worry if you deviate from this)
return Implies(And(Summer, California), Not(Rain))
# END_YOUR_CODE
# Sentence: "It's wet if and only if it is raining or the sprinklers are on."
def formula1b():
# Predicates to use:
Rain = Atom('Rain') # whether it is raining
Wet = Atom('Wet') # whether it it wet
Sprinklers = Atom('Sprinklers') # whether the sprinklers are on
# BEGIN_YOUR_CODE (our solution is 1 line of code, but don't worry if you deviate from this)
return Equiv(Wet, Or(Rain, Sprinklers))
# END_YOUR_CODE
# Sentence: "Either it's day or night (but not both)."
def formula1c():
# Predicates to use:
Day = Atom('Day') # whether it's day
Night = Atom('Night') # whether it's night
# BEGIN_YOUR_CODE (our solution is 1 line of code, but don't worry if you deviate from this)
return Xor(Day, Night)
# END_YOUR_CODE