Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
M2142 - zápisník pro první přednášku
Project: M2142
Path: Uvod.sagews
Views: 470Image: ubuntu2204

Komentář.
2
Error in lines 1-1
Traceback (most recent call last):
File "/cocalc/lib/python3.11/site-packages/smc_sagews/sage_server.py", line 1250, in execute
exec(
File "", line 1, in <module>
NameError: name 'fctor' is not defined
Komentar

Komentář.
Help on function factor in module sage.arith.misc:
factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds)
Return the factorization of ``n``. The result depends on the
type of ``n``.
If ``n`` is an integer, returns the factorization as an object
of type :class:`Factorization`.
If ``n`` is not an integer, ``n.factor(proof=proof, **kwds)`` gets called.
See ``n.factor??`` for more documentation in this case.
.. warning::
This means that applying :func:`factor` to an integer result of
a symbolic computation will not factor the integer, because it is
considered as an element of a larger symbolic ring.
EXAMPLES::
sage: f(n) = n^2 # needs sage.symbolic
sage: is_prime(f(3)) # needs sage.symbolic
False
sage: factor(f(3)) # needs sage.symbolic
9
INPUT:
- ``n`` -- a nonzero integer
- ``proof`` -- bool or ``None`` (default: ``None``)
- ``int_`` -- bool (default: ``False``) whether to return
answers as Python ints
- ``algorithm`` -- string
- ``'pari'`` -- (default) use the PARI c library
- ``'kash'`` -- use KASH computer algebra system (requires that
kash be installed)
- ``'magma'`` -- use Magma (requires magma be installed)
- ``verbose`` -- integer (default: 0); PARI's debug
variable is set to this; e.g., set to 4 or 8 to see lots of output
during factorization.
OUTPUT:
- factorization of `n`
The qsieve and ecm commands give access to highly optimized
implementations of algorithms for doing certain integer
factorization problems. These implementations are not used by the
generic :func:`factor` command, which currently just calls PARI (note that
PARI also implements sieve and ecm algorithms, but they are not as
optimized). Thus you might consider using them instead for certain
numbers.
The factorization returned is an element of the class
:class:`~sage.structure.factorization.Factorization`; use ``Factorization??``
to see more details, and examples below for usage. A :class:`~sage.structure.factorization.Factorization` contains
both the unit factor (`+1` or `-1`) and a sorted list of ``(prime, exponent)``
pairs.
The factorization displays in pretty-print format but it is easy to
obtain access to the ``(prime, exponent)`` pairs and the unit, to
recover the number from its factorization, and even to multiply two
factorizations. See examples below.
EXAMPLES::
sage: factor(500)
2^2 * 5^3
sage: factor(-20)
-1 * 2^2 * 5
sage: f=factor(-20)
sage: list(f)
[(2, 2), (5, 1)]
sage: f.unit()
-1
sage: f.value()
-20
sage: factor(-next_prime(10^2) * next_prime(10^7)) # needs sage.libs.pari
-1 * 101 * 10000019
::
sage: factor(293292629867846432923017396246429, algorithm='flint') # needs sage.libs.flint
3 * 4852301647696687 * 20148007492971089
::
sage: factor(-500, algorithm='kash')
-1 * 2^2 * 5^3
::
sage: factor(-500, algorithm='magma') # optional - magma
-1 * 2^2 * 5^3
::
sage: factor(0)
Traceback (most recent call last):
...
ArithmeticError: factorization of 0 is not defined
sage: factor(1)
1
sage: factor(-1)
-1
sage: factor(2^(2^7) + 1) # needs sage.libs.pari
59649589127497217 * 5704689200685129054721
Sage calls PARI's :pari:`factor`, which has ``proof=False`` by default.
Sage has a global proof flag, set to ``True`` by default (see
:mod:`sage.structure.proof.proof`, or use ``proof.[tab]``). To override
the default, call this function with ``proof=False``.
::
sage: factor(3^89 - 1, proof=False) # needs sage.libs.pari
2 * 179 * 1611479891519807 * 5042939439565996049162197
::
sage: factor(2^197 + 1) # long time (2s) # needs sage.libs.pari
3 * 197002597249 * 1348959352853811313 * 251951573867253012259144010843
Any object which has a factor method can be factored like this::
sage: K.<i> = QuadraticField(-1) # needs sage.rings.number_field
sage: factor(122 - 454*i) # needs sage.rings.number_field
(-i) * (-i - 2)^3 * (i + 1)^3 * (-2*i + 3) * (i + 4)
To access the data in a factorization::
sage: # needs sage.libs.pari
sage: f = factor(420); f
2^2 * 3 * 5 * 7
sage: [x for x in f]
[(2, 2), (3, 1), (5, 1), (7, 1)]
sage: [p for p,e in f]
[2, 3, 5, 7]
sage: [e for p,e in f]
[2, 1, 1, 1]
sage: [p^e for p,e in f]
[4, 3, 5, 7]
We can factor Python, numpy and gmpy2 numbers::
sage: factor(math.pi)
3.141592653589793
sage: import numpy # needs numpy
sage: factor(numpy.int8(30)) # needs numpy sage.libs.pari
2 * 3 * 5
sage: import gmpy2
sage: factor(gmpy2.mpz(30))
2 * 3 * 5
TESTS::
sage: factor(Mod(4, 100))
Traceback (most recent call last):
...
TypeError: unable to factor 4
sage: factor("xyz")
Traceback (most recent call last):
...
TypeError: unable to factor 'xyz'
Test that :issue:`35219` is fixed::
sage: len(factor(2^2203-1,proof=false))
1

2
4
Komentář

Aproximace .
Help on function integral in module sage.misc.functional:
integral(x, *args, **kwds)
Return an indefinite or definite integral of an object ``x``.
First call ``x.integral()`` and if that fails make an object and
integrate it using Maxima, maple, etc, as specified by algorithm.
For symbolic expression calls
:func:`sage.calculus.calculus.integral` - see this function for
available options.
EXAMPLES::
sage: f = cyclotomic_polynomial(10)
sage: integral(f)
1/5*x^5 - 1/4*x^4 + 1/3*x^3 - 1/2*x^2 + x
::
sage: integral(sin(x), x) # needs sage.symbolic
-cos(x)
::
sage: y = var('y') # needs sage.symbolic
sage: integral(sin(x), y) # needs sage.symbolic
y*sin(x)
::
sage: integral(sin(x), x, 0, pi/2) # needs sage.symbolic
1
sage: sin(x).integral(x, 0, pi/2) # needs sage.symbolic
1
sage: integral(exp(-x), (x, 1, oo)) # needs sage.symbolic
e^(-1)
Numerical approximation::
sage: h = integral(tan(x)/x, (x, 1, pi/3)) # needs sage.symbolic
...
sage: h # needs sage.symbolic
integrate(tan(x)/x, x, 1, 1/3*pi)
sage: h.n() # needs sage.symbolic
0.07571599101...
Specific algorithm can be used for integration::
sage: integral(sin(x)^2, x, algorithm='maxima') # needs sage.symbolic
1/2*x - 1/4*sin(2*x)
sage: integral(sin(x)^2, x, algorithm='sympy') # needs sage.symbolic
-1/2*cos(x)*sin(x) + 1/2*x
TESTS:
A symbolic integral from :trac:`11445` that was incorrect in
earlier versions of Maxima::
sage: f = abs(x - 1) + abs(x + 1) - 2*abs(x) # needs sage.symbolic
sage: integrate(f, (x, -Infinity, Infinity)) # needs sage.symbolic
2
Another symbolic integral, from :trac:`11238`, that used to return
zero incorrectly; with Maxima 5.26.0 one gets
``1/2*sqrt(pi)*e^(1/4)``, whereas with 5.29.1, and even more so
with 5.33.0, the expression is less pleasant, but still has the
same value. Unfortunately, the computation takes a very long time
with the default settings, so we temporarily use the Maxima
setting ``domain: real``::
sage: # needs sage.symbolic
sage: sage.calculus.calculus.maxima('domain: real')
real
sage: f = exp(-x) * sinh(sqrt(x))
sage: t = integrate(f, x, 0, Infinity); t # long time
1/4*sqrt(pi)*(erf(1) - 1)*e^(1/4)
- 1/4*(sqrt(pi)*(erf(1) - 1) - sqrt(pi) + 2*e^(-1) - 2)*e^(1/4)
+ 1/4*sqrt(pi)*e^(1/4) - 1/2*e^(1/4) + 1/2*e^(-3/4)
sage: t.canonicalize_radical() # long time
1/2*sqrt(pi)*e^(1/4)
sage: sage.calculus.calculus.maxima('domain: complex')
complex
An integral which used to return -1 before maxima 5.28. See :trac:`12842`::
sage: f = e^(-2*x)/sqrt(1-e^(-2*x)) # needs sage.symbolic
sage: integrate(f, x, 0, infinity) # needs sage.symbolic
1
This integral would cause a stack overflow in earlier versions of
Maxima, crashing sage. See :trac:`12377`. We don't care about the
result here, just that the computation completes successfully::
sage: y = (x^2)*exp(x) / (1 + exp(x))^2 # needs sage.symbolic
sage: _ = integrate(y, x, -1000, 1000) # needs sage.symbolic
When SymPy cannot solve an integral it gives it back, so we must
be able to convert SymPy's ``Integral`` (:trac:`14723`)::
sage: # needs sage.symbolic
sage: x, y, z = var('x,y,z')
sage: f = function('f')
sage: integrate(f(x), x, algorithm='sympy')
integrate(f(x), x)
sage: integrate(f(x), x, 0, 1, algorithm='sympy')
integrate(f(x), x, 0, 1)
sage: integrate(integrate(integrate(f(x,y,z), x, algorithm='sympy'),
....: y, algorithm='sympy'),
....: z, algorithm='sympy')
integrate(integrate(integrate(f(x, y, z), x), y), z)
sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, algorithm='sympy')
-integrate(sin(x)*tan(x)/(cos(x) - 1), x)
sage: _ = var('a,b,x')
sage: integrate(sin(x)*tan(x)/(1-cos(x)), x, a, b, algorithm='sympy')
-integrate(sin(x)*tan(x)/(cos(x) - 1), x, a, b)
sage: # needs sympy
sage: import sympy
sage: x, y, z = sympy.symbols('x y z')
sage: f = sympy.Function('f')
sage: SR(sympy.Integral(f(x,y,z), x, y, z)) # needs sage.symbolic
integrate(integrate(integrate(f(x, y, z), x), y), z)
Ensure that the following integral containing a signum term from
:trac:`11590` can be integrated::
sage: x = SR.symbol('x', domain='real') # needs sage.symbolic
sage: result = integrate(x * sgn(x^2 - 1/4), x, -1, 0) # needs sage.symbolic
...
sage: result # needs sage.symbolic
-1/4
Doplňování jmen
Začněte psát příkaz a stiskněte Klávesu Tab[y == 1/2*pi + x]