//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Problem 4.33 on page 86
//  More accurate recursive implementation of  
//     sine and cosine functions

public class Pr0433
{ public static void main(String[] args)
  { for (double x=0. ; x<1.0; x += 0.1)
      System.out.println(s(x) + "\t" + Math.sin(x));
    for (double x=0. ; x<1.0; x += 0.1)
      System.out.println(c(x) + "\t" + Math.cos(x));
  }
  public static double s(double x)
  { if (Math.abs(x) < 0.00005) 
      return x - x*x*x/6 ;          // basis
    return 2*s(x/2)*c(x/2);         // recursion
  }
  public static double c(double x)
  { if (Math.abs(x) < 0.00005) 
        return 1.0 - x*x/2;          // basis
    return 1 - 2*s(x/2)*s(x/2);      // recursion
  }
}
