This comment is hidden because it contains spoiler information about the solution
What [...Array] means? I didn't get it.
You are right
I think you forgot to multiply the inner derivative on cos, tan and exp.
And the arguments for ^ should also be differentiated in case they are nested expressions.
I will add test cases for these as soon as CW stops timing out.
The [...Array(n)] is brilliant here