2.4 Functional notation

Module: sage.misc.functional

These are function so that you can write foo(x) instead of x.foo() in certain common cases.

Author Log:

Module-level Functions

acos( x)

Return the arc cosine of x.

sage: acos(0.5)
1.0471975511965979
sage: acos(1 + I*1.0)
0.90455689430238140 - 1.0612750619050357*I

additive_order( x)

Return the additive order of $ x$ .

arg( x)

Return the argument of a complex number $ x$ .

sage: z = CC(1+2*i)
sage: theta = arg(z)
sage: cos(theta)*abs(z)
1.0000000000000002
sage: sin(theta)*abs(z)
2.0000000000000000

asin( x)

Return the arc sine of x.

sage: asin(0.5)
0.52359877559829893
sage: asin(1 + I*1.0)
0.66623943249251527 + 1.0612750619050357*I

atan( x)

Return the arc tangent of x.

sage: atan(1/2)
0.46364760900080609
sage: atan(1 + I)
1.0172219678978514 + 0.40235947810852507*I

base_field( x)

Return the base field over which x is defined.

base_ring( x)

Return the base ring over which x is defined.

sage: R = PolynomialRing(GF(7))
sage: base_ring(R)
Finite Field of size 7

basis( x)

Return the fixed basis of x.

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)
]

category( x)

Return the category of x.

sage: V = VectorSpace(QQ,3)
sage: category(V)
Category of vector spaces over Rational Field

ceil( x)

Return the ceiling of x.

ceiling( x)

Return the ceiling of x.

charpoly( x)

Return the characteristic polynomial of x.

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

cos( x)

Return the cosine of x.

sage: z = CC(1+2*i)
sage: theta = arg(z)
sage: cos(theta)*abs(z)
1.0000000000000002
sage: cos(3.141592)
-0.99999999999978639

cyclotomic_polynomial( n)

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

decomposition( x)

Return the decomposition of x.

denominator( x)

Return the numerator of x.

sage: denominator(17/11111)
11111
sage: R = PolynomialRing(RationalField(), 'x')
sage: F = FractionField(R)
sage: r = (x+1)/(x-1)
sage: denominator(r)
x - 1

derivative( x)

Return the derivative of a polynomial x.

sage: f = cyclotomic_polynomial(10)
sage: derivative(f)
4*x^3 - 3*x^2 + 2*x - 1
sage: R = PolynomialRing(GF(7))
sage: gen = R.gen(); x = gen; f = x^7 + x
sage: derivative(f)
1

det( x)

Return the determinant of x.

sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: det(A)
0

dim( x)

Return the dimension of x.

sage: V = VectorSpace(QQ,3)
sage: S = V.subspace([[1,2,0],[2,2,-1]])
sage: dimension(S)
2

dimension( x)

Return the dimension of x.

sage: V = VectorSpace(QQ,3)
sage: S = V.subspace([[1,2,0],[2,2,-1]])
sage: dimension(S)
2

disc( x)

sage: R = PolynomialRing(RationalField(), 'x'); x = R.gen()
sage: S = R.quotient(x**29-17*x-1, 'alpha')
sage: K = S.number_field()
sage: discriminant(K)
-15975100446626038280218213241591829458737190477345113376757479850566957249
523

discriminant( x)

sage: R = PolynomialRing(RationalField(), 'x'); x = R.gen()
sage: S = R.quotient(x**29-17*x-1, 'alpha')
sage: K = S.number_field()
sage: discriminant(K)
-15975100446626038280218213241591829458737190477345113376757479850566957249
523

exp( x)

Return the value of the exponentation function at x.

factor( x)

Return the prime factorization of x.

sage: factor(factorial(10))
2^8 * 3^4 * 5^2 * 7
sage: n = next_prime(10^6); n
1000003
sage: factor(n)
1000003

factorisation( x)

Return the prime factorization of x.

sage: factor(factorial(10))
2^8 * 3^4 * 5^2 * 7
sage: n = next_prime(10^6); n
1000003
sage: factor(n)
1000003

factorization( x)

Return the prime factorization of x.

sage: factor(factorial(10))
2^8 * 3^4 * 5^2 * 7
sage: n = next_prime(10^6); n
1000003
sage: factor(n)
1000003

fcp( x)

Return the factorization of the characteristic polynomial of x.

sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: fcp(A)
x * (x^2 - 15*x - 18)

floor( x)

Return the largest integer $ \leq x$ .

INPUT:
    x -- an object that has a floor method or is coercible to int

OUTPUT:
    an Integer

sage: floor(5.4)
5
sage: floor(float(5.4))
5

gen( x)

Return the generator of x.

gens( x)

Return the generators of x.

hecke_operator( x, n)

Return the n-th Hecke operator T_n acting on x.

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

ideal( )

Return the ideal generated by x where x is an element or list.

sage: ideal(x^2-2*x+1, x^2-1)
Principal ideal (x - 1) of Univariate Polynomial Ring in x over Rational
Field
sage: ideal([x^2-2*x+1, x^2-1])
Principal ideal (x - 1) of Univariate Polynomial Ring in x over Rational
Field

imag( x)

Return the imaginary part of x.

image( x)

Return the image of x.

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]

imaginary( x)

Return the imaginary part of a complex number.

sage: z = CC(1+2*i)
sage: imaginary(z)
2.0000000000000000
sage: imag(z)
2.0000000000000000

integral( x, [var=maxima], [algorithm=None])

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.

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

integral_closure( x)

interval( a, b)

Integers between a and b inclusive (a and b integers).

sage: I = interval(1,3)
sage: 2 in I
True
sage: 1 in I
True
sage: 4 in I
False

is_commutative( x)

sage: R = PolynomialRing(RationalField(), 'x')
sage: is_commutative(R)
True

is_even( x)

Return whether or not an integer x is even, e.g., divisible by 2.

sage: is_even(-1)
False
sage: is_even(4)
True
sage: is_even(-2)
True

is_field( x)

sage: R = PolynomialRing(RationalField(), 'x')
sage: F = FractionField(R)
sage: is_field(F)
True

is_integrally_closed( x)

is_noetherian( x)

is_odd( x)

Return whether or not x is odd. This is by definition the complement of is_even.

sage: is_odd(-2)
False
sage: is_odd(-3)
True
sage: is_odd(0)
False
sage: is_odd(1)
True

isqrt( x)

Return an integer square root, i.e., the floor of a square root.

sage: isqrt(10)
3

kernel( x)

Return the kernel of x.

sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: kernel(A)
Vector space of degree 3 and dimension 1 over Rational Field
Basis matrix:
[ 1 -2  1]

krull_dimension( x)

log( x, [b=None])

Return the log of x to the base b. The default base is e.

INPUT:
    x -- number
    b -- base (default: None, which means natural log)
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.

sage: log(10,2)
3.3219280948873626
sage: log(8,2)
3.0000000000000000
sage: log(10)
2.3025850929940459
sage: log(2.718)
0.99989631572895199

matrix( x, R)

Return the SAGE matrix over $ R$ obtained from x, if possible.

minimal_polynomial( x)

Return the minimal polynomial of x.

multiplicative_order( x)

Return the multiplicative order of self, if self is a unit, or raise ArithmeticError otherwise.

ngens( x)

Return the number of generators of x.

norm( x)

Return the norm of x.

sage: z = CC(1+2*i)
sage: norm(z)
5.0000000000000000

numerator( x)

Return the numerator of x.

sage: R = PolynomialRing(RationalField(), 'x')
sage: F = FractionField(R)
sage: r = (x+1)/(x-1)
sage: numerator(r)
x + 1
sage: numerator(17/11111)
17

objgen( x, [names=None])

sage: R, x = objgen(FractionField(Q['x']))
sage: R
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: x
x

objgens( x, [names=None])

sage: R, x = objgens(MPolynomialRing(Q,3))
sage: R
Polynomial Ring in x0, x1, x2 over Rational Field
sage: x
(x0, x1, x2)

one( R)

Return the one element of the ring R.

sage: R = PolynomialRing(RationalField(), 'x')
sage: one(R)*x == x
True
sage: one(R) in R
True

order( x)

Return the order of x. If x is a ring or module element, this is the additive order of x.

sage: C = CyclicPermutationGroup(10)
sage: order(C)
10
sage: F = GF(7)
sage: order(F)
7

parent( x)

Return x.parent() if defined, or type(x) if not.

sage: Z = parent(int(5))
sage: Z(17)
17
sage: Z
<type 'int'>

quo( x, y, [var=None])

Return the quotient object x/y, e.g., a quotient of numbers or of a polynomial ring x by the ideal generated by y, etc.

quotient( x, y, [var=None])

Return the quotient object x/y, e.g., a quotient of numbers or of a polynomial ring x by the ideal generated by y, etc.

rank( x)

Return the rank of x.

sage: M = MatrixSpace(QQ,3,3)
sage: A = M([1,2,3,4,5,6,7,8,9])
sage: rank(A)
2

real( x)

Return the real part of x.

sage: z = CC(1+2*i)
sage: real(z)
1.0000000000000000

regulator( x)

Return the regulator of x.

sin( x)

Return the sin of x.

sqrt( x)

Return a square root of x.

sage: sqrt(10.1)
3.1780497164141406
sage: sqrt(9)
3

square_free_part( x)

Return the square free part of $ x$ , i.e., a divisor $ z$ such that $ x = z y^2$ , for a perfect square $ y^2$ .

sage: square_free_part(100)
1
sage: square_free_part(12)
3
sage: square_free_part(10)
10

sage: x = Q['x'].0
sage: S = square_free_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 = square_free_part(f); g
x^4 - x^3 + x^2 - 1
sage: g.factor()
(x - 1) * (x^3 + x + 1)

square_root( x)

Return a square root of x with the same parent as x, if possible, otherwise raise a ValueError.

sage: square_root(9)
3
sage: square_root(100)
10

tan( x)

Return the tangent of x.

sage: tan(3.1415)
-0.000092653590058191322
sage: tan(3.1415/4)
0.99995367427815629

transpose( x)

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]

vector( x, R)

Return the SAGE vector over $ R$ obtained from x, if possible.

xinterval( a, b)

Iterator over the integers between a and b, inclusive.

zero( R)

Return the zero element of the ring R.

sage: R = PolynomialRing(RationalField(), 'x')
sage: zero(R) in R
True
sage: zero(R)*x == zero(R)
True

See About this document... for information on suggesting changes.