
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (PI) (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (+ (pow (* (sin (* (* (PI) angle) 0.005555555555555556)) b) 2.0) (pow (* (cos (* (* (PI) 0.005555555555555556) angle)) a) 2.0)))
\begin{array}{l}
\\
{\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2} + {\left(\cos \left(\left(\mathsf{PI}\left(\right) \cdot 0.005555555555555556\right) \cdot angle\right) \cdot a\right)}^{2}
\end{array}
Initial program 80.4%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
inv-powN/A
lower-pow.f6480.2
Applied rewrites80.2%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-pow.f64N/A
unpow-1N/A
div-invN/A
div-invN/A
clear-numN/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6480.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.5
Applied rewrites80.5%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6480.6
Applied rewrites80.6%
Final simplification80.6%
(FPCore (a b angle) :precision binary64 (fma (* (+ (* (cos (* (* -0.005555555555555556 (* (PI) angle)) 2.0)) 0.5) 0.5) a) a (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(\left(\cos \left(\left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right) \cdot 2\right) \cdot 0.5 + 0.5\right) \cdot a, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 80.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites80.6%
lift-pow.f64N/A
unpow2N/A
lift-cos.f64N/A
lift-cos.f64N/A
sqr-cos-aN/A
lower-+.f64N/A
lower-*.f64N/A
lower-cos.f64N/A
lower-*.f6480.6
lift-/.f64N/A
clear-numN/A
associate-/r/N/A
lower-*.f64N/A
metadata-eval80.5
lift-*.f64N/A
*-commutativeN/A
lift-*.f6480.5
Applied rewrites80.5%
Final simplification80.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* 1.0 a) 2.0) (pow (* (sin (* (* (PI) angle) 0.005555555555555556)) b) 2.0)))
\begin{array}{l}
\\
{\left(1 \cdot a\right)}^{2} + {\left(\sin \left(\left(\mathsf{PI}\left(\right) \cdot angle\right) \cdot 0.005555555555555556\right) \cdot b\right)}^{2}
\end{array}
Initial program 80.4%
lift-*.f64N/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-sqr-sqrtN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
lower-/.f64N/A
lift-PI.f64N/A
lower-sqrt.f64N/A
inv-powN/A
lower-pow.f6480.2
Applied rewrites80.2%
lift-*.f64N/A
lift-/.f64N/A
lift-/.f64N/A
frac-timesN/A
lift-sqrt.f64N/A
lift-sqrt.f64N/A
rem-square-sqrtN/A
lift-pow.f64N/A
unpow-1N/A
div-invN/A
div-invN/A
clear-numN/A
div-invN/A
metadata-evalN/A
associate-*r*N/A
*-commutativeN/A
lift-*.f64N/A
lower-*.f6480.5
lift-*.f64N/A
*-commutativeN/A
lower-*.f6480.5
Applied rewrites80.5%
Taylor expanded in angle around inf
*-commutativeN/A
associate-*r*N/A
lower-cos.f64N/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6480.6
Applied rewrites80.6%
Taylor expanded in angle around 0
Applied rewrites80.1%
Final simplification80.1%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.15e-103)
(* (* a a) (pow (cos (* -0.005555555555555556 (* (PI) angle))) 2.0))
(if (<= b 8.5e+151)
(fma
(* (* (* b b) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.15 \cdot 10^{-103}:\\
\;\;\;\;\left(a \cdot a\right) \cdot {\cos \left(-0.005555555555555556 \cdot \left(\mathsf{PI}\left(\right) \cdot angle\right)\right)}^{2}\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 2.15000000000000011e-103Initial program 80.0%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites80.2%
Taylor expanded in a around inf
*-commutativeN/A
lower-*.f64N/A
lower-pow.f64N/A
lower-cos.f64N/A
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-PI.f64N/A
unpow2N/A
lower-*.f6458.9
Applied rewrites58.9%
if 2.15000000000000011e-103 < b < 8.50000000000000051e151Initial program 70.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.6%
Taylor expanded in a around 0
Applied rewrites64.3%
if 8.50000000000000051e151 < b Initial program 99.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.1%
Taylor expanded in a around 0
Applied rewrites62.9%
Applied rewrites82.4%
Final simplification63.2%
(FPCore (a b angle) :precision binary64 (fma (* 1.0 a) a (pow (* (sin (* (* 0.005555555555555556 angle) (PI))) b) 2.0)))
\begin{array}{l}
\\
\mathsf{fma}\left(1 \cdot a, a, {\left(\sin \left(\left(0.005555555555555556 \cdot angle\right) \cdot \mathsf{PI}\left(\right)\right) \cdot b\right)}^{2}\right)
\end{array}
Initial program 80.4%
lift-+.f64N/A
lift-pow.f64N/A
unpow2N/A
lift-*.f64N/A
*-commutativeN/A
associate-*r*N/A
lower-fma.f64N/A
Applied rewrites80.6%
Taylor expanded in angle around 0
Applied rewrites80.0%
(FPCore (a b angle)
:precision binary64
(if (<= b 2.15e-103)
(* a a)
(if (<= b 8.5e+151)
(fma
(* (* (* b b) 3.08641975308642e-5) (* (PI) (PI)))
(* angle angle)
(* a a))
(* (pow (* (* b (PI)) angle) 2.0) 3.08641975308642e-5))))\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.15 \cdot 10^{-103}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right), angle \cdot angle, a \cdot a\right)\\
\mathbf{else}:\\
\;\;\;\;{\left(\left(b \cdot \mathsf{PI}\left(\right)\right) \cdot angle\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}\\
\end{array}
\end{array}
if b < 2.15000000000000011e-103Initial program 80.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.3
Applied rewrites58.3%
if 2.15000000000000011e-103 < b < 8.50000000000000051e151Initial program 70.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.6%
Taylor expanded in a around 0
Applied rewrites64.3%
if 8.50000000000000051e151 < b Initial program 99.5%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites51.1%
Taylor expanded in a around 0
Applied rewrites62.9%
Applied rewrites82.4%
Final simplification62.9%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= b 2.15e-103)
(* a a)
(if (<= b 8.5e+151)
(fma (* (* (* b b) 3.08641975308642e-5) t_0) (* angle angle) (* a a))
(if (<= b 2.6e+206)
(* (* t_0 b) (* (* (* angle angle) 3.08641975308642e-5) b))
(* (* (* (* (* b b) angle) angle) 3.08641975308642e-5) t_0))))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;b \leq 2.15 \cdot 10^{-103}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 8.5 \cdot 10^{+151}:\\
\;\;\;\;\mathsf{fma}\left(\left(\left(b \cdot b\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0, angle \cdot angle, a \cdot a\right)\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+206}:\\
\;\;\;\;\left(t\_0 \cdot b\right) \cdot \left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(b \cdot b\right) \cdot angle\right) \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0\\
\end{array}
\end{array}
if b < 2.15000000000000011e-103Initial program 80.0%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.3
Applied rewrites58.3%
if 2.15000000000000011e-103 < b < 8.50000000000000051e151Initial program 70.7%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites38.6%
Taylor expanded in a around 0
Applied rewrites64.3%
if 8.50000000000000051e151 < b < 2.59999999999999989e206Initial program 99.3%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites52.1%
Taylor expanded in a around 0
Applied rewrites60.5%
Applied rewrites89.5%
if 2.59999999999999989e206 < b Initial program 99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.5%
Taylor expanded in a around 0
Applied rewrites64.2%
Taylor expanded in a around 0
Applied rewrites78.6%
Final simplification62.9%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* (PI) (PI))))
(if (<= b 3.8e+95)
(* a a)
(if (<= b 2.6e+206)
(* (* t_0 b) (* (* (* angle angle) 3.08641975308642e-5) b))
(* (* (* (* (* b b) angle) angle) 3.08641975308642e-5) t_0)))))\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\\
\mathbf{if}\;b \leq 3.8 \cdot 10^{+95}:\\
\;\;\;\;a \cdot a\\
\mathbf{elif}\;b \leq 2.6 \cdot 10^{+206}:\\
\;\;\;\;\left(t\_0 \cdot b\right) \cdot \left(\left(\left(angle \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot b\right)\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(b \cdot b\right) \cdot angle\right) \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot t\_0\\
\end{array}
\end{array}
if b < 3.7999999999999999e95Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 3.7999999999999999e95 < b < 2.59999999999999989e206Initial program 88.9%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites48.2%
Taylor expanded in a around 0
Applied rewrites52.9%
Applied rewrites65.4%
if 2.59999999999999989e206 < b Initial program 99.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites50.5%
Taylor expanded in a around 0
Applied rewrites64.2%
Taylor expanded in a around 0
Applied rewrites78.6%
Final simplification60.9%
(FPCore (a b angle) :precision binary64 (if (<= b 3.8e+95) (* a a) (* (* (* (* (* b b) angle) angle) 3.08641975308642e-5) (* (PI) (PI)))))
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.8 \cdot 10^{+95}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;\left(\left(\left(\left(b \cdot b\right) \cdot angle\right) \cdot angle\right) \cdot 3.08641975308642 \cdot 10^{-5}\right) \cdot \left(\mathsf{PI}\left(\right) \cdot \mathsf{PI}\left(\right)\right)\\
\end{array}
\end{array}
if b < 3.7999999999999999e95Initial program 77.2%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.4
Applied rewrites58.4%
if 3.7999999999999999e95 < b Initial program 93.6%
Taylor expanded in angle around 0
*-commutativeN/A
lower-fma.f64N/A
Applied rewrites49.2%
Taylor expanded in a around 0
Applied rewrites57.9%
Taylor expanded in a around 0
Applied rewrites66.2%
Final simplification59.9%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 80.4%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6454.2
Applied rewrites54.2%
herbie shell --seed 2024331
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* (PI) (/ angle 180.0)))) 2.0) (pow (* b (sin (* (PI) (/ angle 180.0)))) 2.0)))