# Revision history [back]

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


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*y - x*y + x*y
True