;; PROBLEM ONE.
;; FIRST PART.
;;
;; DEFINE FUNCTION (eval-poly p v)
;; Eval polynomial p at value v for x
;;
;; Examples
;; (eval-poly '(1 1 1) 3) -> 13
;; (eval-poly '(2 6) 2) -> 14
;; (eval-poly '(3 5 7) 1) -> 15
;;
;; HINT
;; You can write EVAL-POLY using the structure of the
;; polynomial. But to do so, you need to come up with a mathematical
;; expression relating the polynomial represented by p to the
;; polynomial represented by (cdr p).
;; SECOND PART.
;;
;; DEFINE FUNCION (add-poly p1 p2)
;; Add two polynomials
;;
;; Examples
;; (add-poly '(3 5 7) '(2 6)) -> '(5 11 7)
;; (add-poly '(2 6) '(3 5 7)) -> '(5 11 7)
;;
;; HINT
;; You can also write add-poly using the structure of the
;; polynomial. Here the "trick" is that the polynomials do not have to
;; be the same length.
;; THIRD PART.
;;
;; DEFINE FUNCTION (diff-poly p)
;;
;; Differentiate polynomial p with respect to its variable x
;;
;; Examples
;; (diff-poly '(3 5 7)) -> '(5 14 0)
;; (diff-poly '(1 0 1 4)) -> '(0 2 12 0)
;;
;; HINT
;; You should again write diff-poly directly using the structure
;; of the polynomial. You will have to rely on the same mathematical
;; view of the polynomial you developed for eval-poly: how does
;; the polynomial represented by p relate to the polynomial
;; represented by (cdr p)? Your answer will then involve the
;; product rule and add-poly.
;; PART FOUR
;; DEFINE FUNCTION (diff-aux p n)
;;
;; Diff-aux returns polynomial r such that
;; derivative of x^n * p is x^(n-1) * r
;;
;; Examples
;; (diff-aux '(0 1 4) 1) -> '(0 2 12)
;; (diff-aux '(1 4) 2) -> '(2 12)
;; (diff-aux '(4) 3) -> '(12)
;; DEFINE FUNCTION (diff-poly2 p)
;;
;; Differentiate polynomial p,
;; using diff-aux.
;;
;; Examples
;; (diff-poly2 '(3 5 7)) -> '(5 14)
;; (diff-poly2 '(1 0 1 4)) -> '(0 2 12)
;; PROBLEM 2
;; PROGRAMS AND XML
(require (lib "ssax.ss" "ssax"))
;; UFO IN A NUTSHELL
;; - moves the spacecraft one parsec forward along the x axis.
;; - moves the spacecraft one parsec back along the x axis.
;; - moves the spacecraft one parsec forward along the y axis.
;; - moves the spacecraft one parsec back along the y axis.
;; - moves the spacecraft one parsec forward along the z axis.
;; - moves the spacecraft one parsec back along the z axis.
;; - instantly returns the spacecraft to the
;; origin, position '(0 0 0).
;; ... - runs the embedded \textbf{UFO}
;; program two times in succession.
;; DEFINE FUNCTION (eval-step step start)
;;
;; return the position that the ufo gets to by carrying out
;; ufo-action step from the position start.
;;
;; HINTS
;; A couple hints: if you use a let to define
;; x, y, and z, your code will be much
;; cleaner. The fact that the step may be
;; twice means that eval-step and the next
;; function, eval-program, will be MUTUALLY
;; RECURSIVE...each will call the other.
;; DEFINE FUNCTION (eval-program steps start)
;;
;; return the position that the ufo gets to by carrying out
;; each of the steps in the list steps in order, starting from
;; position start.
;; DEFINE FUNCTION (eval-ufo struct)
;;
;; If struct is the SXML representation of a UFO file, this function
;; returns the position that the embedded program unit leaves
;; the ufo at, if it starts at the origin.
;; PROBLEM 3
;;
;; COMMENT THESE FUNCTIONS
;;
;; HINT
;; Remember: you can test your hypotheses by interacting with Scheme.
;; Here are some places to get started: for what x will
;; (are-all-elts? number? x) be true? for what x will
;; (are-all? list? x) be true?
(define (are-all? pred? here)
(and (pred? here)
(if (pair? here) (are-all-elts? pred? here) #t)))
(define (are-all-elts? pred? here)
(if (pair? here)
(and (are-all? pred? (car here))
(are-all-elts? pred? (cdr here)))
#t))
;; WRITE AND COMMENT
;; (ok-in-tree? n)
;; (is-binary? t)