Processing math: 100%
Ask Your Question
1

Define map with vector argument(s)

asked 7 years ago

Thrash gravatar image

updated 7 years ago

(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?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 7 years ago

eric_g gravatar image

updated 7 years ago

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
Preview: (hide)
link
1

answered 7 years ago

dan_fulea gravatar image

updated 7 years ago

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]
Preview: (hide)
link

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: 7 years ago

Seen: 583 times

Last updated: Jun 22 '17