
(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))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \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 7 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))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \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 (+ (* a a) (pow (* b (sin (/ (* PI angle) 180.0))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin(((((double) M_PI) * angle) / 180.0))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin(((Math.PI * angle) / 180.0))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin(((math.pi * angle) / 180.0))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(Float64(pi * angle) / 180.0))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin(((pi * angle) / 180.0))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(N[(Pi * angle), $MachinePrecision] / 180.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(\frac{\pi \cdot angle}{180}\right)\right)}^{2}
\end{array}
Initial program 81.9%
Simplified81.9%
Taylor expanded in angle around 0 82.5%
metadata-eval82.5%
div-inv82.5%
associate-*r/82.6%
Applied egg-rr82.6%
unpow282.6%
Applied egg-rr82.6%
(FPCore (a b angle) :precision binary64 (if (<= a 5.8e-159) (pow (* b (sin (* 0.005555555555555556 (* PI angle)))) 2.0) (+ (pow a 2.0) (pow (* (* b angle) (* PI 0.005555555555555556)) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 5.8e-159) {
tmp = pow((b * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
} else {
tmp = pow(a, 2.0) + pow(((b * angle) * (((double) M_PI) * 0.005555555555555556)), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 5.8e-159) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (Math.PI * angle)))), 2.0);
} else {
tmp = Math.pow(a, 2.0) + Math.pow(((b * angle) * (Math.PI * 0.005555555555555556)), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 5.8e-159: tmp = math.pow((b * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0) else: tmp = math.pow(a, 2.0) + math.pow(((b * angle) * (math.pi * 0.005555555555555556)), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 5.8e-159) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0; else tmp = Float64((a ^ 2.0) + (Float64(Float64(b * angle) * Float64(pi * 0.005555555555555556)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 5.8e-159) tmp = (b * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0; else tmp = (a ^ 2.0) + (((b * angle) * (pi * 0.005555555555555556)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 5.8e-159], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(N[(b * angle), $MachinePrecision] * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.8 \cdot 10^{-159}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{a}^{2} + {\left(\left(b \cdot angle\right) \cdot \left(\pi \cdot 0.005555555555555556\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 5.79999999999999981e-159Initial program 81.7%
Simplified81.7%
Taylor expanded in a around 0 37.7%
*-commutative37.7%
associate-*r*37.7%
*-commutative37.7%
*-commutative37.7%
unpow237.7%
unpow237.7%
swap-sqr46.4%
unpow246.4%
*-commutative46.4%
*-commutative46.4%
*-commutative46.4%
associate-*r*46.4%
Simplified46.4%
if 5.79999999999999981e-159 < a Initial program 82.2%
Simplified82.2%
Taylor expanded in angle around 0 82.8%
add-sqr-sqrt38.5%
pow238.5%
Applied egg-rr38.5%
Taylor expanded in angle around 0 79.4%
associate-*r*79.4%
unpow279.4%
rem-square-sqrt79.4%
*-commutative79.4%
Simplified79.4%
Final simplification60.1%
(FPCore (a b angle) :precision binary64 (if (<= a 5.4e-158) (pow (* b (sin (* 0.005555555555555556 (* PI angle)))) 2.0) (+ (* a a) (pow (* 0.005555555555555556 (* angle (* b PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 5.4e-158) {
tmp = pow((b * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
} else {
tmp = (a * a) + pow((0.005555555555555556 * (angle * (b * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 5.4e-158) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (Math.PI * angle)))), 2.0);
} else {
tmp = (a * a) + Math.pow((0.005555555555555556 * (angle * (b * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 5.4e-158: tmp = math.pow((b * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0) else: tmp = (a * a) + math.pow((0.005555555555555556 * (angle * (b * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 5.4e-158) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0; else tmp = Float64(Float64(a * a) + (Float64(0.005555555555555556 * Float64(angle * Float64(b * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 5.4e-158) tmp = (b * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0; else tmp = (a * a) + ((0.005555555555555556 * (angle * (b * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 5.4e-158], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 5.4 \cdot 10^{-158}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 5.3999999999999997e-158Initial program 81.7%
Simplified81.7%
Taylor expanded in a around 0 37.7%
*-commutative37.7%
associate-*r*37.7%
*-commutative37.7%
*-commutative37.7%
unpow237.7%
unpow237.7%
swap-sqr46.4%
unpow246.4%
*-commutative46.4%
*-commutative46.4%
*-commutative46.4%
associate-*r*46.4%
Simplified46.4%
if 5.3999999999999997e-158 < a Initial program 82.2%
Simplified82.2%
Taylor expanded in angle around 0 82.8%
metadata-eval82.8%
div-inv82.8%
associate-*r/82.9%
Applied egg-rr82.9%
unpow282.9%
Applied egg-rr82.9%
Taylor expanded in angle around 0 79.5%
*-commutative79.5%
Simplified79.5%
Final simplification60.1%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* b (sin (* angle (* PI 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 81.9%
Simplified81.9%
Taylor expanded in angle around 0 82.5%
metadata-eval82.5%
div-inv82.5%
associate-*r/82.6%
Applied egg-rr82.6%
unpow282.6%
Applied egg-rr82.6%
associate-/l*82.5%
div-inv82.5%
metadata-eval82.5%
*-commutative82.5%
associate-*r*82.6%
Applied egg-rr82.6%
Final simplification82.6%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin((((double) M_PI) * (angle / 180.0)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin((Math.PI * (angle / 180.0)))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin((math.pi * (angle / 180.0)))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin((pi * (angle / 180.0)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 81.9%
Simplified81.9%
Taylor expanded in angle around 0 82.5%
metadata-eval82.5%
div-inv82.5%
associate-*r/82.6%
Applied egg-rr82.6%
unpow282.6%
Applied egg-rr82.6%
*-commutative82.6%
associate-/l*82.6%
Applied egg-rr82.6%
associate-*r/82.6%
*-commutative82.6%
associate-/l*82.5%
Simplified82.5%
(FPCore (a b angle) :precision binary64 (if (<= b 3.6e-7) (* a a) (+ (* a a) (pow (* 0.005555555555555556 (* angle (* b PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 3.6e-7) {
tmp = a * a;
} else {
tmp = (a * a) + pow((0.005555555555555556 * (angle * (b * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 3.6e-7) {
tmp = a * a;
} else {
tmp = (a * a) + Math.pow((0.005555555555555556 * (angle * (b * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 3.6e-7: tmp = a * a else: tmp = (a * a) + math.pow((0.005555555555555556 * (angle * (b * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 3.6e-7) tmp = Float64(a * a); else tmp = Float64(Float64(a * a) + (Float64(0.005555555555555556 * Float64(angle * Float64(b * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 3.6e-7) tmp = a * a; else tmp = (a * a) + ((0.005555555555555556 * (angle * (b * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 3.6e-7], N[(a * a), $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.6 \cdot 10^{-7}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 3.59999999999999994e-7Initial program 79.9%
Simplified79.9%
Taylor expanded in angle around 0 64.8%
unpow280.3%
Applied egg-rr64.8%
if 3.59999999999999994e-7 < b Initial program 88.5%
Simplified88.6%
Taylor expanded in angle around 0 90.0%
metadata-eval90.0%
div-inv90.0%
associate-*r/89.9%
Applied egg-rr89.9%
unpow289.9%
Applied egg-rr89.9%
Taylor expanded in angle around 0 87.5%
*-commutative87.5%
Simplified87.5%
Final simplification70.2%
(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 81.9%
Simplified81.9%
Taylor expanded in angle around 0 61.7%
unpow282.6%
Applied egg-rr61.7%
herbie shell --seed 2024110
(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)))