Question: Problem 4 : Odd and even integers # Return the following 6 laws. Be sure your formulas are exactly in the order specified. # 0

Problem 4: Odd and even integers
# Return the following 6 laws. Be sure your formulas are exactly in the order specified.
#0. Each number $$ has exactly one successor, which is not equal to $$.
# 1. Each number is either even or odd, but not both.
# 2. The successor number of an even number is odd.
# 3. The successor number of an odd number is even.
# 4. For every number $x$, the successor of $x$ is larger than $x$.
# 5. Larger is a transitive property: if $x$ is larger than $y$ and $y$ is
# larger than $z$, then $x$ is larger than $z$.
# Query: For each number, there exists an even number larger than it.
def ints()-> Tuple[List[Formula], Formula]:
def Even (x) : return Atom('Even',x) # whether x is even
def Odd(x) : return Atom('Odd',x) # whether x is odd
def Successor(x,y): return Atom('Successor',x,y) # whether x's successor is y
def Larger(x,y : return Atom('Larger',x,y whether x is larger than y
# Note: all objects are numbers, so we don't need to define Number as an
# explicit predicate.
# Note: pay attention to the order of arguments of Successor and Larger.
# Populate |formulas| with the 6 laws above and set |query| to be the
# query.
# Hint: You might want to use the Equals predicate, defined in
logic.py. This
# predicate is used to assert that two objects are the same.
formulas =[]
query = None
# BEGIN_YOUR_CODE (our solution is 23 lines of code, but don't worry if you deviate from this)
formulas.append(Exists())
# END_YOUR_CODE
query ?-=Forall('$x', Exists('$y', And(Even('$y'), Larger('$y','$x'))))
return (formulas, query)
 Problem 4: Odd and even integers # Return the following 6

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!