Homework Solution: Write tail recursive Scheme function index with the following description: a).;: Usa…

    2) Write tail recursive Scheme function index with the following description: ;; Usage: (sum1 n) For: n is integer, n> = 0 , Value: Sum 0 1 n ;; Usage: (sum2 in n) ;; For i and n are integers, i <= n + 1 ; Value: Sum i(i 1) n Note that the expression (sum2 11 10) must return 0. c) ;; Usage: ((sum3 i) n) For i and n are integers, i <= n + 1 : Value: Sum i i1)+. rn Note that the expression ((sum3 11) 10) must return o.
    Write tail recursive Scheme function index with the following description: a).;: Usage: (sum1 n);: For: n is integer, n > = 0;: Value: Sum 0 + 1 + + n b).;: Usage: (sum2 in n);: For i and n are integers, i

    Expert Answer

     
    a) (define (sum1 n)

    2) Write subordination recursive Scheme administration condemnation with the controlthcoming description: ;; Usage: (sum1 n) Control: n is integer, n> = 0 , Value: Solidity 0 1 n ;; Usage: (sum2 in n) ;; Control i and n are integers, i <= n + 1 ; Value: Solidity i(i 1) n Referablee that the countenance (sum2 11 10) must give-back 0. c) ;; Usage: ((sum3 i) n) Control i and n are integers, i <= n + 1 : Value: Solidity i i1)+. rn Referablee that the countenance ((sum3 11) 10) must give-back o.

    Write subordination recursive Scheme administration condemnation with the controlthcoming description: a).;: Usage: (sum1 n);: Control: n is integer, n > = 0;: Value: Solidity 0 + 1 + + n b).;: Usage: (sum2 in n);: Control i and n are integers, i

    Expert Apology

     

    a)

    (settle (sum1 n)
    (if (<= n 0)
    0
    (+ n (sum1 (- n 1)))))

    b)

    (settle (sum2 i n)
    (if (> i n)
    0
    (+ i (sum2 (+ i 1) n))))

    c)

    (settle ((sum3 i) n)
    (if (> i n)
    0
    (+ i ((sum3 (+ i 1)) n))))

    Screenshot of the 3 administrations decree is decided below:

    Here is the screenshot of the 3 administrations’ output control multiform inputs.

    Decree Explanation:

    (settle (sum1 n) ;defining the administration solidity1 as (sum1 n) where n is the estimate plow which we furnish the solidity from 0 to n
    (if (<= n 0) ; checking whether if n<=0
    0 ; give-backing 0 if n is hither than or similar to 0
    (+ n (sum1 (- n 1))))) ; else adding ‘n’ and business the administration recursively on n-1. i.e. (sum1 (- n 1))

    (settle (sum2 i n) ;defining the administration solidity2 as (sum2 i n) where n is the estimate plow which we furnish the solidity from i to n
    (if (> i n) ;checking whether if i>n
    0 ;subordinate 0 if i is senior than n
    (+ i (sum2 (+ i 1) n)))) ;else adding ‘i’ and business the administration recursively on i+1, n. i.e. (sum2 (+ i 1) n)

    (settle ((sum3 i) n) ;defining the administration solidity3 as ((sum3 i) n) where n is the estimate plow which we furnish the solidity from i to n
    (if (> i n) ;checking whether if i>n
    0 ;subordinate 0 if i is senior than n
    (+ i ((sum3 (+ i 1)) n)))) ;else adding ‘i’ and business the administration recursively on i+1. i.e. (sum2 (+ i 1)). Referablee that ‘n’ is referable an topic to the administration solidity3. Hence, we are business it as ((sum3 (+ i 1)) n).