
(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 (sqrt (PI))))
(*
2.0
(-
(*
(cos (/ (- (PI) (acos (/ g h))) 3.0))
(cos (* -0.6666666666666666 (PI))))
(*
(sin (* 0.3333333333333333 (acos (/ (- g) h))))
(sin (* (* 0.6666666666666666 t_0) t_0)))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sqrt{\mathsf{PI}\left(\right)}\\
2 \cdot \left(\cos \left(\frac{\mathsf{PI}\left(\right) - \cos^{-1} \left(\frac{g}{h}\right)}{3}\right) \cdot \cos \left(-0.6666666666666666 \cdot \mathsf{PI}\left(\right)\right) - \sin \left(0.3333333333333333 \cdot \cos^{-1} \left(\frac{-g}{h}\right)\right) \cdot \sin \left(\left(0.6666666666666666 \cdot t\_0\right) \cdot t\_0\right)\right)
\end{array}
\end{array}
Initial program 98.5%
Applied rewrites98.4%
lift-PI.f64N/A
lift-*.f64N/A
add-sqr-sqrtN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-sqrt.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lift-PI.f64100.0
Applied rewrites100.0%
lift-acos.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
distribute-frac-negN/A
acos-negN/A
frac-2negN/A
distribute-frac-neg2N/A
acos-neg-revN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-acos.f64N/A
lower--.f64N/A
lift-PI.f64N/A
lift-acos.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
acos-neg-revN/A
distribute-frac-neg2N/A
frac-2negN/A
lower-acos.f64N/A
lower-/.f64100.0
Applied rewrites100.0%
Taylor expanded in g around 0
lower-sin.f64N/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-acos.f64N/A
lower-*.f64100.0
Applied rewrites100.0%
(FPCore (g h)
:precision binary64
(*
2.0
(sin
(fma
-0.3333333333333333
(acos (/ (- g) h))
(fma (PI) -0.6666666666666666 (/ (PI) 2.0))))))\begin{array}{l}
\\
2 \cdot \sin \left(\mathsf{fma}\left(-0.3333333333333333, \cos^{-1} \left(\frac{-g}{h}\right), \mathsf{fma}\left(\mathsf{PI}\left(\right), -0.6666666666666666, \frac{\mathsf{PI}\left(\right)}{2}\right)\right)\right)
\end{array}
Initial program 98.5%
lift-cos.f64N/A
sin-+PI/2-revN/A
lower-sin.f64N/A
+-commutativeN/A
lower-+.f64N/A
lower-/.f64N/A
lift-PI.f6497.6
lift-+.f64N/A
lift-/.f64N/A
lift-/.f64N/A
lift-acos.f64N/A
lift-neg.f64N/A
lift-/.f64N/A
div-add-revN/A
lower-/.f64N/A
Applied rewrites97.6%
Applied rewrites97.6%
Applied rewrites100.0%
(FPCore (g h) :precision binary64 (* 2.0 (sin (* (fma (fma (PI) 2.0 (acos (/ (- g) h))) -0.6666666666666666 (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.6666666666666666, \mathsf{PI}\left(\right)\right) \cdot 0.5\right)
\end{array}
Initial program 98.5%
Applied rewrites99.9%
Applied rewrites99.9%
Taylor expanded in g around 0
lower-sin.f64N/A
*-commutativeN/A
lower-*.f64N/A
Applied rewrites99.9%
(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.5%
lift-*.f64N/A
*-commutativeN/A
lower-*.f6498.5
Applied rewrites98.5%
Taylor expanded in g around 0
*-commutativeN/A
+-commutativeN/A
*-commutativeN/A
mul-1-negN/A
distribute-frac-negN/A
lift-/.f64N/A
lift-neg.f64N/A
lift-acos.f64N/A
lift-fma.f64N/A
lift-PI.f64N/A
lower-*.f6498.5
Applied rewrites98.5%
(FPCore (g h) :precision binary64 (* 2.0 (cos (fma 0.3333333333333333 (acos (/ (- g) h)) (* 0.6666666666666666 (PI))))))
\begin{array}{l}
\\
2 \cdot \cos \left(\mathsf{fma}\left(0.3333333333333333, \cos^{-1} \left(\frac{-g}{h}\right), 0.6666666666666666 \cdot \mathsf{PI}\left(\right)\right)\right)
\end{array}
Initial program 98.5%
Taylor expanded in g around 0
mul-1-negN/A
distribute-frac-negN/A
lower-fma.f64N/A
lift-/.f64N/A
lift-neg.f64N/A
lift-acos.f64N/A
lower-*.f64N/A
lift-PI.f6498.4
Applied rewrites98.4%
Final simplification98.4%
herbie shell --seed 2025046
(FPCore (g h)
:name "2-ancestry mixing, negative discriminant"
:precision binary64
(* 2.0 (cos (+ (/ (* 2.0 (PI)) 3.0) (/ (acos (/ (- g) h)) 3.0)))))