
(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 5 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 (* (PI) 0.6666666666666666)) (t_1 (acos (/ (- g) h))))
(*
(- 2.0)
(/
(pow (- (cos (fma t_1 0.3333333333333333 t_0))) 3.0)
(+ (* (cos (* (fma 0.3333333333333333 t_1 t_0) 2.0)) 0.5) 0.5)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot 0.6666666666666666\\
t_1 := \cos^{-1} \left(\frac{-g}{h}\right)\\
\left(-2\right) \cdot \frac{{\left(-\cos \left(\mathsf{fma}\left(t\_1, 0.3333333333333333, t\_0\right)\right)\right)}^{3}}{\cos \left(\mathsf{fma}\left(0.3333333333333333, t\_1, t\_0\right) \cdot 2\right) \cdot 0.5 + 0.5}
\end{array}
\end{array}
Initial program 98.4%
Applied rewrites98.4%
lift-/.f64N/A
lift-/.f64N/A
associate-/r/N/A
lift-*.f64N/A
*-commutativeN/A
Applied rewrites99.9%
Applied rewrites99.9%
lift-+.f64N/A
+-lft-identity99.9
lift-+.f64N/A
lift-*.f64N/A
mul0-lftN/A
+-commutativeN/A
+-lft-identity99.9
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
Applied rewrites99.9%
Final simplification99.9%
(FPCore (g h) :precision binary64 (let* ((t_0 (/ 1.5 (PI)))) (* (cos (/ (fma (acos (/ (- g) h)) t_0 3.0) (* t_0 3.0))) 2.0)))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{1.5}{\mathsf{PI}\left(\right)}\\
\cos \left(\frac{\mathsf{fma}\left(\cos^{-1} \left(\frac{-g}{h}\right), t\_0, 3\right)}{t\_0 \cdot 3}\right) \cdot 2
\end{array}
\end{array}
Initial program 98.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-/.f64N/A
clear-numN/A
frac-addN/A
lower-/.f64N/A
metadata-evalN/A
lower-fma.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-evalN/A
lower-*.f64N/A
lift-*.f64N/A
associate-/r*N/A
lower-/.f64N/A
metadata-eval98.5
Applied rewrites98.5%
Final simplification98.5%
(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.4%
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.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (g h) :precision binary64 (* (cos (fma (PI) 0.6666666666666666 (* 0.3333333333333333 (acos (/ (- g) h))))) 2.0))
\begin{array}{l}
\\
\cos \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.6666666666666666, 0.3333333333333333 \cdot \cos^{-1} \left(\frac{-g}{h}\right)\right)\right) \cdot 2
\end{array}
Initial program 98.4%
lift-+.f64N/A
lift-/.f64N/A
div-invN/A
lift-*.f64N/A
*-commutativeN/A
associate-*l*N/A
lower-fma.f64N/A
metadata-evalN/A
metadata-eval98.4
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval98.4
Applied rewrites98.4%
Final simplification98.4%
(FPCore (g h) :precision binary64 (* (cos (* (fma (PI) 2.0 (acos (/ (- g) h))) 0.3333333333333333)) 2.0))
\begin{array}{l}
\\
\cos \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 2, \cos^{-1} \left(\frac{-g}{h}\right)\right) \cdot 0.3333333333333333\right) \cdot 2
\end{array}
Initial program 98.4%
lift-+.f64N/A
lift-/.f64N/A
div-invN/A
lift-/.f64N/A
div-invN/A
distribute-rgt-outN/A
lower-*.f64N/A
metadata-evalN/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6498.4
Applied rewrites98.4%
Final simplification98.4%
herbie shell --seed 2024276
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))