Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PROLOG: Defining Natural numbers and Common Numerical Operator Part B: Defining Natural numbers and Common Numerical Operators For this part, you will be defining Natural
PROLOG: Defining Natural numbers and Common Numerical Operator
Part B: Defining Natural numbers and Common Numerical Operators For this part, you will be defining Natural numbers (including zero, 'Z') using Prolog using the numbering scheme discussed in class. You should also provide the prolog code for the following predicates/functors listed below. predecessor/2, the second parameter provides the predecessor to the first successor/2, the second parameter provides the successor to the first numeral/2, the second parameter gives the numerical value for the first addition/3, the third parameter gives the numbering scheme value of adding the first and second subtraction/3, the third parameter gives the numbering scheme value of subtracting the first and second multiplication/3, the third parameter gives the numbering scheme value of multiplying the first and second factorial/2, the second parameter gives the numbering scheme value of the factorial of the first equal/2, will answer true if the first and second parameter are equal and false otherwise greater/2, will answer true if the first parameter is greater than the second and false otherwise less/2, will answer true if the first parameter is less than the second and false otherwise Part B Sample Runs: ?- predecessor(2,A). false. ?- predecessor(s(2),A). A=z. ?- predecessor(s(s(z)),A). A = s(z). ?- successor(2,A). A = s(z) ?- successor(s(2),A). A = s(s(z)). ?- successor(s(s(z)),A). A = s(s(s(z))) ?- numeral(20) true. ?- numeral(s(z),0). false. ?- numeral(s(z),1). true. ?- numeral(s(s(s(s(z)))),4). true. ?- addition(z,2,A). A=Z. ?- addition(s(z),z,A). A = s(z). ?- subtraction(s(2),2,A). A = s(z). ?- subtraction(z,s(z),A). false. ?- subtraction(s(2),s(2),A). A=z. ?- subtraction(s(s(z)),s(z),A). A = s(z) ?- multiplication(z,s(2),A). A= z. ?- multiplication(s(2),2,A). A=z. ?- multiplication(z,2,A). A = z. ?- multiplication(s(2),s(2),A). A = s(z). ?- multiplication(s(2),s(s(z)),A). A = s(s(z)). ?- multiplication(s(s(z)),s(s(z)),A). A = s(s(s(S(z)))) ?- factorial(z,A). A = s(z). ?- factorial(s(2),A). A = s(z). ?- factorial(s(s(z)),A). A = s(s(z)). ?- numeral(s(s(s(s(s(S(z)))))),6). true. ?- equal(z,z). true. ?- equal(s(2),z). false. ?- greater(s(z),z). true. ?- greater(z,s(z)). false. ?- less(z,s(z)). true. ?- less(s(2),z). false. Part B: Defining Natural numbers and Common Numerical Operators For this part, you will be defining Natural numbers (including zero, 'Z') using Prolog using the numbering scheme discussed in class. You should also provide the prolog code for the following predicates/functors listed below. predecessor/2, the second parameter provides the predecessor to the first successor/2, the second parameter provides the successor to the first numeral/2, the second parameter gives the numerical value for the first addition/3, the third parameter gives the numbering scheme value of adding the first and second subtraction/3, the third parameter gives the numbering scheme value of subtracting the first and second multiplication/3, the third parameter gives the numbering scheme value of multiplying the first and second factorial/2, the second parameter gives the numbering scheme value of the factorial of the first equal/2, will answer true if the first and second parameter are equal and false otherwise greater/2, will answer true if the first parameter is greater than the second and false otherwise less/2, will answer true if the first parameter is less than the second and false otherwise Part B Sample Runs: ?- predecessor(2,A). false. ?- predecessor(s(2),A). A=z. ?- predecessor(s(s(z)),A). A = s(z). ?- successor(2,A). A = s(z) ?- successor(s(2),A). A = s(s(z)). ?- successor(s(s(z)),A). A = s(s(s(z))) ?- numeral(20) true. ?- numeral(s(z),0). false. ?- numeral(s(z),1). true. ?- numeral(s(s(s(s(z)))),4). true. ?- addition(z,2,A). A=Z. ?- addition(s(z),z,A). A = s(z). ?- subtraction(s(2),2,A). A = s(z). ?- subtraction(z,s(z),A). false. ?- subtraction(s(2),s(2),A). A=z. ?- subtraction(s(s(z)),s(z),A). A = s(z) ?- multiplication(z,s(2),A). A= z. ?- multiplication(s(2),2,A). A=z. ?- multiplication(z,2,A). A = z. ?- multiplication(s(2),s(2),A). A = s(z). ?- multiplication(s(2),s(s(z)),A). A = s(s(z)). ?- multiplication(s(s(z)),s(s(z)),A). A = s(s(s(S(z)))) ?- factorial(z,A). A = s(z). ?- factorial(s(2),A). A = s(z). ?- factorial(s(s(z)),A). A = s(s(z)). ?- numeral(s(s(s(s(s(S(z)))))),6). true. ?- equal(z,z). true. ?- equal(s(2),z). false. ?- greater(s(z),z). true. ?- greater(z,s(z)). false. ?- less(z,s(z)). true. ?- less(s(2),z). falseStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started