
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) (PI)))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \mathsf{PI}\left(\right)\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 b) 1.0) b (pow (* (sin (* (* 0.005555555555555556 (PI)) angle)) a) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(\sin \left(\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot a\right)}^{2}\right)
\end{array}
Initial program 79.6%
Taylor expanded in angle around 0
Applied rewrites79.9%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites80.0%
(FPCore (a b angle) :precision binary64 (fma (* (* 1.0 b) 1.0) b (pow (* a (sin (* (* (PI) angle) -0.005555555555555556))) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(a \cdot \sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot -0.005555555555555556\right)\right)}^{2}\right)
\end{array}
Initial program 79.6%
Taylor expanded in angle around 0
Applied rewrites79.9%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites80.0%
lift-sin.f64N/A
lift-*.f64N/A
remove-double-divN/A
unpow-1N/A
lift-pow.f64N/A
div-invN/A
frac-2negN/A
distribute-frac-neg2N/A
sin-negN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lift-pow.f64N/A
unpow-1N/A
div-invN/A
unpow-1N/A
lift-pow.f64N/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
div-invN/A
lift-pow.f64N/A
unpow-1N/A
Applied rewrites80.0%
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
lift-*.f64N/A
lift-neg.f64N/A
distribute-lft-neg-outN/A
sqr-negN/A
pow2N/A
lower-pow.f64N/A
*-commutativeN/A
lower-*.f6480.0
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.0
Applied rewrites80.0%
(FPCore (a b angle)
:precision binary64
(if (<= a 4500000.0)
(* b b)
(fma
(* (* 1.0 b) 1.0)
b
(pow
(*
(*
(*
(PI)
(fma
(* -2.8577960676726107e-8 (* angle angle))
(* (PI) (PI))
0.005555555555555556))
angle)
a)
2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4500000:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(\left(\left(\mathsf{PI}\left(\right) \cdot \mathsf{fma}\left(-2.8577960676726107 \cdot 10^{-8} \cdot \left(angle \cdot angle\right), \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right), 0.005555555555555556\right)\right) \cdot angle\right) \cdot a\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 4.5e6Initial program 79.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 4.5e6 < a Initial program 80.9%
Taylor expanded in angle around 0
Applied rewrites80.8%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.0%
Taylor expanded in angle around 0
*-commutativeN/A
*-commutativeN/A
associate-*r*N/A
*-commutativeN/A
+-commutativeN/A
lower-*.f64N/A
Applied rewrites76.2%
(FPCore (a b angle)
:precision binary64
(if (<= a 4500000.0)
(* b b)
(if (<= a 1.75e+139)
(fma
(* a a)
(* (pow (* 0.005555555555555556 (PI)) 2.0) (* angle angle))
(* b b))
(* (pow (* (* a (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4500000:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 1.75 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(a \cdot a, {\left(0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right)}^{2} \cdot \left(angle \cdot angle\right), b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(a \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 4.5e6Initial program 79.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 4.5e6 < a < 1.74999999999999989e139Initial program 67.5%
Applied rewrites25.3%
Taylor expanded in angle around 0
+-commutativeN/A
exp-sumN/A
rem-exp-logN/A
*-commutativeN/A
associate-*r*N/A
unpow2N/A
lower-fma.f64N/A
Applied rewrites56.6%
if 1.74999999999999989e139 < a Initial program 96.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites46.2%
Taylor expanded in a around inf
Applied rewrites65.5%
Applied rewrites93.8%
(FPCore (a b angle)
:precision binary64
(if (<= a 4500000.0)
(* b b)
(fma
(* (* 1.0 b) 1.0)
b
(pow (* (* (* -0.005555555555555556 (PI)) angle) (- a)) 2.0))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4500000:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\left(1 \cdot b\right) \cdot 1, b, {\left(\left(\left(-0.005555555555555556 \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right) \cdot \left(-a\right)\right)}^{2}\right)\\
\end{array}
\end{array}
if a < 4.5e6Initial program 79.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 4.5e6 < a Initial program 80.9%
Taylor expanded in angle around 0
Applied rewrites80.8%
lift-+.f64N/A
+-commutativeN/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites81.0%
lift-sin.f64N/A
lift-*.f64N/A
remove-double-divN/A
unpow-1N/A
lift-pow.f64N/A
div-invN/A
frac-2negN/A
distribute-frac-neg2N/A
sin-negN/A
lift-*.f64N/A
distribute-lft-neg-inN/A
metadata-evalN/A
metadata-evalN/A
lift-pow.f64N/A
unpow-1N/A
div-invN/A
unpow-1N/A
lift-pow.f64N/A
times-fracN/A
metadata-evalN/A
metadata-evalN/A
metadata-evalN/A
div-invN/A
lift-pow.f64N/A
unpow-1N/A
Applied rewrites80.8%
Taylor expanded in angle around 0
*-commutativeN/A
associate-*r*N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6476.3
Applied rewrites76.3%
Final simplification66.9%
(FPCore (a b angle)
:precision binary64
(if (<= a 4500000.0)
(* b b)
(if (<= a 1.75e+139)
(fma
(* (* (* 3.08641975308642e-5 (* a a)) (PI)) (PI))
(* angle angle)
(* b b))
(* (pow (* (* a (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4500000:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 1.75 \cdot 10^{+139}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(a \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if a < 4.5e6Initial program 79.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 4.5e6 < a < 1.74999999999999989e139Initial program 67.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites26.6%
Taylor expanded in a around inf
Applied rewrites56.6%
if 1.74999999999999989e139 < a Initial program 96.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites46.2%
Taylor expanded in a around inf
Applied rewrites65.5%
Applied rewrites93.8%
(FPCore (a b angle)
:precision binary64
(if (<= a 4500000.0)
(* b b)
(if (<= a 1.35e+154)
(fma
(* (* (* 3.08641975308642e-5 (* a a)) (PI)) (PI))
(* angle angle)
(* b b))
(* (* 3.08641975308642e-5 (* a (* (* angle angle) a))) (* (PI) (PI))))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 4500000:\\
\;\;\;\;b \cdot b\\
\mathbf{elif}\;a \leq 1.35 \cdot 10^{+154}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot a\right)\right) \cdot \mathsf{PI}\left(\right)\right) \cdot \mathsf{PI}\left(\right), angle \cdot angle, b \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot \left(\left(angle \cdot angle\right) \cdot a\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 4.5e6Initial program 79.1%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6463.5
Applied rewrites63.5%
if 4.5e6 < a < 1.35000000000000003e154Initial program 66.1%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites26.1%
Taylor expanded in a around inf
Applied rewrites55.4%
if 1.35000000000000003e154 < a Initial program 99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites47.4%
Taylor expanded in a around inf
Applied rewrites67.4%
Taylor expanded in a around 0
Applied rewrites77.3%
(FPCore (a b angle) :precision binary64 (if (<= a 7e+135) (* b b) (* (* 3.08641975308642e-5 (* a (* (* angle angle) a))) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 7 \cdot 10^{+135}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\left(3.08641975308642 \cdot 10^{-5} \cdot \left(a \cdot \left(\left(angle \cdot angle\right) \cdot a\right)\right)\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if a < 7.0000000000000005e135Initial program 77.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6460.5
Applied rewrites60.5%
if 7.0000000000000005e135 < a Initial program 95.4%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites45.0%
Taylor expanded in a around inf
Applied rewrites63.7%
Taylor expanded in a around 0
Applied rewrites73.0%
(FPCore (a b angle) :precision binary64 (* b b))
double code(double a, double b, double angle) {
return b * b;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b * b
end function
public static double code(double a, double b, double angle) {
return b * b;
}
def code(a, b, angle): return b * b
function code(a, b, angle) return Float64(b * b) end
function tmp = code(a, b, angle) tmp = b * b; end
code[a_, b_, angle_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b
\end{array}
Initial program 79.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6455.9
Applied rewrites55.9%
herbie shell --seed 2024302
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
(+ (pow (* a (sin (* (/ angle 180.0) (PI)))) 2.0) (pow (* b (cos (* (/ angle 180.0) (PI)))) 2.0)))