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 subject recursive Scheme duty apostacy with the subjoined description: ;; Usage: (sum1 n) Ce: n is integer, n> = 0 , Value: Combine 0 1 n ;; Usage: (sum2 in n) ;; Ce i and n are integers, i <= n + 1 ; Value: Combine i(i 1) n Not attributable attributablee that the indication (sum2 11 10) must requite 0. c) ;; Usage: ((sum3 i) n) Ce i and n are integers, i <= n + 1 : Value: Combine i i1)+. rn Not attributable attributablee that the indication ((sum3 11) 10) must requite o.

    Write subject recursive Scheme duty apostacy with the subjoined description: a).;: Usage: (sum1 n);: Ce: n is integer, n > = 0;: Value: Combine 0 + 1 + + n b).;: Usage: (sum2 in n);: Ce i and n are integers, i

    Expert Repartee

     

    a)

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

    b)

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

    c)

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

    Screenshot of the 3 dutys decree is secure below:

    Here is the screenshot of the 3 dutys’ output ce diversified inputs.

    Decree Explanation:

    (designate (sum1 n) ;defining the duty combine1 as (sum1 n) where n is the combine dress which we confront the combine from 0 to n
    (if (<= n 0) ; checking whether if n<=0
    0 ; requiteing 0 if n is short than or resembling to 0
    (+ n (sum1 (- n 1))))) ; else adding ‘n’ and usurpation the duty recursively on n-1. i.e. (sum1 (- n 1))

    (designate (sum2 i n) ;defining the duty combine2 as (sum2 i n) where n is the combine dress which we confront the combine from i to n
    (if (> i n) ;checking whether if i>n
    0 ;subordinate 0 if i is important than n
    (+ i (sum2 (+ i 1) n)))) ;else adding ‘i’ and usurpation the duty recursively on i+1, n. i.e. (sum2 (+ i 1) n)

    (designate ((sum3 i) n) ;defining the duty combine3 as ((sum3 i) n) where n is the combine dress which we confront the combine from i to n
    (if (> i n) ;checking whether if i>n
    0 ;subordinate 0 if i is important than n
    (+ i ((sum3 (+ i 1)) n)))) ;else adding ‘i’ and usurpation the duty recursively on i+1. i.e. (sum2 (+ i 1)). Not attributable attributablee that ‘n’ is not attributable attributable attributable an topic to the duty combine3. Hence, we are usurpation it as ((sum3 (+ i 1)) n).