#!/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); }