From: ········@ucla.edu
Subject: Symbolic Differentiation of Algebraic Expressions
Date: 
Message-ID: <7198mv$6ch$1@nnrp1.dejanews.com>
I'm a beginner in LISP programming.  This is only the 2nd assignment, and I'm
already lost.  I don't even know how to start this program, and what approach
I should take.

                    ******************************

================
I. Overview
================
Write a scheme program to perform symbolic differentiation
of algebraic expressions, as described in Abelson et. al. Chapter 2
pp. 142--153.

For the purposes of this assignment, an algebraic expression is
any expression whose only primitive procedures are +, *, -, /, and ** (expt).
You may assume all exponents are constant; contrary to what was first
announced in lecture, we will *not* differentiate exponentials
(expressions including terms of the form 2**x, 3**x, etc.).
We *will* differentiate polynomials (i.e. sums of constant multiples
of terms only of the form x**2, x**3, etc.), and quotients of
polynomials.

For example,

(define exp2 '(/ (+ (* 2 (** x 2)) (* 5 (** x 3))) (- (** x 2)  (** x 3))) )

is a scheme-legal representation of the algebraic expression
more commonly denoted as

             2*x**2 + 5*x**3
    exp2 =  -----------------     ;
               x**2 - x**3

whose derivative is calculated as ...

> (deriv exp2 'x)
(/ (- (* (+ (* 2 (* 2 x)) (* 5 (* 3 (** x 2)))) (- (** x 2) (** x 3)))
      (* (+ (* 2 (** x 2)) (* 5 (** x 3))) (- (* 2 x) (* 3 (** x 2)))))
   (** (- (** x 2) (** x 3)) 2))

... which is a mostly unsimplified representation (to which I
have manually added some indentation) of the derivative
of "exp2" obtained by following the quotient rule:

           (2*x**2 + 5*x**3)'*(x**2 - x**3) - (2*x**2 + 5*x**3)*(x**2 - x**3)'
  exp2' =  -------------------------------------------------------------------
                                 (x**2 - x**3)**2


           (4*x + 15*x**2)*(x**2 - x**3) - (2*x**2 + 5*x**3)*(2*x - 3*x**2)
        =  ----------------------------------------------------------------
                                 (x**2 - x**3)**2.

Note that the following scheme expressions are *not* algebraic expressions;
              (sin x), (cos x), (expt 2 x), (log x) .

As in the text, you are *not* required to express answers
in simplest form; however, your code should automatically simplify trivial
binary numerical expressions (e.g., (* 3 9)) as well as all trivial symbolic
expressions of the form (* e 1), (+ e 0), (/ e 1), (- 0 e), and (- e 0),
where in this context "e" denotes an arbitrary algebraic expression.

You are free to copy verbatim any code appearing in the text.
To earn full credit, your program must implement the
"extensions" described in exercises 2.56 - 2.58 on pp. 150-151.
Exercise 58 is significantly harder than 56 and 57.
One way to do it is to implement recursive procedures that convert
infix expressions ( x + 3*x**2 ) to prefix expressions (+ x (* 3 (** x 2)))
and back again.  More suggestions on 58 will be posted here soon.

In addition to the extensions in exercises 2.56-2.58, your program
must be able to handle differences (subtraction)
and quotients (division) of algebraic expressions.

Some important mathematical rules to know for finding the
derivative f' of a function f follow.  Note that the notation
for these rules is "mathematical"; it is not the same notation
you will use in Scheme.

Let a, b, and n denote arbitrary constants (numbers).
Let f, and g denote functions of (or algebraic expressions in) x.
We are differentiating expressions with respect to variable x.
x**n denotes "x raised to the power n";
"a*x**n" means a * ( x**n ), or in Scheme, (* a (expt x n)).

  i)    a'        = 0
  ii)   (x**n)'   = n*x**(n-1)
  iii)  (f + g)'  = f' + g'
  iv)   (a*f)'    = a*f'
  v)    (f*g)'    = f'*g + f*g'
  vi)   (f/g)'    = (f'*g - f*g') / (g*g)     (assuming g not zero)

-----------== Posted via Deja News, The Discussion Network ==----------
http://www.dejanews.com/       Search, Read, Discuss, or Start Your Own    
From: Reini Urban
Subject: Re: Symbolic Differentiation of Algebraic Expressions
Date: 
Message-ID: <36384769.1028028@judy>
········@ucla.edu wrote:
>I'm a beginner in LISP programming.  This is only the 2nd assignment, and I'm
>already lost.  I don't even know how to start this program, and what approach
>I should take.
>
>Write a scheme program to perform symbolic differentiation
>of algebraic expressions, as described in Abelson et. al. Chapter 2
>pp. 142--153.

doesn't the ucla have private newsgroups for their courses?
the line "More suggestions on 58 will be posted here soon."
makes it clear. so why don't you ask in your group instead of bothering
people here. or did your class advisor give you this tip?

btw: hopefully my sicpee will arrive this week. i ordered it via barnes
& nobles online. looks like a fine example though i already know it from
winston/horn.
--                                         
Reini