Skip Menu |

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

Report information
The Basics
Id: 114363
Status: open
Priority: 0/
Queue: Math-Algebra-Symbols

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

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



Subject: Infinite loop with negative powers
Considering the following code: #==BEGIN-CODE==# use Math::Algebra::Symbols; my $x = symbols("3"); my $y = symbols("-4"); print $x**$y; #==END-CODE==# Math::Algebra::Symbols gets stuck in an infinite loop and eats all the available system memory.
Subject: Re: [rt.cpan.org #114363] Infinite loop with negative powers
Date: Fri, 13 May 2016 18:33:49 +0100
To: bug-Math-Algebra-Symbols [...] rt.cpan.org
From: Philip R Brenan <philiprbrenan [...] gmail.com>
Hi Trinzen: Thank you for your excellent bug report. Please try: my ($x) = symbols(qw(x)); print 1/$x**4; print $x**-4; Please remember we are doing symbolic algebra here not numeric computation. To actually evaluate a specific expression I believe you can do something like: my $y = 1/$x**4; print $y->evaluate(x=>3); I.e first create the desired symbolic expression and then evaluate it for a specific value of x. You might find find that *say* is easier to use than *print*. Please let me know if I can help you further? Thanks, Phil <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> Philip R Brenan <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> On Fri, May 13, 2016 at 6:25 PM, Trizen Daniel via RT < bug-Math-Algebra-Symbols@rt.cpan.org> wrote: Show quoted text
> Fri May 13 13:25:33 2016: Request 114363 was acted upon. > Transaction: Ticket created by TRIZEN > Queue: Math-Algebra-Symbols > Subject: Infinite loop with negative powers > Broken in: (no value) > Severity: (no value) > Owner: Nobody > Requestors: TRIZEN@cpan.org > Status: new > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=114363 > > > > Considering the following code: > > #==BEGIN-CODE==# > > use Math::Algebra::Symbols; > > my $x = symbols("3"); > my $y = symbols("-4"); > > print $x**$y; > > #==END-CODE==# > > Math::Algebra::Symbols gets stuck in an infinite loop and eats all the > available system memory. >
On Fri May 13 13:34:18 2016, philiprbrenan@gmail.com wrote: Show quoted text
> Hi Trinzen: > > Thank you for your excellent bug report. Please try: > > my ($x) = symbols(qw(x)); > > print 1/$x**4; > > print $x**-4; > > Please remember we are doing symbolic algebra here not numeric > computation. To actually evaluate a specific expression I believe you can > do something like: > > my $y = 1/$x**4; > > print $y->evaluate(x=>3); > > I.e first create the desired symbolic expression and then evaluate it for a > specific value of x. > > You might find find that *say* is easier to use than *print*. > > Please let me know if I can help you further? > > > Thanks, > > Phil <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> > > Philip R Brenan <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> > > On Fri, May 13, 2016 at 6:25 PM, Trizen Daniel via RT < > bug-Math-Algebra-Symbols@rt.cpan.org> wrote: >
> > Fri May 13 13:25:33 2016: Request 114363 was acted upon. > > Transaction: Ticket created by TRIZEN > > Queue: Math-Algebra-Symbols > > Subject: Infinite loop with negative powers > > Broken in: (no value) > > Severity: (no value) > > Owner: Nobody > > Requestors: TRIZEN@cpan.org > > Status: new > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=114363 > > > > > > > Considering the following code: > > > > #==BEGIN-CODE==# > > > > use Math::Algebra::Symbols; > > > > my $x = symbols("3"); > > my $y = symbols("-4"); > > > > print $x**$y; > > > > #==END-CODE==# > > > > Math::Algebra::Symbols gets stuck in an infinite loop and eats all the > > available system memory. > >
Thanks for your quick reply. To be safe, I ended up using "exp(log(x) * y)" to mean "x**y", but I think this is a bug that can be easily fixed, by checking the sign of "y" before performing the actual computation. I found this bug during the creation and testing of the Math::BigSym module, which is a wrapper around Math::GMPq and Math::Algebra::Symbols. However, using logarithms with Math::Algebra::Symbols seems to be quite dangerous, as there is no support for multiplication of logarithms. Or is this something that is planed to be added somewhere in the near future? That would be very awesome. Thank you very much.
Subject: Re: [rt.cpan.org #114363] Infinite loop with negative powers
Date: Fri, 13 May 2016 19:13:38 +0100
To: bug-Math-Algebra-Symbols [...] rt.cpan.org
From: Philip R Brenan <philiprbrenan [...] gmail.com>
Math::BigSym looks very interesting - I will have to spend some time looking at it so I can fully appreciate what you are doing. You are right that there is no support for multiplication of logarithms as yet in Math::Algebra::Symbols - I will add it to the to-do list. I would urge that if x and y are known numerically in $x**$y that you use the numeric capabilities of Math::GMPq or BigRat or similar. Math::Algebra::Symbols (MAS) comes into play when you have an expression like: *$x**4/$x**2 *which it will simplify to* $x**2* which can then be evaluated much more reliably - or better yet fed into other symbolic expressions. As an extreme example, MAS will agree that cos² 𝝷 + sin² 𝝷 == 1, whereas if you do this sort of thing numerically you tend to get things like 1+1e-63 == 1 which is uncertain - hence the value of symbolic computation in simplifying things before they are evaluated numerically. Please let me know if you have any other questions - your project looks to be a very interesting one and I will be happy to provide some help if that would be useful to you. Thanks, Phil <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> Philip R Brenan <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> On Fri, May 13, 2016 at 6:51 PM, Trizen Daniel via RT < bug-Math-Algebra-Symbols@rt.cpan.org> wrote: Show quoted text
> Queue: Math-Algebra-Symbols > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=114363 > > > On Fri May 13 13:34:18 2016, philiprbrenan@gmail.com wrote:
> > Hi Trinzen: > > > > Thank you for your excellent bug report. Please try: > > > > my ($x) = symbols(qw(x)); > > > > print 1/$x**4; > > > > print $x**-4; > > > > Please remember we are doing symbolic algebra here not numeric > > computation. To actually evaluate a specific expression I believe you
> can
> > do something like: > > > > my $y = 1/$x**4; > > > > print $y->evaluate(x=>3); > > > > I.e first create the desired symbolic expression and then evaluate it
> for a
> > specific value of x. > > > > You might find find that *say* is easier to use than *print*. > > > > Please let me know if I can help you further? > > > > > > Thanks, > > > > Phil <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> > > > > Philip R Brenan <http://www.appaapps.com/cgi-bin/DashBoard/allStarts.pl> > > > > On Fri, May 13, 2016 at 6:25 PM, Trizen Daniel via RT < > > bug-Math-Algebra-Symbols@rt.cpan.org> wrote: > >
> > > Fri May 13 13:25:33 2016: Request 114363 was acted upon. > > > Transaction: Ticket created by TRIZEN > > > Queue: Math-Algebra-Symbols > > > Subject: Infinite loop with negative powers > > > Broken in: (no value) > > > Severity: (no value) > > > Owner: Nobody > > > Requestors: TRIZEN@cpan.org > > > Status: new > > > Ticket <URL: https://rt.cpan.org/Ticket/Display.html?id=114363 > > > > > > > > > > Considering the following code: > > > > > > #==BEGIN-CODE==# > > > > > > use Math::Algebra::Symbols; > > > > > > my $x = symbols("3"); > > > my $y = symbols("-4"); > > > > > > print $x**$y; > > > > > > #==END-CODE==# > > > > > > Math::Algebra::Symbols gets stuck in an infinite loop and eats all the > > > available system memory. > > >
> > > Thanks for your quick reply. > > To be safe, I ended up using "exp(log(x) * y)" to mean "x**y", but I think > this is a bug that can be easily fixed, by checking the sign of "y" before > performing the actual computation. > > I found this bug during the creation and testing of the Math::BigSym > module, which is a wrapper around Math::GMPq and Math::Algebra::Symbols. > > However, using logarithms with Math::Algebra::Symbols seems to be quite > dangerous, as there is no support for multiplication of logarithms. Or is > this something that is planed to be added somewhere in the near future? > That would be very awesome. > > Thank you very much. >