def u(p, r):
 if (r not in [1, 2]):
  raise ValueError('Value of r should lie between 1 and 2')
 (p1, p2, p3) = p
 if (r == 1):
  ksi = Matrix([[1], [0]])
 else:
  ksi = Matrix([[0], [1]])
 a = (((((sigma1 * p1) + (sigma2 * p2)) + (sigma3 * p3)) / (E + m)) * ksi)
 if (a == 0):
  a = zeros(2, 1)
 return (sqrt((E + m)) * Matrix([[ksi[(0, 0)]], [ksi[(1, 0)]], [a[(0, 0)]], [a[(1, 0)]]]))

def u ( p , r ) : if ( r not in [ 1 , 2 ] ) : raise ValueError ( 'Value of r should lie between 1 and 2' ) ( p1 , p2 , p3 ) = p if ( r == 1 ) : ksi = Matrix ( [ [ 1 ] , [ 0 ] ] ) else : ksi = Matrix ( [ [ 0 ] , [ 1 ] ] ) a = ( ( ( ( ( sigma1 * p1 ) + ( sigma2 * p2 ) ) + ( sigma3 * p3 ) ) / ( E + m ) ) * ksi ) if ( a == 0 ) : a = zeros ( 2 , 1 ) return ( sqrt ( ( E + m ) ) * Matrix ( [ [ ksi [ ( 0 , 0 ) ] ] , [ ksi [ ( 1 , 0 ) ] ] , [ a [ ( 0 , 0 ) ] ] , [ a [ ( 1 , 0 ) ] ] ] ) )
emulate ustr in python 2 .