The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Serious bug in integral using Maxima?
 There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic. There was an error processing your request. Please try again. Standard view   View as tree
 20 messages

From:
To:
Cc:
Followup To:
Subject:
 Validation: For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon.

More options Aug 18 2009, 6:51 am
From: Golam Mortuza Hossain <gmhoss...@gmail.com>
Date: Tue, 18 Aug 2009 07:51:52 -0300
Local: Tues, Aug 18 2009 6:51 am
Subject: Serious bug in integral using Maxima?
Hi,

While testing new integral SFunction class for Sage,
I encountered this weird bug.

----------
sage: f(x) = function('f',x)

sage: f(x).integral(x)
integrate(f(x), x)

sage: f(x).integral(x^2)
x^2*f(x)
-----------

It appears to be a Maxima bug
----------
(%i10) integrate(f(x), x^2);
2
(%o10)                              x  f(x)
----------

However, even "integral" of calculus.py seems to do crazy thing as well.
In line 566, it does

elif not is_SymbolicVariable(v):
v = var(repr(v))

Above imply

--------
sage: v = var(repr(x^2))
sage: v
x^2
sage: v.diff(x)
0
-------

The next commented out line in calculus.py seems to be the right
thing do here!!

Cheers,
Golam

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 18 2009, 7:42 pm
From: rjf <fate...@gmail.com>
Date: Tue, 18 Aug 2009 16:42:21 -0700 (PDT)
Local: Tues, Aug 18 2009 7:42 pm
Subject: Re: Serious bug in integral using Maxima?
did you mean to integrate with respect to "x^2" ?

Well, x^2 doesn't occur in   f(x).  So let's rename x^2 as y.
What is the integral of f(x) with respect to y?

It is y*f(x).

substituting back x^2 for y,  you get x^2*f(x).

Or did you mean something else? Certainly Maxima expects "the variable
of integration" as
the second argument.  Anything else is asking for trouble.

On Aug 18, 3:51 am, Golam Mortuza Hossain <gmhoss...@gmail.com> wrote:

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 18 2009, 8:27 pm
From: William Stein <wst...@gmail.com>
Date: Tue, 18 Aug 2009 17:27:32 -0700
Local: Tues, Aug 18 2009 8:27 pm
Subject: Re: [sage-devel] Serious bug in integral using Maxima?
On Tue, Aug 18, 2009 at 3:51 AM, Golam Mortuza

Indeed, what does that mean?  If forced to, I would interpret this as

int f(x) d(x^2)  = int f(x) 2 x dx
= 2x integrate(f(x),x)

So I think the Sage/Maxima answer of x^2*f(x) is bizarre.

Matheamatica just considers this input to be invalid:

sage: mathematica.eval('Integrate[f[x],x^2]')

2
Integrate::ilim: Invalid integration variable or limit(s) in x .

2
Integrate[f[x], x ]

Unless you can give a explanation of what you want integrating wrt x^2
to mean, I think we should also raise an error in Sage.

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 18 2009, 9:48 pm
From: Golam Mortuza Hossain <gmhoss...@gmail.com>
Date: Tue, 18 Aug 2009 22:48:19 -0300
Local: Tues, Aug 18 2009 9:48 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?
Hi,

On Tue, Aug 18, 2009 at 8:42 PM, rjf<fate...@gmail.com> wrote:

> did you mean to integrate with respect to "x^2" ?

Yes.

> Well, x^2 doesn't occur in   f(x).  So let's rename x^2 as y.
> What is the integral of f(x) with respect to y?

> It is y*f(x).

> substituting back x^2 for y,  you get x^2*f(x).

Are you saying during integration maxima is not aware
that "x^2" is the square of "x"?

Take following examples:
----------
(%i4) integrate(log(x), x);
(%o4)                            x log(x) - x

(%i5) integrate(log(x^2), x^2);
2
(%o5)                             2 x  log(x)
----------

"log" is certainly aware of it.

> Certainly Maxima expects "the variable of integration" as
> the second argument.  Anything else is asking for trouble.

Then maxima should throw error instead of giving a wrong
answer silently. This is rather bizarre given maxima is known
to be over-cautious during integration and sometime
it asks too many questions, even something like
--------
(%i6) integrate(1/x, x, 0, 1);
Is  x + 1  positive, negative, or zero?
--------

Cheers,
Golam

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 18 2009, 9:55 pm
From: Golam Mortuza Hossain <gmhoss...@gmail.com>
Date: Tue, 18 Aug 2009 22:55:29 -0300
Local: Tues, Aug 18 2009 9:55 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?
Hi,

I tried that input out of curiosity during testing. I was expecting

I agree, we should raise an error. Ironically,  in "calculus.py" the raise
error line (556) has been commented out for some reason.
-----------
elif not is_SymbolicVariable(v):
v = var(repr(v))
#raise TypeError, 'must integrate with respect to a variable'
---------

Cheers,
Golam

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 18 2009, 11:37 pm
Date: Tue, 18 Aug 2009 20:37:59 -0700
Local: Tues, Aug 18 2009 11:37 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?
On Aug 18, 2009, at 6:55 PM, Golam Mortuza Hossain wrote:

Probably var(repr(var)) is the wrong thing to do here... I have a
feeling I've seen this code before.

- Robert

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 1:40 am
From: rjf <fate...@gmail.com>
Date: Tue, 18 Aug 2009 22:40:33 -0700 (PDT)
Local: Wed, Aug 19 2009 1:40 am
Subject: Re: Serious bug in integral using Maxima?
Can you anticipate all the possible ways of misusing a command, and
catch them all
with a suitable error message?  I think that's pretty hard with a
system that has essentially
free-form input of any length, attached to fairly vague semantics
(like --- let's see what
Maxima does with this ---).

RJF

On Aug 18, 8:37 pm, Robert Bradshaw <rober...@math.washington.edu>
wrote:

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 1:57 am
From: rjf <fate...@gmail.com>
Date: Tue, 18 Aug 2009 22:57:58 -0700 (PDT)
Local: Wed, Aug 19 2009 1:57 am
Subject: Re: Serious bug in integral using Maxima?

On Aug 18, 6:48 pm, Golam Mortuza Hossain <gmhoss...@gmail.com> wrote:

> Hi,

> On Tue, Aug 18, 2009 at 8:42 PM, rjf<fate...@gmail.com> wrote:

> > did you mean to integrate with respect to "x^2" ?

> Yes.

Well then, since you meant to do that,  what response would you
consider correct?
An error message, or William's  interpretation of d(x^2)   as 2xdx?
or something else?

> > Well, x^2 doesn't occur in   f(x).  So let's rename x^2 as y.
> > What is the integral of f(x) with respect to y?

> > It is y*f(x).

> > substituting back x^2 for y,  you get x^2*f(x).

> Are you saying during integration maxima is not aware
> that "x^2" is the square of "x"?

Right, because your "variable of integration" is not in the integrand.
If I search for x^2  in f(x), I get no matches.

> Take following examples:
> ----------
> (%i4) integrate(log(x), x);
> (%o4)                            x log(x) - x

This is a correct usage, and the answer is correct.

> (%i5) integrate(log(x^2), x^2);
>                                      2
> (%o5)                             2 x  log(x)
> ----------

> "log" is certainly aware of it.

This is an incorrect usage.  Following the recipe I gave above, I
think that
Maxima first of all simplified log(x^2)  to 2*log(x). The integrand
does not
contain any x^2. y.  Then the
problem is  integrate(2*log(x),y).  Which is 2*y*log(x).  Now
substitute x^2 for y.

> > Certainly Maxima expects "the variable of integration" as
> > the second argument.  Anything else is asking for trouble.

> Then maxima should throw error instead of giving a wrong

Maybe. or maybe it should return the integral unevaluated.  or maybe
it
should try to compute the differential.

> This is rather bizarre given maxima is known
> to be over-cautious during integration and sometime
> it asks too many questions, even something like
> --------
> (%i6) integrate(1/x, x, 0, 1);
> Is  x + 1  positive, negative, or zero?

When Maxima asks questions,  it is not being cautious..
As it happens, it sometimes asks questions when it could deduce the
This is a deficiency in the deduction system, not integration.
You are probably using an outdated Maxima, since the current one
does not ask questions, but just says the integral is divergent.

You could try integrate(1/x,x,a,b)   and then it asks questions to try
to
determine if a<=0<=b.

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 2:00 am
From: Ondrej Certik <ond...@certik.cz>
Date: Tue, 18 Aug 2009 23:00:20 -0700
Local: Wed, Aug 19 2009 2:00 am
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?

well, I would interpret it differently:

int f(x) d(x^2)  = int f(x) 2 x dx
= 2 integrate(x*f(x),x)

in sympy we just raise an exception:

In [1]: integrate(sin(x), x)
Out[1]: -cos(x)

In [2]: integrate(sin(x), x**2)
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)

/home/ondrej/repos/sympy/<ipython console> in <module>()

/home/ondrej/repos/sympy/sympy/utilities/decorator.pyc in
54                     return Add(*[ func(f, *args, **kwargs) for
f in expr.args ])
55                 else:
---> 56                     return func(expr, *args, **kwargs)
57

/home/ondrej/repos/sympy/sympy/integrals/integrals.pyc in
integrate(*args, **kwargs)
480     """
481     new_args = [sympify(arg) for arg in args]
--> 482     integral = Integral(*new_args, **kwargs)
483
484     if isinstance(integral, Integral):

/home/ondrej/repos/sympy/sympy/integrals/integrals.pyc in __new__(cls,
function, *symbols, **assumptions)
46                             continue
47
---> 48                 raise ValueError("Invalid integration variable
or limits: %s" % str(symbols))
49         else:
50             # no symbols provided -- let's compute full antiderivative

ValueError: Invalid integration variable or limits: (x**2,)

Ondrej

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 2:17 am
From: Robert Dodier <robert.dod...@gmail.com>
Date: Tue, 18 Aug 2009 23:17:47 -0700 (PDT)
Local: Wed, Aug 19 2009 2:17 am
Subject: Re: [sage-devel] Serious bug in integral using Maxima?

William Stein wrote:
> Unless you can give a explanation of what you want integrating wrt x^2
> to mean, I think we should also raise an error in Sage.

That would be unfortunate. Faced with some unrecognized construct,
the mathematical thing to do is to just leave it be. Whether it's
meaningful is for the user to decide. You don't know what
integrate(f(x), g(x)) means. Why not let someone else come
up with an interpretation? Why must you close that door?

Incidentally, integrate(f(x), g(x)) = integrate(f(g^(-1)(y)), y), when
g^(-1) is well defined, seems plausible. I'm not saying Sage should
apply such an identity, only that Sage should not prevent the user
from applying it.

I agree that Maxima's result for integrate(f(x), x^2) is spurious.

FWIW

Robert Dodier

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 2:34 am
From: Ondrej Certik <ond...@certik.cz>
Date: Tue, 18 Aug 2009 23:34:17 -0700
Local: Wed, Aug 19 2009 2:34 am
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?

On Tue, Aug 18, 2009 at 11:17 PM, Robert Dodier<robert.dod...@gmail.com> wrote:

> William Stein wrote:

>> Unless you can give a explanation of what you want integrating wrt x^2
>> to mean, I think we should also raise an error in Sage.

> That would be unfortunate. Faced with some unrecognized construct,
> the mathematical thing to do is to just leave it be. Whether it's
> meaningful is for the user to decide. You don't know what
> integrate(f(x), g(x)) means. Why not let someone else come
> up with an interpretation? Why must you close that door?

Is there any other interpretation besides:

int f(x)  d g(x)  = int f(x) * dg/dx    dx

? Example used in physics:

int P(cos(x)) sin(x) dx = int P(cos(x)) dcos(x)

where P is a Legendre polynomial.

Ondrej

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 4:38 am
From: Simon King <simon.k...@nuigalway.ie>
Date: Wed, 19 Aug 2009 01:38:45 -0700 (PDT)
Local: Wed, Aug 19 2009 4:38 am
Subject: Re: Serious bug in integral using Maxima?

On 19 Aug., 08:34, Ondrej Certik <ond...@certik.cz> wrote:
...

> Is there any other interpretation besides:

> int f(x)  d g(x)  = int f(x) * dg/dx    dx

> ? Example used in physics:

> int P(cos(x)) sin(x) dx = int P(cos(x)) dcos(x)

> where P is a Legendre polynomial.

Indeed this seems like a natural interpretation, and it would be
convenient (at least for physicists, perhaps also for engineers) if f
(x).integral(g(x)) would return "int f(x) d g(x)", rather than to try
and match g(x) as a sub-expression of f(x).

Of course, said physicist/engineer could compute d g(x) and change the
integrand accordingly, so that s/he is left with just the integration
variable x. But this is one additional step of work that would better
be automated.

On the other hand, how should Maxima know that in the end, we want the
integration variable x? For example, if g depends on two parameters
x,y, but y is supposed to be a constant parameter rather than a
variable?

What do you think about the following syntax:
f.integral(x,g)  - f a function, x a variable, g (optional, default g
(x)=x) is a function
Output:
int f(x) dg(x) = int f(x) dg(x)/dx dx

If I am not mistaken, that would also be meaningful if f or g depended
on further variables.

Advantage of that syntax: g is optional, hence, existing code wouldn't
break. And the corresponding changes could be done in the Sage library
("integral") without to touch Maxima.

Cheers,
Simon

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 6:15 am
From: Golam Mortuza Hossain <gmhoss...@gmail.com>
Date: Wed, 19 Aug 2009 07:15:48 -0300
Local: Wed, Aug 19 2009 6:15 am
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?

+1

Yes, I think now I agree with you. It is better to return it un-evaluated
than raising an error. As you, Ondrej and Simon pointed out that for some
g, it has un-ambiguous interpretation and may be Sage should apply
the identity where possible (definitely for expression with single variable)
before  passing it to maxima.

Cheers,
Golam

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 10:53 am
From: rjf <fate...@gmail.com>
Date: Wed, 19 Aug 2009 07:53:16 -0700 (PDT)
Local: Wed, Aug 19 2009 10:53 am
Subject: Re: Serious bug in integral using Maxima?

Consider
integrate(f(x,y),x*y).

do you compute   d(x*y)  as x*dy+y*dx and compute    integrate(f(x)
*x,y) + integrate(f(x)*y,x)?

Here's another interpretation of variable = x^2...

integrate(f(x),x^2)  =  integrate(integrate(f(x),x),x).
that is, an iterated integral.  This is like

(d ^2 f(x))/dx^2   notation for derivatives, where the derivative is
definitely NOT with respect to x^2.

Blame Newton, I think, or maybe Leibniz?

RJF

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 11:26 am
From: Simon King <simon.k...@nuigalway.ie>
Date: Wed, 19 Aug 2009 08:26:45 -0700 (PDT)
Local: Wed, Aug 19 2009 11:26 am
Subject: Re: Serious bug in integral using Maxima?
Hi!

On Aug 19, 3:53 pm, rjf <fate...@gmail.com> wrote:

> Consider
> integrate(f(x,y),x*y).

> do you compute   d(x*y)  as x*dy+y*dx and compute    integrate(f(x)
> *x,y) + integrate(f(x)*y,x)?

> Here's another interpretation of variable = x^2...

> integrate(f(x),x^2)  =  integrate(integrate(f(x),x),x).
> that is, an iterated integral.  This is like

> (d ^2 f(x))/dx^2   notation for derivatives, where the derivative is
> definitely NOT with respect to x^2.

But would you agree that my suggestion
f.integral(x[,g])  --- f function, x variable, g function (optional,
default g(x)=x)
makes sense, which should return the integral (f * dg/dx) dx ?

I think that has no ambiguity in it (even if f or g depends on further
variables), and it would just mean to extend Sage's .integral() method
so that Maxima is used in a more clever way.

Cheers,
Simon

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 1:30 pm
From: William Stein <wst...@gmail.com>
Date: Wed, 19 Aug 2009 10:30:53 -0700
Local: Wed, Aug 19 2009 1:30 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?

That's exactly what I meant.  I was just being very sloppy because I
was in a hurry.  The point is that "int f(x) d(x^2)  = int f(x) 2 x
dx" seems very reasonable.    We could easily make Sage use this
interpretation even though Maxima doesn't.  It woud be an additional
2-3 lines of code in calculus.py.

I am equally for either:

(1) raising an error like Mathematica does
and
(2) Use the interpretation that Ondrej and I agree upon above.

I favor (1) a little bit more than (2), because it's clear that there
is some confusion over this issue, and (1) will definitively reduce
confusion, at the expense of making some user code slightly longer
(but probably easier to understand!).

William

--
William Stein
Associate Professor of Mathematics
University of Washington
http://wstein.org

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 1:40 pm
From: Tim Lahey <tim.la...@gmail.com>
Date: Wed, 19 Aug 2009 13:40:26 -0400
Local: Wed, Aug 19 2009 1:40 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?

On Aug 19, 2009, at 1:30 PM, William Stein wrote:

I'm in favour of (1). If it isn't possible to integrate with respect to
that variable, it should raise an error, not try to interpret what the
user means.

---
Tim Lahey
PhD Candidate, Systems Design Engineering
University of Waterloo

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 2:27 pm
From: Golam Mortuza Hossain <gmhoss...@gmail.com>
Date: Wed, 19 Aug 2009 15:27:31 -0300
Local: Wed, Aug 19 2009 2:27 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?
Hi,

Hmm, could you please clarify a bit? When you say "raise an error"
do you mean

(A) (damn the user!!)
-------
sage: integrate( sin(x), x^2)
....
TypeError: blah.. blah...
-------

or (B) (leave it symbolic)
-------
sage: integrate(f(x), x^2)
integrate( sin(x), x^2)
-------

(A) will have some bad consequences like

-----
sage: h =  sin(x) + integrate( sin(x), x)
sage: h.subs(x==2*x)
sin(2*x) - cos(2*x)
-----
will work but
-----
sage: h =  sin(x) + integrate( sin(x)/x, x)
sage: h.subs(x==2*x)
...
TypeError: .....
-----

It would be bad if we don't allow even constant scaling
of variable in the integration.

I guess, there are no ambiguity when it is an expression
containing single variable and we should process it as you
and Ondrej suggested. For other cases, we leave
it symbolic as Robert (Dodier) suggested.

Cheers,
Golam

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 7:19 pm
From: Gonzalo Tornaria <torna...@math.utexas.edu>
Date: Wed, 19 Aug 2009 20:19:05 -0300
Local: Wed, Aug 19 2009 7:19 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?

On Wed, Aug 19, 2009 at 3:17 AM, Robert Dodier<robert.dod...@gmail.com> wrote:

> William Stein wrote:

>> Unless you can give a explanation of what you want integrating wrt x^2
>> to mean, I think we should also raise an error in Sage.

> That would be unfortunate. Faced with some unrecognized construct,
> the mathematical thing to do is to just leave it be. Whether it's
> meaningful is for the user to decide. You don't know what
> integrate(f(x), g(x)) means. Why not let someone else come
> up with an interpretation? Why must you close that door?

http://en.wikipedia.org/wiki/Riemann%E2%80%93Stieltjes_integral

Gonzalo

To post a message you must first join this group.
You do not have the permission required to post.
More options Aug 19 2009, 8:16 pm
From: William Stein <wst...@gmail.com>
Date: Wed, 19 Aug 2009 17:16:57 -0700
Local: Wed, Aug 19 2009 8:16 pm
Subject: Re: [sage-devel] Re: Serious bug in integral using Maxima?
2009/8/19 Golam Mortuza Hossain <gmhoss...@gmail.com>:

I am personally fine with Robert Dodier's suggestion, i.e., A above
and don't "damn the user".

William