Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Perl > Perl Misc > integrate()

Reply
Thread Tools

integrate()

 
 
Dr.Ruud
Guest
Posts: n/a
 
      08-28-2006
I found this interesting example on comp.lang.misc
<news:44f24874$0$3585$>
that I think would be nice to translate to Perl.


> The following Mathematica code implements polynomial integration
> using only Mathematica's pattern matcher and the FreeQ[e, f] function
> (which checks that the pattern "f" does not match any subexpression
> of "e"):
>
> integrate[y_ + z_ , x_] := integrate[y, x] + integrate[z, x]
> integrate[c_ y_ , x_] := c integrate[y, x] /; FreeQ[c, x]
> integrate[c_ , x_] := c x /; FreeQ[c, x]
> integrate[x_^n_. , x_] := x^(n + 1)/(n + 1) /; FreeQ[n, x] && n != -1
>
> For example:
>
> integrate[3 a x^2 + 2 b x + c, x]
> => c x + b x^2 + a x^3


That seems to come from
http://documents.wolfram.com/mathema...section-2.3.14
which also mentions:

integrate[ 1/(a_. x_ + b_.), x_] := Log[a x + b]/a /; FreeQ[{a,b}, x]
integrate[Exp[a_. x_ + b_.], x_] := Exp[a x + b]/a /; FreeQ[{a,b}, x]


I assumed that somebody would have done something in this area already
(without calling Mathematica), so I checked CPAN, but I found nothing
for polynomial integration, so I probably just didn't look well enough,
did I?


Note that you can write the (trivial) example as

['c', '2 b', '3 a'] --> ['', 'c', 'b', 'a']

A variant:

['c', 'b', 'a'] --> ['', 'c', 'b / 2', 'a / 3']


See also google: mathematica FreeQ.
http://documents.wolfram.com/mathema.../section-1.8.5
http://www.physic.ut.ee/~kkannike/en...rns/index.html

Legenda:
"^n." : the trailing "." means optional. If absent, than 1 is used.
Perlish: /(\d+)/ ? $1 : 1
"/;" : constraint follows.
Perlish: if ...


Solution-1: s/.*/c x + b x^2 + a x^3/


--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
 
 
 
anno4000@radom.zrz.tu-berlin.de
Guest
Posts: n/a
 
      08-29-2006
Dr.Ruud <rvtol+> wrote in comp.lang.perl.misc:
> I found this interesting example on comp.lang.misc
> <news:44f24874$0$3585$>
> that I think would be nice to translate to Perl.
>
>
> > The following Mathematica code implements polynomial integration


[...]

> I assumed that somebody would have done something in this area already
> (without calling Mathematica), so I checked CPAN, but I found nothing
> for polynomial integration, so I probably just didn't look well enough,
> did I?


There's a huge family of modules Math::Symbolic::*. I'm sure there
is something...

Anno
 
Reply With Quote
 
 
 
 
Dr.Ruud
Guest
Posts: n/a
 
      08-29-2006
schreef:
> Dr.Ruud:


>> I found this interesting example on comp.lang.misc
>> <news:44f24874$0$3585$>
>> that I think would be nice to translate to Perl.
>> [...]
>> I assumed that somebody would have done something in this area
>> already (without calling Mathematica), so I checked CPAN, but I
>> found nothing for polynomial integration, so I probably just didn't
>> look well enough, did I?

>
> There's a huge family of modules Math::Symbolic::*. I'm sure there
> is something...


I searched again (like on "integration" and on "integral")
and found only
Math::Integral::Romberg - scalar numerical integration
but that is a different area. <g>

See also
http://www.tangentspace.net/cz/archi...mbolic-modules


Math::Integral is i:
http://search.cpan.org/~aqumsieh/


These have 9000 hits:
google: perl "symbolic integration"
google: perl risch integral OR integration

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      08-29-2006
[symbolic integration]

This is also interesting:

http://maxima.sourceforge.net/ (Lisp)
http://symaxx.sourceforge.net/ (Perl)

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
Ilya Zakharevich
Guest
Posts: n/a
 
      08-29-2006
[A complimentary Cc of this posting was NOT [per weedlist] sent to
Dr.Ruud
<rvtol+>], who wrote in article <>:
> > There's a huge family of modules Math::Symbolic::*. I'm sure there
> > is something...

>
> I searched again (like on "integration" and on "integral")
> and found only
> Math::Integral::Romberg - scalar numerical integration
> but that is a different area. <g>


perl -MMath:ari=:all -wle "$x = PARIvar q(x); print $p = ($x**7 - 1)/($x - 1); print intformal $p"
x^6+x^5+x^4+x^3+x^2+x+1
1/7*x^7+1/6*x^6+1/5*x^5+1/4*x^4+1/3*x^3+1/2*x^2+x

Hope this helps,
Ilya

P.S. This is with PARI 2.3.0; older version might have this function
named differently; check the docs.
 
Reply With Quote
 
jl_post@hotmail.com
Guest
Posts: n/a
 
      08-29-2006
Ilya Zakharevich wrote:
>
> perl -MMath:ari=:all -wle "$x = PARIvar q(x); print $p = ($x**7 - 1)/($x - 1); print intformal $p"
> x^6+x^5+x^4+x^3+x^2+x+1
> 1/7*x^7+1/6*x^6+1/5*x^5+1/4*x^4+1/3*x^3+1/2*x^2+x
>
> Hope this helps,
> Ilya



Thanks, Ilya! I've been looking for something like this for a long
time.

And I'm happy to see that this module is even available on Win32
ActiveState Perl! (All that was needed to install it was the command
"ppm install Math-Pari".)

Thanks again.

-- Jean-Luc

--
perl -le "print(pack'B*','0'.unpack'B*',pack'w*',
5592691776,37562575106519616,25926642752,354130435 682904)"

 
Reply With Quote
 
Dr.Ruud
Guest
Posts: n/a
 
      08-30-2006
Ilya Zakharevich schreef:
> Dr.Ruud:


>> I searched again (like on "integration" and on "integral")
>> and found only
>> Math::Integral::Romberg - scalar numerical integration
>> but that is a different area. <g>

>
> perl -MMath:ari=:all -wle "
> $x = PARIvar q(x);
> print $p = ($x**7 - 1)/($x - 1);
> print intformal $p
> "
> x^6+x^5+x^4+x^3+x^2+x+1
> 1/7*x^7+1/6*x^6+1/5*x^5+1/4*x^4+1/3*x^3+1/2*x^2+x
>
> P.S. This is with PARI 2.3.0; older version might have this function
> named differently; check the docs.


Yes, very nice example indeed.

I should have searched for "integrals".

--
Affijn, Ruud

"Gewoon is een tijger."


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off




Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57