| |
- ComplexDoubleField(...)
- File: sage/rings/complex_double.pyx (starting at line 1590)
Returns the field of double precision complex numbers.
EXAMPLE:
sage: ComplexDoubleField()
Complex Double Field
sage: ComplexDoubleField() is CDF
True
- ComplexNumber = create_ComplexNumber(...)
- File: sage/rings/complex_number.pyx (starting at line 889)
Return the complex number defined by the strings s_real and s_imag as an element of
\code{ComplexField(prec=n)}, where n potentially has slightly more
(controlled by pad) bits than given by s.
INPUT:
s_real -- a string that defines a real number (or something whose
string representation defines a number)
s_imag -- a string that defines a real number (or something whose
string representation defines a number)
pad -- an integer >= 0.
min_prec -- number will have at least this many bits of precision, no matter what.
EXAMPLES:
sage: ComplexNumber('2.3')
2.30000000000000
sage: ComplexNumber('2.3','1.1')
2.30000000000000 + 1.10000000000000*I
sage: ComplexNumber(10)
10.0000000000000
sage: ComplexNumber(10,10)
10.0000000000000 + 10.0000000000000*I
sage: ComplexNumber(1.000000000000000000000000000,2)
1.000000000000000000000000000 + 2.000000000000000000000000000*I
sage: ComplexNumber(1,2.000000000000000000000)
1.000000000000000000000 + 2.000000000000000000000*I
- DWT = WaveletTransform(...)
- File: sage/gsl/dwt.pyx (starting at line 33)
This function initializes an GSLDoubleArray of length n which
can perform a discrete wavelet transform.
INPUT:
n -- a power of 2.
T -- the data in the GSLDoubleArray must be real.
wavelet_type -- the name of the type of wavelet,
valid choices are:
'daubechies','daubechies_centered',
'haar','haar_centered','bspline', and
'bspline_centered'.
For daubechies wavelets, wavelet_k specifies a daubechie wavelet
with k/2 vanishing moments. k = 4,6,...,20 for k even are the
only ones implemented.
For Haar wavelets, wavelet_k must be 2.
For bspline wavelets, wavelet_k = 103,105,202,204,206,208,301,305,
307,309 will give biorthogonal B-spline wavelets of order (i,j) where
wavelet_k=100*i+j.
The wavelet transfrom uses J=log_2(n) levels.
OUTPUT:
An array of the form
(s_{-1,0},d_{0,0},d_{1,0},d_{1,1}, d_{2,0}...,d_{J-1,2^{J-1}-1})
for d_{j,k} the detail coefficients of level j.
The centered forms align the coefficients of the sub-bands on edges.
EXAMPLES:
sage: a = WaveletTransform(128,'daubechies',4)
sage: for i in range(1, 11):
... a[i] = 1
... a[128-i] = 1
sage: a.plot().show(ymin=0)
sage: a.forward_transform()
sage: a.plot().show()
sage: a = WaveletTransform(128,'haar',2)
sage: for i in range(1, 11): a[i] = 1; a[128-i] = 1
sage: a.forward_transform()
sage: a.plot().show(ymin=0)
sage: a = WaveletTransform(128,'bspline_centered',103)
sage: for i in range(1, 11): a[i] = 1; a[100+i] = 1
sage: a.forward_transform()
sage: a.plot().show(ymin=0)
This example gives a simple example of wavelet compression.
sage: a = DWT(2048,'daubechies',6)
sage: for i in range(2048): a[i]=float(sin((i*5/2048)**2))
sage: a.plot().show()
sage: a.forward_transform()
sage: for i in range(1800): a[2048-i-1] = 0
sage: a.backward_transform()
sage: a.plot().show()
- FFT = FastFourierTransform(...)
- File: sage/gsl/fft.pyx (starting at line 34)
EXAMPLES:
sage: a = FastFourierTransform(128)
sage: for i in range(1, 11):
... a[i] = 1
... a[128-i] = 1
sage: a.plot().show(ymin=0)
sage: a.forward_transform()
sage: a.plot().show()
- FastFourierTransform(...)
- File: sage/gsl/fft.pyx (starting at line 34)
EXAMPLES:
sage: a = FastFourierTransform(128)
sage: for i in range(1, 11):
... a[i] = 1
... a[128-i] = 1
sage: a.plot().show(ymin=0)
sage: a.forward_transform()
sage: a.plot().show()
- ForgetfulFunctor(...)
- File: sage/categories/functor.pyx (starting at line 135)
Construct the forgetful function from one category to another.
EXAMPLES:
sage: rings = Rings()
sage: abgrps = AbelianGroups()
sage: F = ForgetfulFunctor(rings, abgrps)
sage: F
The forgetful functor from Rings to AbelianGroups
- HeilbronnCremonaList(...)
- File: sage/modular/modsym/heilbronn.pyx (starting at line 44)
The Heilbronn matrices of determinant p, as defined by Cremona.
- HeilbronnMerelList(...)
- File: sage/modular/modsym/heilbronn.pyx (starting at line 77)
Set of Heilbronn matrices of determinant n, as defined by Merel.
- IdentityFunctor(...)
- File: sage/categories/functor.pyx (starting at line 132)
- IntegerMod(...)
- File: sage/rings/integer_mod.pyx (starting at line 102)
Create an integer modulo $n$ with the given parent.
This is mainly for internal use.
- IntegerRing(...)
- File: sage/rings/integer_ring.pyx (starting at line 646)
- Mod(...)
- File: sage/rings/integer_mod.pyx (starting at line 75)
Return the equivalence class of n modulo m as an element of
$\Z/m\Z$.
EXAMPLES:
sage: x = Mod(12345678, 32098203845329048)
sage: x
12345678
sage: x^100
1017322209155072
You can also use the lowercase version:
sage: mod(12,5)
2
- PowComputer(...)
- File: sage/rings/padics/pow_computer.pyx (starting at line 275)
Returns a PowComputer that caches the values $1, m, m^2, \ldots, m^cache_limit$.
Once you create a PowComputer, merely call it to get values out.
You can input any integer, even if it's outside of the precomputed range.
INPUT:
m -- An integer, the base that you want to exponentiate.
cache_limit -- A positive integer that you want to cache powers up to.
EXAMPLES:
sage: PC = PowComputer(3, 5, 10)
sage: PC(4)
81
sage: PC(6)
729
sage: PC(-1)
1/3
- RealDoubleField(...)
- File: sage/rings/real_double.pyx (starting at line 1517)
- RealInterval(...)
- File: sage/rings/real_mpfi.pyx (starting at line 2765)
Return the real number defined by the string s as an element of
\code{RealIntervalField(prec=n)}, where n potentially has slightly more
(controlled by pad) bits than given by s.
INPUT:
s -- a string that defines a real number (or something whose
string representation defines a number)
upper -- (default: None) -- upper endpoint of interval if given, in
which case s is the lower endpoint.
base -- an integer between 2 and 36
pad -- an integer >= 0.
min_prec -- number will have at least this many bits of
precision, no matter what.
EXAMPLES:
sage: RealInterval('2.3')
[2.2999999999999998 .. 2.3000000000000003]
sage: RealInterval(10)
[10.000000000000000 .. 10.000000000000000]
sage: RealInterval('1.0000000000000000000000000000000000')
[1.000000000000000000000000000000000000 .. 1.000000000000000000000000000000000000]
sage: RealInterval(29308290382930840239842390482, 3^20)
[3486784401.00000000000000000000 .. 29308290382930840239842390482.0]
- RealNumber = create_RealNumber(...)
- File: sage/rings/real_mpfr.pyx (starting at line 2963)
Return the real number defined by the string s as an element of
\code{RealField(prec=n)}, where n potentially has slightly more
(controlled by pad) bits than given by s.
INPUT:
s -- a string that defines a real number (or something whose
string representation defines a number)
base -- an integer between 2 and 36
pad -- an integer >= 0.
rnd -- rounding mode: RNDN, RNDZ, RNDU, RNDD
min_prec -- number will have at least this many bits of precision, no matter what.
EXAMPLES:
sage: RealNumber('2.3')
2.30000000000000
sage: RealNumber(10)
10.0000000000000
sage: RealNumber('1.0000000000000000000000000000000000')
1.0000000000000000000000000000000000
- RealQuadDoubleField(...)
- File: sage/rings/real_rqdf.pyx (starting at line 1735)
- WaveletTransform(...)
- File: sage/gsl/dwt.pyx (starting at line 33)
This function initializes an GSLDoubleArray of length n which
can perform a discrete wavelet transform.
INPUT:
n -- a power of 2.
T -- the data in the GSLDoubleArray must be real.
wavelet_type -- the name of the type of wavelet,
valid choices are:
'daubechies','daubechies_centered',
'haar','haar_centered','bspline', and
'bspline_centered'.
For daubechies wavelets, wavelet_k specifies a daubechie wavelet
with k/2 vanishing moments. k = 4,6,...,20 for k even are the
only ones implemented.
For Haar wavelets, wavelet_k must be 2.
For bspline wavelets, wavelet_k = 103,105,202,204,206,208,301,305,
307,309 will give biorthogonal B-spline wavelets of order (i,j) where
wavelet_k=100*i+j.
The wavelet transfrom uses J=log_2(n) levels.
OUTPUT:
An array of the form
(s_{-1,0},d_{0,0},d_{1,0},d_{1,1}, d_{2,0}...,d_{J-1,2^{J-1}-1})
for d_{j,k} the detail coefficients of level j.
The centered forms align the coefficients of the sub-bands on edges.
EXAMPLES:
sage: a = WaveletTransform(128,'daubechies',4)
sage: for i in range(1, 11):
... a[i] = 1
... a[128-i] = 1
sage: a.plot().show(ymin=0)
sage: a.forward_transform()
sage: a.plot().show()
sage: a = WaveletTransform(128,'haar',2)
sage: for i in range(1, 11): a[i] = 1; a[128-i] = 1
sage: a.forward_transform()
sage: a.plot().show(ymin=0)
sage: a = WaveletTransform(128,'bspline_centered',103)
sage: for i in range(1, 11): a[i] = 1; a[100+i] = 1
sage: a.forward_transform()
sage: a.plot().show(ymin=0)
This example gives a simple example of wavelet compression.
sage: a = DWT(2048,'daubechies',6)
sage: for i in range(2048): a[i]=float(sin((i*5/2048)**2))
sage: a.plot().show()
sage: a.forward_transform()
sage: for i in range(1800): a[2048-i-1] = 0
sage: a.backward_transform()
sage: a.plot().show()
- add = sum(...)
- sum(sequence, start=0) -> value
Returns the sum of a sequence of numbers (NOT strings) plus the value
of parameter 'start'. When the sequence is empty, returns start.
- allocatemem(...)
- File: sage/libs/pari/gen.pyx (starting at line 5943)
Double the \emph{PARI} stack.
- bernoulli_mod_p(...)
- File: sage/rings/bernoulli_mod_p.pyx (starting at line 85)
Returns the bernoulli numbers $B_0, B_2, ... B_{p-3}$ modulo $p$.
INPUT:
p -- integer, a prime
OUTPUT:
list -- Bernoulli numbers modulo $p$ as a list
of integers [B(0), B(2), ... B(p-3)].
ALGORITHM:
Described in accompanying latex file.
PERFORMANCE:
Should be complexity $O(p \log p)$.
EXAMPLES:
Check the results against PARI's C-library implemention (that
computes exact rationals) for $p = 37$:
sage: bernoulli_mod_p(37)
[1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2]
sage: [bernoulli(n) % 37 for n in xrange(0, 36, 2)]
[1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2]
Boundary case:
sage: bernoulli_mod_p(3)
[1]
AUTHOR:
-- David Harvey (2006-08-06)
- bernoulli_mod_p_single(...)
- File: sage/rings/bernoulli_mod_p.pyx (starting at line 211)
Returns the bernoulli number $B_k$ mod $p$.
INPUT:
p -- integer, a prime
k -- even integer in the range $0 \leq k \leq p-3$
OUTPUT:
The $k$-th bernoulli number mod $p$.
ALGORITHM:
Uses the identity
$$ (1-g^k) B_k/k = 2\sum_{r=1}^{(p-1)/2} g^{r(k-1)} ( [g^r/p] - g [g^(r-1)/p] + (g-1)/2 ), $$
where $g$ is a primitive root mod $p$, and where square brackets
denote the fractional part. This identity can be derived from
Theorem 2.3, chapter 2 of Lang's book "Cyclotomic fields".
PERFORMANCE:
Linear in $p$. In particular the running time doesn't depend on k.
It's much faster than computing *all* bernoulli numbers by using
bernoulli_mod_p(). For p = 1000003, the latter takes about 3s on my
laptop, whereas this function takes only 0.06s.
It may or may not be faster than computing literally bernoulli(k) % p,
depending on how big k and p are relative to each other. For example on
my laptop, computing bernoulli(2000) % p only takes 0.01s. But
computing bernoulli(100000) % p takes 40s, whereas this function still
takes only 0.06s.
EXAMPLES:
sage: bernoulli_mod_p_single(1009, 48)
628
sage: bernoulli(48) % 1009
628
sage: bernoulli_mod_p_single(1, 5)
Traceback (most recent call last):
...
ValueError: p (=1) must be a prime >= 3
sage: bernoulli_mod_p_single(100, 4)
Traceback (most recent call last):
...
ValueError: p (=100) must be a prime
sage: bernoulli_mod_p_single(19, 5)
Traceback (most recent call last):
...
ValueError: k (=5) must be even
sage: bernoulli_mod_p_single(19, 18)
Traceback (most recent call last):
...
ValueError: k (=18) must be non-negative, and at most p-3
sage: bernoulli_mod_p_single(19, -4)
Traceback (most recent call last):
...
ValueError: k (=-4) must be non-negative, and at most p-3
Check results against bernoulli_mod_p:
sage: bernoulli_mod_p(37)
[1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2]
sage: [bernoulli_mod_p_single(37, n) % 37 for n in xrange(0, 36, 2)]
[1, 31, 16, 15, 16, 4, 17, 32, 22, 31, 15, 15, 17, 12, 29, 2, 0, 2]
sage: bernoulli_mod_p(31)
[1, 26, 1, 17, 1, 9, 11, 27, 14, 23, 13, 22, 14, 8, 14]
sage: [bernoulli_mod_p_single(31, n) % 31 for n in xrange(0, 30, 2)]
[1, 26, 1, 17, 1, 9, 11, 27, 14, 23, 13, 22, 14, 8, 14]
sage: bernoulli_mod_p(3)
[1]
sage: [bernoulli_mod_p_single(3, n) % 3 for n in xrange(0, 2, 2)]
[1]
sage: bernoulli_mod_p(5)
[1, 1]
sage: [bernoulli_mod_p_single(5, n) % 5 for n in xrange(0, 4, 2)]
[1, 1]
sage: bernoulli_mod_p(7)
[1, 6, 3]
sage: [bernoulli_mod_p_single(7, n) % 7 for n in xrange(0, 6, 2)]
[1, 6, 3]
AUTHOR:
-- David Harvey (2007-08-31)
- bin_op(...)
- File: sage/structure/element.pyx (starting at line 2643)
- canonical_coercion(...)
- File: sage/structure/element.pyx (starting at line 2622)
canonical_coercion(x,y) is what is called before doing an
arithmetic operation between x and y. It returns a pair (z,w)
such that z is got from x and w from y via canonical coercion and
the parents of z and w are identical.
EXAMPLES:
sage: A = Matrix([[0,1],[1,0]])
sage: canonical_coercion(A,1)
([0 1]
[1 0], [1 0]
[0 1])
- clear_vars(...)
- File: sage/calculus/var.pyx (starting at line 113)
Delete all 1-letter symbolic variables that are predefined at
startup of SAGE. Any one-letter global variables that are not
symbolic variables are not cleared.
EXAMPLES:
sage: var('x y z')
(x, y, z)
sage: (x+y)^z
(y + x)^z
sage: k = 15
sage: clear_vars()
sage: (x+y)^z
Traceback (most recent call last):
...
NameError: name 'x' is not defined
sage: expand((e + i)^2)
2*e*I + e^2 - 1
sage: k
15
- crt_basis(...)
- File: sage/rings/integer_ring.pyx (starting at line 658)
Compute and return a Chinese Remainder Theorem basis for the list
X of coprime integers.
INPUT:
X -- a list of Integers that are coprime in pairs
OUTPUT:
E -- a list of Integers such that E[i] = 1 (mod X[i])
and E[i] = 0 (mod X[j]) for all j!=i.
The E[i] have the property that if A is a list of objects, e.g.,
integers, vectors, matrices, etc., where A[i] is moduli X[i], then
a CRT lift of A is simply
sum E[i] * A[i].
ALGORITHM:
To compute E[i], compute integers s and t such that
s * X[i] + t * (prod over i!=j of X[j]) = 1. (*)
Then E[i] = t * (prod over i!=j of X[j]). Notice that equation
(*) implies that E[i] is congruent to 1 modulo X[i] and to 0
modulo the other X[j] for j!=i.
COMPLEXITY: We compute len(X) extended GCD's.
EXAMPLES:
sage: X = [11,20,31,51]
sage: E = crt_basis([11,20,31,51])
sage: E[0]%X[0]; E[1]%X[0]; E[2]%X[0]; E[3]%X[0]
1
0
0
0
sage: E[0]%X[1]; E[1]%X[1]; E[2]%X[1]; E[3]%X[1]
0
1
0
0
sage: E[0]%X[2]; E[1]%X[2]; E[2]%X[2]; E[3]%X[2]
0
0
1
0
sage: E[0]%X[3]; E[1]%X[3]; E[2]%X[3]; E[3]%X[3]
0
0
0
1
- cython(...)
- File: sage/misc/cython_c.pyx (starting at line 4)
Given a block of CYTHON (SAGE's variant of Pyrex) code (as a text
string), this function compiles it using your C compiler, and
includes it into the global scope of the module that called this
function.
WARNING: Only use this from Python code, not from extension code,
since from extension code you would change the global scope (i.e.,
of the SAGE interpreter). And it would be stupid, since you're
already writing Cython!
Also, never use this in the standard SAGE library. Any code that
uses this can only run on a system that has a C compiler
installed, and we want to avoid making that assumption for casual
SAGE usage. Also, any code that uses this in the library would
greatly slow down startup time, since currently there is no
caching.
AUTHOR: William Stein, 2006-10-31
TODO: Need to create a clever caching system so code only gets
compiled once.
- dumps(...)
- File: sage/structure/sage_object.pyx (starting at line 488)
dumps(obj):
Dump obj to a string s. To recover obj, use loads(s).
EXAMPLES:
sage: a = 2/3
sage: s = dumps(a)
sage: print len(s)
49
sage: loads(s)
2/3
- expnums(...)
- File: sage/combinat/expnums.pyx (starting at line 17)
Compute the first $n$ exponential numbers around $aa$, starting
with the zero-th.
INPUT:
n -- C machine int
aa -- C machine int
OUTPUT:
A list of length $n$.
ALGORITHM: We use the same integer addition algorithm as GAP.
This is an extension of Bell's triangle to the general case of
exponential numbers. The recursion performs $O(n^2)$ additions,
but the running time is dominated by the cost of the last integer
addition, because the growth of the integer results of partial
computations is exponential in $n$. The algorithm stores $O(n)$
integers, but each is exponential in $n$.
EXAMPLES:
sage: expnums(10, 1)
[1, 1, 2, 5, 15, 52, 203, 877, 4140, 21147]
sage: expnums(10, -1)
[1, -1, 0, 1, 1, -2, -9, -9, 50, 267]
sage: expnums(1, 1)
[1]
sage: expnums(0, 1)
[]
sage: expnums(-1, 0)
[]
AUTHOR:
-- Nick Alexander
- fqmodule(arg0=None, arg1=None, **args)
- Create an instance of the class quad_module.
INPUT
Supported formats
1. fgmodule():
the trivial quadratic module
2. fgmodule( list):
discriminant module constructed from the diagonal matrix
with the integers in list on its diagonal.
3. fgmodule( matrix):
discriminant module constructed from a regular
symmetric half integral matrix.
4. fgmodule( list_of_orders, list_of_coeffs):
for a list of orders $[e_i]$ of size $n$ and a list of
coeficients $[a_{ij}]$, the quadratic module
$(\ZZ/e_1\times\cdots\times\ZZ/e_n,class(x)\mapsto\sum_{i\le j} a_{ij} x_i x_j)$.
5. fgmodule( list_of_orders, Gram_matrix):
for a list of orders $[e_i]$ of size $n$ and a
symmetric matric $G$, the quadratic module
$(\ZZ/e_1 \times \cdots \times \ZZ/e_n, class(x) \mapsto G[x] + \ZZ)$.
6. fgmodule( matrix, list_of_coeffs):
for a matrix $M$ of size $n$ and a list of coeficients
$[a_{ij}]$, the quadratic module
$(\ZZ^n/M\ZZ^n, x+M\ZZ^n \mapsto \sum_{i\le j} a_{ij} x_i x_j)$.
7. fgmodule( matrix, Gram_matrix):
for a matrix $M$ and a symmetric matric $G$, the
quadratic module $(\ZZ^n/M\ZZ^n, x+M\ZZ^n \mapsto G[x] + \ZZ)$.
( --- Hatice: ---
8. fgmodule( number_field_element)
For a nonzero $\omega$ in a numberfield $K$,
the quadratic module $(\ZZ_K/A, x+A \mapsto tr( \omega x^2) + \ZZ)$,
where $A$ is determined by
$\omega D^{-1} = B/A$ with relatively prime ideals $A$, $B$,
and with $D$ denoting the different of $K$.
)
EXAMPLES
sage: phi0 = fqmodule(); phi0
Finite quadratic module ([1],0)
sage: phi1 = fqmodule([2,5]); phi1
Finite quadratic module ([20, 2],7/40*x0^2 + 1/2*x0*x1 + 1/4*x1^2)
sage: F=matrix(3,3,[1,1/2,3/2,1/2,2,1/2,3/2,1/2,1]); F
[ 1 1/2 3/2]
[1/2 2 1/2]
[3/2 1/2 1]
sage: phi2 = fqmodule(F); phi2
Finite quadratic module ([18],29/36*x^2)
sage: phi3 = fqmodule([3,4,30],[1/3,0,1/3,1/8,5/2,7/60]); phi3
Finite quadratic module ([60, 6],49/120*x0^2 + 1/3*x0*x1 + 11/12*x1^2)
- free_module_element = vector(...)
- File: sage/modules/free_module_element.pyx (starting at line 100)
Return a vector over R with given entries.
CALL FORMATS:
1. vector(object)
2. vector(ring, object)
3. vector(object, ring)
4. vector(numpy_array)
In each case, give sparse=[True|False] as an option.
INPUT:
elts -- entries of a vector (either a list or dict).
R -- ring
sparse -- optional
OUTPUT:
An element of the free module over R of rank len(elts).
EXAMPLES:
sage: v = vector([1,2,3]); v
(1, 2, 3)
sage: v.parent()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
sage: v = vector([1,2,3/5]); v
(1, 2, 3/5)
sage: v.parent()
Vector space of dimension 3 over Rational Field
All entries must \emph{canonically} coerce to some common ring:
sage: v = vector([17, GF(11)(5), 19/3]); v
Traceback (most recent call last):
...
TypeError: unable to find a common ring for all elements
sage: v = vector([17, GF(11)(5), 19]); v
(6, 5, 8)
sage: v.parent()
Vector space of dimension 3 over Finite Field of size 11
sage: v = vector([17, GF(11)(5), 19], QQ); v
(17, 5, 19)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector((1,2,3), QQ); v
(1, 2, 3)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector(QQ, (1,2,3)); v
(1, 2, 3)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector(vector([1,2,3])); v
(1, 2, 3)
sage: v.parent()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
You can also use \code{free_module_element}, which is the same as \code{vector}.
sage: free_module_element([1/3, -4/5])
(1/3, -4/5)
Make a vector mod 3 out of a vector over ZZ:
sage: vector(vector([1,2,3]), GF(3))
(1, 2, 0)
Any 1 dimensional numpy array of type float or complex may be passed to vector. The result
will vector in the appropriate dimensional vector space over the real double field or the
complex double field. The data in the array must be contiguous so columnwise slices of numpy matrices
will rase an exception.
sage: import numpy
sage: x=numpy.random.randn(10)
sage: y=vector(x)
sage: v=numpy.random.randn(10)*numpy.complex(0,1)
sage: w=vector(v)
- function(...)
- File: sage/calculus/var.pyx (starting at line 62)
Create a formal symbolic function with the name \emph{s}.
INPUT:
s -- a string, either a single variable name,
or a space or comma separated list of
variable names.
NOTE: The new function is both returned and automatically injected
into the global namespace. If you use var in library code, it is
better to use sage.calculus.calculus.function, since it won't
touch the global namespace.
EXAMPLES:
We create a formal function called supersin.
sage: f = function('supersin', x)
sage: f
supersin(x)
We can immediately use supersin in symbolic expressions:
sage: y, z, A = var('y z A')
sage: supersin(y+z) + A^3
A^3 + supersin(z + y)
We can define other functions in terms of supersin.
sage: g(x,y) = supersin(x)^2 + sin(y/2)
sage: g
(x, y) |--> sin(y/2) + supersin(x)^2
sage: g.diff(y)
(x, y) |--> cos(y/2)/2
sage: g.diff(x)
(x, y) |--> 2*supersin(x)*diff(supersin(x), x, 1)
sage: k = g.diff(x); k
(x, y) |--> 2*supersin(x)*diff(supersin(x), x, 1)
sage: k.substitute(supersin=sin)
2*cos(x)*sin(x)
- getrandbits(...)
- getrandbits(k) -> x. Generates a long int with k random bits.
- inject_off(...)
- File: sage/ext/interactive_constructors_c.pyx (starting at line 84)
- inject_on(...)
- File: sage/ext/interactive_constructors_c.pyx (starting at line 15)
Replace several constructors by versions that inject their
variables into the global namespace.
INPUT:
verbose -- (default: True) if True, print which constructors
become interactive, and also print variables as
they are implicitly defined.
EXAMPLES:
sage: inject_on(verbose=True)
Redefining: Frac FreeMonoid GF FractionField FiniteField PolynomialRing quotient NumberField LaurentSeriesRing quo
sage: GF(9,'b')
Defining b
Finite Field in b of size 3^2
sage: b^3
2*b + 1
sage: inject_off()
sage: GF(9,'c')
Finite Field in c of size 3^2
sage: c^3
Traceback (most recent call last):
...
NameError: name 'c' is not defined
sage: inject_on(verbose=False)
sage: GF(9,'c')
Finite Field in c of size 3^2
sage: c^3
2*c + 1
ROLL YOUR OWN: If a constructor you would like to auto inject
variables isn't made to do so by running this command your options
are:
(1) Make your own constructor (factory function) using the explicit
inject_variables() method. This is *very* easy:
sage: def poly(*args, **kwds):
... R = PolynomialRing(*args, **kwds)
... R.inject_variables()
... return R
sage: R = poly(QQ, 'z')
Defining z
sage: z^3 + 3
z^3 + 3
(2) Add code to do it to devel/sage/sage/ext/interactive_constructors_c.pyx,
rebuild SAGE (with sage -br), and send William Stein a patch :-).
- integral_numerical = numerical_integral(...)
- File: sage/gsl/integration.pyx (starting at line 59)
Returns the numerical integral of the function on the interval
from xmin to xmax and an error bound.
EXAMPLES:
To integrate the function $x^2$ from 0 to 1, we do
sage: numerical_integral(lambda x: x^2, 0, 1, max_points=100)
(0.33333333333333331, 3.7007434154171879e-15)
To integrate the function $\sin(x)^3 + \sin(x)$ we do
sage: numerical_integral(lambda x: sin(x)^3 + sin(x), 0, pi)
(3.333333333333333, 3.7007434154171883e-14)
We check this with a symbolic integration:
sage: (sin(x)^3+sin(x)).integral(x,0,pi)
10/3
INPUT:
-- a, b: The interval of integration, specified as two numbers
or a as a tuple/list with the first element the lower bound
and the second element the upper bound. Use
'+inf' and '-inf' for plus or minus infinity.
-- algorithm: valid choices are
'qag' -- for an adaptive integration
'qng' -- for a non-adaptive gauss kronrod (samples at a maximum of 87pts)
-- max_points: sets the maximum number of sample points
-- params: used to pass parameters to your function
-- eps_abs, eps_rel: absolute and relative error tolerances
-- rule: This controls the Gauss-Kronrod rule used in the adaptive integration
rule=1: 15 pt rule
rule=2: 21 pt rule
rule=3: 31 pt rule
rule=4: 41 pt rule
rule=5: 51 pt rule
rule=6: 61 pt rule
Higher key values are more accurate for smooth functions but lower
key values deal better with discontinuities.
OUTPUT:
numerical_integral returns a tuple whose first component is
the answer and whose second component is an error estimate.
REMARK:
There is also a method \code{nintegral} on symbolic expressions
that implements numerical integration using Maxima. It is potentially
very useful for symbolic expressions.
MORE EXAMPLES:
If we want to change the error tolerances and gauss rule used
sage: f = lambda x: x^2
sage: numerical_integral(f, 0, 1, max_points=200, eps_abs=1e-7, eps_rel=1e-7, rule=4)
(0.33333333333333331, 3.7007434154171879e-15)
For a Python function with parameters:
sage: f = lambda x, a:1.0/(a[0]+x**2)
sage: [numerical_integral(f, 1, 2, max_points=100, params=[n]) for n in range(10)] # slightly random output (architecture and os dependent)
[(0.49999999999998657, 5.5511151231256336e-15),
(0.32175055439664557, 3.5721487367706477e-15),
(0.24030098317249229, 2.6678768435816325e-15),
(0.19253082576711697, 2.1375215571674764e-15),
(0.16087527719832367, 1.7860743683853337e-15),
(0.13827545676349412, 1.5351659583939151e-15),
(0.12129975935702741, 1.3466978571966261e-15),
(0.10806674191683065, 1.1997818507228991e-15),
(0.09745444625548845, 1.0819617008493815e-15),
(0.088750683050217577, 9.8533051773561173e-16)]
Note the parameters are always a tuple even if they have one component.
It is possible to perform on infinite intervals as well by using
'inf' or '-inf' in the interval argument. For example,
sage: f = lambda x: float(exp(RR(-x)))
sage: numerical_integral(f, 0, 'inf') # slightly random output
(0.99999999999957279, 1.8429811298996553e-07)
Note the coercion to the real field RR, which prevents underflow.
sage: f = lambda x: float(exp(RR(-x**2)))
sage: numerical_integral(f,'-inf', 'inf') # slightly random output
(1.7724538509060035, 3.4295192165889879e-08)
One can integrate any real-valued callable function:
sage: numerical_integral(lambda x: abs(zeta(x)), [1.1,1.5]) # slightly random output
(1.8488570602160455, 2.052643677492633e-14)
We can also numerically integrate symbolic expressions using either this
function (which uses GSL) or the native integration (which uses Maxima):
sage: exp(-1/x).nintegral(x, 1, 2) # via maxima
(0.50479221787318396, 5.6043194293440752e-15, 21, 0)
sage: numerical_integral(exp(-1/x), 1, 2)
(0.50479221787318407, 5.6043194293440744e-15)
IMPLEMENTATION NOTES:
Uses calls to the GSL -- the GNU Scientific Library -- C library.
AUTHORS:
-- Josh Kantor
-- William Stein
- is_AdditiveGroupElement(...)
- File: sage/structure/element.pyx (starting at line 1143)
Return True if x is of type AdditiveGroupElement.
- is_AlgebraElement(...)
- File: sage/structure/element.pyx (starting at line 2580)
Return True if x is of type AlgebraElement.
- is_CommutativeAlgebraElement(...)
- File: sage/structure/element.pyx (starting at line 2589)
Return True if x is of type CommutativeAlgebraElement.
- is_CommutativeRingElement(...)
- File: sage/structure/element.pyx (starting at line 1601)
Return True if x is of type CommutativeRingElement.
- is_ComplexDoubleElement(...)
- File: sage/rings/complex_double.pyx (starting at line 348)
- is_ComplexNumber(...)
- File: sage/rings/complex_number.pyx (starting at line 39)
- is_DedekindDomainElement(...)
- File: sage/structure/element.pyx (starting at line 2127)
Return True if x is of type DedekindDomainElement.
- is_Element(...)
- File: sage/structure/element.pyx (starting at line 247)
Return True if x is of type Element.
EXAMPLES:
sage: is_Element(2/3)
True
sage: is_Element(QQ^3)
False
- is_EuclideanDomainElement(...)
- File: sage/structure/element.pyx (starting at line 2176)
Return True if x is of type EuclideanDomainElement.
- is_Field(...)
- File: sage/rings/ring.pyx (starting at line 963)
Return True if x is a field.
EXAMPLES:
sage: is_Field(QQ)
True
sage: is_Field(ZZ)
False
sage: is_Field(pAdicField(2))
True
sage: is_Field(5)
False
- is_FieldElement(...)
- File: sage/structure/element.pyx (starting at line 2238)
Return True if x is of type FieldElement.
- is_FiniteField(...)
- File: sage/rings/ring.pyx (starting at line 1572)
Return True if x is of type finite field, and False otherwise.
EXAMPLES:
sage: is_FiniteField(GF(9,'a'))
True
sage: is_FiniteField(GF(next_prime(10^10)))
True
Note that the integers modulo n are not of type finite field,
so this function returns False:
sage: is_FiniteField(Integers(7))
False
- is_FreeModuleElement(...)
- File: sage/modules/free_module_element.pyx (starting at line 97)
- is_Functor(...)
- File: sage/categories/functor.pyx (starting at line 76)
- is_InfinityElement(...)
- File: sage/structure/element.pyx (starting at line 2598)
Return True if x is of type InfinityElement.
- is_Integer(...)
- File: sage/rings/integer.pyx (starting at line 165)
Return true if x is of the SAGE integer type.
EXAMPLES:
sage: is_Integer(2)
True
sage: is_Integer(2/1)
False
sage: is_Integer(int(2))
False
sage: is_Integer(long(2))
False
sage: is_Integer('5')
False
- is_IntegerMod(...)
- File: sage/rings/integer_mod.pyx (starting at line 128)
Return try if and only if x is an integer modulo n.
EXAMPLES:
sage: is_IntegerMod(5)
False
sage: is_IntegerMod(Mod(5,10))
True
- is_IntegralDomainElement(...)
- File: sage/structure/element.pyx (starting at line 2116)
Return True if x is of type IntegralDomainElement.
- is_LaurentSeries(...)
- File: sage/rings/laurent_series_ring_element.pyx (starting at line 61)
- is_MPolynomialRing(...)
- File: sage/rings/polynomial/multi_polynomial_ring_generic.pyx (starting at line 13)
- is_Matrix(...)
- File: sage/structure/element.pyx (starting at line 2113)
- is_Module(...)
- File: sage/modules/module.pyx (starting at line 65)
Return True if x is a module.
EXAMPLES:
sage: M = FreeModule(RationalField(),30)
sage: is_Module(M)
True
sage: is_Module(10)
False
- is_ModuleElement(...)
- File: sage/structure/element.pyx (starting at line 666)
Return True if x is of type ModuleElement.
This is even faster than using isinstance inline.
EXAMPLES:
sage: is_ModuleElement(2/3)
True
sage: is_ModuleElement((QQ^3).0)
True
sage: is_ModuleElement('a')
False
- is_MonoidElement(...)
- File: sage/structure/element.pyx (starting at line 1059)
Return True if x is of type MonoidElement.
- is_Morphism(...)
- File: sage/categories/morphism.pyx (starting at line 42)
- is_MultiplicativeGroupElement(...)
- File: sage/structure/element.pyx (starting at line 1176)
Return True if x is of type MultiplicativeGroupElement.
- is_NumberField(...)
- File: sage/rings/number_field/number_field_base.pyx (starting at line 10)
Return True if x is of number field type.
EXAMPLES:
sage: is_NumberField(NumberField(x^2+1,'a'))
True
sage: is_NumberField(QuadraticField(-97,'theta'))
True
sage: is_NumberField(CyclotomicField(97))
True
Note that the rational numbers QQ are a number field.
sage: is_NumberField(QQ)
True
sage: is_NumberField(ZZ)
False
- is_NumberFieldElement(...)
- File: sage/rings/number_field/number_field_element.pyx (starting at line 71)
Return True if x is of type NumberFieldElement, i.e., an
element of a number field.
EXAMPLES:
sage: is_NumberFieldElement(2)
False
sage: k.<a> = NumberField(x^7 + 17*x + 1)
sage: is_NumberFieldElement(a+1)
True
- is_Parent(...)
- File: sage/structure/parent.pyx (starting at line 33)
Return True if x is a parent object, i.e., derives from
sage.structure.parent.Parent and False otherwise.
EXAMPLES:
sage: is_Parent(2/3)
False
sage: is_Parent(ZZ)
True
sage: is_Parent(Primes())
True
- is_ParentWithAdditiveAbelianGens(...)
- File: sage/structure/parent_gens.pyx (starting at line 81)
Return True if x is a parent object with additive abelian
generators, i.e., derives from
sage.structure.parent.ParentWithAdditiveAbelianGens and False
otherwise.
EXAMPLES:
sage: is_ParentWithAdditiveAbelianGens(QQ)
False
sage: is_ParentWithAdditiveAbelianGens(QQ^3)
True
- is_ParentWithBase(...)
- File: sage/structure/parent_base.pyx (starting at line 36)
Return True if x is a parent object with base.
- is_ParentWithGens(...)
- File: sage/structure/parent_gens.pyx (starting at line 66)
Return True if x is a parent object with generators, i.e., derives
from sage.structure.parent.ParentWithGens and False otherwise.
EXAMPLES:
sage: is_ParentWithGens(QQ['x'])
True
sage: is_ParentWithGens(CC)
True
sage: is_ParentWithGens(Primes())
False
- is_ParentWithMultiplicativeAbelianGens(...)
- File: sage/structure/parent_gens.pyx (starting at line 96)
Return True if x is a parent object with additive abelian
generators, i.e., derives from
sage.structure.parent.ParentWithMultiplicativeAbelianGens and False
otherwise.
EXAMPLES:
sage: is_ParentWithMultiplicativeAbelianGens(QQ)
False
sage: is_ParentWithMultiplicativeAbelianGens(DirichletGroup(11))
True
- is_Polynomial(...)
- File: sage/rings/polynomial/polynomial_element.pyx (starting at line 67)
- is_PowerSeries(...)
- File: sage/rings/power_series_ring_element.pyx (starting at line 111)
- is_PrincipalIdealDomainElement(...)
- File: sage/structure/element.pyx (starting at line 2136)
Return True if x is of type PrincipalIdealDomainElement.
- is_RealDoubleElement(...)
- File: sage/rings/real_double.pyx (starting at line 1522)
- is_RealField(...)
- File: sage/rings/real_mpfr.pyx (starting at line 3008)
- is_RealIntervalField(...)
- File: sage/rings/real_mpfi.pyx (starting at line 2803)
- is_RealIntervalFieldElement(...)
- File: sage/rings/real_mpfi.pyx (starting at line 2806)
- is_RealNumber(...)
- File: sage/rings/real_mpfr.pyx (starting at line 3011)
Return True if x is of type RealNumber, meaning that it is an
element of the MPFR real field with some precision.
EXAMPLES:
sage: is_RealNumber(2.5)
True
sage: is_RealNumber(float(2.3))
False
sage: is_RealNumber(RDF(2))
False
sage: is_RealNumber(pi)
False
- is_Ring(...)
- File: sage/rings/ring.pyx (starting at line 1624)
Return true if x is a ring.
EXAMPLES:
sage: is_Ring(ZZ)
True
- is_RingElement(...)
- File: sage/structure/element.pyx (starting at line 1231)
Return True if x is of type RingElement.
- is_RingHomomorphism(...)
- File: sage/rings/morphism.pyx (starting at line 338)
- is_Vector(...)
- File: sage/structure/element.pyx (starting at line 1917)
- is_VectorSpace(...)
- File: sage/modules/module.pyx (starting at line 78)
Return True if x is a vector space.
EXAMPLES:
sage: M = FreeModule(RationalField(),30)
sage: is_VectorSpace(M)
True
sage: M = FreeModule(IntegerRing(),30)
sage: is_Module(M)
True
sage: is_VectorSpace(M)
False
- jumpahead(...)
- jumpahead(int) -> None. Create new state from existing state and integer.
- lift_to_sl2z(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 617)
Return a list of Python ints [a,b,c',d'] that are the entries of a
2x2 matrix with determinant 1 and lower two entries congruent to
c,d modulo N.
EXAMPLES:
sage: lift_to_sl2z(2,3,6)
[1, 1, 2, 3]
sage: lift_to_sl2z(15,6,24)
[-2, -17, 15, 126]
sage: lift_to_sl2z(15,6,2400000)
[-2L, -320001L, 15L, 2400006L]
- lift_to_sl2z_int(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 507)
Lift a pair (c, d) to an element of SL(2, Z)
(c,d) is assumed to be an element of P1(Z/NZ). This function
computes and returns a list [a, b, c', d'] that defines a 2x2
matrix, with determinant 1 and integer entries, such that
c=c'(mod N) and d=d'(mod N).
EXAMPLES
sage: lift_to_sl2z_int(2,6,11)
[1, 8, 2, 17]
sage: m=Matrix(Integers(),2,2,lift_to_sl2z_int(2,6,11))
sage: m
[ 1 8]
[ 2 17]
AUTHOR:
-- Justin Walker
- lift_to_sl2z_llong(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 562)
Lift a pair (c, d) to an element of SL(2, Z)
(c,d) is assumed to be an element of P1(Z/NZ). This function
computes and returns a list [a, b, c', d'] that defines a 2x2
matrix, with determinant 1 and integer entries, such that
c=c'(mod N) and d=d'(mod N).
EXAMPLES
sage: lift_to_sl2z_llong(2,6,11)
[1L, 8L, 2L, 17L]
sage: m=Matrix(Integers(),2,2,lift_to_sl2z_llong(2,6,11))
sage: m
[ 1 8]
[ 2 17]
AUTHOR:
-- Justin Walker
- load(...)
- File: sage/structure/sage_object.pyx (starting at line 397)
load(filename):
Load \sage object from the file with name filename, which will
have an .sobj extension added if it doesn't have one.
NOTE: There is also a special SAGE command (that is not
available in Python) called load that you use by typing
sage: load filename.sage # not tested
The documentation below is not for that command. The documentation
for load is almost identical to that for attach. Type attach? for
help on attach.
This also loads a ".sobj" file over a network by specifying the full URL.
(Setting "verbose = False" suppresses the loading progress indicator.)
EXAMPLE:
sage: u = 'http://sage.math.washington.edu/home/was/db/test.sobj' # optional
sage: s = load(u) # optional
Attempting to load remote file: http://sage.math.washington.edu/home/was/db/test.sobj
Loading: [.]
sage: s # optional
'hello SAGE'
- loads(...)
- File: sage/structure/sage_object.pyx (starting at line 510)
Recover an object x that has been dumped to a string s
using s = dumps(x).
EXAMPLES:
sage: a = matrix(2, [1,2,3,-4/3])
sage: s = dumps(a)
sage: loads(s)
[ 1 2]
[ 3 -4/3]
- mod = Mod(...)
- File: sage/rings/integer_mod.pyx (starting at line 75)
Return the equivalence class of n modulo m as an element of
$\Z/m\Z$.
EXAMPLES:
sage: x = Mod(12345678, 32098203845329048)
sage: x
12345678
sage: x^100
1017322209155072
You can also use the lowercase version:
sage: mod(12,5)
2
- mul = prod(...)
- File: sage/misc/misc_c.pyx (starting at line 24)
Return the product of the elements in the list x. If optional
argument z is not given, start the product with the first element
of the list, otherwise use z. The empty product is the int 1 if z
is not specified, and is z if given.
This assumes that your multiplication is associative; we don't promise
which end of the list we start at.
EXAMPLES:
sage: prod([1,2,34])
68
sage: prod([2,3], 5)
30
sage: prod((1,2,3), 5)
30
sage: F = factor(-2006); F
-1 * 2 * 17 * 59
sage: prod(F)
-2006
AUTHORS:
Joel B. Mohler (2007-10-03 -- Reimplemented in Cython and optimized)
Robert Bradshaw (2007-10-26) -- Balanced product tree, other optimizations, (lazy) generator support
- mwrank_initprimes = initprimes(...)
- File: sage/libs/mwrank/mwrank.pyx (starting at line 102)
mwrank_initprimes(filename, verb=False):
INPUT:
filename -- (string) the name of a file of primes
verb -- (bool: default False) verbose or not?
EXAMPLES:
sage: file= SAGE_TMP + '/PRIMES'
sage: open(file,'w').write(' '.join([str(p) for p in prime_range(10^6)]))
sage: mwrank_initprimes(file, verb=False)
sage: mwrank_initprimes("x" + file, True)
Traceback (most recent call last):
...
IOError: No such file or directory: ...
- numerical_integral(...)
- File: sage/gsl/integration.pyx (starting at line 59)
Returns the numerical integral of the function on the interval
from xmin to xmax and an error bound.
EXAMPLES:
To integrate the function $x^2$ from 0 to 1, we do
sage: numerical_integral(lambda x: x^2, 0, 1, max_points=100)
(0.33333333333333331, 3.7007434154171879e-15)
To integrate the function $\sin(x)^3 + \sin(x)$ we do
sage: numerical_integral(lambda x: sin(x)^3 + sin(x), 0, pi)
(3.333333333333333, 3.7007434154171883e-14)
We check this with a symbolic integration:
sage: (sin(x)^3+sin(x)).integral(x,0,pi)
10/3
INPUT:
-- a, b: The interval of integration, specified as two numbers
or a as a tuple/list with the first element the lower bound
and the second element the upper bound. Use
'+inf' and '-inf' for plus or minus infinity.
-- algorithm: valid choices are
'qag' -- for an adaptive integration
'qng' -- for a non-adaptive gauss kronrod (samples at a maximum of 87pts)
-- max_points: sets the maximum number of sample points
-- params: used to pass parameters to your function
-- eps_abs, eps_rel: absolute and relative error tolerances
-- rule: This controls the Gauss-Kronrod rule used in the adaptive integration
rule=1: 15 pt rule
rule=2: 21 pt rule
rule=3: 31 pt rule
rule=4: 41 pt rule
rule=5: 51 pt rule
rule=6: 61 pt rule
Higher key values are more accurate for smooth functions but lower
key values deal better with discontinuities.
OUTPUT:
numerical_integral returns a tuple whose first component is
the answer and whose second component is an error estimate.
REMARK:
There is also a method \code{nintegral} on symbolic expressions
that implements numerical integration using Maxima. It is potentially
very useful for symbolic expressions.
MORE EXAMPLES:
If we want to change the error tolerances and gauss rule used
sage: f = lambda x: x^2
sage: numerical_integral(f, 0, 1, max_points=200, eps_abs=1e-7, eps_rel=1e-7, rule=4)
(0.33333333333333331, 3.7007434154171879e-15)
For a Python function with parameters:
sage: f = lambda x, a:1.0/(a[0]+x**2)
sage: [numerical_integral(f, 1, 2, max_points=100, params=[n]) for n in range(10)] # slightly random output (architecture and os dependent)
[(0.49999999999998657, 5.5511151231256336e-15),
(0.32175055439664557, 3.5721487367706477e-15),
(0.24030098317249229, 2.6678768435816325e-15),
(0.19253082576711697, 2.1375215571674764e-15),
(0.16087527719832367, 1.7860743683853337e-15),
(0.13827545676349412, 1.5351659583939151e-15),
(0.12129975935702741, 1.3466978571966261e-15),
(0.10806674191683065, 1.1997818507228991e-15),
(0.09745444625548845, 1.0819617008493815e-15),
(0.088750683050217577, 9.8533051773561173e-16)]
Note the parameters are always a tuple even if they have one component.
It is possible to perform on infinite intervals as well by using
'inf' or '-inf' in the interval argument. For example,
sage: f = lambda x: float(exp(RR(-x)))
sage: numerical_integral(f, 0, 'inf') # slightly random output
(0.99999999999957279, 1.8429811298996553e-07)
Note the coercion to the real field RR, which prevents underflow.
sage: f = lambda x: float(exp(RR(-x**2)))
sage: numerical_integral(f,'-inf', 'inf') # slightly random output
(1.7724538509060035, 3.4295192165889879e-08)
One can integrate any real-valued callable function:
sage: numerical_integral(lambda x: abs(zeta(x)), [1.1,1.5]) # slightly random output
(1.8488570602160455, 2.052643677492633e-14)
We can also numerically integrate symbolic expressions using either this
function (which uses GSL) or the native integration (which uses Maxima):
sage: exp(-1/x).nintegral(x, 1, 2) # via maxima
(0.50479221787318396, 5.6043194293440752e-15, 21, 0)
sage: numerical_integral(exp(-1/x), 1, 2)
(0.50479221787318407, 5.6043194293440744e-15)
IMPLEMENTATION NOTES:
Uses calls to the GSL -- the GNU Scientific Library -- C library.
AUTHORS:
-- Josh Kantor
-- William Stein
- p1_normalize(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 295)
- p1_normalize_int(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 91)
p1_normalize_int(N, u, v):
Computes the canonical representative of $\PP^1(\Z/N\Z)$ equivalent
to $(u,v)$ along with a transforming scalar.
INPUT:
N -- an integer
u -- an integer
v -- an integer
OUTPUT:
If gcd(u,v,N) = 1, then returns
uu -- an integer
vv -- an integer
ss -- an integer
such that (ss*uu, ss*vv) is equivalent to (u,v) mod N
and if gcd(u,v,N) != 1, returns
0, 0, 0
- p1_normalize_llong(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 235)
p1_normalize_llong(N, u, v):
Computes the canonical representative of $\PP^1(\Z/N\Z)$ equivalent
to $(u,v)$ along with a transforming scalar.
INPUT:
N -- an integer
u -- an integer
v -- an integer
OUTPUT:
If gcd(u,v,N) = 1, then returns
uu -- an integer
vv -- an integer
ss -- an integer
such that (ss*uu, ss*vv) is equivalent to (u,v) mod N
and if gcd(u,v,N) != 1, returns
0, 0, 0
- p1list(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 287)
- p1list_int(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 116)
p1list_int(int N):
Make a list of the normalized elements of $\PP^1(\Z/N\Z)$.
- p1list_llong(...)
- File: sage/modular/modsym/p1list.pyx (starting at line 259)
p1list_llong(int N):
Make a list of the normalized elements of $\PP^1(\Z/N\Z)$.
- pmem_malloc(...)
- File: sage/rings/memory.pyx (starting at line 20)
Use our own memory manager for for GMP memory management.
WARNING: Call this before the integer initialization or evil
things might happen.
- prod(...)
- File: sage/misc/misc_c.pyx (starting at line 24)
Return the product of the elements in the list x. If optional
argument z is not given, start the product with the first element
of the list, otherwise use z. The empty product is the int 1 if z
is not specified, and is z if given.
This assumes that your multiplication is associative; we don't promise
which end of the list we start at.
EXAMPLES:
sage: prod([1,2,34])
68
sage: prod([2,3], 5)
30
sage: prod((1,2,3), 5)
30
sage: F = factor(-2006); F
-1 * 2 * 17 * 59
sage: prod(F)
-2006
AUTHORS:
Joel B. Mohler (2007-10-03 -- Reimplemented in Cython and optimized)
Robert Bradshaw (2007-10-26) -- Balanced product tree, other optimizations, (lazy) generator support
- pyrex = cython(...)
- File: sage/misc/cython_c.pyx (starting at line 4)
Given a block of CYTHON (SAGE's variant of Pyrex) code (as a text
string), this function compiles it using your C compiler, and
includes it into the global scope of the module that called this
function.
WARNING: Only use this from Python code, not from extension code,
since from extension code you would change the global scope (i.e.,
of the SAGE interpreter). And it would be stupid, since you're
already writing Cython!
Also, never use this in the standard SAGE library. Any code that
uses this can only run on a system that has a C compiler
installed, and we want to avoid making that assumption for casual
SAGE usage. Also, any code that uses this in the library would
greatly slow down startup time, since currently there is no
caching.
AUTHOR: William Stein, 2006-10-31
TODO: Need to create a clever caching system so code only gets
compiled once.
- random(...)
- random() -> x in the interval [0, 1).
- reset(...)
- File: sage/misc/reset.pyx (starting at line 3)
Delete all user defined variables, reset all globals variables
back to their default state, and reset all interfaces to other
computer algebra systems.
If vars is specified, just restore the value of vars and leave
all other variables alone (i.e., call restore).
INPUT:
vars -- (default: None), a list, or space or comma separated
string.
EXAMPLES:
sage: x = 5
sage: reset()
sage: x
x
- restore(...)
- File: sage/misc/reset.pyx (starting at line 37)
Restore predefined global variables to their default values.
INPUT:
vars -- string or list (default: None) if not None, restores
just the given variables to the default value.
EXAMPLES:
sage: x = 10; y = 15/3; QQ='red'
sage: QQ
'red'
sage: restore('QQ')
sage: QQ
Rational Field
sage: x
10
sage: y = var('y')
sage: restore('x y')
sage: x
x
sage: y
Traceback (most recent call last):
...
NameError: name 'y' is not defined
sage: x = 10; y = 15/3; QQ='red'
sage: ww = 15
sage: restore()
sage: x, QQ, ww
(x, Rational Field, 15)
sage: restore('ww')
sage: ww
Traceback (most recent call last):
...
NameError: name 'ww' is not defined
- sagex = cython(...)
- File: sage/misc/cython_c.pyx (starting at line 4)
Given a block of CYTHON (SAGE's variant of Pyrex) code (as a text
string), this function compiles it using your C compiler, and
includes it into the global scope of the module that called this
function.
WARNING: Only use this from Python code, not from extension code,
since from extension code you would change the global scope (i.e.,
of the SAGE interpreter). And it would be stupid, since you're
already writing Cython!
Also, never use this in the standard SAGE library. Any code that
uses this can only run on a system that has a C compiler
installed, and we want to avoid making that assumption for casual
SAGE usage. Also, any code that uses this in the library would
greatly slow down startup time, since currently there is no
caching.
AUTHOR: William Stein, 2006-10-31
TODO: Need to create a clever caching system so code only gets
compiled once.
- save(...)
- File: sage/structure/sage_object.pyx (starting at line 452)
save(obj, filename=None):
Save obj to the file with name filename, which will
have an .sobj extension added if it doesn't have one.
This will \emph{replace} the contents of filename.
EXAMPLES:
sage: a = matrix(2, [1,2,3,-5/2])
sage: save(a, 'test.sobj')
sage: load('test.sobj')
[ 1 2]
[ 3 -5/2]
sage: E = EllipticCurve([-1,0])
sage: P = plot(E)
sage: save(P, 'test.sobj')
sage: save(P, filename="sage.png", xmin=-2)
sage: load('test.sobj')
Graphics object consisting of 2 graphics primitives
- search(...)
- File: sage/misc/search.pyx (starting at line 28)
Return (True,i) where i is such that v[i] == x if there is such an i,
or (False,j) otherwise, where j is the position that a should be inserted
so that v remains sorted.
INPUT:
v -- a list, which is assumed sorted
x -- Python object
OUTPUT:
bool, int
- sleep(...)
- sleep(seconds)
Delay execution for a given number of seconds. The argument may be
a floating point number for subsecond precision.
- var(...)
- File: sage/calculus/var.pyx (starting at line 3)
Create a symbolic variable with the name \emph{s}.
INPUT:
s -- a string, either a single variable name,
or a space or comma separated list of
variable names.
NOTE: The new variable is both returned and automatically injected
into the global namespace. If you use var in library code, it is
better to use sage.calculus.calculus.var, since it won't touch the
global namespace.
EXAMPLES:
We define some symbolic variables:
sage: var('n xx yy zz')
(n, xx, yy, zz)
Then we make an algebraic expression out of them.
sage: f = xx^n + yy^n + zz^n; f
zz^n + yy^n + xx^n
We can substitute a new variable name for n.
sage: f(n = var('sigma'))
zz^sigma + yy^sigma + xx^sigma
If you make an important builtin variable into a symbolic variable,
you can get back the original value using restore:
sage: var('QQ RR')
(QQ, RR)
sage: QQ
QQ
sage: restore('QQ')
sage: QQ
Rational Field
We make two new variables separated by commas:
sage: var('theta, gamma')
(theta, gamma)
sage: theta^2 + gamma^3
gamma^3 + theta^2
The new variables are of type SymbolicVariable, and belong
to the symbolic expression ring:
sage: type(theta)
<class 'sage.calculus.calculus.SymbolicVariable'>
sage: parent(theta)
Symbolic Ring
- vecsmall_to_intlist(...)
- File: sage/libs/pari/gen.pyx (starting at line 6478)
INPUT:
v -- a gen of type Vecsmall
OUTPUT:
a Python list of Python ints
- vector(...)
- File: sage/modules/free_module_element.pyx (starting at line 100)
Return a vector over R with given entries.
CALL FORMATS:
1. vector(object)
2. vector(ring, object)
3. vector(object, ring)
4. vector(numpy_array)
In each case, give sparse=[True|False] as an option.
INPUT:
elts -- entries of a vector (either a list or dict).
R -- ring
sparse -- optional
OUTPUT:
An element of the free module over R of rank len(elts).
EXAMPLES:
sage: v = vector([1,2,3]); v
(1, 2, 3)
sage: v.parent()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
sage: v = vector([1,2,3/5]); v
(1, 2, 3/5)
sage: v.parent()
Vector space of dimension 3 over Rational Field
All entries must \emph{canonically} coerce to some common ring:
sage: v = vector([17, GF(11)(5), 19/3]); v
Traceback (most recent call last):
...
TypeError: unable to find a common ring for all elements
sage: v = vector([17, GF(11)(5), 19]); v
(6, 5, 8)
sage: v.parent()
Vector space of dimension 3 over Finite Field of size 11
sage: v = vector([17, GF(11)(5), 19], QQ); v
(17, 5, 19)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector((1,2,3), QQ); v
(1, 2, 3)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector(QQ, (1,2,3)); v
(1, 2, 3)
sage: v.parent()
Vector space of dimension 3 over Rational Field
sage: v = vector(vector([1,2,3])); v
(1, 2, 3)
sage: v.parent()
Ambient free module of rank 3 over the principal ideal domain Integer Ring
You can also use \code{free_module_element}, which is the same as \code{vector}.
sage: free_module_element([1/3, -4/5])
(1/3, -4/5)
Make a vector mod 3 out of a vector over ZZ:
sage: vector(vector([1,2,3]), GF(3))
(1, 2, 0)
Any 1 dimensional numpy array of type float or complex may be passed to vector. The result
will vector in the appropriate dimensional vector space over the real double field or the
complex double field. The data in the array must be contiguous so columnwise slices of numpy matrices
will rase an exception.
sage: import numpy
sage: x=numpy.random.randn(10)
sage: y=vector(x)
sage: v=numpy.random.randn(10)*numpy.complex(0,1)
sage: w=vector(v)
|