Skip Menu |

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

Report information
The Basics
Id: 27301
Status: resolved
Priority: 0/
Queue: Math-Symbolic

People
Owner: Nobody in particular
Requestors: JMASTROS [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Normal
Broken in: 0.507
Fixed in: (no value)



Subject: Simplifying sums inserts a 0 constant term
Before this patch, if there is no constant term when simplifying, or if the constant term is zero, Math::Symbolic will insert a zero constant term. # Before perl -Ilib -MMath::Symbolic -le'print Math::Symbolic->parse_from_string("x+x^2")->simplify' (0 + x) + (x ^ 2) The patch will suppress the constant term if it would be zero. # After perl -Ilib -MMath::Symbolic -le'print Math::Symbolic->parse_from_string("x+x^2")->simplify' x + (x ^ 2) # After, unexpectedly. perl -Ilib -MMath::Symbolic -le'print Math::Symbolic->parse_from_string("x+x^2+3-3")->simplify' (3 + (x + (x ^ 2))) - 3 I'm afraid I just discovered the second one, and this patch doesn't include a test case (for either). I'm a bit busy at present, and wanted to get this out while I had a moment -- I'll reply with more if I fix either of those issues. (PS - double-simplifying the "unexpectedly" case *does* give the wanted result.)
Subject: math-symbolic-simplify.diff
--- lib/Math/Symbolic/Operator.pm.orig 2007-05-26 00:48:17.000000000 +0100 +++ lib/Math/Symbolic/Operator.pm 2007-05-26 01:08:37.000000000 +0100 @@ -814,11 +814,11 @@ : $mul; } - my $const = 0; + my $const; $const += $_ foreach @const; - $const = Math::Symbolic::Constant->new($const) if $const != 0; + $const = Math::Symbolic::Constant->new($const) if defined $const and $const != 0; - $const = shift @vars if not defined $const; + $const = shift @vars if not defined $const; foreach ( @vars ) { $const = Math::Symbolic::Operator->new('+', $const, $_); }
Hi James, thank you for your bug report and patch. Sorry I didn't address it earlier. I didn't have access to my development machine. On Sat May 26 05:20:42 2007, JMASTROS wrote: Show quoted text
> Before this patch, if there is no constant term when simplifying, or if > the constant term is zero, Math::Symbolic will insert a zero constant
term. Show quoted text
> > # Before > perl -Ilib -MMath::Symbolic -le'print > Math::Symbolic->parse_from_string("x+x^2")->simplify' > (0 + x) + (x ^ 2) > > The patch will suppress the constant term if it would be zero. > > # After > perl -Ilib -MMath::Symbolic -le'print > Math::Symbolic->parse_from_string("x+x^2")->simplify' > x + (x ^ 2)
Great! I had somewhen observed this odd behaviour but did not have the time to track down the problem. I applied the patch to the svn trunk. Show quoted text
> # After, unexpectedly. > perl -Ilib -MMath::Symbolic -le'print > Math::Symbolic->parse_from_string("x+x^2+3-3")->simplify' > (3 + (x + (x ^ 2))) - 3 > > I'm afraid I just discovered the second one, and this patch doesn't > include a test case (for either). I'm a bit busy at present, and wanted > to get this out while I had a moment -- I'll reply with more if I fix > either of those issues.
I wrote a simple test, that's easy enough. While at coding, I did some very minor improvements to the simplification routine and fixed the second bug. (And added more tests...) I'll make a release with these changes now. Thanks again! Cheers, Steffen