Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please write the code in Scheme programming language: 1. Young Jeanie knows she has two parents, four grandparents, eight great grandparents, and so on. (a)
Please write the code in Scheme programming language:
1. Young Jeanie knows she has two parents, four grandparents, eight great grandparents, and so on. (a) Write a recursive function to compute the number of Jeanie's ancestors in the nth previous generation without using the expt function. The number of ancestors in each generation back produces a sequence that may look familiar: 2, 4, 8, 16, ... For each generation back, there are twice the number of ancestors than in the previous generation back. That is, an = 2an-1. Of course, Jeanie knows she has two ancestors, her parents, one generation back. (b) Write a recursive function to compute Jeanie's total number of ancestors if we go back n generations. Specifically, (num-ancestors n) should return: 2+4+8+ ... tan Use your function in part (a) as a "helper function in the definition of (num-ancestors n). 2. Perhaps you remember learning at some point that is an approximation for 1, which is an irrational number. In fact, in number theory, there is a field of study named Diophantine ap- proximation, which deals with rational approximation of irrational numbers. The Pell numbers are an infinite sequence of integers which correspond to the denominators of the closest rational approximations of 2. The Pell numbers are defined by the following recurrence relation (which looks very similar to the Fibonacci sequence): 1 0 if n=0 P ={ 1 if n=1 ( 2Pn-1 + Pn-2 otherwise Of course, we can use the closed-form solution for the geometric progression to compute num-ancestors (ancestors(n) = 2n+1 2) but that doesn't give us any experience with recursive functions. However, this is a useful fact we can use when testing our functions to ensure they are correct. (a) Use this recurrence relation to write a recursive function, pell-num, which takes one pa- rameter, n, and returns the nth Pell number The numerator for the rational approximation of 2 corresponding to a particular Pell number is half of the corresponding number in the sequence referred to as the companion Pell numbers (or Pell-Lucas numbers). The companion Pell numbers are defined by the recurrence relation: ( 2 if n=0 On = 2 if n = 1 2Qn-1 +Qn-2 otherwise (b) Use this recurrence relation to write a function, named comp-pell-num, which returns the nth companion Pell number. (c) Finally write a function that uses the Pell number and companion Pell number functions to compute the nth approximation for 2. Use your new function to compute the approx- imation for 2 for the sixth Pell and companion Pell numbers. 1. Young Jeanie knows she has two parents, four grandparents, eight great grandparents, and so on. (a) Write a recursive function to compute the number of Jeanie's ancestors in the nth previous generation without using the expt function. The number of ancestors in each generation back produces a sequence that may look familiar: 2, 4, 8, 16, ... For each generation back, there are twice the number of ancestors than in the previous generation back. That is, an = 2an-1. Of course, Jeanie knows she has two ancestors, her parents, one generation back. (b) Write a recursive function to compute Jeanie's total number of ancestors if we go back n generations. Specifically, (num-ancestors n) should return: 2+4+8+ ... tan Use your function in part (a) as a "helper function in the definition of (num-ancestors n). 2. Perhaps you remember learning at some point that is an approximation for 1, which is an irrational number. In fact, in number theory, there is a field of study named Diophantine ap- proximation, which deals with rational approximation of irrational numbers. The Pell numbers are an infinite sequence of integers which correspond to the denominators of the closest rational approximations of 2. The Pell numbers are defined by the following recurrence relation (which looks very similar to the Fibonacci sequence): 1 0 if n=0 P ={ 1 if n=1 ( 2Pn-1 + Pn-2 otherwise Of course, we can use the closed-form solution for the geometric progression to compute num-ancestors (ancestors(n) = 2n+1 2) but that doesn't give us any experience with recursive functions. However, this is a useful fact we can use when testing our functions to ensure they are correct. (a) Use this recurrence relation to write a recursive function, pell-num, which takes one pa- rameter, n, and returns the nth Pell number The numerator for the rational approximation of 2 corresponding to a particular Pell number is half of the corresponding number in the sequence referred to as the companion Pell numbers (or Pell-Lucas numbers). The companion Pell numbers are defined by the recurrence relation: ( 2 if n=0 On = 2 if n = 1 2Qn-1 +Qn-2 otherwise (b) Use this recurrence relation to write a function, named comp-pell-num, which returns the nth companion Pell number. (c) Finally write a function that uses the Pell number and companion Pell number functions to compute the nth approximation for 2. Use your new function to compute the approx- imation for 2 for the sixth Pell and companion Pell numbersStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started