Ask Your Question

Revision history [back]

Symbolic expressions in Sage tend to be computed to some extend.

Some operations provide a "hold" keyword to prevent actual computation.

This keyword is in particular available for the integrate function.

Example.

Sage and Python versions used for this example:

sage: print("{}, Python {}.{}.{}".format(version(), *sys.version_info[:3]))
SageMath version 9.8, Release Date: 2023-02-11, Python 3.10.8

Define a symbolic variable:

sage: z = SR.var('z')

The integral is computed before being latexed...

sage: latex(integrate(z^4, z))
\frac{1}{5} \, z^{5}

... unless we hold off the computation:

sage: latex(integrate(z^4, z, hold=True))
\int z^{4}\,{d z}

We can use an equation with both forms:

sage: latex(integrate(z^4, z, hold=True) == integrate(z^4, z))
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}

Symbolic expressions in Sage tend to be computed to some extend.extent.

Some operations provide Sometimes we can hold off this computation with a "hold" keyword to prevent actual computation.keyword.

This keyword is in particular available for the The integrate function.function, in particular, does support that keyword.

Example.

Sage and Python versions used for this example:

sage: print("{}, Python {}.{}.{}".format(version(), *sys.version_info[:3]))
SageMath version 9.8, Release Date: 2023-02-11, Python 3.10.8

Define a symbolic variable:

sage: z = SR.var('z')

The integral is computed before being latexed...

sage: latex(integrate(z^4, z))
\frac{1}{5} \, z^{5}

... unless we hold off the computation:

sage: latex(integrate(z^4, z, hold=True))
\int z^{4}\,{d z}

We can use an equation with both forms:

sage: latex(integrate(z^4, z, hold=True) == integrate(z^4, z))
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}

Symbolic expressions in Sage tend to be computed to some extent.

Sometimes we can hold off this computation with a "hold" keyword.

The integrate function, in particular, does support that keyword.

Example.

Sage and Python versions used for this example:

sage: print("{}, Python {}.{}.{}".format(version(), *sys.version_info[:3]))
SageMath version 9.8, Release Date: 2023-02-11, Python 3.10.8

Define a symbolic variable:

sage: z = SR.var('z')

The integral is computed before being latexed...

sage: latex(integrate(z^4, z))
\frac{1}{5} \, z^{5}

... unless we hold off the computation:

sage: latex(integrate(z^4, z, hold=True))
\int z^{4}\,{d z}

We can use an equation with both forms:

sage: latex(integrate(z^4, z, hold=True) == integrate(z^4, z))
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}

Or, giving the held integral a name:

sage: a = integrate(z^4, z, hold=True)

sage: a
integrate(z^4, z)
sage: a.unhold()
1/5*z^5

sage: latex(a == a.unhold())
\int z^{4}\,{d z} = \frac{1}{5} \, z^{5}