rem stringlengths 0 322k | add stringlengths 0 2.05M | context stringlengths 8 228k |
|---|---|---|
AssertionError: morphims is not triangular on 1 | AssertionError: morphism is not triangular on 1 | def _test_triangular(self, **options): """ Tests that ``self`` is actually triangular |
AssertionError: morphims is not untriangular on 1 | AssertionError: morphism is not untriangular on 1 | def _test_triangular(self, **options): """ Tests that ``self`` is actually triangular |
LazyFormat("morphims is not untriangular on %s")%(x)) | LazyFormat("morphism is not untriangular on %s")%(x)) | def _test_triangular(self, **options): """ Tests that ``self`` is actually triangular |
LazyFormat("morphims is not triangular on %s")%(x)) | LazyFormat("morphism is not triangular on %s")%(x)) | def _test_triangular(self, **options): """ Tests that ``self`` is actually triangular |
depends = ["sage/libs/mwrank/wrap.h"], | depends = ["sage/libs/mwrank/wrap.h"] + [ SAGE_INC + "eclib/" + h for h in ["curve.h","egr.h","descent.h","points.h","isogs.h", "marith.h","htconst.h","interface.h"] ], | def uname_specific(name, value, alternative): if name in os.uname()[0]: return value else: return alternative |
define_macros = [("NTL_ALL",None)]), | define_macros = [("NTL_ALL",None)], depends = [ SAGE_INC + "eclib/" + h for h in ["interface.h","bigrat.h","rat.h","curve.h", "moddata.h","symb.h","cusp.h","homspace.h","mat.h"] ]), | def uname_specific(name, value, alternative): if name in os.uname()[0]: return value else: return alternative |
define_macros = [("NTL_ALL",None)]), | define_macros = [("NTL_ALL",None)], depends = [ SAGE_INC + "eclib/" + h for h in ["interface.h","bigrat.h","rat.h","curve.h", "moddata.h","symb.h","cusp.h","xsplit.h","method.h", "oldforms.h","homspace.h","cperiods.h","newforms.h"] ]), | def uname_specific(name, value, alternative): if name in os.uname()[0]: return value else: return alternative |
basis = matrix( M.columns() + M.integer_kernel().basis() ).transpose() self._dual_embedding_scale = basis.det() | basis = M.columns() + M.integer_kernel().basis() basis = matrix(basis).transpose() self._dual_embedding_scale = abs(basis.det()) | def _compute_dim(self, compute_vertices): r""" Compute the dimension of this polytope and its vertices, if necessary. If ``compute_vertices`` is ``True``, then ``self._vertices`` should contain points whose convex hull will be computed and placed back into ``self._vertices``. If the dimension of this polytope is not ... |
A lattice polytope of strictly smaller dimension (=2) than the ambient dimension(=4):: sage: LatticePolytope(matrix([(1, -1, 0), (-1, -1, 0), (1, 1, 0), (3, 3, 0)])) | This is a 2-dimensional lattice polytope in a 4-dimensional space:: sage: m = matrix([(1,-1,1,3), (-1,-1,1,3), (0,0,0,0)]) sage: p = LatticePolytope(m.transpose()) sage: p | def facet_constant(self, i): r""" Return the constant in the ``i``-th facet inequality of this polytope. The i-th facet inequality is given by self.facet_normal(i) * X + self.facet_constant(i) >= 0. INPUT: - ``i`` - integer, the index of the facet OUTPUT: - integer -- the constant in the ``i``-th facet inequality.... |
sage: lp = LatticePolytope(matrix([(1, -1, 0), (-1, -1, 0), (1, 1, 0), (3, 3, 0)])) sage: lp.vertices() | sage: p.vertices() | def facet_constant(self, i): r""" Return the constant in the ``i``-th facet inequality of this polytope. The i-th facet inequality is given by self.facet_normal(i) * X + self.facet_constant(i) >= 0. INPUT: - ``i`` - integer, the index of the facet OUTPUT: - integer -- the constant in the ``i``-th facet inequality.... |
sage: matrix([[ lp.facet_normal(i)*lp.vertex(j) + lp.facet_constant(i) for i in range(0,3)] for j in range(0,3)]) [-22 0 0] [ 0 -22 0] [ 0 0 -11] | sage: fns = [p.facet_normal(i) for i in range(p.nfacets())] sage: fns [(11, -1, 1, 3), (-11, -1, 1, 3), (0, 1, -1, -3)] sage: fcs = [p.facet_constant(i) for i in range(p.nfacets())] sage: fcs [0, 0, 11] Now we manually compute the distance matrix of this polytope. Since it is a triangle, each line (corresponding to a ... | def facet_constant(self, i): r""" Return the constant in the ``i``-th facet inequality of this polytope. The i-th facet inequality is given by self.facet_normal(i) * X + self.facet_constant(i) >= 0. INPUT: - ``i`` - integer, the index of the facet OUTPUT: - integer -- the constant in the ``i``-th facet inequality.... |
parallel to the affine subspace spanned by this polytope. | orthogonal to the integer kernel of the affine subspace spanned by this polytope. | def facet_normal(self, i): r""" Return the inner normal to the ``i``-th facet of this polytope. If this polytope is not full-dimensional, facet normals will be parallel to the affine subspace spanned by this polytope. INPUT: - ``i`` -- integer, the index of the facet OUTPUT: - vectors -- the inner normal of the ``... |
Here is an example of a 3-dimensional polytope in 4d:: sage: lp = LatticePolytope(matrix([[1,1,-1,0],[1,-1,-1,0],[1,1,1,0],[3,3,3,0]])) sage: lp.vertices() [ 1 1 -1 0] [ 1 -1 -1 0] [ 1 1 1 0] [ 3 3 3 0] sage: ker = lp.vertices().integer_kernel().matrix() | Here is an example of a 3-dimensional polytope in a 4-dimensional space:: sage: m = matrix([(0,0,0,0), (1,1,1,3), (1,-1,1,3), (-1,-1,1,3)]) sage: p = LatticePolytope(m.transpose()) sage: p.vertices() [ 0 1 1 -1] [ 0 1 -1 -1] [ 0 1 1 1] [ 0 3 3 3] sage: ker = p.vertices().integer_kernel().matrix() | def facet_normal(self, i): r""" Return the inner normal to the ``i``-th facet of this polytope. If this polytope is not full-dimensional, facet normals will be parallel to the affine subspace spanned by this polytope. INPUT: - ``i`` -- integer, the index of the facet OUTPUT: - vectors -- the inner normal of the ``... |
sage: [ ker * lp.facet_normal(i) for i in range(0,4) ] | sage: [ker * p.facet_normal(i) for i in range(p.nfacets())] | def facet_normal(self, i): r""" Return the inner normal to the ``i``-th facet of this polytope. If this polytope is not full-dimensional, facet normals will be parallel to the affine subspace spanned by this polytope. INPUT: - ``i`` -- integer, the index of the facet OUTPUT: - vectors -- the inner normal of the ``... |
sage: matrix([lp.facet_normal(i) for i in range(0,4)]) * lp.vertices() [ 0 0 -20 0] [ 0 -20 0 0] [ 10 10 10 0] [-20 0 0 0] sage: matrix([[ lp.facet_normal(i)*lp.vertex(j) + lp.facet_constant(i) for i in range(0,4)] for j in range(0,4)]) [ 0 0 0 -20] [ 0 -20 0 0] [-20 0 0 0] [ 0 0 ... | Now we manually compute the distance matrix of this polytope. Since it is a simplex, each line (corresponding to a facet) should consist of zeros (indicating generating vertices of the corresponding facet) and a single positive number (since our normals are inner):: sage: matrix([[p.facet_normal(i) * p.vertex(j) ... ... | def facet_normal(self, i): r""" Return the inner normal to the ``i``-th facet of this polytope. If this polytope is not full-dimensional, facet normals will be parallel to the affine subspace spanned by this polytope. INPUT: - ``i`` -- integer, the index of the facet OUTPUT: - vectors -- the inner normal of the ``... |
Returns a list of the immediate super categories of self. | Returns a list of the immediate super categories of ``self``. | def super_categories(self): """ Returns a list of the immediate super categories of self. |
- often uses self.one(). | - often uses ``self.one()``. | def one(self): r""" Returns the one of the monoid, that is the unique neutral element for `*`. |
Backward compatibility alias for :meth:`self.one()`. | Backward compatibility alias for :meth:`one`. | def one_element(self): r""" Backward compatibility alias for :meth:`self.one()`. |
Returns the product of the elements in `args`, as an element of `self`. EXAMPLES: | Returns the product of the elements in ``args``, as an element of ``self``. EXAMPLES:: | def prod(self, args): r""" n-ary product |
Returns whether self is the one of the monoid | Returns whether ``self`` is the one of the monoid | def is_one(self): r""" Returns whether self is the one of the monoid |
- n: a non negative integer | - ``n``: a non negative integer | def __pow__(self, n): r""" INPUTS: - n: a non negative integer |
A naive implementation of __pow__ | A naive implementation of ``__pow__`` | def _pow_naive(self, n): r""" A naive implementation of __pow__ |
- n: a non negative integer | - ``n``: a non negative integer | def _pow_naive(self, n): r""" A naive implementation of __pow__ |
faster du to size explotion). | faster due to size explosion). | def _pow_naive(self, n): r""" A naive implementation of __pow__ |
sage: latex(maxima(derivative(ceil(x*y*d), d,x,x,y))) d^3\,\left({{{\it \partial}^4}\over{{\it \partial}\,d^4}}\, {\it ceil}\left(d , x , y\right)\right)\,x^2\,y^3+5\,d^2\,\left({{ {\it \partial}^3}\over{{\it \partial}\,d^3}}\,{\it ceil}\left(d , x , y\right)\right)\,x\,y^2+4\,d\,\left({{{\it \partial}^2}\over{ {\... | sage: f = function('f') sage: latex(maxima(derivative(f(x*y*d), d,x,x,y))) Traceback (most recent call last): ... NotImplementedError: arguments must be distinct variables sage: latex(maxima(derivative(f(x,y,d), d,x,x,y))) {{{\it \partial}^4}\over{{\it \partial}\,d\,{\it \partial}\,x^2\, {\it \partial}\,y}}\,f\left(x ... | def _latex_(self): """ Return Latex representation of this Maxima object. This calls the tex command in Maxima, then does a little post-processing to fix bugs in the resulting Maxima output. EXAMPLES:: sage: maxima('sqrt(2) + 1/3 + asin(5)')._latex_() '\\sin^{-1}\\cdot5+\\sqrt{2}+{{1}\\over{3}}' |
nr_common = len(reduce(sets.Set.intersection, \ [sets.Set(c1[r]), sets.Set(c2[c]), sets.Set(c3[s])])) | nr_common = len(reduce(set.intersection, \ [set(c1[r]), set(c2[c]), set(c3[s])])) | def tau_to_bitrade(t1, t2, t3): """ Given permutations t1, t2, t3 that represent a latin bitrade, convert them to an explicit latin bitrade (T1, T2). The result is unique up to isotopism. EXAMPLE:: sage: from sage.combinat.matrices.latin import * sage: T1 = back_circulant(5) sage: x = isotopism( (0,1,2,3,4) ) sage: y... |
val1 = sets.Set(filter(lambda x: x >= 0, T1.row(r))) val2 = sets.Set(filter(lambda x: x >= 0, T2.row(r))) | val1 = set(filter(lambda x: x >= 0, T1.row(r))) val2 = set(filter(lambda x: x >= 0, T2.row(r))) | def is_row_and_col_balanced(T1, T2): """ Partial latin squares T1 and T2 are balanced if the symbols appearing in row r of T1 are the same as the symbols appearing in row r of T2, for each r, and if the same condition holds on columns. EXAMPLES:: sage: from sage.combinat.matrices.latin import * sage: T1 = matrix([[0,... |
val1 = sets.Set(filter(lambda x: x >= 0, T1.column(c))) val2 = sets.Set(filter(lambda x: x >= 0, T2.column(c))) | val1 = set(filter(lambda x: x >= 0, T1.column(c))) val2 = set(filter(lambda x: x >= 0, T2.column(c))) | def is_row_and_col_balanced(T1, T2): """ Partial latin squares T1 and T2 are balanced if the symbols appearing in row r of T1 are the same as the symbols appearing in row r of T2, for each r, and if the same condition holds on columns. EXAMPLES:: sage: from sage.combinat.matrices.latin import * sage: T1 = matrix([[0,... |
sage: region_plot([y>0, x>0, x^2+y^2<1], (-1.1, 1.1), (-1.1, 1.1), plot_points = 400).show(aspect_ratio=1) | sage: region_plot([y>0, x>0, x^2+y^2<1], (x,-1.1, 1.1), (y,-1.1, 1.1), plot_points = 400).show(aspect_ratio=1) | def region_plot(f, xrange, yrange, plot_points, incol, outcol, bordercol, borderstyle, borderwidth): r""" ``region_plot`` takes a boolean function of two variables, `f(x,y)` and plots the region where f is True over the specified ``xrange`` and ``yrange`` as demonstrated below. ``region_plot(f, (xmin, xmax), (ymin, ym... |
variables = reduce(lambda g1, g2: g1.union(g2), [set(g.variables()) for g in f], set([])) f = [equify(g, variables) for g in f] | f = [equify(g) for g in f] | def region_plot(f, xrange, yrange, plot_points, incol, outcol, bordercol, borderstyle, borderwidth): r""" ``region_plot`` takes a boolean function of two variables, `f(x,y)` and plots the region where f is True over the specified ``xrange`` and ``yrange`` as demonstrated below. ``region_plot(f, (xmin, xmax), (ymin, ym... |
def equify(f, variables = None): | def equify(f): | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... |
x |--> x^2 - 2 | x^2 - 2 | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... |
x |--> -x^2 + 2 | -x^2 + 2 | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... |
(x, y) |--> -x*y + 1 sage: equify(y > 0, (x,y)) (x, y) |--> -y | -x*y + 1 sage: equify(y > 0) -y | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... |
if variables == None: variables = f.variables() | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... | |
s = symbolic_expression(f.rhs() - f.lhs()).function(*variables) return s | return symbolic_expression(f.rhs() - f.lhs()) | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... |
s = symbolic_expression(f.lhs() - f.rhs()).function(*variables) return s | return symbolic_expression(f.lhs() - f.rhs()) | def equify(f, variables = None): """ Returns the equation rewritten as a symbolic function to give negative values when True, positive when False. EXAMPLES:: sage: from sage.plot.contour_plot import equify sage: var('x, y') (x, y) sage: equify(x^2 < 2) x |--> x^2 - 2 sage: equify(x^2 > 2) x |--> -x^2 + 2 sage: equify... |
Returns the intermediate shape of the pm diagram (innner shape plus positions of plusses) | Returns the intermediate shape of the pm diagram (inner shape plus positions of plusses) | def intermediate_shape(self): """ Returns the intermediate shape of the pm diagram (innner shape plus positions of plusses) |
p = p + [0,0] | p = p + [0 for i in range(self.n)] | def intermediate_shape(self): """ Returns the intermediate shape of the pm diagram (innner shape plus positions of plusses) |
.. warning:: This function calls a Singular function that appears to be very buggy and should not be trusted. | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: | |
- ``sort`` - bool (default: True), if True return the point list sorted. If False, returns the points in the order computed by Singular. | - ``D`` - a divisor OUTPUT: A list of function field elements that form a basis of the Riemann-Roch space | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: |
sage: D = C.divisor([ (4, pts[0]), (0,pts[1]), (4, pts[2]) ]) | sage: D = C.divisor([ (4, pts[0]), (4, pts[2]) ]) | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: |
The following example illustrates that the Riemann-Roch space function in Singular doesn't *not* work correctly. | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: | |
sage: C.riemann_roch_basis(D) [x/(y + x), (z + y)/(y + x)] The answer has dimension 2 (confirmed via Magma). But it varies between 1 and quite large with Singular. | sage: C.riemann_roch_basis(D) [(-2*x + y)/(x + y), (-x + z)/(x + y)] .. NOTE:: Currently this only works over prime field and divisors supported on rational points. | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: |
X3 = singular.extcurve(1, X2) R = X3[1][5] | v = X2[3].sage_flattened_str_list() v = [ v[i].partition(',') for i in range(len(v)) ] pnts = [ ( int(v[i][0]), int(v[i][2])-1 ) for i in range(len(v))] R = X2[5][1][1] | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: |
pnts = [self(int(v[3*i]), int(v[3*i+1]), int(v[3*i+2])) for i in range(len(v)/3)] | coords = [self(int(v[3*i]), int(v[3*i+1]), int(v[3*i+2])) for i in range(len(v)/3)] | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: |
Dcoeffs.append(D.coefficient(x)) | if x[0] == 1: Dcoeffs.append(D.coefficient(coords[x[1]])) else: Dcoeffs.append(0) | def riemann_roch_basis(self, D): r""" Return a basis for the Riemann-Roch space corresponding to `D`. .. warning:: |
""" | sage: def square_for_met(f): ... @sage_wraps(f) ... def new_f(self, x): ... return f(self,x)*f(self,x) ... return new_f sage: class T: ... @square_for_met ... def g(self, x): ... "My little method" ... return x sage: t = T() sage: t.g(2) 4 sage: t.g._sage_src_() ' @square_f... | '@square...def g(x)...' |
0.85914091422952255 | 0.859140914229522... | def integral(f, *args, **kwds): r""" The integral of `f`. EXAMPLES:: sage: integral(sin(x), x) -cos(x) sage: integral(sin(x)^2, x, pi, 123*pi/2) 121/4*pi sage: integral( sin(x), x, 0, pi) 2 We integrate a symbolic function:: sage: f(x,y,z) = x*y/z + sin(z) sage: integral(f, z) (x, y, z) |--> x*y*log(z) - cos(z) ::... |
def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=None): | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): """ Return the Lagrange interpolation polynomial in ``self`` associated to the given list of points. Given a list of points, i.e. tuples of elements of ``self``'s base ring, this function returns the interpolation polynomial in the... |
- ``previous_row`` -- (default: ``[]``) This option is only relevant | - ``previous_row`` -- (default: ``None``) This option is only relevant | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): """ Return the Lagrange interpolation polynomial in ``self`` associated to the given list of points. Given a list of points, i.e. tuples of elements of ``self``'s base ring, this function returns the interpolation polynomial in the... |
The return value should always be an element of ``self'', in the case of ``divided_difference'', or a list of elements of ``self'', in the case of ``neville'':: | Make sure that ticket be an element of ``self`` in the case of ``divided_difference``, or a list of elements of ``self`` in the case of ``neville``. :: | def lagrange_polynomial(self, points, algorithm="divided_difference", previous_row=[]): """ Return the Lagrange interpolation polynomial in ``self`` associated to the given list of points. Given a list of points, i.e. tuples of elements of ``self``'s base ring, this function returns the interpolation polynomial in the... |
libraries=['polybori','pboriCudd', 'groebner', 'gd', 'png', 'm4ri'], | libraries=['polybori','pboriCudd', 'groebner', 'gd', 'png12', 'm4ri'], | def uname_specific(name, value, alternative): if name in os.uname()[0]: return value else: return alternative |
NOTE:: | NOTE: | def sturm_bound(self, M=None): r""" For a space M of modular forms, this function returns an integer B such that two modular forms in either self or M are equal if and only if their q-expansions are equal to precision B (note that this is 1+ the usual Sturm bound, since `O(q^\mathrm{prec})` has precision prec). If M is... |
from sage.rings.real_mpfr cimport RealField, RealNumber | from sage.rings.real_mpfr cimport RealField_class, RealNumber | cdef RealNumber result = domain(fn(*py_args)) |
/* Automatically generated. Do not edit! */ ... | /* Automatically generated by ext/gen_interpreters.py. Do not edit! */ ... | def write_interpreter(self, write): r""" Generate the code for the C interpreter. |
/* Automatically generated. Do not edit! */ | /* Automatically generated by ext/gen_interpreters.py. Do not edit! */ | def write_interpreter(self, write): r""" Generate the code for the C interpreter. |
/* Automatically generated. Do not edit! */ | /* Automatically generated by ext/gen_interpreters.py. Do not edit! */ | def get_interpreter(self): r""" Returns the code for the C interpreter. |
from sage.rings.real_mpfr cimport RealField, RealNumber | from sage.rings.real_mpfr cimport RealField_class, RealNumber | def get_pxd(self): r""" Returns the code for the Cython .pxd file. |
'/* Automatically generated. Do not edit! */\n' | '/* Automatically generated by ext/gen_interpreters.py. Do not edit! */\n' | def build_interp(interp_spec, dir): r""" Given an InterpreterSpec, writes the C interpreter and the Cython wrapper (generates a pyx and a pxd file). EXAMPLES: sage: from sage.ext.gen_interpreters import * sage: testdir = tmp_filename() sage: os.mkdir(testdir) sage: rdf_interp = RDFInterpreter() sage: build_interp(rdf_... |
return sage_eval(x, self.gens_dict()) | return self(sage_eval(x, self.gens_dict())) | def __call__(self, x, check=True): """ Convert ``x`` to an element of this multivariate polynomial ring, possibly non-canonically. EXAMPLES: |
- ``legend_*`` - all the options valid for :meth:`set_legend_options` prefixed with 'legend_' | - ``legend_*`` - all the options valid for :meth:`set_legend_options` prefixed with ``legend_`` | def show(self, **kwds): """ Show this graphics image with the default image viewer. |
""" from sage.rings.all import ZZ | Check if sage: c.get_fake_div(1/pi/x) FakeExpression([1, FakeExpression([pi, x], <built-in function mul>)], <built-in function div>) """ | def get_fake_div(self, ex): """ EXAMPLES:: |
if len(n) == 1: | if len(n) == 0: return FakeExpression([SR.one_element(), d], _operator.div) elif len(n) == 1: | def get_fake_div(self, ex): """ EXAMPLES:: |
from sage.rings.all import Rational | def arithmetic(self, ex, operator): r""" EXAMPLES:: | |
'How big the point is.' | 'How big the point is (i.e., area in points^2=(1/72 inch)^2).' | def _allowed_options(self): """ Return the allowed options for the Point class. |
'size': 'How big the point is.', | 'size': 'How big the point is (i.e., area in points^2=(1/72 inch)^2).', | def _allowed_options(self): """ Return the allowed options for the Point class. |
""" g = self.division_points(m, poly_only=True) return len(g.roots(multiplicities=False)) > 0 | A finite field example:: sage: E = EllipticCurve(GF(101),[23,34]) sage: E.cardinality().factor() 2 * 53 sage: Set([T.order() for T in E.points()]) {1, 106, 2, 53} sage: len([T for T in E.points() if T.is_divisible_by(2)]) 53 sage: len([T for T in E.points() if T.is_divisible_by(3)]) 106 TESTS: This shows that the bu... | def is_divisible_by(self, m): """ Return True if there exists a point `Q` defined over the same field as self such that `mQ` == self. |
sage: P5.homology() | The following computation can take a long time -- over half an hour -- with Sage's default computation of homology groups, but if you have CHomP installed, Sage will use that and the computation should only take a second or two. (You can download CHomP from http://chomp.rutgers.edu/, or you can install it as a Sage pa... | def RealProjectiveSpace(self, n): r""" A triangulation of `\Bold{R}P^n` for any `n \geq 0`. |
non negative integer | non negative real number | def height(self): r""" Returns the height of self. |
non negative integer | non negative real number | def width(self): r""" Returns the width of self. |
We can also create spaces corresponding to the groups `\GammaH(N)` intermediate | We can also create spaces corresponding to the groups `\Gamma_H(N)` intermediate | def ModularForms(group = 1, weight = 2, base_ring = None, use_cache = True, prec = defaults.DEFAULT_PRECISION): r""" Create an ambient space of modular forms. INPUT: - ``group`` - A congruence subgroup or a Dirichlet character eps. - ``weight`` - int, the weight, which must be an integer = 1. - ``base_ring`` -... |
sage: f1(x) = 1 sage: f2(x) = 1-x sage: f = Piecewise([[(0,1),f1],[(1,2),f2]]) | sage: f1(x) = 1-x sage: f = Piecewise([[(0,1),1],[(1,2),f1]]) | def integral(self, x=None, a=None, b=None, definite=False): r""" By default, returns the indefinite integral of the function. If definite=True is given, returns the definite integral. |
Digraph on 6 vertices | Hasse diagram of a poset containing 6 elements | def hasse_diagram(self): """ Returns the Hasse_diagram of the poset as a Sage DiGraph object. EXAMPLES:: sage: Q = Poset({5:[2,3], 1:[3,4], 2:[0], 3:[0], 4:[0]}) sage: Q.hasse_diagram() Digraph on 6 vertices |
'ton_force':'Defined to be the magnitude of the force exerted on one ton of mass (2000 pounds) by a 9.80665 meter/second^2 gravitational field.\nApproximately equal to 8896.4432 newtons.'}, | 'ton_force':'Defined to be 2000 pounds of force.\nApproximately equal to 8896.4432 newtons.'}, | def evalunitdict(): """ Replace all the string values of the unitdict variable by their evaluated forms, and builds some other tables for ease of use. This function is mainly used internally, for efficiency (and flexibility) purposes, making it easier to describe the units. EXAMPLES:: sage: sage.symbolic.units.evalun... |
{'candela':'SI base unit of luminous intensity.\nDefined to be the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540*10^12 hertz and that has a radiant intensity in that direction of 1\xe2\x81\x84683 watt per steradian.', | {'candela':'SI base unit of luminous intensity.\nDefined to be the luminous intensity, in a given direction, of a source that emits monochromatic radiation of frequency 540*10^12 hertz and that has a radiant intensity in that direction of 1/683 watt per steradian.', | def evalunitdict(): """ Replace all the string values of the unitdict variable by their evaluated forms, and builds some other tables for ease of use. This function is mainly used internally, for efficiency (and flexibility) purposes, making it easier to describe the units. EXAMPLES:: sage: sage.symbolic.units.evalun... |
'solar_mass':'Defined to be the mass of the Sun.\nAbout 332,950 times the size of the Earth or 1,048 times the mass of Jupiter.\nApproximately equal to 1.98892*10^30 kilograms.', | 'solar_mass':'Defined to be the mass of the Sun.\nAbout 332,950 times the mass of the Earth or 1,048 times the mass of Jupiter.\nApproximately equal to 1.98892*10^30 kilograms.', | def evalunitdict(): """ Replace all the string values of the unitdict variable by their evaluated forms, and builds some other tables for ease of use. This function is mainly used internally, for efficiency (and flexibility) purposes, making it easier to describe the units. EXAMPLES:: sage: sage.symbolic.units.evalun... |
Collection power of units: cheval_vapeur horsepower watt | Collection of units of power: cheval_vapeur horsepower watt | def str_to_unit(name): """ Create the symbolic unit with given name. A symbolic unit is a class that derives from symbolic expression, and has a specialized docstring. INPUT: - ``name`` -- string OUTPUT: - UnitExpression EXAMPLES:: sage: sage.symbolic.units.str_to_unit('acre') acre sage: type(sage.symbolic.unit... |
Collection all units of units: acceleration ... volume | Collection of units of all units: acceleration ... volume | def __init__(self, data, name=''): """ EXAMPLES:: |
Collection area of units: acre are barn hectare rood section square_chain square_meter township | Collection of units of area: acre are barn hectare rood section square_chain square_meter township | def __getattr__(self, name): """ Return the unit with the given name. |
'Collection area of units: acre are barn hectare rood section square_chain square_meter township' """ name = self.__name + ' ' if self.__name else '' return "Collection %sof units: %s"%(name, ' '.join(sorted([str(x) for x in self.__data]))) | 'Collection of units of area: acre are barn hectare rood section square_chain square_meter township' """ name = ' of ' + self.__name if self.__name else '' return "Collection of units{0}: {1}".format(name, ' '.join(sorted([str(x) for x in self.__data]))) | def __repr__(self): """ Return string representation of this collection of units. |
- ``string`` -- a string EXAMPLE:: | - ``string`` -- a string of symbols over some alphabet. OUTPUT: - A table of frequency of each unique symbol in ``string``. If ``string`` is an empty string, return an empty table. EXAMPLES: The frequency table of a non-empty string:: | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a': 5, ' ': 9, 'c': 1, 'b': 1, 'e': 8, 'g': 3, 'f': 1, 'i': 2, 'm': 4, 's': 5, 'o': 4, 'n': 1, 'p': 3, 'S': 1, 'r': 5, 'u': 2, 't': 4, 'v': 1, 'y': 2, 'l': 2} | sage: str = "Stop counting my characters!" sage: T = sorted(frequency_table(str).items()) sage: for symbol, code in T: ... print symbol, code ... 3 ! 1 S 1 a 2 c 3 e 1 g 1 h 1 i 1 m 1 n 2 o 2 p 1 r 2 s 1 t 3 u 1 y 1 The frequency of an empty string:: sage: frequency_table("") {} | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
for l in string: d[l] = d.get(l,0) + 1 | for s in string: d[s] = d.get(s, 0) + 1 | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
class Huffman(): | class Huffman(SageObject): | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
Huffman Encoding This class implements the basic functionalities of Huffman's encoding. It can build a Huffman code from a given string, or from the information of a dictionary associating to each key (the elements of the alphabet) a weight (most of the time, a probability value or a number of occurrences). For examp... | This class implements the basic functionalities of Huffman codes. It can build a Huffman code from a given string, or from the information of a dictionary associating to each key (the elements of the alphabet) a weight (most of the time, a probability value or a number of occurrences). INPUT: - ``string`` -- (defaul... | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
We could have obtained the same result by "training" the Huffman code on the following table of frequency :: | We can obtain the same result by "training" the Huffman code with the following table of frequency:: | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
sage: h2 = Huffman(frequencies = ft) Once ``h1`` has been trained, and hence possesses an encoding code, | sage: h2 = Huffman(table=ft) Once ``h1`` has been trained, and hence possesses an encoding table, | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
Which can be decoded the following way:: | We can decode the above encoded string in the following way:: | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
... precisely what we deserved :-) INPUT: One among the following: - ``string`` -- a string from which the Huffman encoding should be created - ``frequencies`` -- a dictionary associating its frequency or its number of occurrences to each letter of the alphabet. | This does not look like our original string. Instead of using frequency, we can assign weights to each alphabetic symbol:: sage: from sage.coding.source_coding.huffman import Huffman sage: T = {"a":45, "b":13, "c":12, "d":16, "e":9, "f":5} sage: H = Huffman(table=T) sage: L = ["deaf", "bead", "fab", "bee"] sage: E = ... | def frequency_table(string): r""" Return the frequency table corresponding to the given string. INPUT: - ``string`` -- a string EXAMPLE:: sage: from sage.coding.source_coding.huffman import frequency_table sage: str = "Sage is my most favorite general purpose computer algebra system" sage: frequency_table(str) {'a'... |
def __init__(self, string = None, frequencies = None): r""" Constructor for Huffman INPUT: One among the following: - ``string`` -- a string from which the Huffman encoding should be created - ``frequencies`` -- a dictionary associating its frequency or its number of occurrences to each letter of the alphabet. EXA... | def __init__(self, string=None, table=None): r""" Constructor for Huffman. See the docstring of this class for full documentation. 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) TESTS: If b... | def __init__(self, string = None, frequencies = None): r""" Constructor for Huffman |
ValueError: Exactly one of `string` or `frequencies` parameters must be defined """ | ValueError: Exactly one of 'string' and 'table' cannot be None. """ if (string is not None) and (table is not None): raise ValueError( "Exactly one of 'string' and 'table' cannot be None.") | def __init__(self, string = None, frequencies = None): r""" Constructor for Huffman |
if sum([string is not None, frequencies is not None]) != 1: raise ValueError("Exactly one of `string` or `frequencies` parameters must be defined") | self._tree = None self._index = None | def __init__(self, string = None, frequencies = None): r""" Constructor for Huffman |
elif frequencies is not None: self._build_code(frequencies) def _build_code_from_tree(self, tree, d, prefix=''): r""" Builds the code corresponding to a given tree and prefix | elif table is not None: self._build_code(table) def _build_code_from_tree(self, tree, d, prefix): r""" Builds the Huffman code corresponding to a given tree and prefix. | def __init__(self, string = None, frequencies = None): r""" Constructor for Huffman |
EXAMPLE:: | EXAMPLES:: | def _build_code_from_tree(self, tree, d, prefix=''): r""" Builds the code corresponding to a given tree and prefix |
sage: h._build_code_from_tree(h._tree, d) """ | sage: h._build_code_from_tree(h._tree, d, prefix="") """ | def _build_code_from_tree(self, tree, d, prefix=''): r""" Builds the code corresponding to a given tree and prefix |
self._build_code_from_tree(tree[0], d, prefix=prefix+'0') self._build_code_from_tree(tree[1], d, prefix=prefix+'1') | self._build_code_from_tree(tree[0], d, prefix="".join([prefix, "0"])) self._build_code_from_tree(tree[1], d, prefix="".join([prefix, "1"])) | def _build_code_from_tree(self, tree, d, prefix=''): r""" Builds the code corresponding to a given tree and prefix |
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. | Constructs a Huffman code corresponding to an alphabet with the given weight table. INPUT: - ``dic`` -- a dictionary that associates to each symbol of an alphabet a numeric value. If we consider the frequency of each alphabetic symbol, then ``dic`` is considered as the frequency table of the alphabet with each numeri... | 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. |
index = 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. | |
for i,(e,w) in enumerate(index): heappush(heap, (w, i) ) while len(heap)>=2: (w1, i1) = heappop(heap) (w2, i2) = heappop(heap) heappush(heap, (w1+w2,[i1,i2])) | for i, (s, w) in enumerate(dic.items()): heappush(heap, (w, i)) for i in range(1, len(dic)): weight_a, node_a = heappop(heap) weight_b, node_b = heappop(heap) heappush(heap, (weight_a + weight_b, [node_a, node_b])) | 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. |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.