1
0
Fork 0
Libraries for bc and dc.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

34 lines
685 B

#!/usr/local/bin/bc -l
### SRR.BC - Sum of Repeated Roots (less one);
### calculate the value of sum[n=1..oo] x^(2^(-n))-1
define srr(x) {
auto s,t,os;
if(x<=0){print "srr: Negative Infinity\n";return 1-A^scale}
scale+=6
s=x ; os=s+1
t=0;while(os!=s){
os=s
s=sqrt(s)
t+=s-1
}
scale-=6;t/=1
return(t);
}
define srr_n(n,x) { # Generalisation of srr; srr(x) == srr_n(2,x)
auto s,t,os;
if(x<=0){print "srr_n: Negative Infinity\n";return 1-A^scale}
if(n==2)return(srr(x))
if(n<=1){print "srr_n: Infinity\n";return A^scale-1}
scale+=6
s=x ; os=s+1
t=0;while(os!=s){
os=s
s=e(l(s)/n)
t+=s-1
}
scale-=6;t/=1
return(t);
}