Eduardo Cavazos wrote:

Chapter 6 of the Elementary Algorithms volume by Cohen[1] covers basic algorithms for manipulation of polynomial expressions. I've added libraries which implement some of these techiques.

I added 'rationalize-expression' and 'rational-expand' also from
Chapter 6.

Examples from the unit tests are included.

Some of the code as currently written isn't in idiomatic Scheme style. This is because I ususally do a more or less direct translation of the pseudo code from the book. I'd like to get things working and stable first before I fancy things up. The code is easier to debug when it still resembles what's in the book. The good news is that, with a bunch of unit tests, converting to idiomatic code down the line can be done with more confidence.

Ed

    ;; rationalize-expression

    (test-equal "EA: page 266 - 1"

                (rationalize-expression (alge " (1 + 1/x)^2 "))

                (alge " (x+1)^2 / x^2 "))

    (test-equal "EA: page 266 - 1"

                (rationalize-expression (alge " (1 + 1/x)^(1/2) "))

                (alge " ( (x+1)/x ) ^ (1/2) "))

    (test-equal "EA: Example 6.59"

                (rationalize-expression
                 (alge " 1 / (1+1/x)^(1/2) + (1+1/x)^(3/2) "))

(alge " ( x^2 + (x+1)^2 ) / ( x^2 * ( (x+1) / x ) ^ (1/2) ) ")

                )

    (test-equal "EA: Example 6.60"

                (rationalize-expression (alge " a + b/2 "))

                (alge " (2 a + b)/2 ")

                )

    ;; rational-expand

    (test-equal "EA: Example 6.62"

                (rational-expand
                 (alge
                  " ( ( ( 1 / ( (x+y)^2 + 1 ) ) ^ (1/2) + 1 )
                      *
                      ( ( 1 / ( (x+y)^2 + 1 ) ) ^ (1/2) - 1 ) )
                    /
                    (x+1) "))

                (alge
                 " ( - x^2 - 2 x y - y^2 )
                   /
                   ( x^3 + x^2 + 2 x^2 y + 2 x y + x y^2 + y^2 + x + 1 ) ")

                )

    (test-equal

     "EA: page 269"

     (rational-expand
      (alge
       " 1 / ( 1/a + c / (a b) ) + ( a b c + a c^2 ) / (b+c)^2 - a "))

     0)

Reply via email to