Ask Your Question

Define map with vector argument(s)

asked 2017-06-22 00:14:46 +0200

Thrash gravatar image

updated 2017-06-22 01:25:27 +0200

(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

answered 2017-06-22 11:05:57 +0200

eric_g gravatar image

updated 2017-06-22 11:53:14 +0200

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)
sage: phi(x,y) == x[1]*y[1] - x[2]*y[2] + x[3]*y[3]
edit flag offensive delete link more

answered 2017-06-22 11:36:17 +0200

dan_fulea gravatar image

updated 2017-06-22 11:49:54 +0200

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)

(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)) ] )

(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()
sage: sum( [ (-1)^k*x[k]*y[k] for k in range(len(x)) ] )
sage: ( x*PHI ).inner_product(y) 

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

sage: y.column()
[ 2]
[ 3]
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


Asked: 2017-06-22 00:14:46 +0200

Seen: 424 times

Last updated: Jun 22 '17