These are function so that you can write foo(x) instead of x.foo() in certain common cases.
AUTHORS:
Return a numerical approximation of x with at least prec bits of precision.
Note
Both upper case N and lower case n are aliases for numerical_approx().
INPUT:
If neither the prec or digits are specified, the default is 53 bits of precision.
EXAMPLES:
sage: numerical_approx(pi, 10)
3.1
sage: numerical_approx(pi, digits=10)
3.141592654
sage: numerical_approx(pi^2 + e, digits=20)
12.587886229548403854
sage: n(pi^2 + e)
12.5878862295484
sage: N(pi^2 + e)
12.5878862295484
sage: n(pi^2 + e, digits=50)
12.587886229548403854194778471228813633070946500941
sage: a = CC(-5).n(prec=100)
sage: b = ComplexField(100)(-5)
sage: a == b
True
sage: type(a) == type(b)
True
You can also usually use method notation:
sage: (pi^2 + e).n()
12.5878862295484
TESTS:
sage: numerical_approx(I)
1.00000000000000*I
sage: x = QQ['x'].gen()
sage: F.<k> = NumberField(x^2+2, embedding=sqrt(CC(2))*CC.0)
sage: numerical_approx(k)
1.41421356237309*I
sage: type(numerical_approx(CC(1/2)))
<type 'sage.rings.complex_number.ComplexNumber'>
Return the argument of a complex number .
EXAMPLES:
sage: z = CC(1,2)
sage: theta = arg(z)
sage: cos(theta)*abs(z)
1.00000000000000
sage: sin(theta)*abs(z)
2.00000000000000
Return the base ring over which x is defined.
EXAMPLES:
sage: R = PolynomialRing(GF(7), 'x')
sage: base_ring(R)
Finite Field of size 7
Return the fixed basis of x.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: S = V.subspace([[1,2,0],[2,2,-1]])
sage: basis(S)
[
(1, 0, -1),
(0, 1, 1/2)
]
Return the category of x.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: category(V)
Category of vector spaces over Rational Field
Return the characteristic polynomial of x in the given variable.
EXAMPLES:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: charpoly(A)
x^3 - 15*x^2 - 18*x
sage: charpoly(A, 't')
t^3 - 15*t^2 - 18*t
sage: k.<alpha> = GF(7^10); k
Finite Field in alpha of size 7^10
sage: alpha.charpoly('T')
T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3
sage: characteristic_polynomial(alpha, 'T')
T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3
Return the characteristic polynomial of x in the given variable.
EXAMPLES:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: charpoly(A)
x^3 - 15*x^2 - 18*x
sage: charpoly(A, 't')
t^3 - 15*t^2 - 18*t
sage: k.<alpha> = GF(7^10); k
Finite Field in alpha of size 7^10
sage: alpha.charpoly('T')
T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3
sage: characteristic_polynomial(alpha, 'T')
T^10 + T^6 + T^5 + 4*T^4 + T^3 + 2*T^2 + 3*T + 3
EXAMPLES:
sage: cyclotomic_polynomial(3)
x^2 + x + 1
sage: cyclotomic_polynomial(4)
x^2 + 1
sage: cyclotomic_polynomial(9)
x^6 + x^3 + 1
sage: cyclotomic_polynomial(10)
x^4 - x^3 + x^2 - x + 1
sage: cyclotomic_polynomial(11)
x^10 + x^9 + x^8 + x^7 + x^6 + x^5 + x^4 + x^3 + x^2 + x + 1
Return the denominator of x.
EXAMPLES:
sage: denominator(17/11111)
11111
sage: R.<x> = PolynomialRing(QQ)
sage: F = FractionField(R)
sage: r = (x+1)/(x-1)
sage: denominator(r)
x - 1
Return the determinant of x.
EXAMPLES:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: det(A)
0
Return the dimension of x.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: S = V.subspace([[1,2,0],[2,2,-1]])
sage: dimension(S)
2
Return the dimension of x.
EXAMPLES:
sage: V = VectorSpace(QQ,3)
sage: S = V.subspace([[1,2,0],[2,2,-1]])
sage: dimension(S)
2
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S = R.quotient(x^29 - 17*x - 1, 'alpha')
sage: K = S.number_field()
sage: discriminant(K)
-15975100446626038280218213241591829458737190477345113376757479850566957249523
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: S = R.quotient(x^29 - 17*x - 1, 'alpha')
sage: K = S.number_field()
sage: discriminant(K)
-15975100446626038280218213241591829458737190477345113376757479850566957249523
Return the value of the eta function at , which must be
in the upper half plane.
The function is
EXAMPLES:
sage: eta(1+I)
0.742048775837 + 0.19883137023*I
Return the prime factorization of x.
EXAMPLES:
sage: factor(factorial(10))
2^8 * 3^4 * 5^2 * 7
sage: n = next_prime(10^6); n
1000003
sage: factor(n)
1000003
Return the prime factorization of x.
EXAMPLES:
sage: factor(factorial(10))
2^8 * 3^4 * 5^2 * 7
sage: n = next_prime(10^6); n
1000003
sage: factor(n)
1000003
Return the prime factorization of x.
EXAMPLES:
sage: factor(factorial(10))
2^8 * 3^4 * 5^2 * 7
sage: n = next_prime(10^6); n
1000003
sage: factor(n)
1000003
Return the factorization of the characteristic polynomial of x.
EXAMPLES:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: fcp(A, 'x')
x * (x^2 - 15*x - 18)
Return the n-th Hecke operator T_n acting on x.
EXAMPLES:
sage: M = ModularSymbols(1,12)
sage: hecke_operator(M,5)
Hecke operator T_5 on Modular Symbols space of dimension 3 for Gamma_0(1) of weight 12 with sign 0 over Rational Field
Return the image of x.
EXAMPLES:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: image(A)
Vector space of degree 3 and dimension 2 over Rational Field
Basis matrix:
[ 1 0 -1]
[ 0 1 2]
Return an indefinite integral of an object x.
First call x.integrate() and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm.
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)
-cos(x)
sage: y = var('y')
sage: integral(sin(x),y)
y*sin(x)
sage: integral(sin(x), x, 0, pi/2)
1
sage: sin(x).integral(x, 0,pi/2)
1
Return an indefinite integral of an object x.
First call x.integrate() and if that fails make an object and integrate it using Maxima, maple, etc, as specified by algorithm.
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)
-cos(x)
sage: y = var('y')
sage: integral(sin(x),y)
y*sin(x)
sage: integral(sin(x), x, 0, pi/2)
1
sage: sin(x).integral(x, 0,pi/2)
1
Integers between a and b inclusive (a and b integers).
EXAMPLES:
sage: I = interval(1,3)
sage: 2 in I
True
sage: 1 in I
True
sage: 4 in I
False
EXAMPLES:
sage: R = PolynomialRing(QQ, 'x')
sage: is_commutative(R)
True
Return whether or not an integer x is even, e.g., divisible by 2.
EXAMPLES:
sage: is_even(-1)
False
sage: is_even(4)
True
sage: is_even(-2)
True
EXAMPLES:
sage: R = PolynomialRing(QQ, 'x')
sage: F = FractionField(R)
sage: is_field(F)
True
Return whether or not x is odd. This is by definition the complement of is_even.
EXAMPLES:
sage: is_odd(-2)
False
sage: is_odd(-3)
True
sage: is_odd(0)
False
sage: is_odd(1)
True
Return an integer square root, i.e., the floor of a square root.
EXAMPLES:
sage: isqrt(10)
3
sage: isqrt(10r)
3
Return the left kernel of x.
EXAMPLES:
sage: M = MatrixSpace(QQ,3,2)
sage: A = M([1,2,3,4,5,6])
sage: kernel(A)
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 -2 1]
sage: kernel(A.transpose())
Vector space of degree 2 and dimension 0 over Rational Field
Basis matrix:
[]
Lift an object of a quotient ring to
.
EXAMPLES: We lift an integer modulo .
sage: Mod(2,3).lift()
2
We lift an element of a quotient polynomial ring.
sage: R.<x> = QQ['x']
sage: S.<xmod> = R.quo(x^2 + 1)
sage: lift(xmod-7)
x - 7
Return the log of x to the base b. The default base is e.
INPUT:
OUTPUT: number
Note
In Magma, the order of arguments is reversed from in Sage, i.e., the base is given first. We use the opposite ordering, so the base can be viewed as an optional second argument.
Return the minimal polynomial of x.
EXAMPLES:
sage: a = matrix(ZZ, 2, [1..4])
sage: minpoly(a)
x^2 - 5*x - 2
sage: minpoly(a,'t')
t^2 - 5*t - 2
sage: minimal_polynomial(a)
x^2 - 5*x - 2
sage: minimal_polynomial(a,'theta')
theta^2 - 5*theta - 2
Return the minimal polynomial of x.
EXAMPLES:
sage: a = matrix(ZZ, 2, [1..4])
sage: minpoly(a)
x^2 - 5*x - 2
sage: minpoly(a,'t')
t^2 - 5*t - 2
sage: minimal_polynomial(a)
x^2 - 5*x - 2
sage: minimal_polynomial(a,'theta')
theta^2 - 5*theta - 2
Return a numerical approximation of x with at least prec bits of precision.
Note
Both upper case N and lower case n are aliases for numerical_approx().
INPUT:
If neither the prec or digits are specified, the default is 53 bits of precision.
EXAMPLES:
sage: numerical_approx(pi, 10)
3.1
sage: numerical_approx(pi, digits=10)
3.141592654
sage: numerical_approx(pi^2 + e, digits=20)
12.587886229548403854
sage: n(pi^2 + e)
12.5878862295484
sage: N(pi^2 + e)
12.5878862295484
sage: n(pi^2 + e, digits=50)
12.587886229548403854194778471228813633070946500941
sage: a = CC(-5).n(prec=100)
sage: b = ComplexField(100)(-5)
sage: a == b
True
sage: type(a) == type(b)
True
You can also usually use method notation:
sage: (pi^2 + e).n()
12.5878862295484
TESTS:
sage: numerical_approx(I)
1.00000000000000*I
sage: x = QQ['x'].gen()
sage: F.<k> = NumberField(x^2+2, embedding=sqrt(CC(2))*CC.0)
sage: numerical_approx(k)
1.41421356237309*I
sage: type(numerical_approx(CC(1/2)))
<type 'sage.rings.complex_number.ComplexNumber'>
Return the norm of x.
EXAMPLES:
sage: z = 1+2*I
sage: norm(z)
5
sage: norm(CDF(z))
5.0
sage: norm(CC(z))
5.00000000000000
Return the numerator of x.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: F = FractionField(R)
sage: r = (x+1)/(x-1)
sage: numerator(r)
x + 1
sage: numerator(17/11111)
17
Return a numerical approximation of x with at least prec bits of precision.
Note
Both upper case N and lower case n are aliases for numerical_approx().
INPUT:
If neither the prec or digits are specified, the default is 53 bits of precision.
EXAMPLES:
sage: numerical_approx(pi, 10)
3.1
sage: numerical_approx(pi, digits=10)
3.141592654
sage: numerical_approx(pi^2 + e, digits=20)
12.587886229548403854
sage: n(pi^2 + e)
12.5878862295484
sage: N(pi^2 + e)
12.5878862295484
sage: n(pi^2 + e, digits=50)
12.587886229548403854194778471228813633070946500941
sage: a = CC(-5).n(prec=100)
sage: b = ComplexField(100)(-5)
sage: a == b
True
sage: type(a) == type(b)
True
You can also usually use method notation:
sage: (pi^2 + e).n()
12.5878862295484
TESTS:
sage: numerical_approx(I)
1.00000000000000*I
sage: x = QQ['x'].gen()
sage: F.<k> = NumberField(x^2+2, embedding=sqrt(CC(2))*CC.0)
sage: numerical_approx(k)
1.41421356237309*I
sage: type(numerical_approx(CC(1/2)))
<type 'sage.rings.complex_number.ComplexNumber'>
EXAMPLES:
sage: R, x = objgen(FractionField(QQ['x']))
sage: R
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: x
x
EXAMPLES:
sage: R, x = objgens(PolynomialRing(QQ,3, 'x'))
sage: R
Multivariate Polynomial Ring in x0, x1, x2 over Rational Field
sage: x
(x0, x1, x2)
Return the one element of the ring R.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: one(R)*x == x
True
sage: one(R) in R
True
Return the order of x. If x is a ring or module element, this is the additive order of x.
EXAMPLES:
sage: C = CyclicPermutationGroup(10)
sage: order(C)
10
sage: F = GF(7)
sage: order(F)
7
Return x.parent() if defined, or type(x) if not.
EXAMPLE:
sage: Z = parent(int(5))
sage: Z(17)
17
sage: Z
<type 'int'>
Return the rank of x.
EXAMPLES: We compute the rank of a matrix:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: rank(A)
2
We compute the rank of an elliptic curve:
sage: E = EllipticCurve([0,0,1,-1,0])
sage: rank(E)
1
round(number[, ndigits]) - double-precision real number
Round a number to a given precision in decimal digits (default 0 digits). This always returns a real double field element.
EXAMPLES:
sage: round(sqrt(2),2)
1.41
sage: round(sqrt(2),5)
1.41421
sage: round(pi)
3.0
sage: b = 5.4999999999999999
sage: round(b)
5.0
Since we use floating-point with a limited range, some roundings can’t be performed:
sage: round(sqrt(Integer('1'*1000)))
+infinity
IMPLEMENTATION: If ndigits is specified, it calls Python’s builtin round function, and converts the result to a real double field element. Otherwise, it tries the argument’s .round() method, and if that fails, it falls back to the builtin round function.
Note
This is currently slower than the builtin round function, since it does more work - i.e., allocating an RDF element and initializing it. To access the builtin version do import __builtin__; __builtin__.round.
Show a graphics object x.
For additional ways to show objects in the notebook, look at the methods on the html object. For example, html.table will produce an HTML table from a nested list.
OPTIONAL INPUT:
SOME OF THESE MAY APPLY:
EXAMPLES:
sage: show(graphs(3))
sage: show(list(graphs(3)))
Return a square root of x.
This function (numerical_sqrt) is deprecated. Use sqrt(x, prec=n) instead.
EXAMPLES:
sage: numerical_sqrt(10.1)
doctest:1: DeprecationWarning: numerical_sqrt is deprecated, use sqrt(x, prec=n) instead
3.17804971641414
sage: numerical_sqrt(9)
3
Return the square free part of , i.e., a divisor
such that
, for a perfect square
.
EXAMPLES:
sage: squarefree_part(100)
1
sage: squarefree_part(12)
3
sage: squarefree_part(10)
10
sage: x = QQ['x'].0
sage: S = squarefree_part(-9*x*(x-6)^7*(x-3)^2); S
-9*x^2 + 54*x
sage: S.factor()
(-9) * (x - 6) * x
sage: f = (x^3 + x + 1)^3*(x-1); f
x^10 - x^9 + 3*x^8 + 3*x^5 - 2*x^4 - x^3 - 2*x - 1
sage: g = squarefree_part(f); g
x^4 - x^3 + x^2 - 1
sage: g.factor()
(x - 1) * (x^3 + x + 1)
EXAMPLES:
sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: transpose(A)
[1 4 7]
[2 5 8]
[3 6 9]
Return the zero element of the ring R.
EXAMPLES:
sage: R.<x> = PolynomialRing(QQ)
sage: zero(R) in R
True
sage: zero(R)*x == zero(R)
True