
(FPCore (cosTheta alpha)
:precision binary32
(let* ((t_0 (- (* alpha alpha) 1.0)))
(/
t_0
(* (* (PI) (log (* alpha alpha))) (+ 1.0 (* (* t_0 cosTheta) cosTheta))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \alpha \cdot \alpha - 1\\
\frac{t\_0}{\left(\mathsf{PI}\left(\right) \cdot \log \left(\alpha \cdot \alpha\right)\right) \cdot \left(1 + \left(t\_0 \cdot cosTheta\right) \cdot cosTheta\right)}
\end{array}
\end{array}
Sampling outcomes in binary32 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (cosTheta alpha)
:precision binary32
(let* ((t_0 (- (* alpha alpha) 1.0)))
(/
t_0
(* (* (PI) (log (* alpha alpha))) (+ 1.0 (* (* t_0 cosTheta) cosTheta))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \alpha \cdot \alpha - 1\\
\frac{t\_0}{\left(\mathsf{PI}\left(\right) \cdot \log \left(\alpha \cdot \alpha\right)\right) \cdot \left(1 + \left(t\_0 \cdot cosTheta\right) \cdot cosTheta\right)}
\end{array}
\end{array}
(FPCore (cosTheta alpha)
:precision binary32
(let* ((t_0 (- (* alpha alpha) 1.0)))
(/
t_0
(*
(log (pow (* alpha alpha) (PI)))
(+ 1.0 (* (* t_0 cosTheta) cosTheta))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \alpha \cdot \alpha - 1\\
\frac{t\_0}{\log \left({\left(\alpha \cdot \alpha\right)}^{\mathsf{PI}\left(\right)}\right) \cdot \left(1 + \left(t\_0 \cdot cosTheta\right) \cdot cosTheta\right)}
\end{array}
\end{array}
Initial program 98.6%
lift-PI.f32N/A
lift-*.f32N/A
lift-log.f32N/A
log-pow-revN/A
lift-*.f32N/A
pow2N/A
lower-log.f32N/A
lower-pow.f32N/A
pow2N/A
lift-*.f32N/A
lift-PI.f3298.8
Applied rewrites98.8%
(FPCore (cosTheta alpha)
:precision binary32
(let* ((t_0 (- (* alpha alpha) 1.0))
(t_1 (* (* cosTheta cosTheta) t_0))
(t_2 (- 1.0 t_1)))
(/
t_0
(* (* (PI) (log (* alpha alpha))) (- (/ 1.0 t_2) (/ (* t_1 t_1) t_2))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \alpha \cdot \alpha - 1\\
t_1 := \left(cosTheta \cdot cosTheta\right) \cdot t\_0\\
t_2 := 1 - t\_1\\
\frac{t\_0}{\left(\mathsf{PI}\left(\right) \cdot \log \left(\alpha \cdot \alpha\right)\right) \cdot \left(\frac{1}{t\_2} - \frac{t\_1 \cdot t\_1}{t\_2}\right)}
\end{array}
\end{array}
Initial program 98.6%
lift-+.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
flip-+N/A
metadata-evalN/A
div-subN/A
lower--.f32N/A
Applied rewrites98.6%
lift-pow.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
unpow2N/A
lower-*.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
lift-*.f3298.6
Applied rewrites98.6%
(FPCore (cosTheta alpha)
:precision binary32
(let* ((t_0 (- (* alpha alpha) 1.0)))
(/
t_0
(* (PI) (* (log (* alpha alpha)) (fma (* cosTheta cosTheta) t_0 1.0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \alpha \cdot \alpha - 1\\
\frac{t\_0}{\mathsf{PI}\left(\right) \cdot \left(\log \left(\alpha \cdot \alpha\right) \cdot \mathsf{fma}\left(cosTheta \cdot cosTheta, t\_0, 1\right)\right)}
\end{array}
\end{array}
Initial program 98.6%
lift-*.f32N/A
lift-PI.f32N/A
lift-*.f32N/A
lift-log.f32N/A
lift-*.f32N/A
pow2N/A
lift-+.f32N/A
lift-*.f32N/A
lift-*.f32N/A
lift--.f32N/A
lift-*.f32N/A
associate-*l*N/A
lower-*.f32N/A
lift-PI.f32N/A
lower-*.f32N/A
Applied rewrites98.6%
(FPCore (cosTheta alpha) :precision binary32 (/ (- (* alpha alpha) 1.0) (* (* (PI) (log (* alpha alpha))) (+ 1.0 (* (- cosTheta) cosTheta)))))
\begin{array}{l}
\\
\frac{\alpha \cdot \alpha - 1}{\left(\mathsf{PI}\left(\right) \cdot \log \left(\alpha \cdot \alpha\right)\right) \cdot \left(1 + \left(-cosTheta\right) \cdot cosTheta\right)}
\end{array}
Initial program 98.6%
Taylor expanded in alpha around 0
mul-1-negN/A
lower-neg.f3297.7
Applied rewrites97.7%
(FPCore (cosTheta alpha) :precision binary32 (/ (- (* alpha alpha) 1.0) (* (* (PI) (log (* alpha alpha))) 1.0)))
\begin{array}{l}
\\
\frac{\alpha \cdot \alpha - 1}{\left(\mathsf{PI}\left(\right) \cdot \log \left(\alpha \cdot \alpha\right)\right) \cdot 1}
\end{array}
Initial program 98.6%
Taylor expanded in cosTheta around 0
Applied rewrites96.2%
(FPCore (cosTheta alpha) :precision binary32 (/ (- (* alpha alpha) 1.0) (* (* (log alpha) (PI)) 2.0)))
\begin{array}{l}
\\
\frac{\alpha \cdot \alpha - 1}{\left(\log \alpha \cdot \mathsf{PI}\left(\right)\right) \cdot 2}
\end{array}
Initial program 98.6%
lift-PI.f32N/A
lift-*.f32N/A
lift-log.f32N/A
log-pow-revN/A
lift-*.f32N/A
pow2N/A
lower-log.f32N/A
lower-pow.f32N/A
pow2N/A
lift-*.f32N/A
lift-PI.f3298.8
Applied rewrites98.8%
Taylor expanded in cosTheta around 0
pow-powN/A
log-pow-revN/A
associate-*r*N/A
*-commutativeN/A
lower-*.f32N/A
*-commutativeN/A
lift-log.f32N/A
lift-*.f32N/A
lift-PI.f3296.1
Applied rewrites96.1%
(FPCore (cosTheta alpha) :precision binary32 (/ -1.0 (* (* (PI) (log (* alpha alpha))) 1.0)))
\begin{array}{l}
\\
\frac{-1}{\left(\mathsf{PI}\left(\right) \cdot \log \left(\alpha \cdot \alpha\right)\right) \cdot 1}
\end{array}
Initial program 98.6%
Taylor expanded in cosTheta around 0
Applied rewrites96.2%
Taylor expanded in alpha around 0
Applied rewrites67.4%
(FPCore (cosTheta alpha) :precision binary32 (/ -1.0 (* 2.0 (* (PI) (log alpha)))))
\begin{array}{l}
\\
\frac{-1}{2 \cdot \left(\mathsf{PI}\left(\right) \cdot \log \alpha\right)}
\end{array}
Initial program 98.6%
Taylor expanded in cosTheta around 0
Applied rewrites96.2%
Taylor expanded in alpha around 0
Applied rewrites67.4%
lift-log.f32N/A
lift-*.f32N/A
log-prodN/A
count-2-revN/A
*-commutativeN/A
lower-*.f32N/A
lower-log.f3267.4
Applied rewrites67.4%
Taylor expanded in cosTheta around 0
lower-*.f32N/A
lower-*.f32N/A
lift-PI.f32N/A
lift-log.f3267.4
Applied rewrites67.4%
herbie shell --seed 2025051
(FPCore (cosTheta alpha)
:name "GTR1 distribution"
:precision binary32
:pre (and (and (<= 0.0 cosTheta) (<= cosTheta 1.0)) (and (<= 0.0001 alpha) (<= alpha 1.0)))
(/ (- (* alpha alpha) 1.0) (* (* (PI) (log (* alpha alpha))) (+ 1.0 (* (* (- (* alpha alpha) 1.0) cosTheta) cosTheta)))))