Re: [PEPr] Comment on Math::Math_Polynomial (Re-proposal)

From: Date: Mon, 19 Dec 2005 15:51:57 +0000
Subject: Re: [PEPr] Comment on Math::Math_Polynomial (Re-proposal)
Groups: php.pear.dev 
Request: Send a blank email to pear-dev+get-40794@lists.php.net to get a copy of this message
With regard to the a^x bit: It might be nice to have a method which takes a string expression and either converts it to either valid PHP code or creates a lambda-style function from it with www.php.net/create_function(). I have a Math_PolynomialOp::createFunction() method which takes the polynomial string like this: ax^2 + bx + c and uses create_function() to create a function taking an x parameter. So you could to this: $my_func = Math_PolynomialOp::createFunction("ax^2 + bx + c"); print("That Polynomial evaluated at 2 is: " . $my_func(2) . "\n"); I have an evaluate() method as well which does exactly what you indicated your evaluate() method would do. - Keith Etienne Kneuss wrote .. > The code is mostly finished: > > > http://www.colder.ch/repository/php/Math_Derivative/Math_Derivative.php > > > > >Etienne: What did you have in mind for an API? > >Parameter/return value is a string? Parameter is some new type/generic > Math_Equation object? > > > > > > > > I was thinking about parameter/return value as strings. > > There are two main issues: > 1) lack of simplification > My workaround: I've no magic method to simplify the results. A > complete simplify method would be a enormous work and I can't afford it. > Some simple simplification rules could be implemented though. > > 2) my package interprets "a^2" as "a*a" as its the most common way to > express powers. But this is not the expected result when using php's > evaluator (bitwise XOR operator). > So: Its worthless trying to evaluate results that contains "^" > using php's eval(). > My workaround: implementing an eval method that internally evaluates > powers before using eval() [not implemented yet] > > -- > Etienne Kneuss > > http://www.colder.ch/ > colder@php.net > > -- > PEAR Development Mailing List (http://pear.php.net/) > To unsubscribe, visit: http://www.php.net/unsub.php

« previous php.pear.dev (#40794) next »