|
From: Gilles S. <gsc...@gm...> - 2017-01-25 23:09:30
|
Dear all, I'm new here, so first of all I'd like to thank the developers for all the hard work they've put into Maxima! I'd also like to propose a contribution in return. I've ported Sympy's code for denesting square roots to Maxima. I hope it turns out to be useful. (see attachments) Since it's my first Maxima package I'm not so sure either that I'm always using the most appropriate functions, that I'm handling the local and global variables (e.g. domain...) as I should, etc. Any feedback will be appreciated. Most of the code is a rather direct port of Sympy's functionality, but there are some extensions to it that apply to cube roots or n-th roots. There's also an extensive test suite. (BTW, for two problems maxima detects an erroneous result when in fact the shown result is identical to the expected one!? That's with maxima 5.37.2.) The main algorithms are those of Borodin et al.: "Decreasing the Nesting Depth of Expressions Involving Square Roots" http://researcher.watson.ibm.com/researcher/files/us-fagin/symb85.pdf Other references are in the code comments. I'm aware that there are more general approaches (e.g. by Landau, Blömer) but I haven't tried (yet?) to implement those. Below you'll find the output of the included demo file. Kind regards, Gilles Schintgen (%i5) demo(raddenest); read and interpret file: #p/home/gilles/.maxima/raddenest.dem At the '_' prompt, type ';' and <enter> to get next demonstration. (%i6) raddenest(sqrt(5+2*sqrt(6))) (%o6) sqrt(3) + sqrt(2) _; (%i7) sqrt(3+sqrt(5+2*sqrt(7))) (%o7) sqrt(sqrt(2 sqrt(7) + 5) + 3) _; (%i8) raddenest(%) 1/4 sqrt(6 sqrt(7) + 12) 3 (5 + 2 sqrt(7)) (%o8) -------------------- + --------------------------- 1/4 sqrt(2) sqrt(3 sqrt(7) + 6) 2 (5 + 2 sqrt(7)) _; (%i9) sqrt(sqrt((-2*sqrt(29))+2*sqrt(55-10*sqrt(29))+16)-sqrt(5)) (%o9) sqrt(sqrt((- 2 sqrt(29)) + 2 sqrt(55 - 10 sqrt(29)) + 16) - sqrt(5)) _; (%i10) raddenest(%) 1/4 (%o10) (11 - 2 sqrt(29)) _; (%i11) sqrt((6*sqrt(2))/11+(2*sqrt(22))/11+(6*sqrt(11))/11+2) 3/2 2 sqrt(22) 6 3 2 (%o11) sqrt(---------- + -------- + ------ + 2) 11 sqrt(11) 11 _; (%i12) raddenest(%) 2 3 (%o12) -------- + -------- + 1 sqrt(22) sqrt(11) _; (%i13) sqrt(1/(7+4*sqrt(3))+1) 1 (%o13) sqrt(------------- + 1) 4 sqrt(3) + 7 _; (%i14) raddenest(%) (%o14) sqrt(6) - sqrt(2) _; (%i15) sqrt(expand((1+sqrt(sqrt(2+x)+3))^2)) (%o15) sqrt(2 sqrt(sqrt(x + 2) + 3) + sqrt(x + 2) + 4) _; (%i16) raddenest(%) (%o16) sqrt(sqrt(x + 2) + 3) + 1 _; (%i17) raddenest(sqrt(5^(1/3)-4^(1/3))) 1/3 1/3 1/3 2 + 20 - 25 (%o17) -------------------- 3 _; (%i18) raddenest((41-29*sqrt(2))^(1/5)) (%o18) 1 - sqrt(2) |