11.07.2015 Views

Advanced Programming Guide

Advanced Programming Guide

Advanced Programming Guide

SHOW MORE
SHOW LESS
  • No tags were found...

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

132 • Chapter 3: <strong>Programming</strong> with ModulesRR := module()export‘ + ‘, ‘ ∗ ‘, ‘ − ‘, ‘/‘, zero, one, iszero, isone, make,numer, denom, normal , embed ;description “a quotient field”;end module> type( RR, ’Field’ );trueTo make printed fractions more readable, introduce the following extensionto the print command.> ‘print/FRACTION‘ := ( n, d ) -> sort( n ) / sort( d ):Finally, construct a few examples, and test the arithmetic.> a := RR:-make( randpoly( ’T’, ’degree’ = 4, ’terms’ = 3 ),> randpoly( ’T’, ’degree’ = 4, ’terms’ = 3 ) );a := −2072 T 2 − 1960 T + 5432T 3 + 7 8 T 2 + 9 8> b := RR:-make( randpoly( ’T’, ’degree’ = 4, ’terms’ = 3 ),> randpoly( ’T’, ’degree’ = 4, ’terms’ = 3 ) );> use RR in> a + b;> a * b;> a / b> end use;b := −2790 T 3 + 496 T 2 + 5766T 2 − 7762 T − 3331

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!