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

  Analyse the program and execute it

I am working on a program that I want to use for a simple home energy data information system.

  Calculate display the area of a rectangle (length * width)

Use the input.txt file. Have it read in the number of records to work on. Then for each record read in a character. If it is a C then read in a value and calculate and display the area of a circle (pi*r 2 ), a R then read in two values and calculate ..

  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.

  Program to store item-s price

Suppose a c++ program requires to store item's price. Price will range from $15.50 to $20. Write down assignment statement which allots value $16.23 to variable.

  Write program in java to input basic salary of persons

Write the program in java to input basic salary of 15 persons. Each one of them gets 25% of basic as hra (house rent allowance), 15 % of basic as conveyance and 10 % of basic as entertainment allowance.

  Write program to help students learn periods of geology time

You are taking a geology class, and the professor wants you to write a program to help students learn the periods of geologic time. The program should let the user enter a range of prehistoric dates (in millions of years), and then output the peri..

  Use-professional translator in creting website-other country

When and why would you need to use the services of a professional translator to help prepare your website for an audience in another country?

  Test a program for calculate interest

Test the program for a mortgage of $240,000 at 6% annual rate of interest, and duration 360 months. Such a mortgage will have a monthly payment of $1,438.92 and total interest of $278,011.65.

  Develop the flow diagram

Develop the flow diagram of the information and any control elements needed to ensure proper access for the information.Submit a draft PowerPoint presentation with the following elements

  What runtimeexception if any will the following program

q1. what runtimeexception if any will the following program throw?class exception1 public static void mainstring

  Design electronic submission of assignments from students

This system must manage electronic submission of assignments from students to instructors. It must keep track of which students have submitted assignments and must allow instructors to manage the grading.

  Write a perl program that performs show current date

Write a Perl program that performs the following tasks: Generate a menu to ask the user for the task that he or she would like to see performed. The available tasks are as follows: Show current date and time

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