Re: How to work with principal value when a definite integral?

140 views
Skip to first unread message

kcrisman

unread,
Sep 17, 2012, 1:24:32 PM9/17/12
to sage-...@googlegroups.com


On Monday, September 17, 2012 7:45:17 AM UTC-4, Mizuchi wrote:
Hello, all:

In symbolic integration document, there is an example::

    sage: integrate(1/x^3,x,-1,3)
    Traceback (most recent call last):
    ...
    ValueError: Integral is divergent.

However, in maxima, it returns:

    (%i1) integrate(1/x^3,x,-1,3);                  
    Principal Value
                        4
    (%o1)               -
                        9

Sometimes we only care about the cauchy principal value. How to get it from sage?


Hmm, I thought we had a ticket for accessing this.  And the thing that should work

sage: f = 1/x^3
sage: g = f.maxima_methods()
sage: g.integrate(x,-1,3)

yields the same error. 

Note that http://trac.sagemath.org/sage_trac/attachment/ticket/11987/trac_11987-principal-value.patch is also related, though I don't think that we want  Sage to automatically calculate this for divergent integrals.


maxima version: 5.28.0
sage version: 5.2

Regards,
Mizuchi

Nils Bruin

unread,
Sep 17, 2012, 2:14:19 PM9/17/12
to sage-devel
On Sep 17, 4:45 am, Mizuchi <ytj...@gmail.com> wrote:
> Sometimes we only care about the cauchy principal value. How to get it from sage?

You could just use the definition:

sage: var('x,e')
(x, e)
sage: assume(e>0,e<1); integrate(1/x^3,x,-1,-e)+integrate(1/x^3,x,e,3)
4/9

In maxima_lib this line:

ecl_eval('(defun principal nil (cond ($noprincipal (diverg)) ((not
pcprntd) (merror "Divergent Integral"))))')

is responsible for installing code that throws an error rather than
print a warning. We changed it at some point because internally maxima
needs principal values to evaluate certain integrals (it has by then
ensured it's safe to do so). So if you want write a routine that gives
access to principal values this way, you'd have to create the right
cirmumstances (I guess make sure that $noprincipal is nil and pcprntd
is T. That's how maxima fakes the code into computing a principal
value without printing a warning at some point).

See

http://trac.sagemath.org/sage_trac/ticket/11987

for details. If you do write a wrapped integration routine, make sure
to only change the value of pcprntd locally, i.e.,

(let ((pcprntd t)) (integrate ...))

and double check that evaluating a divergent integral afterwards gives
a warning again

Mizuchi

unread,
Sep 20, 2012, 12:58:15 AM9/20/12
to sage-...@googlegroups.com
Hi, Nils:

Thanks for reply. IMHO, for many physical problems, we  just want to know principal value. As you mentioned, we can use other definition to void this issue. However, for more complicated formula, it is hard find the healthy definition. I think it could be better if either (1) sage provide a parameter for integrate that whether accept the principal value, (2) or at least print a warning instead throw an exception.

Currently I have to use maxima directly to deal with integral, though maxima is a good tool, I just not famillar with.

Regards,
Mizuchi


在 2012年9月18日星期二UTC+7:59.583333333333314上午2时13分56秒,Nils Bruin写道:

kcrisman

unread,
Sep 20, 2012, 8:18:23 AM9/20/12
to sage-...@googlegroups.com


On Thursday, September 20, 2012 12:58:15 AM UTC-4, Mizuchi wrote:
Hi, Nils:

Thanks for reply. IMHO, for many physical problems, we  just want to know principal value. As you mentioned, we can use other definition to void this issue. However, for more complicated formula, it is hard find the healthy definition. I think it could be better if either (1) sage provide a parameter for integrate that whether accept the principal value, (2) or at least print a warning instead throw an exception.

Currently I have to use maxima directly to deal with integral, though maxima is a good tool, I just not famillar with.

Regards,


I've made http://trac.sagemath.org/sage_trac/ticket/13511 to track this enhancement request.  I'm not sure what the "right" solution is, though.

Nils Bruin

unread,
Sep 20, 2012, 8:25:22 PM9/20/12
to sage-devel
On Sep 19, 9:58 pm, Mizuchi <ytj...@gmail.com> wrote:
> I think it could be better if either (1) sage provide a
> parameter for integrate that whether accept the principal value, (2) or at
> least print a warning instead throw an exception.

Well here's a way that voids your warranty (which you didn't have
anyway):

sage: integrate(x,x) #ensure maxima is initialized
1/2*x^2
sage: sage.libs.ecl.ecl_eval('(defun principal nil t)')
<ECL: PRINCIPAL>
sage: integrate(1/x^3,x,-1,3)
4/9
sage: sage.libs.ecl.ecl_eval('(defun principal nil (cond ($noprincipal
(diverg)) ((not pcprntd) (merror "Divergent Integral"))))')
<ECL: PRINCIPAL>

Everything should be back to normal after this, but this is obviously
not the way in which we'd put this in the library.
Reply all
Reply to author
Forward
0 new messages