This text is supposed to serve as both a lesson and a warning for how you read rules vs laws and how you implement these in your programs.
If you have been through the English schooling system, you have probably learnt the following set of rules in your GCSEs / O-Levels:
$$ \Large \begin{gather} a^n \times a^k = a^{n+k} \tag{a} \\ \frac{a^n}{a^k} = a^{n-k} \tag{b} \\ (a^n)^k = a^{n \times k} \tag{c} \end{gather} $$
I'd like to point out an issue with \(c\). How would you simplify the following equation?
$$ \Large \sqrt{x^2} $$
You would most likely reply by doing the following:
$$ \Large \begin{gather} \sqrt{x^2} = (x^2)^{\frac{1}{2}} = x \end{gather} $$
But, what if I were to ask you to put \(-1\) into this formula. Using the original formula:
$$ \sqrt{(-1)^2} = 1 $$
But with our answer, we get:
$$ x = -1 $$
This is wrong, right?
Which one is correct?
Well, the truth is, the formula \(\sqrt{x^2}\) is actually a mathematical identity, and it looks like this:
$$ \sqrt{x^2} = \lvert x \rvert $$
If you studied an Advanced Level maths course you should probably recognise this as the modulus function.
The Modulus Function: The absolute value of a number. \(\lvert x \rvert \geq 0\)
But this actually depends who you ask. If you look at the first section of the Wikipedia Article, it states that the symbol \(\sqrt{\quad}\) finds the "principal square root" (the root that is positive) and one should specifically denote a square root function as: \(\pm\sqrt{\quad}\) to mean both the negative and positive root. Therefore the function generates the non-negativity and in saying \((x^2)^{\frac{1}{2}}\) you are implying only positive values in itself. So the resultant value you get, will always be positive.
Let's take a step back, and actually read what the rule says. On "byjus", we see that it is actually defined as: "\((a^m)^n\) where a is a non-zero term and m and n are integers."
This shows the key problem with the method of teaching children something as fact and then later on down the line saying that this rule isn't exactly as it was first taught. Although it gives people a step into the system, to help them understand a certain percentage of mathematics. I believe there should always be links provided to students explaining exactly how these things work and how to deal with them in real, pure mathematics.
This isn't supposed to be a dig at any of these CAS because they are genuinely all works of art and massive feats and I fully respect anybody who could develop a system such as these, they have my greatest respect. I merely wished to point out a few things about the different CAS systems I have used in the past.
Take for example, a computer algebra system, like, for example:
Due to the fact we know that \((x^2)^{\frac{1}{2}} = \lvert x \rvert \), let's check the chain rule for differentiation, and see if it works for this.
The \(\frac{d}{dx}\) of \(\lvert x \rvert\) is \(\frac{x}{\lvert x \rvert }\) where \(x \neq 0\). If you plot this graph it is very obvious. If you want to really be specific the differentiation of the modulus is actually signum / sgn(x).
Let's have a look at applying the chain rule to the following function: \(y = (x^2)^{\frac{1}{2}}\).
$$ \Large \begin{align} y &= (u)^{\frac{1}{2}} \text{ where } u = x^2 \\ \frac{dy}{dx} &= \frac{1}{2} \times (x^2)^{-\frac{1}{2}} \times 2x \\ &= x(x^2)^{-\frac{1}{2}} \\ &= \frac{x}{(x^2)^{\frac{1}{2}}} \\ &= \frac{x}{\lvert x \rvert} \\ \end{align} $$
Let's test this against some Computer Algebra Systems: