1
$\begingroup$

I have tried

(a[i])^2

and alternatively

(a^2)[i]

Apparently both seem to work, but I was wondering what was the right way to do it? This might sound like a silly question (apologies if it is). But I am doing some tedious calculations and I don't want a silly mistake to carry forward.

Thanks in advance.

$\endgroup$
2
  • 1
    $\begingroup$ With a[i] = 2 compare what (a[i])^2 evaluates versus what (a^2)[i] evaluates. $\endgroup$
    – Edmund
    Oct 8, 2017 at 18:38
  • 1
    $\begingroup$ Short answer is the first. For explanation see this excellent answer. Also I suggest you read this post. $\endgroup$
    – ercegovac
    Oct 8, 2017 at 18:57

1 Answer 1

2
$\begingroup$

The universal answer for such kind of questions is to compare FullForms of the expessions. You will see their actual internal structure in a readable and (usually) easy-to-interpret form.

Recommended reading:

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.