What are the composition of functions

Assignment Help Programming Languages
Reference no: EM13935914

Consider the following function definitions:

def y():
""" y does this function exist?
** just to illustrate a 0-input function...
"""
return 1

def w(x):
""" w computes thrice its input plus one
** plus it offers a chance to use the word "thrice"
input x: any number (int or float)
"""
return 3*(x+1)

def t(x):
""" t computes thrice its input plus one
** and shows how python is more precise than English
input x: any number (int or float)
"""
return 3*x + 1

def r(x,y):
""" r shows some less-common arithmetic operators
input x: any number (int or float)
input y: any number (int or float, more likely int)
"""
return ( x**2 % y ) + 2

def f(a,b):
""" f demonstrates the use of conditionals (if/elif/else)
** and that input parameters' names don't matter
input a: any number (int or float)
input b: any number (int or float)
"""
if a < b:
return (b-1) * (b-2)
else:
return (a+42) * (b+42)

Compositions
Here is an example of the kind of function composition that the following problems will ask you to create:

What composition of the functions w and t (above), along with the the literal value 0 will return the value 6? (No other literal values may be used.)

Solution to this example: w(t(0))

USE WORDS TO DESCRIBE THE SOLUTION STEPS

PROBLEM 1

Note that no literal numeric values ("numbers you type") other than 0 are allowed for these questions. Allowing any input takes away all the fun... not to mention that it would remove the need to compose funtions at all!

1i What composition of the functions w and t (above), along with the the literal value 0 will return the value 10?

1j Is it possible to compose the functions w and t (above), along with the literal value 0, to return any positive integer? Explain why or why not in a sentence or two.

1k What composition of all the functions above, along with the the literal value 0 will return the value 42?

1e For that last problem, what is the shortest composition, in terms of the number of functions called, that yields 42? (You'll know it when you see it -- in fact, you might have already come up with it for your answer to 1k.) Explain in a sentence or two why your answer is the shortest possible.

Reference no: EM13935914

Questions Cloud

Name few languages that allow use of variables : What is a keyword in a programming language? Why it is not a good practice to use reserved words as variable names?
How is it possible for ppp to hold if the ife does not : Comparing PPP and IFE. How is it possible for PPP to hold if IFE does not? How will this spot rate adjust according to PPP if the United Kingdom experiences an inflation rate of 7% while US experiences an inflation rate of 2%?
Compare and contrast humoral and cellular immunity : Protozoans are grouped through their means of locomotion; describe the three different types of locomotion. Compare and contrast humoral and cellular immunity.
Length of values defined for city column : There is a table called USER_TABLES that stores the information about each user's table. Use the select statement to make sure your tables are all created from assignment 2
What are the composition of functions : What composition of all the functions above, along with the the literal value 0 will return the value 42?
What will the spot rate be in one year according to the ife : The one-year interest rate is 11% in the United Kingdom and 7% in Singapore. What will the spot rate be in one year according to the IFE?
Analyse the leadership of a 21st century : Using relevant theories and models critically evaluate and analyse the leadership of a 21st century leader of a organisation.
Derive forecasts of the future spot rate : Deriving forecasts of the future spot rate. Use the forward rate to forecast the percentage change in the Mexican peso over the next year.
Does variable costing profit present a more realistic : Does variable costing profit present a more realistic view of firm performance in the two years?Explain.

Reviews

Write a Review

Programming Languages Questions & Answers

  Write a haskell program to calculates a balanced partition

Write a program in Haskell which calculates a balanced partition of N items where each item has a value between 0 and K such that the difference b/w the sum of the values of first partition,

  Create an application to run in the amazon ec2 service

In this project you will create an application to run in the Amazon EC2 service and you will also create a client that can run on local machine and access your application.

  Explain the process to develop a web page locally

Explain the process to develop a Web page locally

  Write functions

These 14 questions covers java class, Array, link list , generic class.

  Programming assignment

If the user wants to read the input from a file, then the output will also go into a different file . If the user wants to read the input interactively, then the output will go to the screen .

  Write a prolog program using swi proglog

Write a Prolog program using swi proglog

  Create a custom application using eclipse

Create a custom Application Using Eclipse Android Development

  Create a application using the mvc architecture

create a application using the MVC architecture. No scripting elements are allowed in JSP pages.

  Develops bespoke solutions for the rubber industry

Develops bespoke solutions for the rubber industry

  Design a program that models the worms behavior

Design a program that models the worm's behavior.

  Writing a class

Build a class for a type called Fraction

  Design a program that assigns seats on an airplane

Write a program that allows an instructor to keep a grade book and also design and implement a program that assigns seats on an airplane.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd