
(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.4%
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
(let* ((t_0 (acos (/ (- g) h)))
(t_1 (* (PI) 0.6666666666666666))
(t_2 (cos (fma -0.3333333333333333 t_0 t_1))))
(* (/ (cos (fma t_0 0.3333333333333333 t_1)) t_2) (* t_2 2.0))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos^{-1} \left(\frac{-g}{h}\right)\\
t_1 := \mathsf{PI}\left(\right) \cdot 0.6666666666666666\\
t_2 := \cos \left(\mathsf{fma}\left(-0.3333333333333333, t\_0, t\_1\right)\right)\\
\frac{\cos \left(\mathsf{fma}\left(t\_0, 0.3333333333333333, t\_1\right)\right)}{t\_2} \cdot \left(t\_2 \cdot 2\right)
\end{array}
\end{array}
Initial program 98.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
lift-*.f64N/A
*-commutativeN/A
metadata-evalN/A
associate-/r/N/A
*-inversesN/A
associate-/r*N/A
lift-*.f64N/A
lift-/.f64N/A
Applied rewrites100.0%
Final simplification100.0%
(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.4%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.4
Applied rewrites98.4%
Final simplification98.4%
herbie shell --seed 2024277
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))