
(FPCore (g h) :precision binary64 (* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
\begin{array}{l}
\\
2 \cdot \cos \left(\frac{2 \cdot \mathsf{PI}\left(\right)}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 2 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (g h) :precision binary64 (* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))
\begin{array}{l}
\\
2 \cdot \cos \left(\frac{2 \cdot \mathsf{PI}\left(\right)}{3} + \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)
\end{array}
(FPCore (g h) :precision binary64 (* (sin (fma (- (acos (/ (- g) h)) (PI)) 0.3333333333333333 (* 0.5 (PI)))) -2.0))
\begin{array}{l}
\\
\sin \left(\mathsf{fma}\left(\cos^{-1} \left(\frac{-g}{h}\right) - \mathsf{PI}\left(\right), 0.3333333333333333, 0.5 \cdot \mathsf{PI}\left(\right)\right)\right) \cdot -2
\end{array}
Initial program 98.5%
Taylor expanded in g around 0
Applied rewrites98.5%
Applied rewrites100.0%
Taylor expanded in g around 0
Applied rewrites100.0%
(FPCore (g h) :precision binary64 (* (cos (* -0.3333333333333333 (acos (/ g h)))) -2.0))
double code(double g, double h) {
return cos((-0.3333333333333333 * acos((g / h)))) * -2.0;
}
real(8) function code(g, h)
real(8), intent (in) :: g
real(8), intent (in) :: h
code = cos(((-0.3333333333333333d0) * acos((g / h)))) * (-2.0d0)
end function
public static double code(double g, double h) {
return Math.cos((-0.3333333333333333 * Math.acos((g / h)))) * -2.0;
}
def code(g, h): return math.cos((-0.3333333333333333 * math.acos((g / h)))) * -2.0
function code(g, h) return Float64(cos(Float64(-0.3333333333333333 * acos(Float64(g / h)))) * -2.0) end
function tmp = code(g, h) tmp = cos((-0.3333333333333333 * acos((g / h)))) * -2.0; end
code[g_, h_] := N[(N[Cos[N[(-0.3333333333333333 * N[ArcCos[N[(g / h), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * -2.0), $MachinePrecision]
\begin{array}{l}
\\
\cos \left(-0.3333333333333333 \cdot \cos^{-1} \left(\frac{g}{h}\right)\right) \cdot -2
\end{array}
Initial program 98.5%
Taylor expanded in g around 0
Applied rewrites98.5%
Applied rewrites98.5%
Taylor expanded in g around 0
Applied rewrites98.5%
herbie shell --seed 2024332
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))