functional programming - Convert a polynomial represented as a list of coefficients to a string -


i know newbish question. trying create function 'displaypoly' display polynomial in scheme. example list given '(2 0 1 5.1 8) should display 2x^4 + x^2 + 5.1x + 8.

i have defined "degree" following:

 (define degree  (lambda(list)   (if (null? list)        (- 1)   (+ 1  (degree (cdr list)))))) 

please note strictly limited basic scheme functions •define, lambda, if, cond, cons,car, cdr, list , member, list-ref •predicates : null? list? equal? string? number? member? •arithmetic operators , relational operators, logical operators •sort, map, filter, foldr, foldl, length, reverse, append, last , let, let*, letrec, print, begin, newline, display, expt, string-append, reduce, range

you need write helper functions.

  1. write function given polynomial returns list of degrees.

    input: '(2 0 1 5.1 8) output: (4 3 2 1 0)

  2. write function mono given coefficient , degree outputs monomial string.

    input: 2 4 output: "2x^4"

  3. use (map mono '(2 0 1 5.1 8) (4 3 2 1 0)) produce list of monomials.

  4. use add-between (or write 1 yourself) add "+" between monomials.

  5. use (apply string-append your-list-of-monomials) final string.

note: it's possible produce prettier output, start.


Comments

Popular posts from this blog

asp.net - How to correctly use QUERY_STRING in ISAPI rewrite? -

jsf - "PropertyNotWritableException: Illegal Syntax for Set Operation" error when setting value in bean -

laravel - Undefined property: Illuminate\Pagination\LengthAwarePaginator::$id (View: F:\project\resources\views\admin\carousels\index.blade.php) -