integrate()

Discussion in 'Perl Misc' started by Dr.Ruud, Aug 28, 2006.

  1. Dr.Ruud

    Dr.Ruud Guest

    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/mathematica/book/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/mathematica/book/section-1.8.5
    http://www.physic.ut.ee/~kkannike/english/prog/mathematica/patterns/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."
     
    Dr.Ruud, Aug 28, 2006
    #1
    1. Advertising

  2. Dr.Ruud

    -berlin.de Guest

    Dr.Ruud <> 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
     
    -berlin.de, Aug 29, 2006
    #2
    1. Advertising

  3. Dr.Ruud

    Dr.Ruud Guest

    -berlin.de 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/archives/2005/05/mathsymbolic-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."
     
    Dr.Ruud, Aug 29, 2006
    #3
  4. Dr.Ruud

    Dr.Ruud Guest

    Dr.Ruud, Aug 29, 2006
    #4
  5. [A complimentary Cc of this posting was NOT [per weedlist] sent to
    Dr.Ruud
    <>], 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::pari=: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.
     
    Ilya Zakharevich, Aug 29, 2006
    #5
  6. Dr.Ruud

    Guest

    Ilya Zakharevich wrote:
    >
    > perl -MMath::pari=: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,354130435682904)"
     
    , Aug 29, 2006
    #6
  7. Dr.Ruud

    Dr.Ruud Guest

    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::pari=: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."
     
    Dr.Ruud, Aug 30, 2006
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Sarah E. Green

    Can you properly integrate PHP and Perl?

    Sarah E. Green, Aug 9, 2003, in forum: Perl
    Replies:
    1
    Views:
    2,826
    Nikolai Chuvakhin
    Aug 10, 2003
  2. Paul nevegue

    integrate two apps, Help!!!

    Paul nevegue, Oct 27, 2003, in forum: ASP .Net
    Replies:
    1
    Views:
    355
    Konrad Rotuski
    Oct 27, 2003
  3. P McGinness
    Replies:
    0
    Views:
    297
    P McGinness
    Jan 14, 2004
  4. =?Utf-8?B?QmVuamFtaW4=?=
    Replies:
    0
    Views:
    311
    =?Utf-8?B?QmVuamFtaW4=?=
    Feb 12, 2004
  5. Grey

    integrate with SSL Cert

    Grey, May 21, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    335
    Eliyahu Goldin
    May 21, 2004
Loading...

Share This Page