Skip Menu |

This queue is for tickets about the Math-Polynomial CPAN distribution.

Report information
The Basics
Id: 44831
Status: resolved
Priority: 0/
Queue: Math-Polynomial

People
Owner: hasch-cpan [...] cozap.com
Requestors: user42 [...] zip.com.au
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.04
Fixed in: 1.001



Subject: allow blessed constants in overloads (patch)
Date: Tue, 07 Apr 2009 07:36:45 +1000
To: bug-Math-Polynomial [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
It'd be good if Math::Polynomial allowed multiply etc by a constant which is not a plain number but instead some class like Math::BigRat. For example, use Math::Polynomial; use Math::BigRat; $p1 = Math::Polynomial->new (Math::BigRat->new('1/6'), 0); $p1 *= Math::BigRat->new('1/8'); print "$p1\n"; which currently gets an error Not an ARRAY reference at /usr/share/perl5/Math/Polynomial.pm line 345. where it'd be good to print (1/48 0) I think all it might need is for the overload funcs to check isa('Math::Polynomial') instead of assuming any ref() is a poly, perhaps per below (including swapping a multiply in interpolate() to hit the poly multiply instead of anything the coeff might have).

Message body is not shown because sender requested not to inline it.

Thanks for the suggestion. Arbitrary operand types (and a lot of other improvements) are addressed in Math::Polynomial 1.000, which is now very close to release. You do sound like a user who will appreciate the changes. -Martin
Subject: Re: [rt.cpan.org #44831] allow blessed constants in overloads (patch)
Date: Fri, 10 Apr 2009 11:27:15 +1000
To: bug-Math-Polynomial [...] rt.cpan.org
From: Kevin Ryde <user42 [...] zip.com.au>
"Martin Becker via RT" <bug-Math-Polynomial@rt.cpan.org> writes: Show quoted text
> > other improvements
One thing I wanted was an '==' operator to ask if two polys are equal, ie. identical coeffs, and to ask if equal to a constant, in particular asking if equal to 0.
On Mon Apr 06 17:38:34 2009, user42@zip.com.au wrote: Show quoted text
> It'd be good if Math::Polynomial allowed multiply etc by a constant > which is not a plain number but instead some class like Math::BigRat. > For example, > > use Math::Polynomial; > use Math::BigRat; > $p1 = Math::Polynomial->new (Math::BigRat->new('1/6'), 0); > $p1 *= Math::BigRat->new('1/8'); > print "$p1\n";
Math::Polynomial 1.001 is designed for use cases like this. Your example would look slightly different, though: use Math::Polynomial 1.001; use Math::BigRat; $p1 = Math::Polynomial->new( Math::BigRat->new('0'), Math::BigRat->new('1/6'), ); # or: $p1 = Math::Polynomial->monomial(1, Math::BigRat->new('1/6')); $p1->string_config({ fold_sign=>1 }); # print prettier $p1 *= Math::BigRat->new('1/8'); # or: $p1 = $p1->mul_const(Math::BigRat->new('1/8')); print "$p1\n"; # prints: (1/48 x) Note that you should not mix different coefficient types for new(), although you can do so in expressions once the coefficient space has been established: $p2 = $p1 * 2; print "$p2\n"; # prints: (1/24 x) Note, too, that the order of arguments for new has changed. Yours, -Martin
On Thu Apr 09 21:27:49 2009, user42@zip.com.au wrote: Show quoted text
> "Martin Becker via RT" <bug-Math-Polynomial@rt.cpan.org> writes:
> > > > other improvements
> > One thing I wanted was an '==' operator to ask if two polys are equal, > ie. identical coeffs, and to ask if equal to a constant, in particular > asking if equal to 0.
The '==' operator and the '!' operator will do this for you in Math::Polynomial 1.001. Yours, -Martin