Path: blob/master/sage/modules/vector_callable_symbolic_dense.py
4057 views
"""1Vectors over callable symbolic rings23AUTHOR:4-- Jason Grout (2010)56EXAMPLES::78sage: f(r, theta, z) = (r*cos(theta), r*sin(theta), z)9sage: f.parent()10Vector space of dimension 3 over Callable function ring with arguments (r, theta, z)11sage: f12(r, theta, z) |--> (r*cos(theta), r*sin(theta), z)13sage: f[0]14(r, theta, z) |--> r*cos(theta)15sage: f+f16(r, theta, z) |--> (2*r*cos(theta), 2*r*sin(theta), 2*z)17sage: 3*f18(r, theta, z) |--> (3*r*cos(theta), 3*r*sin(theta), 3*z)19sage: f*f # dot product20(r, theta, z) |--> r^2*sin(theta)^2 + r^2*cos(theta)^2 + z^221sage: f.diff()(0,1,2) # the matrix derivative22[cos(1) 0 0]23[sin(1) 0 0]24[ 0 0 1]252627TESTS::2829sage: f(u,v,w) = (2*u+v,u-w,w^2+u)30sage: loads(dumps(f)) == f31True323334"""3536#*****************************************************************************37# Copyright (C) 2010 Jason Grout <[email protected]>38#39# Distributed under the terms of the GNU General Public License (GPL)40#41# This code is distributed in the hope that it will be useful,42# but WITHOUT ANY WARRANTY; without even the implied warranty of43# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU44# General Public License for more details.45#46# The full text of the GPL is available at:47#48# http://www.gnu.org/licenses/49#*****************************************************************************5051import free_module_element52from sage.symbolic.ring import SR535455class Vector_callable_symbolic_dense(free_module_element.FreeModuleElement_generic_dense):56575859def _repr_(self):60"""61Returns the string representation of the vector6263EXAMPLES::64sage: f(u,v,w) = (2*u+v,u-w,w^2+u)65sage: f66(u, v, w) |--> (2*u + v, u - w, w^2 + u)67sage: r(t) = (cos(t), sin(t))68sage: r69t |--> (cos(t), sin(t))70"""71ring=self.base_ring()72args = ring.arguments()73repr_x=self.change_ring(SR)._repr_()74if len(args) == 1:75return "%s |--> %s" % (args[0], repr_x)76else:77args = ", ".join(map(str, args))78return "(%s) |--> %s" % (args, repr_x)798081def _latex_(self):82"""83Returns the latex representation of the vector8485EXAMPLES::86sage: f(u,v,w) = (2*u+v,u-w,w^2+u)87sage: f88(u, v, w) |--> (2*u + v, u - w, w^2 + u)89sage: latex(f)90\left( u, v, w \right) \ {\mapsto} \ \left(2 \, u + v,\,u - w,\,w^{2} + u\right)91sage: r(t) = (cos(t), sin(t))92sage: r93t |--> (cos(t), sin(t))94sage: latex(r)95t \ {\mapsto}\ \left(\cos\left(t\right),\,\sin\left(t\right)\right)96"""97from sage.misc.latex import latex98ring=self.base_ring()99args = ring.arguments()100args = [latex(arg) for arg in args]101latex_x = self.change_ring(SR)._latex_()102if len(args) == 1:103return r"%s \ {\mapsto}\ %s" % (args[0], latex_x)104else:105vars = ", ".join(args)106# the weird TeX is to workaround an apparent JsMath bug107return r"\left( %s \right) \ {\mapsto} \ %s" % (vars, latex_x)108109110