Skip to content

Latest commit

 

History

History
12 lines (9 loc) · 1.1 KB

w4_4.1_opt_partial_applications.md

File metadata and controls

12 lines (9 loc) · 1.1 KB

OPTIMIZING PARTIAL APPLICATIONS (35 points possible)

Every triangle has a circumscribed circle, that is a circle that goes through the three points of a given triangle. Trigonometry tells us that the radius of this circle is s/(2⋅cos(a/2)⋅2⋅cos(b/2)⋅2⋅cos(c/2)) where a, b and c are the angles of the triangle, and s is its circumference.

  1. Define a function ccr: float -> float -> float -> float -> float that takes as arguments a, b, c and s, and returns the radius of circumscribed circle as described above.

  2. Update ccr so that it does as much work as possible when partially applied to each argument, and minimizes the total number of operations (multiplications, divisions and calls to cos).

YOUR OCAML ENVIRONMENT

let ccr = fun a -> fun b -> fun c -> fun s ->
  "Replace this string with your implementation." ;;