~ubuntu-fr-scripts/ufrs-math/math-dev

« back to all changes in this revision

Viewing changes to bc-lib/ss.bc

  • Committer: Jean-Michel Juzan
  • Date: 2009-04-01 12:03:01 UTC
  • Revision ID: jean-michel@juzan.org-20090401120301-j6g6xj1z0561zdg3
copie de la branche principale

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
## ss.bc calculate the value of sum[n=1..oo] x^(2^(-n))-1 with GNU bc
 
2
## i.e. sum of repeated square roots, less one.
 
3
 
 
4
define ss(x) {
 
5
  auto s,t,os;
 
6
  if(x<=0){print "Negative Infinity\n";-1/0}
 
7
  scale+=6
 
8
  s=x ; os=s+1
 
9
  t=0;while(os!=s){
 
10
    os=s
 
11
    s=sqrt(s)
 
12
    t+=s-1
 
13
  }
 
14
  scale-=6;t/=1
 
15
  return(t);
 
16
}
 
17
 
 
18
define ss_n(n,x) { # Generalisation of ss; ss(x) == ss_n(2,x)
 
19
  auto s,t,os;
 
20
  if(x<=0){print "Negative Infinity\n";-1/0}
 
21
  if(n==2)return(ss(x))
 
22
  if(n<=1){print "Infinity\n";1/0}
 
23
  scale+=6
 
24
  s=x ; os=s+1
 
25
  t=0;while(os!=s){
 
26
    os=s
 
27
    s=e(l(s)/n)
 
28
    t+=s-1
 
29
  }
 
30
  scale-=6;t/=1
 
31
  return(t);
 
32
}