Ask Your Question

Revision history [back]

When you write:

sage: f = 1

You define f as the integer 1:

sage: f.parent()
Integer Ring

So, it is unlikely that we will define a .integral() method for this, otherwise there will be too much methods for such a universal object. See

sage: f.<TAB>

to see how many methods there exist already for the integer 1. So i guess there should not be a .integral() method for integers (or Python should have a mechanism to understand that it should try the integrate function, or something like that).

Note that x is a symbolic expression (and an element of the symbolic ring), hence it has an .integral() method:

sage: x.parent()
Symbolic Ring
sage: type(x)
<type 'sage.symbolic.expression.Expression'>

Now, when you write:

sage: f = 1 + x - x

There is a coercion mechanism that transforms the integer 1 as an element of the symbolic ring so that it can be added to x, hence here f is a symbolic expression, not an integer:

sage: f.parent()
Symbolic Ring

This is why you can apply the .integral() method.

So, there are two ways to integrate 1 easily. First, you can use the integrate() function:

sage: integrate(1,x,0,1)
1

Second, you can transform the integer 1 as an element of the symbolic ring:

sage: f = SR(1)
sage: f.integrate(x,0,1)
1

When you write:

sage: f = 1

You define f as the integer 1:

sage: f.parent()
Integer Ring

So, it is unlikely that we will define a .integral().integrate() method for this, otherwise there will be too much methods for such a universal object. See

sage: f.<TAB>

to see how many methods there exist already for the integer 1. So i guess there should not be a .integral().integrate() method for integers (or Python should have a mechanism to understand that it should try the integrate function, or something like that).

Note that x is a symbolic expression (and an element of the symbolic ring), hence it has an .integral().integrate() method:

sage: x.parent()
Symbolic Ring
sage: type(x)
<type 'sage.symbolic.expression.Expression'>

Now, when you write:

sage: f = 1 + x - x

There is a coercion mechanism that transforms the integer 1 as an element of the symbolic ring so that it can be added to x, hence here f is a symbolic expression, not an integer:

sage: f.parent()
Symbolic Ring

This is why you can apply the .integral().integrate() method.

So, there are two ways to integrate 1 easily. First, you can use the integrate() function:

sage: integrate(1,x,0,1)
1

Second, you can transform the integer 1 as an element of the symbolic ring:

sage: f = SR(1)
sage: f.integrate(x,0,1)
1