title: Sympy: prevent a subscripted symbol to be evaluated
body: <p>Given a symbol <code>s</code>, which ultimately will be an Array, I want to define the following expression</p>
  <pre><code>A = Array([-s[1]/2, s[0]/2])
  </code></pre>
  <p>but I'd like <code>A</code> to be evaluated only when I compute some other expressions containing it, because <code>s</code> changes over time. I tried</p>
  <pre><code>A = UnevaluatedExpr(Array([-s[1]/2,s[0]/2]))
  </code></pre>
  <p>but I got the error <code>TypeError: 'Symbol' object is not subscriptable</code>, which make me think that some evaluation is performed on <code>s</code>.</p>
  <p>Thanks for your patience, I'm just learning Sympy and I'm used to <a href="https://wxmaxima-developers.github.io/wxmaxima/index.html" rel="nofollow noreferrer">Maxima</a> where this kind of construct is straightforward. To be more precise, with Maxima the full working code I'm trying to <em>translate</em> into Sympy is (in Maxima everything is a symbol, colon is the assignment operator, <code>ev</code> forces evaluation with custom values, the dot before <code>diff</code> is the vector scalar product):</p>
  <pre><code>A: [-s[2],s[1]]/2; /* define A in terms of subscripted symbols */
  P1: [x1,y1];
  P2: [x2,y2];
  segment: P1+t*(P2-P1); /* --&gt; [t*(x2-x1)+x1,t*(y2-y1)+y1] */
  factor(integrate(ev(A,s=segment).diff(segment,t),t,0,1)); /* integrates the scalar product of A evaluated over segment and the derivative of segment */
  </code></pre>
  <h4>Follow up</h4>
  <p>Thanks to Oscar answer I was able to come up with a working Sympy translation of the above Maxima code (improvements are welcomed!):</p>
  <pre><code>from sympy import *
  
  def dotprod(*vectors): # scalar product, is there a built in better way?
      return sum(Mul(*x) for x in zip(*vectors))
  
  s = IndexedBase('s')
  A = Array([-s[1]/2,s[0]/2])
  
  t,x1,y1,x2,y2 = symbols('t x1 y1 x2 y2')
  P1 = Array([x1,y1])
  P2 = Array([x2,y2])
  segment = P1 + t * (P2-P1)
  
  dotprod(A.subs(s,segment),segment.diff(t)).integrate((t,0,1)).factor()
  </code></pre>
  <p>Apart from the <code>IndexedBase</code> <em>magic</em> the structure of the code in Maxima and Sympy is very similar.</p>