Perl - maths equation - need help

if input to the perl program is ' ( p * ((a+b) * (c+d))) + q ' it shuld give the output as ' pac + pad + pbc + pbd + q ' .can anyone suggest a way to do this ?

Perl doesn't support that out-of-the-box, but maybe this can help you: Math::Symbolic - Symbolic calculations - search.cpan.org (First & Third result when searching for "perl symbolic math")

Thanks Pludi for replying...But it didn help.Can anyone suggest a metho may b by pattern matching or something

If it were for just that one specific pattern it would be possible, but I suspect the user input can be any number of varying combinations of math expressions, in which case trying to convert them to some other format needs a much more thought out approach.

actually, a lexicographical parser is required. then, some sort of commonizing engine.

i'll build it for a fee. :slight_smile:

I don't think its "required" if the input can be limited to something reasonable. Not that I would want to try and code such a parser myself even for a limited set of equations.

Of course a lexicographical parser would be a great solution if money and time were no problem. :wink:

As others noted - this has the potential to be hellishly complex.
you could write a simple perl frontend to pari using one of it's interfaces, if you have to use perl. Pari interprets algebraic statements and then can work with them.

http://clisp.sourceforge.net/impnotes/pari.html

Ya u got it rite.Its not just for one pattern.The user input can be any number of variying combinations of math expressions.