
(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 4 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 (cos (fma (PI) 0.6666666666666666 (/ (acos (/ (- g) h)) 3.0))))
(t_1 (* t_0 t_0))
(t_2 (pow t_0 3.0)))
(/ (+ t_2 t_2) (fma t_0 t_0 (- t_1 t_1)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.6666666666666666, \frac{\cos^{-1} \left(\frac{-g}{h}\right)}{3}\right)\right)\\
t_1 := t\_0 \cdot t\_0\\
t_2 := {t\_0}^{3}\\
\frac{t\_2 + t\_2}{\mathsf{fma}\left(t\_0, t\_0, t\_1 - t\_1\right)}
\end{array}
\end{array}
Initial program 98.5%
Applied rewrites99.9%
(FPCore (g h) :precision binary64 (* 2.0 (sin (fma (fma (PI) 2.0 (acos (/ (- g) h))) -0.3333333333333333 (* (PI) 0.5)))))
\begin{array}{l}
\\
2 \cdot \sin \left(\mathsf{fma}\left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 2, \cos^{-1} \left(\frac{-g}{h}\right)\right), -0.3333333333333333, \mathsf{PI}\left(\right) \cdot 0.5\right)\right)
\end{array}
Initial program 98.5%
Applied rewrites98.5%
Taylor expanded in g around 0
Applied rewrites99.9%
(FPCore (g h) :precision binary64 (* 2.0 (cos (/ (fma 2.0 (PI) (acos (/ (- g) h))) 3.0))))
\begin{array}{l}
\\
2 \cdot \cos \left(\frac{\mathsf{fma}\left(2, \mathsf{PI}\left(\right), \cos^{-1} \left(\frac{-g}{h}\right)\right)}{3}\right)
\end{array}
Initial program 98.5%
Applied rewrites98.5%
(FPCore (g h) :precision binary64 (* 2.0 (cos (fma (PI) 0.6666666666666666 (* (acos (/ (- g) h)) 0.3333333333333333)))))
\begin{array}{l}
\\
2 \cdot \cos \left(\mathsf{fma}\left(\mathsf{PI}\left(\right), 0.6666666666666666, \cos^{-1} \left(\frac{-g}{h}\right) \cdot 0.3333333333333333\right)\right)
\end{array}
Initial program 98.5%
Taylor expanded in g around 0
Applied rewrites98.4%
Applied rewrites98.5%
herbie shell --seed 2025036 -o generate:simplify -o generate:proofs
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))