Features & Development

? Context( 'RationalNmbrs' ) ??

? Context( 'RationalNmbrs' ) ??

by Dick Lane -
Number of replies: 3
I am writing some problems involving polynomial functions with rational coefficients.  It appears I need to manage each coefficient because Context('Fraction') does not play nicely with function objects.  For instance, my attached examples which differ with
    $ac = Fraction( $a , $c );
    $bc = Fraction( $b , $c );
    $fcn = Formula( "$ac x + $bc" ) ;
replaced by
    $fcn = Compute( "($a/$c) x + $b/$c" ) ;
both elicit error message
    Undefined subroutine &context::Fraction::Real::cmp_defaults ...

Gavin's reduced_frac in Library/macros/Michigan/hhAdditionalMacros.pl shows one approach to coping with a part of this dilemma.

While it may be possible to extend tools in
    pg/macros/PGpolynomialmacros.pl
a more general extension of the system might be feasible.

I just stumbled across the Math::Polynomial class for Perl.  The documentation
    http://search.cpan.org/~mhasch/Math-Polynomial-1.005/lib/Math/Polynomial.pm
says it can handle coefficients from a variety of rings: decimal real, decimal complex, rational, matrices, finite fields, etc.  Could that provide support for development of a Context('Rational') that handles both numbers and functions (domain and range)?  [RationalNmbrs should probably be distinguished from RationalFcns.]
In reply to Dick Lane

Re: ? Context( 'RationalNmbrs' ) ??

by Michael Gage -
As long as we are thinking of extensions, another possibility might be to use Sage's capabilities in this regard.  That might not be a better solution than what you propose above but it is worth considering.  We've been working on integration with sage for other reasons for a while now.

In reply to Michael Gage

Re: ? Context( 'RationalNmbrs' ) ??

by Dick Lane -
Adding a Computer Algebra System (CAS) to WeBWorK's toolbox would be extremely useful.  Although using a CAS for checking of student answers involves major issues about security (the STACK project may have some documents describing their approach), using a CAS to support creation of problem components seems relatively safe.

Maxima (Sage's CAS) is not the only open-source CAS to consider (I need to update my list in http://lennes.math.umt.edu/391/cas.html).  Work by the GeoGebra project may suggest ways to select a good subset of functionality from a major CAS, e.g, see
    https://dev.geogebra.org/trac/wiki/GeoGebraCAS

In reply to Dick Lane

Re: ? Context( 'RationalNmbrs' ) ??

by Dick Lane -
The attached problem file uses a sequence of
    ($n,$d) = $fraction -> value ;
    $ratnl = ($d == 1)  ? $n  : "\frac{$n}{$d} " ;
to get full-size fractions for display in a solution.
(A RationalNmbr context would eliminate the need for that sort ot fiddling.)

There are also two uses of
    $fraction->with(isHorizontal=>true);
which fail to have the desired effect.