def twoform_to_matrix(expr):
 if ((covariant_order(expr) != 2) or contravariant_order(expr)):
  raise ValueError('The input expression is not a two-form.')
 coord_sys = expr.atoms(CoordSystem)
 if (len(coord_sys) != 1):
  raise ValueError('The input expression concerns more than one coordinate systems, hence there is no unambiguous way to choose a coordinate system for the matrix.')
 coord_sys = coord_sys.pop()
 vectors = coord_sys.base_vectors()
 expr = expr.expand()
 matrix_content = [[expr.rcall(v1, v2) for v1 in vectors] for v2 in vectors]
 return Matrix(matrix_content)

def twoform_to_matrix ( expr ) : if ( ( covariant_order ( expr ) != 2 ) or contravariant_order ( expr ) ) : raise ValueError ( 'The input expression is not a two-form.' ) coord_sys = expr . atoms ( CoordSystem ) if ( len ( coord_sys ) != 1 ) : raise ValueError ( 'The input expression concerns more than one coordinate systems, hence there is no unambiguous way to choose a coordinate system for the matrix.' ) coord_sys = coord_sys . pop ( ) vectors = coord_sys . base_vectors ( ) expr = expr . expand ( ) matrix_content = [ [ expr . rcall ( v1 , v2 ) for v1 in vectors ] for v2 in vectors ] return Matrix ( matrix_content )
return the matrix representing the twoform .