Vectors over callable symbolic rings

AUTHOR:
– Jason Grout (2010)

EXAMPLES:

sage: f(r, theta, z) = (r*cos(theta), r*sin(theta), z)
sage: f.parent()
Vector space of dimension 3 over Callable function ring with arguments (r, theta, z)
sage: f
(r, theta, z) |--> (r*cos(theta), r*sin(theta), z)
sage: f[0]
(r, theta, z) |--> r*cos(theta)
sage: f+f
(r, theta, z) |--> (2*r*cos(theta), 2*r*sin(theta), 2*z)
sage: 3*f
(r, theta, z) |--> (3*r*cos(theta), 3*r*sin(theta), 3*z)
sage: f*f # dot product
(r, theta, z) |--> r^2*cos(theta)^2 + r^2*sin(theta)^2 + z^2
sage: f.diff()(0,1,2) # the matrix derivative
[cos(1)      0      0]
[sin(1)      0      0]
[     0      0      1]

TESTS:

sage: f(u,v,w) = (2*u+v,u-w,w^2+u)
sage: loads(dumps(f)) == f
True
class sage.modules.vector_callable_symbolic_dense.Vector_callable_symbolic_dense

Bases: sage.modules.free_module_element.FreeModuleElement_generic_dense

EXAMPLES:

sage: type(vector(RR, [-1,0,2/3,pi,oo]))
<type 'sage.modules.free_module_element.FreeModuleElement_generic_dense'>

We can initialize with lists, tuples and derived types:

sage: from sage.modules.free_module_element import FreeModuleElement_generic_dense
sage: FreeModuleElement_generic_dense(RR^5, [-1,0,2/3,pi,oo])
(-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity)
sage: FreeModuleElement_generic_dense(RR^5, (-1,0,2/3,pi,oo))
(-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity)
sage: FreeModuleElement_generic_dense(RR^5, Sequence([-1,0,2/3,pi,oo]))
(-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity)
sage: FreeModuleElement_generic_dense(RR^0, 0)
()

TESTS:

Disabling coercion can lead to illegal objects:

sage: FreeModuleElement_generic_dense(RR^5, [-1,0,2/3,pi,oo], coerce=False)
(-1, 0, 2/3, pi, +Infinity)

We test the copy flag:

sage: from sage.modules.free_module_element import FreeModuleElement_generic_dense
sage: L = [RR(x) for x in (-1,0,2/3,pi,oo)]
sage: FreeModuleElement_generic_dense(RR^5, tuple(L), coerce=False, copy=False)
(-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity)
sage: v = FreeModuleElement_generic_dense(RR^5, L, coerce=False, copy=False)
sage: L[4] = 42.0
sage: v  # last entry changed since we didn't copy
(-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, 42.0000000000000)
sage: L = [RR(x) for x in (-1,0,2/3,pi,oo)]
sage: v = FreeModuleElement_generic_dense(RR^5, L, coerce=False, copy=True)
sage: L[4] = 42.0
sage: v  # last entry did not change
(-1.00000000000000, 0.000000000000000, 0.666666666666667, 3.14159265358979, +infinity)

Check that trac ticket #11751 is fixed:

sage: K.<x> = QQ[]
sage: M = K^1
sage: N = M.span([[1/x]]); N
Free module of degree 1 and rank 1 over Univariate Polynomial Ring in x over Rational Field
Echelon basis matrix:
[1/x]
sage: N([1/x]) # this used to fail prior to #11751
(1/x)
sage: N([1/x^2])
Traceback (most recent call last):
...
TypeError: element (= [1/x^2]) is not in free module
sage: L=K^2
sage: R=L.span([[x,0],[0,1/x]], check=False, already_echelonized=True)
sage: R.basis()[0][0].parent()
Fraction Field of Univariate Polynomial Ring in x over Rational Field
sage: R=L.span([[x,x^2]])
sage: R.basis()[0][0].parent()
Univariate Polynomial Ring in x over Rational Field

Previous topic

Pickling for the old RDF vector class

Next topic

Space of Morphisms of Vector Spaces (Linear Transformations)

This Page