title: How to simplify sympy vectors?
body: <p>I am doing some symbolic vector calculations using <code>sympy</code>, but I can't simplify the arguments of the vector class in a proper way. Consider this code:</p>
  
  <pre class="lang-py prettyprint-override"><code>from sympy.physics.mechanics import ReferenceFrame, dot, cross
  from sympy import symbols, sin, cos, simplify
  
  alpha, theta, l = symbols('alpha theta l')
  
  def Rodrigues(v, k, angle):
      return cos(angle) * v + cross(k, v) * sin(angle) + k * dot(k, v) * (1- cos(angle))
  
  N = ReferenceFrame('N')
  P0 = -l * N.y
  
  P2 = Rodrigues(
      Rodrigues(P0, -N.z, alpha), 
      Rodrigues(N.x, -N.z, alpha), 
      theta)
  </code></pre>
  
  <p>which returns:</p>
  
  <pre>
           <img src="https://i.stack.imgur.com/23bEd.png" width="500" />
  </pre>
  
  <p>trying the <code>simplify(P2)</code> I get the error:</p>
  
  <blockquote>
    <p>AttributeError: 'function' object has no attribute 'x'</p>
  </blockquote>
  
  <p>which I think is because the <code>simplify</code> requires a <code>sympy</code> expression object. trying the <code>dir(P2)</code> there is a <code>simplify</code> method which returns: </p>
  
  <pre><code>&lt;bound method Vector.simplify of - l*sin(alpha)*cos(theta)*N.x - l*cos(alpha)*cos(theta)*N.y + (-l*sin(alpha)**2 - l*cos(alpha)**2)*sin(theta)*N.z&gt;
  </code></pre>
  
  <p>which I have no idea what it is! trying the <code>P2.args</code> I get:</p>
  
  <pre><code>[(Matrix([
    [                       -l*sin(alpha)*cos(theta)],
    [                       -l*cos(alpha)*cos(theta)],
    [(-l*sin(alpha)**2 - l*cos(alpha)**2)*sin(theta)]]), N)]
  </code></pre>
  
  <p>which is a 1D List of a 2D tuple with a nested 3x1 <code>sympy</code> Matrix! I don't know whos choice was to make the vector class so obscure, but now I can simplify the last element with <code>simplify(P2.args[0][0][2])</code> and change the function to:</p>
  
  <pre class="lang-py prettyprint-override"><code>def Rodrigues(v, k, angle):
      tmpVec = cos(angle) * v + cross(k, v) * sin(angle) + k * dot(k, v) * (1- cos(angle))
      tmpFrame = tmpVec.args[0][1]
      return simplify(tmpVec.args[0][0][0]) * tmpFrame.x + simplify(tmpVec.args[0][0][1]) * tmpFrame.y + simplify(tmpVec.args[0][0][2]) * tmpFrame.z
  </code></pre>
  
  <p>which to me seems like a very bad solution. </p>
  
  <p>I was wondering if you could help me know if there is a more Pythonic way to do this. For example, force <code>sympy</code> to simplify all expressions by default. Or maybe I'm using the <code>vector.simplify</code> method in a wrong way? Thanks for your support in advance.</p>
  
  <p>P.S. <a href="https://en.wikipedia.org/wiki/Rodrigues%27_rotation_formula" rel="nofollow noreferrer">Rodrigues</a> rotation formula</p>