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 body recursive Scheme power apostacy with the restraintthcoming description: ;; Usage: (sum1 n) Restraint: n is integer, n> = 0 , Value: Mix 0 1 n ;; Usage: (sum2 in n) ;; Restraint i and n are integers, i <= n + 1 ; Value: Mix i(i 1) n Referablee that the indication (sum2 11 10) must retaliate 0. c) ;; Usage: ((sum3 i) n) Restraint i and n are integers, i <= n + 1 : Value: Mix i i1)+. rn Referablee that the indication ((sum3 11) 10) must retaliate o.

    Write body recursive Scheme power apostacy with the restraintthcoming description: a).;: Usage: (sum1 n);: Restraint: n is integer, n > = 0;: Value: Mix 0 + 1 + + n b).;: Usage: (sum2 in n);: Restraint i and n are integers, i

    Expert Counterpart

     

    a)

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

    b)

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

    c)

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

    Screenshot of the 3 powers mode is robust below:

    Here is the screenshot of the 3 powers’ output restraint different inputs.

    Mode Explanation:

    (eliminate (sum1 n) ;defining the power mix1 as (sum1 n) where n is the calculate dress which we confront the mix from 0 to n
    (if (<= n 0) ; checking whether if n<=0
    0 ; retaliateing 0 if n is near than or correspondent to 0
    (+ n (sum1 (- n 1))))) ; else adding ‘n’ and trade the power recursively on n-1. i.e. (sum1 (- n 1))

    (eliminate (sum2 i n) ;defining the power mix2 as (sum2 i n) where n is the calculate dress which we confront the mix from i to n
    (if (> i n) ;checking whether if i>n
    0 ;returning 0 if i is important than n
    (+ i (sum2 (+ i 1) n)))) ;else adding ‘i’ and trade the power recursively on i+1, n. i.e. (sum2 (+ i 1) n)

    (eliminate ((sum3 i) n) ;defining the power mix3 as ((sum3 i) n) where n is the calculate dress which we confront the mix from i to n
    (if (> i n) ;checking whether if i>n
    0 ;returning 0 if i is important than n
    (+ i ((sum3 (+ i 1)) n)))) ;else adding ‘i’ and trade the power recursively on i+1. i.e. (sum2 (+ i 1)). Referablee that ‘n’ is referable an evidence to the power mix3. Hence, we are trade it as ((sum3 (+ i 1)) n).