Question
Program #12 Write the following function in PROLOG , must run using swipl. Write a function evaluate_polynomial that takes a list of coefficients, the value
Program #12
Write the following function in PROLOG, must run using swipl. Write a function evaluate_polynomial that takes a list of coefficients, the value of X, and returns the Y value. Each position, i, is the coefficient of xi. For example, the list [3,2, 1] represents the polynomial, 1x2 + 2x1 + 3x0 or, equivalently, x2 + 2x + 3. Using a helper function will help in solving this problem.
You may use the following functions:
operators: =, \=, and is
math operators (+, ^, ***, -, etc.),
List syntax such as: [Head|Tail]
write and nl
reverse
Use the following template:
% evaluate_polynomial/3 - evaluates Polynomial using X value and return answer in Y | |
evaluate_polynomial(Polynomial, X, Y) :- true. |
Examples:
?- evaluate_polynomial([1, -2, 1], 3, Y). Y = 4. ?- evaluate_polynomial([-1, 2, 4, -8], 5, Y). Y = -891.
Step 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