Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions