Ask Your Question
1

Define map with vector argument(s)

asked 2017-06-21 17:14:46 -0500

Tommy Angelo gravatar image

updated 2017-06-21 18:25:27 -0500

(Is it possible to use LaTeX code here in order to get a nice output?)

Let's say I want to put the map phi: Q^3 x Q^3 -> Q defined by (x,y) -> x1y1 - x2y2 + x3*y3 into Sage. How do I do this? I want to have later for example:

sage: x=vector((1,2,3)); y=vector((2,3,1))
sage: phi(x,y)

Then the output should be the value phi(x,y).

Is it only possible via the def command (withx[1] etc.)? Or how can you specify the domain of a map? How would you do this?

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
0

answered 2017-06-22 04:05:57 -0500

eric_g gravatar image

updated 2017-06-22 04:53:14 -0500

Assuming phi is bilinear, one possibility is

sage: Q3 = FiniteRankFreeModule(QQ, 3, 'Q^3', start_index=1)
sage: e = Q3.basis('e') # Q^3 canonical basis
sage: phi = Q3.tensor((0,2))
sage: phi[1,1], phi[2,2], phi[3,3] = 1, -1, 1
sage: phi
Type-(0,2) tensor on the 3-dimensional vector space Q^3 over the Rational Field
sage: phi.display()
e^1*e^1 - e^2*e^2 + e^3*e^3
sage: x = Q3((1,2,3)); x
Element of the 3-dimensional vector space Q^3 over the Rational Field
sage: y = Q3((2,3,1))
sage: phi(x,y)
-1
sage: phi(x,y) == x[1]*y[1] - x[2]*y[2] + x[3]*y[3]
True
edit flag offensive delete link more
0

answered 2017-06-22 04:36:17 -0500

dan_fulea gravatar image

updated 2017-06-22 04:49:54 -0500

The inner_product is the implemented method in the case of the phi associated to the $(1,1,1)$ diagonal matrix, for instance:

sage: x=vector((1,2,3)); y=vector((2,3,11))
sage: x.inner_product(y)
41

(That 11 instead of the one in the postshould make the result bigger and avoid "coincidences".)

An explicit check:

sage: sum( [x[k]*y[k] for k in range(len(x)) ] )
41

(The range(len(x)) could have been simply (0,1,2) in this simple case.)

In the more general case the matrix giving the bilinear form can be inserted, we have in the same spirit:

sage: PHI = diagonal_matrix( 3, [1,-1,1] )
sage: x * PHI * y.column()
(29)
sage: sum( [ (-1)^k*x[k]*y[k] for k in range(len(x)) ] )
29
sage: ( x*PHI ).inner_product(y) 
29

Above, y.column() is the column vector related to y.

sage: y.column()
[ 2]
[ 3]
[11]
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower

Stats

Asked: 2017-06-21 17:14:46 -0500

Seen: 123 times

Last updated: Jun 22