# Re: [fricas-devel] Square root bug

```On Sun, Feb 4, 2018 at 2:42 PM, oldk1331 <oldk1...@gmail.com> wrote:
> After r2337, sqrt(sqrt(2)) is not automatically simplified to 2^(1/4).
>
> But there should be a function that allows such manual simplification.
>
> Currently function 'rootPower' simplifies  '(a^(1/n))^m', when m
> and n are positive integers.
>
> We should extend it for cases where m is Fraction Integer,
> and this simplification will be picked by 'simplify',
> and it won't break current codebase.```
```
https://github.com/oldk1331/fricas/commit/e4b9b6fa0f1ae369817984e98a50ba5e47530c3c.patch

@@ -390,13 +390,23 @@
nlk := cons(nk, nlk)
rootPower1(x, lk, nlk)

--- replaces (a^(1/n))^m in p by a power of a simpler radical of a if
--- n and m have a common factor
+-- 'k' is a nthRoot kernel: 'a^(1/n)'.  This function
+-- replaces '(a^(1/n))^m' in 'p' by a power of a simpler radical of 'a' if
+-- n and m have a common factor.  If 'a' itself is a nthRoot kernel
+-- 'b^(1/l)', then 'k' is replaced by simpler radical of 'b'.
a := first(arg := argument k)
n := (retract(second arg)@Integer)::NonNegativeInteger
ans : F := 0
q := univariate(p, k)
+        -- Check if 'a' itself is nthRoot.
+        ka1 := retractIfCan(a)@Union(K, "failed")
+        if ka1 case K and is?(ka1::K, 'nthRoot) then
+            ka := ka1::K
+            arg := argument ka
+            a := first arg
+            n := n * (retract(second arg)@Integer::NonNegativeInteger)
+            k := kernel(operator ka, [a, n::F], height ka)
while (d := degree q) > 0 repeat
term :F :=
g := gcd(d, n)

diff --git a/src/input/bugs2018.input b/src/input/bugs2018.input
index 5fb9d84a..d2dff97c 100644
--- a/src/input/bugs2018.input
+++ b/src/input/bugs2018.input
@@ -14,6 +14,11 @@ testEquals("flist(1).exponent", "2")
testEquals("flist(2).factor", "(a+c)^2*d + b")
testEquals("flist(2).exponent", "4")

+testcase "simplify nested radicals in rootPower"
+
+testEquals("rootPower(sqrt sqrt 2)", "2^(1/4)")
+testEquals("rootPower(((sqrt 7)^(1/5))^4)", "7^(2/5)")
+
)set output algebra on

statistics()

--
You received this message because you are subscribed to the Google Groups
"FriCAS - computer algebra system" group.
To unsubscribe from this group and stop receiving emails from it, send an email