def list_derivarives(ex, list_d, exponent=0): r""" Function to find the occurences of FDerivativeOperator in the expression; inspired by http://ask.sagemath.org/question/10256/how-can-extract-different-terms-from-a-symbolic-expression/?answer=26136#post-id-26136 INPUT: - ``ex`` -- symbolic expression to be analyzed - ``exponent`` -- (optional) exponent of FDerivativeOperator, passed to a next level in the expression tree OUTPUT: - ``list_d`` -- tuple containing the details of FDerivativeOperator found, in a following order: 1. operator 2. function name 3. LaTeX function name 4. parameter set 5. operands 6. exponent (if found, else 0) TESTS:: sage: f = function('f_x', x, latex_name=r"{\cal F}") sage: df = f.diff(x)^2 sage: from sage.geometry.manifolds.utilities import list_derivarives sage: list_d = [] sage: list_derivarives(df, list_d) sage: list_d [(D[0](f_x)(x), 'f_x', {\cal F}, [0], [x], 2)] """ op = ex.operator() operands = ex.operands() import operator from sage.misc.latex import latex, latex_variable_name from sage.symbolic.operators import FDerivativeOperator if op: if op is operator.pow: if isinstance(operands[0].operator(), FDerivativeOperator): exponent = operands[1] if isinstance(op, FDerivativeOperator): parameter_set = op.parameter_set() function = repr(op.function()) latex_function = latex(op.function()) # case when no latex_name given if function == latex_function: latex_function = latex_variable_name(str(op.function())) list_d.append((ex, function, latex_function, parameter_set, operands, exponent)) for operand in operands: list_derivarives(operand, list_d, exponent)
def _latex_(self): if self._name: l_name = latex_variable_name(self._name) + ': \\left(' else: l_name = '\\left(' return l_name + latex(self._red_edges) + '\\mapsto red; ' + latex( self._blue_edges) + '\\mapsto blue\\right)'
def list_functions(ex, list_f): r""" Function to find the occurences of symbolic functions in the expression. INPUT: - ``ex`` -- symbolic expression to be analyzed OUTPUT: - ``list_f`` -- tuple containing the details of a symbolic function found, in a following order: 1. operator 2. function name 3. arguments 4. LaTeX version of function name 5. LaTeX version of arguments TESTS:: sage: var('x y z') (x, y, z) sage: f = function('f', x, y, latex_name=r"{\cal F}") sage: g = function('g_x', x, y) sage: d = sin(x)*g.diff(x)*x*f - x^2*f.diff(x,y)/g sage: from sage.geometry.manifolds.utilities import list_functions sage: list_f = [] sage: list_functions(d, list_f) sage: list_f [(f, 'f', '(x, y)', {\cal F}, \left(x, y\right)), (g_x, 'g_x', '(x, y)', 'g_{x}', \left(x, y\right))] """ op = ex.operator() operands = ex.operands() from sage.misc.latex import latex, latex_variable_name if op: if str(type(op)) == "<class 'sage.symbolic.function_factory.NewSymbolicFunction'>": repr_function = repr(op) latex_function = latex(op) # case when no latex_name given if repr_function == latex_function: latex_function = latex_variable_name(str(op)) repr_args = repr(ex.arguments()) # remove comma in case of singleton if len(ex.arguments())==1: repr_args = repr_args.replace(",","") latex_args = latex(ex.arguments()) list_f.append((op, repr_function, repr_args, latex_function, latex_args)) for operand in operands: list_functions(operand, list_f)
def __init__(self, field, prec, log_radii, names, order, integral=False): """ Initialize the Tate algebra TESTS:: sage: A.<x,y> = TateAlgebra(Zp(2), log_radii=1) sage: TestSuite(A).run() We check that univariate Tate algebras work correctly:: sage: B.<t> = TateAlgebra(Zp(3)) """ from sage.misc.latex import latex_variable_name from sage.rings.polynomial.polynomial_ring_constructor import _multi_variate self.element_class = TateAlgebraElement self._field = field self._cap = prec self._log_radii = ETuple(log_radii) # TODO: allow log_radii in QQ self._names = names self._latex_names = [latex_variable_name(var) for var in names] uniformizer = field.change(print_mode='terse', show_prec=False).uniformizer() self._uniformizer_repr = uniformizer._repr_() self._uniformizer_latex = uniformizer._latex_() self._ngens = len(names) self._order = order self._integral = integral if integral: base = field.integer_ring() else: base = field CommutativeAlgebra.__init__(self, base, names, category=CommutativeAlgebras(base)) self._polynomial_ring = _multi_variate(field, names, order=order) one = field(1) self._parent_terms = TateTermMonoid(self) self._oneterm = self._parent_terms(one, ETuple([0] * self._ngens)) if integral: # This needs to be update if log_radii are allowed to be non-integral self._gens = [ self((one << log_radii[i]) * self._polynomial_ring.gen(i)) for i in range(self._ngens) ] self._integer_ring = self else: self._gens = [self(g) for g in self._polynomial_ring.gens()] self._integer_ring = TateAlgebra_generic(field, prec, log_radii, names, order, integral=True) self._integer_ring._rational_ring = self._rational_ring = self
def expression_tree(s, list_derivs, exponent=0): r""" Function to find the occurences of FDerivativeOperator in the expression; inspired by http://ask.sagemath.org/question/10256/how-can-extract-different-terms-from-a-symbolic-expression/?answer=26136#post-id-26136 INPUT: - ``s`` -- symbolic expression to be analyzed - ``exponent`` -- (optional) exponent of FDerivativeOperator, passed to a next level in the expression tree OUTPUT: - ``list_derivs`` -- tuple containing the details of FDerivativeOperator found, in a following order: 1. operator 2. function 3. LaTeX function name string 4. parameter set 5. operands 6. exponent (if found, else 0) TESTS:: sage: f = function('f_x', x) sage: df = f.diff(x)^2 sage: from sage.geometry.manifolds.utilities import expression_tree sage: list_derivs = [] sage: expression_tree(df, list_derivs) sage: list_derivs [(D[0](f_x)(x), f_x, 'f_{x}', [0], [x], 2)] """ from sage.symbolic.operators import FDerivativeOperator from sage.misc.latex import latex_variable_name import operator op = s.operator() operands = s.operands() if op: if op is operator.pow: if isinstance(operands[0].operator(), FDerivativeOperator): exponent = operands[1] if isinstance(op, FDerivativeOperator): parameter_set = op.parameter_set() function = op.function() latex_function = latex_variable_name(str(function)) list_derivs.append((s, function, latex_function, parameter_set, operands, exponent)) for operand in operands: expression_tree(operand, list_derivs, exponent)
def _list_functions(ex, list_f): r""" Function to find the occurrences of symbolic functions in a symbolic expression. INPUT: - ``ex`` -- symbolic expression to be analyzed OUTPUT: - ``list_f`` -- tuple containing the details of a symbolic function found, in the following order: 1. operator 2. function name 3. arguments 4. LaTeX version of function name 5. LaTeX version of arguments TESTS:: sage: var('x y z') (x, y, z) sage: f = function('f', latex_name=r"{\cal F}")(x, y) sage: g = function('g_x')(x, y) sage: d = sin(x)*g.diff(x)*x*f - x^2*f.diff(x,y)/g sage: from sage.manifolds.utilities import _list_functions sage: list_f = [] sage: _list_functions(d, list_f) sage: list_f [(f, 'f', '(x, y)', {\cal F}, \left(x, y\right)), (g_x, 'g_x', '(x, y)', 'g_{x}', \left(x, y\right))] """ op = ex.operator() operands = ex.operands() from sage.misc.latex import latex, latex_variable_name if op: # FIXME: This hack is needed because the NewSymbolicFunction is # a class defined inside of the *function* function_factory(). if str( type(op) ) == "<class 'sage.symbolic.function_factory.NewSymbolicFunction'>": repr_function = repr(op) latex_function = latex(op) # case when no latex_name given if repr_function == latex_function: latex_function = latex_variable_name(str(op)) repr_args = repr(ex.arguments()) # remove comma in case of singleton if len(ex.arguments()) == 1: repr_args = repr_args.replace(",", "") latex_args = latex(ex.arguments()) list_f.append( (op, repr_function, repr_args, latex_function, latex_args)) for operand in operands: _list_functions(operand, list_f)
def _list_derivatives(ex, list_d, exponent=0): r""" Function to find the occurrences of ``FDerivativeOperator`` in a symbolic expression; inspired by http://ask.sagemath.org/question/10256/how-can-extract-different-terms-from-a-symbolic-expression/?answer=26136#post-id-26136 INPUT: - ``ex`` -- symbolic expression to be analyzed - ``exponent`` -- (optional) exponent of ``FDerivativeOperator``, passed to a next level in the expression tree OUTPUT: - ``list_d`` -- tuple containing the details of ``FDerivativeOperator`` found, in the following order: 1. operator 2. function name 3. LaTeX function name 4. parameter set 5. operands 6. exponent (if found, else 0) TESTS:: sage: f = function('f_x', latex_name=r"{\cal F}")(x) sage: df = f.diff(x)^2 sage: from sage.manifolds.utilities import _list_derivatives sage: list_d = [] sage: _list_derivatives(df, list_d) sage: list_d [(diff(f_x(x), x), 'f_x', {\cal F}, [0], [x], 2)] """ op = ex.operator() operands = ex.operands() import operator from sage.misc.latex import latex, latex_variable_name from sage.symbolic.operators import FDerivativeOperator if op: if op is operator.pow: if isinstance(operands[0].operator(), FDerivativeOperator): exponent = operands[1] if isinstance(op, FDerivativeOperator): parameter_set = op.parameter_set() function = repr(op.function()) latex_function = latex(op.function()) # case when no latex_name given if function == latex_function: latex_function = latex_variable_name(str(op.function())) list_d.append((ex, function, latex_function, parameter_set, operands, exponent)) for operand in operands: _list_derivatives(operand, list_d, exponent)
def plot(self, grid_pos=False, zigzag=False): r""" Return a plot of the NAC-coloring. EXAMPLES:: sage: from flexrilog import FlexRiGraph sage: G = FlexRiGraph(graphs.CompleteBipartiteGraph(3,3)) sage: delta = G.NAC_colorings()[0] sage: delta.plot() Graphics object consisting of 16 graphics primitives .. PLOT:: from flexrilog import FlexRiGraph G = FlexRiGraph(graphs.CompleteBipartiteGraph(3,3)) sphinx_plot(G.NAC_colorings()[0]) :: sage: from flexrilog import GraphGenerator sage: G = GraphGenerator.ThreePrismGraph() sage: delta = G.NAC_colorings()[0].conjugated() sage: delta.plot(grid_pos=True) Graphics object consisting of 16 graphics primitives .. PLOT:: from flexrilog import GraphGenerator G = GraphGenerator.ThreePrismGraph() delta = G.NAC_colorings()[0].conjugated() sphinx_plot(delta.plot(grid_pos=True)) :: sage: from flexrilog import GraphGenerator sage: G = GraphGenerator.ThreePrismGraph() sage: delta = G.NAC_colorings()[0].conjugated() sage: delta.plot(grid_pos=True, zigzag=True) Graphics object consisting of 16 graphics primitives .. PLOT:: from flexrilog import GraphGenerator G = GraphGenerator.ThreePrismGraph() delta = G.NAC_colorings()[0].conjugated() sphinx_plot(delta.plot(grid_pos=True, zigzag=True)) :: sage: from flexrilog import GraphGenerator sage: G = GraphGenerator.ThreePrismGraph() sage: delta = G.NAC_colorings()[0].conjugated() sage: delta.plot(grid_pos=True, zigzag=[[[0,0], [0,1]], [[0,0], [1,1/2], [2,0]]]) Graphics object consisting of 16 graphics primitives .. PLOT:: from flexrilog import GraphGenerator G = GraphGenerator.ThreePrismGraph() delta = G.NAC_colorings()[0].conjugated() sphinx_plot(delta.plot(grid_pos=True, zigzag=[[[0,0], [0,1]], [[0,0], [1,1/2], [2,0]]])) TODO: doc """ args_kwd = {} if self.name(): args_kwd['title'] = '$' + latex_variable_name(self.name()) + '$' if grid_pos: from graph_motion import GraphMotion args_kwd['pos'] = GraphMotion.GridConstruction( self._graph, self, zigzag).realization(0, numeric=True) # grid_coor = self.grid_coordinates() # if zigzag: # if type(zigzag) == list and len(zigzag) == 2: # a = [vector(c) for c in zigzag[0]] # b = [vector(c) for c in zigzag[1]] # else: # m = max([k for _, k in grid_coor.values()]) # n = max([k for k, _ in grid_coor.values()]) # a = [vector([0.3*((-1)^i-1)+0.3*sin(i), i]) for i in range(0,m+1)] # b = [vector([j, 0.3*((-1)^j-1)+0.3*sin(j)]) for j in range(0,n+1)] # else: # positions = {} # m = max([k for _, k in grid_coor.values()]) # n = max([k for k, _ in grid_coor.values()]) # a = [vector([0, i]) for i in range(0,m+1)] # b = [vector([j, 0]) for j in range(0,n+1)] # alpha = 0 # rotation = matrix([[cos(alpha), sin(alpha)], [-sin(alpha), cos(alpha)]]) # positions = {} # for v in self._graph.vertices(): # positions[v] = rotation * a[grid_coor[v][1]] + b[grid_coor[v][0]] # return self._graph.plot(NAC_coloring=self, pos=positions) return self._graph.plot(NAC_coloring=self, name_in_title=False, **args_kwd)