Question

Given the following Prolog function: fn([Y], Y). fn([_|Z], Y) :- fn(Z, Y). (a) Determine what output...

Given the following Prolog function:

fn([Y], Y).

fn([_|Z], Y) :- fn(Z, Y).

(a) Determine what output will be produced if we run the query:   fn([1, 2, 3], Y).

(b) Explain what the function fn does (do NOT list steps, give the final result).

Homework Answers

Answer #1

PROLOG functions are quite straight forward such as :

addition(A, B, C):- C is A + B.

subtraction(A, B, C):- C is A - B.

division(A, B, C):- C is A / B.

multiplication(A, B, C):- C is A * B.

For the question you mentioned:

a) It will store the sum of all the three numbers into the Y variable and will give us the result

b) The function just takes the initial parameters and perform operations on them and finally store the result into the terminal variable.

HOpe this will help you.. THanks

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
A firm’s production function is given as y=(x1)^(1/2) * (x2-1)^(1/2) where y≥0 for the output, x1≥0...
A firm’s production function is given as y=(x1)^(1/2) * (x2-1)^(1/2) where y≥0 for the output, x1≥0 for the input 1 and x2≥0 for the input 2. The prices of input 1 and input 2 are given as w1>0 and w2>0, respectively. Answer the following questions. Which returns to scale does the production function exhibit? Derive the long-run conditional input demand functions and the long-run cost function.
Consider the following production function Y=z*(a*K + (1-a)*N) where z represents total factor productivity, a is...
Consider the following production function Y=z*(a*K + (1-a)*N) where z represents total factor productivity, a is a parameter between 0 and 1, K is the level of capital, and N is labor. We want to check if this function satisfies our basic assumptions about production functions. 1. Does this production function exhibit constant returns to scale? Ex- plain 2. Is the marginal product of labor always positive? Explain 3. Does this function exhibit diminishing marginal product of labor? Ex- plain...
The production function is given by y=L1/2, where y is the output, and L is the...
The production function is given by y=L1/2, where y is the output, and L is the amount of labor input. Assume the wage rate is w so that the cost of using L unit of labor input is wL. Let p denote the unit price of the output. Note that w and p are exogenously given. (1) Find the function for the profit (in terms of p, w and L). (2) Find the optimal choice of labor input and the...
Given the following function: Y= (2x + 1)3 (x-1) a) Determine where the function is increasing...
Given the following function: Y= (2x + 1)3 (x-1) a) Determine where the function is increasing or decreasing. b) Determine where the function is concave up or down
Consider the Solow Model with the following production function for output Y=AK1/2 L1/2   Being at the...
Consider the Solow Model with the following production function for output Y=AK1/2 L1/2   Being at the steady state suppose that climate changes and the global warming reduce the life of physical capital by 20% i. While in country 0 no counter interventions are implemented, in country 1 the governmetn wants to avoid any short run fluctuation in output and consumption. Which policies could the government implement? Explain ii. Describe what will happen in the two countries in the short run...
Consider the following Cobb-Douglass production function?≡??(?,?):?=??1/3?2/3 where Y is output, the constant z measures productivity, K...
Consider the following Cobb-Douglass production function?≡??(?,?):?=??1/3?2/3 where Y is output, the constant z measures productivity, K is physical capital, and N is labor. Suppose ?=2, ?=0.16, ?=0.06, and ?=0.02. a. What are the steady-state (numerical) values of ?, ?, and ?? b. What is the golden-rule (numerical) level of capital per worker? c. If the government wants to achieve the golden rule level of k, should savings increase, decrease or remain unchanged? Solve for/obtain its (numerical) value. Explain briefly.
We are given a level surface F ( x , y , z ) = 0...
We are given a level surface F ( x , y , z ) = 0 where F ( x , y , z ) = x^3 - y^2 + z^4 - 20 . Find the equation of the tangent plane to the surface at the point P ( 2 , 2 , 2 ) . Write the final answer in the form a x + b y + c z + d = 0
What is the antigradient of the given gradient function \nabla f = (z, x, y)
What is the antigradient of the given gradient function \nabla f = (z, x, y)
You are given the following partial Stata output: regress y x z Source | SS df...
You are given the following partial Stata output: regress y x z Source | SS df MS -------------+--------------------------------------- Model | 810                  1                                Residual |         270               19 -------------+---------------------------------------- Total |     1080                    20 ------------------------------------------------------------------------------ y |     Coef. Std. Err. t P>|t| [95% Conf. Interval] ------------------------------------------------------------------------------   x| 9 1.5   z| 6 3.0 Number of obs = 21 F( 2, 18) = Prob > F = R-squared = Adj R-squared = Root MSE = Fill out all the remaining entries in this Stata output....
In racket, Given the function definition: (define (guess   a_list)                             &nbsp
In racket, Given the function definition: (define (guess   a_list)                                          (if (null? a_list)    0    (+ 1 (guess (cdr a_list))) )) (a) write the derivation of the following function call:  (guess ‘(3 1 2 5)) => (b) explain what this function is doing when given a parameter a_list (NOT the steps of execution, but the result).
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT