
(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
(let* ((t_0 (/ (acos (/ (- g) h)) 3.0)) (t_1 (/ (PI) 3.0)))
(*
2.0
(fma (cos t_0) (cos (* t_1 2.0)) (* (sin (fma t_1 2.0 (PI))) (sin t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\\
t_1 := \frac{\mathsf{PI}\left(\right)}{3}\\
2 \cdot \mathsf{fma}\left(\cos t\_0, \cos \left(t\_1 \cdot 2\right), \sin \left(\mathsf{fma}\left(t\_1, 2, \mathsf{PI}\left(\right)\right)\right) \cdot \sin t\_0\right)
\end{array}
\end{array}
Initial program 98.4%
Applied rewrites97.6%
Applied rewrites100.0%
(FPCore (g h) :precision binary64 (* (cos (/ (fma (PI) 2.0 (acos (/ (- g) h))) 3.0)) 2.0))
\begin{array}{l}
\\
\cos \left(\frac{\mathsf{fma}\left(\mathsf{PI}\left(\right), 2, \cos^{-1} \left(\frac{-g}{h}\right)\right)}{3}\right) \cdot 2
\end{array}
Initial program 98.4%
Applied rewrites98.5%
herbie shell --seed 2025021
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))