I’m writing a symbolic differentiation library for Julia (see https://www.microsoft.com/en-us/research/wp-content/uploads/2016/02/main-65.pdf if you are interested) and ran into a problem with promote rules and ^. In an expression like a^7, where a is one of my symbolic numbers, I expected the promotion rule to be applied to the exponent to turn it into a symbolic constant returning a symbolic expression a^7. Instead it seems that before the promote rule is called a^7 is transformed into ((a * (a * a)) * ((a * a) * (a * a))). This is a harder expression to differentiate efficiently. My code doesn’t control when the promote rule to convert from numbers to symbolic numbers gets called.

Is there any way around this behavior?