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

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!