rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
self._build_code_from_tree(self._tree, d) self._index = dict([(i,e) for i,(e,w) in enumerate(index)]) self._character_to_code = dict([(e,d[i]) for i,(e,w) in enumerate(index)]) | self._build_code_from_tree(self._tree, d, prefix="") self._index = dict((i, s) for i, (s, w) in enumerate(dic.items())) self._character_to_code = dict( (s, d[i]) for i, (s, w) in enumerate(dic.items())) | def _build_code(self, dic): r""" Returns a Huffman code for each one of the given elements. INPUT: - ``dic`` (dictionary) -- associates to each letter of the alphabet a frequency or a number of occurrences. |
Returns an encoding of the given string based on the current encoding table INPUT: - ``string`` (string) EXAMPLE: This is how a string is encoded then decoded :: | Encode the given string based on the current encoding table. INPUT: - ``string`` -- a string of symbols over an alphabet. OUTPUT: - A Huffman encoding of ``string``. EXAMPLES: This is how a string is encoded and then decoded:: | def encode(self, string): r""" Returns an encoding of the given string based on the current encoding table |
return join(map(lambda x:self._character_to_code[x],string), '') | return "".join(map(lambda x: self._character_to_code[x], string)) | def encode(self, string): r""" Returns an encoding of the given string based on the current encoding table |
Returns a decoded version of the given string corresponding to the current encoding table. INPUT: - ``string`` (string) EXAMPLE: This is how a string is encoded then decoded :: | Decode the given string using the current encoding table. INPUT: - ``string`` -- a string of Huffman encodings. OUTPUT: - The Huffman decoding of ``string``. EXAMPLES: This is how a string is encoded and then decoded:: | def decode(self, string): r""" Returns a decoded version of the given string corresponding to the current encoding table. |
ValueError: The given string does not only contain 0 and 1 """ | ValueError: Input must be a binary string. """ | def decode(self, string): r""" Returns a decoded version of the given string corresponding to the current encoding table. |
if i == '0': | if i == "0": | def decode(self, string): r""" Returns a decoded version of the given string corresponding to the current encoding table. |
elif i == '1': | elif i == "1": | def decode(self, string): r""" Returns a decoded version of the given string corresponding to the current encoding table. |
raise ValueError('The given string does not only contain 0 and 1') if not isinstance(tree,list): | raise ValueError("Input must be a binary string.") if not isinstance(tree, list): | def decode(self, string): r""" Returns a decoded version of the given string corresponding to the current encoding table. |
return join(chars, '') | return "".join(chars) | def decode(self, string): r""" Returns a decoded version of the given string corresponding to the current encoding table. |
Returns the current encoding table | Returns the current encoding table. INPUT: - None. | def encoding_table(self): r""" Returns the current encoding table |
A dictionary associating its code to each trained letter of the alphabet EXAMPLE:: sage: from sage.coding.source_coding.huffman import Huffman sage: str = "Sage is my most favorite general purpose computer algebra system" sage: h = Huffman(str) sage: h.encoding_table() {'S': '00000', 'a': '1101', ' ': '101', 'c': '11... | - A dictionary associating an alphabetic symbol to a Huffman encoding. EXAMPLES:: sage: from sage.coding.source_coding.huffman import Huffman sage: str = "Sage is my most favorite general purpose computer algebra system" sage: h = Huffman(str) sage: T = sorted(h.encoding_table().items()) sage: for symbol, code in T: ... | def encoding_table(self): r""" Returns the current encoding table |
Returns the Huffman tree corresponding to the current encoding | Returns the Huffman tree corresponding to the current encoding. INPUT: - None. | def tree(self): r""" Returns the Huffman tree corresponding to the current encoding |
A tree EXAMPLE:: | - The binary tree representing a Huffman code. EXAMPLES:: | def tree(self): r""" Returns the Huffman tree corresponding to the current encoding |
""" | <BLANKLINE> """ | def tree(self): r""" Returns the Huffman tree corresponding to the current encoding |
def _generate_edges(self, tree, father='', id=''): if father=='': u = 'root' | def _generate_edges(self, tree, parent="", bit=""): """ Generate the edges of the given Huffman tree. INPUT: - ``tree`` -- a Huffman binary tree. - ``parent`` -- (default: empty string) a parent vertex with exactly two children. - ``bit`` -- (default: empty string) the bit signifying either the left or right branch... | def _generate_edges(self, tree, father='', id=''): if father=='': u = 'root' else: u = father try: return self._generate_edges(tree[0], father=father+id, id='0') + \ self._generate_edges(tree[1], father=father+id, id='1') + \ ([(u, father+id)] if (father+id) != '' else []) |
u = father | u = parent s = "".join([parent, bit]) | def _generate_edges(self, tree, father='', id=''): if father=='': u = 'root' else: u = father try: return self._generate_edges(tree[0], father=father+id, id='0') + \ self._generate_edges(tree[1], father=father+id, id='1') + \ ([(u, father+id)] if (father+id) != '' else []) |
return self._generate_edges(tree[0], father=father+id, id='0') + \ self._generate_edges(tree[1], father=father+id, id='1') + \ ([(u, father+id)] if (father+id) != '' else []) | left = self._generate_edges(tree[0], parent=s, bit="0") right = self._generate_edges(tree[1], parent=s, bit="1") L = [(u, s)] if s != "" else [] return left + right + L | def _generate_edges(self, tree, father='', id=''): if father=='': u = 'root' else: u = father try: return self._generate_edges(tree[0], father=father+id, id='0') + \ self._generate_edges(tree[1], father=father+id, id='1') + \ ([(u, father+id)] if (father+id) != '' else []) |
return [(u, self.decode(father+id)+' : '+(father+id))] | return [(u, "".join([self.decode(s), ": ", s]))] | def _generate_edges(self, tree, father='', id=''): if father=='': u = 'root' else: u = father try: return self._generate_edges(tree[0], father=father+id, id='0') + \ self._generate_edges(tree[1], father=father+id, id='1') + \ ([(u, father+id)] if (father+id) != '' else []) |
- ``alphabet`` - (default: (1,2)) any container that is suitable to build an instance of OrderedAlphabet (list, tuple, str, ...) | - ``alphabet`` - (default: (1,2)) an iterable of two positive integers | def KolakoskiWord(self, alphabet=(1,2)): r""" Returns the Kolakoski word over the given alphabet and starting with the first letter of the alphabet. |
[1] William Kolakoski, proposal 5304, American Mathematical Monthly 72 (1965), 674; for a partial solution, see "Self Generating Runs," by Necdet Üçoluk, Amer. Math. Mon. 73 (1966), 681-2. """ try: a = int(alphabet[0]) b = int(alphabet[1]) if a <=0 or b <= 0 or a == b: raise ValueError, 'The alphabet (=%s) must consist... | - [1] William Kolakoski, proposal 5304, American Mathematical Monthly 72 (1965), 674; for a partial solution, see "Self Generating Runs," by Necdet Üçoluk, Amer. Math. Mon. 73 (1966), 681-2. """ a, b = alphabet if a not in ZZ or a <= 0 or b not in ZZ or b <= 0 or a == b: msg = 'The alphabet (=%s) must consist of two di... | def KolakoskiWord(self, alphabet=(1,2)): r""" Returns the Kolakoski word over the given alphabet and starting with the first letter of the alphabet. |
def is_prime(n, flag=0): | def is_prime(n): | def is_prime(n, flag=0): r""" Returns True if `x` is prime, and False otherwise. The result is proven correct - *this is NOT a pseudo-primality test!*. INPUT: - ``flag`` - int - ``0`` (default) - use a combination of algorithms. - ``1`` - certify primality using the Pocklington-Lehmer Test. - ``2`` - certify pri... |
Returns True if `x` is prime, and False otherwise. The result is proven correct - *this is NOT a pseudo-primality test!*. INPUT: - ``flag`` - int - ``0`` (default) - use a combination of algorithms. - ``1`` - certify primality using the Pocklington-Lehmer Test. - ``2`` - certify primality using the APRCL test. | Returns ``True`` if `n` is prime, and ``False`` otherwise. AUTHORS: - Kevin Stueve kstueve@uw.edu (2010-01-17): delegated calculation to ``n.is_prime()`` INPUT: - ``n`` - the object for which to determine primality | def is_prime(n, flag=0): r""" Returns True if `x` is prime, and False otherwise. The result is proven correct - *this is NOT a pseudo-primality test!*. INPUT: - ``flag`` - int - ``0`` (default) - use a combination of algorithms. - ``1`` - certify primality using the Pocklington-Lehmer Test. - ``2`` - certify pri... |
- ``bool`` - True or False .. note:: We do not consider negatives of prime numbers as prime. | - ``bool`` - ``True`` or ``False`` | def is_prime(n, flag=0): r""" Returns True if `x` is prime, and False otherwise. The result is proven correct - *this is NOT a pseudo-primality test!*. INPUT: - ``flag`` - int - ``0`` (default) - use a combination of algorithms. - ``1`` - certify primality using the Pocklington-Lehmer Test. - ``2`` - certify pri... |
IMPLEMENTATION: Calls the PARI isprime function. """ n = ZZ(n) return pari(n).isprime() | ALGORITHM:: Calculation is delegated to the ``n.is_prime()`` method, or in special cases (e.g., Python ``int``s) to ``Integer(n).is_prime()``. If an ``n.is_prime()`` method is not available, it otherwise raises a ``TypeError``. """ if type(n) == int or type(n)==long: from sage.rings.integer import Integer return Inte... | def is_prime(n, flag=0): r""" Returns True if `x` is prime, and False otherwise. The result is proven correct - *this is NOT a pseudo-primality test!*. INPUT: - ``flag`` - int - ``0`` (default) - use a combination of algorithms. - ``1`` - certify primality using the Pocklington-Lehmer Test. - ``2`` - certify pri... |
return u[0] | return u[0].vector() | def _discrete_log(self,x): # EVEN DUMBER IMPLEMENTATION! u = [y for y in self.list() if y.element() == x] if len(u) == 0: raise TypeError, "Not in group" if len(u) > 1: raise NotImplementedError return u[0] |
K = self.base_ring()._magma_init_(magma) | K = magma(self.base_ring()) | def _magma_init_(self, magma): r""" EXAMPLES: We first coerce a square matrix. :: sage: magma(MatrixSpace(QQ,3)) # optional - magma Full Matrix Algebra of degree 3 over Rational Field :: sage: magma(MatrixSpace(Integers(8),2,3)) # optional - magma Full RMatrixSpace of 2 by 3 matrices ... |
s = 'MatrixAlgebra(%s,%s)'%(K, self.__nrows) | s = 'MatrixAlgebra(%s,%s)'%(K.name(), self.__nrows) | def _magma_init_(self, magma): r""" EXAMPLES: We first coerce a square matrix. :: sage: magma(MatrixSpace(QQ,3)) # optional - magma Full Matrix Algebra of degree 3 over Rational Field :: sage: magma(MatrixSpace(Integers(8),2,3)) # optional - magma Full RMatrixSpace of 2 by 3 matrices ... |
s = 'RMatrixSpace(%s,%s,%s)'%(K, self.__nrows, self.__ncols) | s = 'RMatrixSpace(%s,%s,%s)'%(K.name(), self.__nrows, self.__ncols) | def _magma_init_(self, magma): r""" EXAMPLES: We first coerce a square matrix. :: sage: magma(MatrixSpace(QQ,3)) # optional - magma Full Matrix Algebra of degree 3 over Rational Field :: sage: magma(MatrixSpace(Integers(8),2,3)) # optional - magma Full RMatrixSpace of 2 by 3 matrices ... |
cones = tuple(tuple(new_fan_rays.index(cone_polytope.vertex(v)) for v in range(cone_polytope.nvertices() - 1)) | cones = tuple(tuple(sorted(new_fan_rays.index(cone_polytope.vertex(v)) for v in range(cone_polytope.nvertices() - 1))) | def _subdivide_palp(self, new_rays, verbose): r""" Subdivide ``self`` adding ``new_rays`` one by one. |
for cone, polytope in zip(fan.generating_cones(), cone_polytopes): cone._lattice_polytope = polytope | def _subdivide_palp(self, new_rays, verbose): r""" Subdivide ``self`` adding ``new_rays`` one by one. | |
key = (polynomial, polynomial.base_ring(), name, embedding, embedding.parent() if embedding is not None else None) | key = (polynomial, polynomial.base_ring(), name, latex_name, embedding, embedding.parent() if embedding is not None else None) | def NumberField(polynomial, name=None, check=True, names=None, cache=True, embedding=None, latex_name=None): r""" Return *the* number field defined by the given irreducible polynomial and with variable with the given name. If check is True (the default), also verify that the defining polynomial is irreducible and over ... |
def QuadraticField(D, names, check=True, embedding=True, latex_name=None): | def QuadraticField(D, names, check=True, embedding=True, latex_name='sqrt'): | def QuadraticField(D, names, check=True, embedding=True, latex_name=None): r""" Return a quadratic field obtained by adjoining a square root of `D` to the rational numbers, where `D` is not a perfect square. INPUT: - ``D`` - a rational number - ``names`` - variable name - ``check`` - bool (default: True) - ``... |
root. | or upper half plane root. | def QuadraticField(D, names, check=True, embedding=True, latex_name=None): r""" Return a quadratic field obtained by adjoining a square root of `D` to the rational numbers, where `D` is not a perfect square. INPUT: - ``D`` - a rational number - ``names`` - variable name - ``check`` - bool (default: True) - ``... |
We can give the generator a special name for latex:: | By default, quadratic fields come with a nice latex representation:: sage: K.<a> = QuadraticField(-7) sage: latex(a) \sqrt{-7} sage: latex(1/(1+a)) -\frac{1}{8} \sqrt{-7} + \frac{1}{8} sage: K.latex_variable_name() '\\sqrt{-7}' We can provide our own name as well:: | def QuadraticField(D, names, check=True, embedding=True, latex_name=None): r""" Return a quadratic field obtained by adjoining a square root of `D` to the rational numbers, where `D` is not a perfect square. INPUT: - ``D`` - a rational number - ``names`` - variable name - ``check`` - bool (default: True) - ``... |
Returns the rim of ``self`` | Returns the rim of ``self``. | def rim(self): r""" Returns the rim of ``self`` |
For example if `p=(5,5,2,1)`, the rim is composed from the dashed cells below:: | The rim of the partition `[5,5,2,1]` consists of the cells marked with `` | def rim(self): r""" Returns the rim of ``self`` |
Returns the outer rim of ``self`` | Returns the outer rim of ``self``. | def outer_rim(self): """ Returns the outer rim of ``self`` |
For example, the dashed cell below is the outer_rim of the partitions `(4,1)`:: | The outer rim of the partition `[4,1]` consists of the cells marked with `` | def outer_rim(self): """ Returns the outer rim of ``self`` |
solution is not SymbolisEquation (as happens for example for | solution is not SymbolicEquation (as happens for example for | def desolve(de, dvar, ics=None, ivar=None, show_method=False, contrib_ode=False): """ Solves a 1st or 2nd order linear ODE via maxima. Including IVP and BVP. *Use* ``desolve? <tab>`` *if the output in truncated in notebook.* INPUT: - ``de`` - an expression or equation representing the ODE - ``dvar`` - the dependent... |
""" | r""" | def desolve_system_strings(des,vars,ics=None): """ Solves any size system of 1st order ODE's. Initials conditions are optional. INPUT: de -- a list of strings representing the ODEs in maxima notation (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") vars -- a list of strings representing the variables (eg, vars = [... |
de -- a list of strings representing the ODEs in maxima notation (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") vars -- a list of strings representing the variables (eg, vars = ["s","x","y"], where s is the independent variable and x,y the dependent variables) ics -- a list of numbers representing initial condit... | - ``de`` - a list of strings representing the ODEs in maxima notation (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") - ``vars`` - a list of strings representing the variables (eg, vars = ["s","x","y"], where s is the independent variable and x,y the dependent variables) - ``ics`` - a list of numbers representing ini... | def desolve_system_strings(des,vars,ics=None): """ Solves any size system of 1st order ODE's. Initials conditions are optional. INPUT: de -- a list of strings representing the ODEs in maxima notation (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") vars -- a list of strings representing the variables (eg, vars = [... |
The given ics sets the initial values of the dependent vars in maxima, so subsequent ODEs involving these variables will have these initial conditions automatically imposed. EXAMPLES: | The given ics sets the initial values of the dependent vars in maxima, so subsequent ODEs involving these variables will have these initial conditions automatically imposed. EXAMPLES:: | def desolve_system_strings(des,vars,ics=None): """ Solves any size system of 1st order ODE's. Initials conditions are optional. INPUT: de -- a list of strings representing the ODEs in maxima notation (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") vars -- a list of strings representing the variables (eg, vars = [... |
AUTHORS: David Joyner (3-2006, 8-2007) | AUTHORS: - David Joyner (3-2006, 8-2007) | def desolve_system_strings(des,vars,ics=None): """ Solves any size system of 1st order ODE's. Initials conditions are optional. INPUT: de -- a list of strings representing the ODEs in maxima notation (eg, de = "diff(f(x),x,2)=diff(f(x),x)+sin(x)") vars -- a list of strings representing the variables (eg, vars = [... |
""" | r""" | def eulers_method(f,x0,y0,h,x1,method="table"): """ This implements Euler's method for finding numerically the solution of the 1st order ODE ``y' = f(x,y)``, ``y(a)=c``. The "x" column of the table increments from ``x0`` to ``x1`` by ``h`` (so ``(x1-x0)/h`` must be an integer). In the "y" column, the new y-value equals... |
""" | r""" | def eulers_method_2x2(f,g, t0, x0, y0, h, t1,method="table"): """ This implements Euler's method for finding numerically the solution of the 1st order system of two ODEs ``x' = f(t, x, y), x(t0)=x0.`` ``y' = g(t, x, y), y(t0)=y0.`` The "t" column of the table increments from `t_0` to `t_1` by `h` (so `\\frac{t_1-t_0... |
""" | r""" Plots solution of ODE | def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): """ This plots the soln in the rectangle ``(xrange[0],xrange[1]) x (yrange[0],yrange[1])`` and plots using Euler's method the numerical solution of the 1st order ODEs `x' = f(t,x,y)`, `x(a)=x_0`, `y' = g(t,x,y)`, `y(a) = y_0`. *For pedagogical purposes only.* EXAMPL... |
`\\theta''+\\sin(\\theta)=0`, `\\theta(0)=\\frac 34`, `\\theta'(0) = | `\theta''+\sin(\theta)=0`, `\theta(0)=\frac 34`, `\theta'(0) = | def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): """ This plots the soln in the rectangle ``(xrange[0],xrange[1]) x (yrange[0],yrange[1])`` and plots using Euler's method the numerical solution of the 1st order ODEs `x' = f(t,x,y)`, `x(a)=x_0`, `y' = g(t,x,y)`, `y(a) = y_0`. *For pedagogical purposes only.* EXAMPL... |
``(P[0]+P[1]).show()`` to plot `(t,\\theta(t))` and `(t,\\theta'(t))`:: sage: from sage.calculus.desolvers import eulers_method_2x2_plot | ``(P[0]+P[1]).show()`` to plot `(t,\theta(t))` and `(t,\theta'(t))`:: | def eulers_method_2x2_plot(f,g, t0, x0, y0, h, t1): """ This plots the soln in the rectangle ``(xrange[0],xrange[1]) x (yrange[0],yrange[1])`` and plots using Euler's method the numerical solution of the 1st order ODEs `x' = f(t,x,y)`, `x(a)=x_0`, `y' = g(t,x,y)`, `y(a) = y_0`. *For pedagogical purposes only.* EXAMPL... |
if self._style == "coroots" and all(xv in ZZ for xv in x): | if self._style == "coroots" and isinstance(x, tuple) and all(xv in ZZ for xv in x): | def __call__(self, *args): """ Coerces the element into the ring. You may pass a vector in the ambient space, an element of the base_ring, or an argument list of integers (or half-integers for the spin types) which are the components of a vector in the ambient space. INPUT: - ``x`` - a ring element to be coerced; o... |
A stochastic matrix is a matrix such that the sum of the elements of any row is equal to 1. A bistochastic matrix is a stochastic matrix whose transpose matrix is also stochastic ( there are conditions both on the rows and on the columns ). | A stochastic matrix is a matrix with nonnegative real entries such that the sum of the elements of any row is equal to 1. A bistochastic matrix is a stochastic matrix whose transpose matrix is also stochastic ( there are conditions both on the rows and on the columns ). | def bistochastic_as_sum_of_permutations(M, check = True): r""" Returns the positive sum of permutations corresponding to the bistochastic matrix. A stochastic matrix is a matrix such that the sum of the elements of any row is equal to 1. A bistochastic matrix is a stochastic matrix whose transpose matrix is also stoch... |
- ``check`` (boolean) -- set to ``True`` (default) to checl | - ``check`` (boolean) -- set to ``True`` (default) to check | def bistochastic_as_sum_of_permutations(M, check = True): r""" Returns the positive sum of permutations corresponding to the bistochastic matrix. A stochastic matrix is a matrix such that the sum of the elements of any row is equal to 1. A bistochastic matrix is a stochastic matrix whose transpose matrix is also stoch... |
An exception is raised when the matrix is not bistochastic:: | An exception is raised when the matrix is not positive and bistochastic:: | def bistochastic_as_sum_of_permutations(M, check = True): r""" Returns the positive sum of permutations corresponding to the bistochastic matrix. A stochastic matrix is a matrix such that the sum of the elements of any row is equal to 1. A bistochastic matrix is a stochastic matrix whose transpose matrix is also stoch... |
from sage.rings.real_mpfr import RR | from sage.rings.all import RR | def bistochastic_as_sum_of_permutations(M, check = True): r""" Returns the positive sum of permutations corresponding to the bistochastic matrix. A stochastic matrix is a matrix such that the sum of the elements of any row is equal to 1. A bistochastic matrix is a stochastic matrix whose transpose matrix is also stoch... |
approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z` is a good approximation to an algebraic number of degree less than `degree`. You can specify the number of known bits or digits with ``known_bits=k`` or ``known_digits=k``; Pari is t... | approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z` is a good approximation to an algebraic number of degree less than `degree`. You can specify the number of known bits or digits of `z` with ``known_bits=k`` or ``known_digits=k``. PA... | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
- ``height_bound`` - an integer (default ``None``) specifying the maximum | - ``height_bound`` - an integer (default: ``None``) specifying the maximum | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
- ``proof`` - a boolean (default ``False``), requres height_bound to be set | - ``proof`` - a boolean (default: ``False``), requires height_bound to be set | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
This example involves a complex number. :: | This example involves a complex number:: | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
This example involves a `p`-adic number. :: | This example involves a `p`-adic number:: | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
compute a 200-bit approximation to sqrt(2) which is wrong in the 33'rd bit. :: | compute a 200-bit approximation to `sqrt(2)` which is wrong in the 33'rd bit:: | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
Using the ``height_bound`` and ``proof`` parameters, we can see that `pi` is not the root of an integer polynomial of degree at most 5 and coefficients bounded above by 10. :: | Using the ``height_bound`` and ``proof`` parameters, we can see that `pi` is not the root of an integer polynomial of degree at most 5 and coefficients bounded above by 10:: | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
For stronger results, we need more precicion. :: | For stronger results, we need more precicion:: | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
We can also use ``proof=True`` to get positive results. :: | We can also use ``proof=True`` to get positive results:: | def algdep(z, degree, known_bits=None, use_bits=None, known_digits=None, use_digits=None, height_bound=None, proof=False): """ Returns a polynomial of degree at most `degree` which is approximately satisfied by the number `z`. Note that the returned polynomial need not be irreducible, and indeed usually won't be if `z`... |
- ``bound (default 1024)`` - int: highest power to test. | - ``bound (default: 1024)`` - int: highest power to test. | def is_pseudoprime_small_power(n, bound=1024, get_data=False): r""" Return True if `n` is a small power of a pseudoprime, and False otherwise. The result is *NOT* proven correct - *this IS a pseudo-primality test!*. If `get_data` is set to true and `n = p^d`, for a pseudoprime `p` and power `d`, return [(p, d)]. IN... |
- ``verbose`` - integer (default 0); pari's debug | - ``verbose`` - integer (default: 0); PARI's debug | def factor(n, proof=None, int_=False, algorithm='pari', verbose=0, **kwds): """ Returns the factorization of n. The result depends on the type of n. If n is an integer, factor returns the factorization of the integer n as an object of type Factorization. If n is not an integer, ``n.factor(proof=proof, **kwds)`` gets ... |
See also: :function:`Partition`, :meth:`Partition.to_exp` | See also: :func:`Partition`, :meth:`Partition.to_exp` | def from_polynomial_exp(self, p): r""" Conversion from polynomial in exponential notation |
of `pi`. | of `\pi`. | sage: def maple_leaf(t): |
for best style in that case. | for best style in that case. :: sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=["latex",pi]) | sage: def maple_leaf(t): |
sage: plot(arcsin(x),(x,-1,1),ticks=[None,pi/6],tick_formatter=["latex",pi]) | sage: def maple_leaf(t): | |
if F.derivative(v)(xyz).valuation(P) == 0: | c = (F.derivative(v))(xyz) try: val = c.valuation(P) except AttributeError: val = c.constant_coefficient().valuation(P) if val == 0: | def has_good_reduction(self, P=None): r""" Returns True iff this point has good reduction modulo a prime. |
X = list(X) | return Set_object_enumerated(list(X)) | def Set(X): r""" Create the underlying set of $X$. If $X$ is a list, tuple, Python set, or ``X.is_finite()`` is true, this returns a wrapper around Python's enumerated immutable frozenset type with extra functionality. Otherwise it returns a more formal wrapper. If you need the functionality of mutable sets, use Pyt... |
def iter_morphisms(self, l=None, codomain=None, min_length=1): | @rename_keyword(deprecated='Sage version 4.6.1', l='arg') def iter_morphisms(self, arg=None, codomain=None, min_length=1): | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
- ``l`` - (optional, default: None) It can be one of the following : | - ``arg`` - (optional, default: None) It can be one of the following : | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
- list of nonnegative integers - The length of the list must be the number of letters in the alphabet, and the `i`-th integer of ``l`` determines the length of the word mapped to by the `i`-th letter of the (ordered) alphabet. | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. | |
- ``min_length`` - (default: 1) nonnegative integer. If ``l`` is | - ``min_length`` - (default: 1) nonnegative integer. If ``arg`` is | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
``min_length``. This is ignored if ``l`` is a list. | ``min_length``. This is ignored if ``arg`` is a list. | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
TypeError: l (=[0, 1, 2]) must be an iterable of 2 integers | TypeError: arg (=[0, 1, 2]) must be an iterable of 2 integers | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
TypeError: l (=[0, 'a']) must be an iterable of 2 integers | TypeError: arg (=[0, 'a']) must be an iterable of 2 integers | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
if l is None: | if arg is None: | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
elif isinstance(l, tuple): if not len(l) == 2 or not all(isinstance(a, (int,Integer)) for a in l): raise TypeError("l (=%s) must be a tuple of 2 integers" %l) | elif isinstance(arg, tuple): if not len(arg) == 2 or not all(isinstance(a, (int,Integer)) for a in arg): raise TypeError("arg (=%s) must be a tuple of 2 integers" %arg) | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
compositions = IntegerListsLex(range(*l), | compositions = IntegerListsLex(range(*arg), | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
l = list(l) if (not len(l) == n or not all(isinstance(a, (int,Integer)) for a in l)): | arg = list(arg) if (not len(arg) == n or not all(isinstance(a, (int,Integer)) for a in arg)): | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
"l (=%s) must be an iterable of %s integers" %(l, n)) compositions = [l] | "arg (=%s) must be an iterable of %s integers" %(arg, n)) compositions = [arg] | def iter_morphisms(self, l=None, codomain=None, min_length=1): r""" Iterate over all morphisms with domain ``self`` and the given codmain. |
- Oscar Lazo, William Cauchois (2009-2010): Adding coordinate transformations | - Oscar Lazo, William Cauchois, Jason Grout (2009-2010): Adding coordinate transformations | sage: def f(x,y): return math.exp(x/5)*math.cos(y) |
class _CoordTrans(object): | class _Coordinates(object): | sage: def f(x,y): return math.exp(x/5)*math.cos(y) |
Sub-classes must implement the ``gen_transform`` method which, given | Sub-classes must implement the :meth:`transform` method which, given | sage: def f(x,y): return math.exp(x/5)*math.cos(y) |
def __init__(self, indep_var, dep_vars): | def __init__(self, dep_var, indep_vars): | sage: def f(x,y): return math.exp(x/5)*math.cos(y) |
- ``indep_var`` - The independent variable (the function value will be | - ``dep_var`` - The dependent variable (the function value will be | def __init__(self, indep_var, dep_vars): """ INPUT: |
- ``dep_vars`` - A list of dependent variables (the parameters will be | - ``indep_vars`` - A list of independent variables (the parameters will be | def __init__(self, indep_var, dep_vars): """ INPUT: |
sage: from sage.plot.plot3d.plot3d import _CoordTrans sage: _CoordTrans('y', ['x']) Unknown coordinate system (y in terms of x) """ if hasattr(self, 'all_vars'): if set(self.all_vars) != set(dep_vars + [indep_var]): raise ValueError, 'not all variables were specified for ' + \ 'this coordinate system' self.indep_var = ... | sage: from sage.plot.plot3d.plot3d import _ArbitraryCoordinates as arb sage: x,y,z=var('x,y,z') sage: c=arb((x+z,y*z,z), z, (x,y)) sage: c._name 'Arbitrary Coordinates' """ return self.__class__.__name__ def transform(self, **kwds): """ Return the transformation for this coordinate system in terms of the | def __init__(self, indep_var, dep_vars): """ INPUT: |
def to_cartesian(self, func, params): | def to_cartesian(self, func, params=None): | def to_cartesian(self, func, params): """ Returns a 3-tuple of functions, parameterized over ``params``, that represents the cartesian coordinates of the value of ``func``. |
- ``params`` - The parameters of func. Correspond to the dependent | - ``params`` - The parameters of func. Corresponds to the dependent | def to_cartesian(self, func, params): """ Returns a 3-tuple of functions, parameterized over ``params``, that represents the cartesian coordinates of the value of ``func``. |
sage: from sage.plot.plot3d.plot3d import _ArbCoordTrans | sage: from sage.plot.plot3d.plot3d import _ArbitraryCoordinates | def to_cartesian(self, func, params): """ Returns a 3-tuple of functions, parameterized over ``params``, that represents the cartesian coordinates of the value of ``func``. |
sage: T = _ArbCoordTrans((x + y, x - y, z), z) sage: f(x, y) = x * y sage: T.to_cartesian(f, [x, y]) [x + y, x - y, x*y] """ | sage: T = _ArbitraryCoordinates((x + y, x - y, z), z,[x,y]) sage: f(x, y) = 2*x+y sage: T.to_cartesian(f, [x, y]) (x + y, x - y, 2*x + y) sage: [h(1,2) for h in T.to_cartesian(lambda x,y: 2*x+y)] [3, -1, 4] """ | def to_cartesian(self, func, params): """ Returns a 3-tuple of functions, parameterized over ``params``, that represents the cartesian coordinates of the value of ``func``. |
if any([is_Expression(func), is_RealNumber(func), is_Integer(func)]): return self.gen_transform(**{ self.indep_var: func, self.dep_vars[0]: params[0], self.dep_vars[1]: params[1] | if params is not None and (is_Expression(func) or is_RealNumber(func) or is_Integer(func)): return self.transform(**{ self.dep_var: func, self.indep_vars[0]: params[0], self.indep_vars[1]: params[1] | def to_cartesian(self, func, params): """ Returns a 3-tuple of functions, parameterized over ``params``, that represents the cartesian coordinates of the value of ``func``. |
indep_var_dummy = sage.symbolic.ring.var(self.indep_var) dep_var_dummies = sage.symbolic.ring.var(','.join(self.dep_vars)) transformation = self.gen_transform(**{ self.indep_var: indep_var_dummy, self.dep_vars[0]: dep_var_dummies[0], self.dep_vars[1]: dep_var_dummies[1] | dep_var_dummy = sage.symbolic.ring.var(self.dep_var) indep_var_dummies = sage.symbolic.ring.var(','.join(self.indep_vars)) transformation = self.transform(**{ self.dep_var: dep_var_dummy, self.indep_vars[0]: indep_var_dummies[0], self.indep_vars[1]: indep_var_dummies[1] | def to_cartesian(self, func, params): """ Returns a 3-tuple of functions, parameterized over ``params``, that represents the cartesian coordinates of the value of ``func``. |
indep_var_dummy: func(x, y), dep_var_dummies[0]: x, dep_var_dummies[1]: y | dep_var_dummy: func(x, y), indep_var_dummies[0]: x, indep_var_dummies[1]: y | def subs_func(t): return lambda x,y: t.subs({ indep_var_dummy: func(x, y), dep_var_dummies[0]: x, dep_var_dummies[1]: y }) |
_name = 'Unknown coordinate system' | def subs_func(t): return lambda x,y: t.subs({ indep_var_dummy: func(x, y), dep_var_dummies[0]: x, dep_var_dummies[1]: y }) | |
return '%s (%s in terms of %s)' % \ (self._name, self.indep_var, ', '.join(self.dep_vars)) class _ArbCoordTrans(_CoordTrans): """ An arbitrary coordinate system transformation. """ def __init__(self, custom_trans, fvar): """ | return '%s coordinate transform (%s in terms of %s)' % \ (self._name, self.dep_var, ', '.join(self.indep_vars)) class _ArbitraryCoordinates(_Coordinates): """ An arbitrary coordinate system. """ _name = "Arbitrary Coordinates" def __init__(self, custom_trans, dep_var, indep_vars): """ Initialize an arbitrary coordina... | def __repr__(self): return '%s (%s in terms of %s)' % \ (self._name, self.indep_var, ', '.join(self.dep_vars)) |
- ``custom_trans`` - A 3-tuple of transformations. This will be returned almost unchanged by ``gen_transform``, except the function variable will be substituted. - ``fvar`` - The function variable. """ super(_ArbCoordTrans, self).__init__('f', ['u', 'v']) self.custom_trans = custom_trans self.fvar = fvar def gen_tran... | - ``custom_trans`` - A 3-tuple of transformation functions. - ``dep_var`` - The dependent (function) variable. - ``indep_vars`` - a list of the two other independent variables. EXAMPLES:: sage: from sage.plot.plot3d.plot3d import _ArbitraryCoordinates sage: x, y, z = var('x y z') sage: T = _ArbitraryCoordinates((x ... | def __init__(self, custom_trans, fvar): """ INPUT: |
sage: from sage.plot.plot3d.plot3d import _ArbCoordTrans | sage: from sage.plot.plot3d.plot3d import _ArbitraryCoordinates | def gen_transform(self, f=None, u=None, v=None): """ EXAMPLE:: sage: from sage.plot.plot3d.plot3d import _ArbCoordTrans sage: x, y, z = var('x y z') sage: T = _ArbCoordTrans((x + y, x - y, z), x) |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.