
(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 3 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))) (t_1 (sqrt (PI))))
(*
(fma
(+
(cos (* (fma -2.0 (PI) t_0) -0.3333333333333333))
(cos (fma 0.3333333333333333 t_0 (* (PI) 0.6666666666666666))))
0.5
(*
(sin (* t_0 0.3333333333333333))
(- (sin (* (* t_1 0.6666666666666666) t_1)))))
2.0)))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(\frac{-g}{h}\right)\\
t_1 := \sqrt{\mathsf{PI}\left(\right)}\\
\mathsf{fma}\left(\cos \left(\mathsf{fma}\left(-2, \mathsf{PI}\left(\right), t\_0\right) \cdot -0.3333333333333333\right) + \cos \left(\mathsf{fma}\left(0.3333333333333333, t\_0, \mathsf{PI}\left(\right) \cdot 0.6666666666666666\right)\right), 0.5, \sin \left(t\_0 \cdot 0.3333333333333333\right) \cdot \left(-\sin \left(\left(t\_1 \cdot 0.6666666666666666\right) \cdot t\_1\right)\right)\right) \cdot 2
\end{array}
\end{array}
Initial program 98.5%
Applied rewrites98.4%
lift-*.f64N/A
lift-PI.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f64100.0
Applied rewrites100.0%
Final simplification100.0%
(FPCore (g h) :precision binary64 (* (cos (/ (fma (acos (/ (- g) h)) 3.0 (* 6.0 (PI))) 9.0)) 2.0))
\begin{array}{l}
\\
\cos \left(\frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-g}{h}\right), 3, 6 \cdot \mathsf{PI}\left(\right)\right)}{9}\right) \cdot 2
\end{array}
Initial program 98.5%
lift-+.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-addN/A
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lift-*.f64N/A
associate-*r*N/A
metadata-evalN/A
metadata-evalN/A
lower-*.f64N/A
metadata-evalN/A
metadata-eval98.5
Applied rewrites98.5%
Final simplification98.5%
(FPCore (g h) :precision binary64 (* (cos (fma 0.3333333333333333 (acos (/ (- g) h)) (* (PI) 0.6666666666666666))) 2.0))
\begin{array}{l}
\\
\cos \left(\mathsf{fma}\left(0.3333333333333333, \cos^{-1} \left(\frac{-g}{h}\right), \mathsf{PI}\left(\right) \cdot 0.6666666666666666\right)\right) \cdot 2
\end{array}
Initial program 98.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
Final simplification98.5%
herbie shell --seed 2024244
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))