/usr/share/yacas/scripts/radsimp.rep/code.ys is in yacas 1.3.6-2+b1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | /* Simplification of nested radicals.
*/
RadSimp(_n) <--
[
Local(max, result);
Set(max, MathCeil(N(Eval(n^2))));
Set(result,0);
Set(result,RadSimpTry(n,0,1,max));
//Echo("result is ",result);
if (CheckRadicals(n,result))
result
else
n;
];
/*Echo({"Try ",test}); */
CheckRadicals(_n,_test) <-- Abs(N(Eval(n-test),20)) < 0.000001;
10 # ClampRadicals(_r)_(N(Eval(Abs(r)), 20)<0.000001) <-- 0;
20 # ClampRadicals(_r) <-- r;
RadSimpTry(_n,_result,_current,_max)<--
[
//Echo(result," ",n," ",current);
if (LessThan(N(Eval(result-n)), 0))
[
Local(i);
// First, look for perfect match
i:=BSearch(max,Hold({{try},ClampRadicals(N(Eval((result+Sqrt(try))-n),20))}));
If(i>0,
[
Set(result,result+Sqrt(i));
Set(i,MathAdd(max,1));
Set(current,MathAdd(max,1));
]);
// Otherwise, search for another solution
if (LessThan(N(Eval(result-n)), 0))
[
For (Set(i,current),i<=max,Set(i,MathAdd(i,1)))
[
Local(new, test);
Set(test,result+Sqrt(i));
/* Echo({"Full-try ",test}); */
Set(new,RadSimpTry(n,test,i,max));
if (CheckRadicals(n,new))
[
Set(result,new);
Set(i,MathAdd(max,1));
];
];
];
];
result;
];
|