//  Data Structures with Java by John R. Hubbard
//  Copyright McGraw-Hill, 2001
//  Example 4.15 on page 84
//  The Sine and Cosine Functions Computed by Mutual Recursion


public class Ex0416
{ 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 (-0.005 < x && x < 0.005) return x - x*x*x/6;  // basis
    return 2*s(x/2)*c(x/2);                           // recursion
  }
  public static double c(double x)
  { if (-0.005 < x && x < 0.005) return 1.0 - x*x/2;  // basis
    return 1 - 2*s(x/2)*s(x/2);                       // recursion
  }
}
