
(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))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\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 7 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))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\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 (+ (pow (* a (sin (/ (* angle PI) 180.0))) 2.0) (* b b)))
double code(double a, double b, double angle) {
return pow((a * sin(((angle * ((double) M_PI)) / 180.0))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(((angle * Math.PI) / 180.0))), 2.0) + (b * b);
}
def code(a, b, angle): return math.pow((a * math.sin(((angle * math.pi) / 180.0))), 2.0) + (b * b)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64(angle * pi) / 180.0))) ^ 2.0) + Float64(b * b)) end
function tmp = code(a, b, angle) tmp = ((a * sin(((angle * pi) / 180.0))) ^ 2.0) + (b * b); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(angle * Pi), $MachinePrecision] / 180.0), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle \cdot \pi}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 74.6%
unpow274.6%
associate-*l/74.7%
associate-/l*74.7%
unpow274.7%
Simplified74.8%
Taylor expanded in angle around 0 75.2%
associate-*r/75.2%
Applied egg-rr75.2%
*-rgt-identity75.2%
unpow275.2%
Applied egg-rr75.2%
(FPCore (a b angle) :precision binary64 (+ (* b b) (pow (* a (sin (* angle (/ PI 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return (b * b) + pow((a * sin((angle * (((double) M_PI) / 180.0)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (b * b) + Math.pow((a * Math.sin((angle * (Math.PI / 180.0)))), 2.0);
}
def code(a, b, angle): return (b * b) + math.pow((a * math.sin((angle * (math.pi / 180.0)))), 2.0)
function code(a, b, angle) return Float64(Float64(b * b) + (Float64(a * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (b * b) + ((a * sin((angle * (pi / 180.0)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(b * b), $MachinePrecision] + N[Power[N[(a * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b + {\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2}
\end{array}
Initial program 74.6%
unpow274.6%
associate-*l/74.7%
associate-/l*74.7%
unpow274.7%
Simplified74.8%
Taylor expanded in angle around 0 75.2%
*-rgt-identity75.2%
unpow275.2%
Applied egg-rr75.2%
Final simplification75.2%
(FPCore (a b angle) :precision binary64 (if (<= a 2.8e+86) (pow b 2.0) (+ (* b b) (pow (* 0.005555555555555556 (* a (* angle PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.8e+86) {
tmp = pow(b, 2.0);
} else {
tmp = (b * b) + pow((0.005555555555555556 * (a * (angle * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.8e+86) {
tmp = Math.pow(b, 2.0);
} else {
tmp = (b * b) + Math.pow((0.005555555555555556 * (a * (angle * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 2.8e+86: tmp = math.pow(b, 2.0) else: tmp = (b * b) + math.pow((0.005555555555555556 * (a * (angle * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 2.8e+86) tmp = b ^ 2.0; else tmp = Float64(Float64(b * b) + (Float64(0.005555555555555556 * Float64(a * Float64(angle * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 2.8e+86) tmp = b ^ 2.0; else tmp = (b * b) + ((0.005555555555555556 * (a * (angle * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 2.8e+86], N[Power[b, 2.0], $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.8 \cdot 10^{+86}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(0.005555555555555556 \cdot \left(a \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 2.80000000000000004e86Initial program 72.7%
unpow272.7%
associate-*l/72.8%
associate-/l*72.7%
unpow272.7%
Simplified72.8%
Taylor expanded in angle around 0 59.1%
if 2.80000000000000004e86 < a Initial program 87.2%
unpow287.2%
associate-*l/87.4%
associate-/l*87.4%
unpow287.4%
Simplified87.4%
Taylor expanded in angle around 0 87.4%
associate-*r/87.4%
Applied egg-rr87.4%
*-rgt-identity87.4%
unpow287.4%
Applied egg-rr87.4%
Taylor expanded in angle around 0 85.6%
Final simplification62.6%
(FPCore (a b angle) :precision binary64 (if (<= a 1.08e+108) (pow b 2.0) (pow (* a (* (* angle PI) 0.005555555555555556)) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.08e+108) {
tmp = pow(b, 2.0);
} else {
tmp = pow((a * ((angle * ((double) M_PI)) * 0.005555555555555556)), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.08e+108) {
tmp = Math.pow(b, 2.0);
} else {
tmp = Math.pow((a * ((angle * Math.PI) * 0.005555555555555556)), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.08e+108: tmp = math.pow(b, 2.0) else: tmp = math.pow((a * ((angle * math.pi) * 0.005555555555555556)), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.08e+108) tmp = b ^ 2.0; else tmp = Float64(a * Float64(Float64(angle * pi) * 0.005555555555555556)) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.08e+108) tmp = b ^ 2.0; else tmp = (a * ((angle * pi) * 0.005555555555555556)) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.08e+108], N[Power[b, 2.0], $MachinePrecision], N[Power[N[(a * N[(N[(angle * Pi), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.08 \cdot 10^{+108}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \left(\left(angle \cdot \pi\right) \cdot 0.005555555555555556\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.0800000000000001e108Initial program 72.2%
unpow272.2%
associate-*l/72.2%
associate-/l*72.2%
unpow272.2%
Simplified72.3%
Taylor expanded in angle around 0 58.3%
if 1.0800000000000001e108 < a Initial program 93.7%
unpow293.7%
associate-*l/94.0%
associate-/l*93.9%
unpow293.9%
Simplified93.9%
Taylor expanded in a around inf 64.9%
unpow264.9%
*-commutative64.9%
associate-*r*64.8%
unpow264.8%
swap-sqr77.7%
unpow277.7%
associate-*r*77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in angle around 0 79.9%
Final simplification60.8%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* a (* angle (* PI 0.005555555555555556))))) (if (<= a 5.5e+109) (pow b 2.0) (* t_0 t_0))))
double code(double a, double b, double angle) {
double t_0 = a * (angle * (((double) M_PI) * 0.005555555555555556));
double tmp;
if (a <= 5.5e+109) {
tmp = pow(b, 2.0);
} else {
tmp = t_0 * t_0;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = a * (angle * (Math.PI * 0.005555555555555556));
double tmp;
if (a <= 5.5e+109) {
tmp = Math.pow(b, 2.0);
} else {
tmp = t_0 * t_0;
}
return tmp;
}
def code(a, b, angle): t_0 = a * (angle * (math.pi * 0.005555555555555556)) tmp = 0 if a <= 5.5e+109: tmp = math.pow(b, 2.0) else: tmp = t_0 * t_0 return tmp
function code(a, b, angle) t_0 = Float64(a * Float64(angle * Float64(pi * 0.005555555555555556))) tmp = 0.0 if (a <= 5.5e+109) tmp = b ^ 2.0; else tmp = Float64(t_0 * t_0); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = a * (angle * (pi * 0.005555555555555556)); tmp = 0.0; if (a <= 5.5e+109) tmp = b ^ 2.0; else tmp = t_0 * t_0; end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(a * N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 5.5e+109], N[Power[b, 2.0], $MachinePrecision], N[(t$95$0 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\\
\mathbf{if}\;a \leq 5.5 \cdot 10^{+109}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot t\_0\\
\end{array}
\end{array}
if a < 5.4999999999999998e109Initial program 72.2%
unpow272.2%
associate-*l/72.2%
associate-/l*72.2%
unpow272.2%
Simplified72.3%
Taylor expanded in angle around 0 58.3%
if 5.4999999999999998e109 < a Initial program 93.7%
unpow293.7%
associate-*l/94.0%
associate-/l*93.9%
unpow293.9%
Simplified93.9%
Taylor expanded in a around inf 64.9%
unpow264.9%
*-commutative64.9%
associate-*r*64.8%
unpow264.8%
swap-sqr77.7%
unpow277.7%
associate-*r*77.8%
*-commutative77.8%
Simplified77.8%
Taylor expanded in angle around 0 80.1%
unpow280.1%
*-commutative80.1%
associate-*l*80.1%
associate-*r*80.1%
*-commutative80.1%
associate-*l*80.0%
associate-*r*79.9%
Applied egg-rr79.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* a (* angle (* PI 0.005555555555555556))))) (* t_0 t_0)))
double code(double a, double b, double angle) {
double t_0 = a * (angle * (((double) M_PI) * 0.005555555555555556));
return t_0 * t_0;
}
public static double code(double a, double b, double angle) {
double t_0 = a * (angle * (Math.PI * 0.005555555555555556));
return t_0 * t_0;
}
def code(a, b, angle): t_0 = a * (angle * (math.pi * 0.005555555555555556)) return t_0 * t_0
function code(a, b, angle) t_0 = Float64(a * Float64(angle * Float64(pi * 0.005555555555555556))) return Float64(t_0 * t_0) end
function tmp = code(a, b, angle) t_0 = a * (angle * (pi * 0.005555555555555556)); tmp = t_0 * t_0; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(a * N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := a \cdot \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\\
t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 74.6%
unpow274.6%
associate-*l/74.7%
associate-/l*74.7%
unpow274.7%
Simplified74.8%
Taylor expanded in a around inf 30.3%
unpow230.3%
*-commutative30.3%
associate-*r*30.3%
unpow230.3%
swap-sqr35.9%
unpow235.9%
associate-*r*35.9%
*-commutative35.9%
Simplified35.9%
Taylor expanded in angle around 0 37.6%
unpow237.6%
*-commutative37.6%
associate-*l*37.6%
associate-*r*37.7%
*-commutative37.7%
associate-*l*37.6%
associate-*r*37.6%
Applied egg-rr37.6%
(FPCore (a b angle) :precision binary64 (* 0.005555555555555556 (* (* a (* angle PI)) (* (* a angle) (* PI 0.005555555555555556)))))
double code(double a, double b, double angle) {
return 0.005555555555555556 * ((a * (angle * ((double) M_PI))) * ((a * angle) * (((double) M_PI) * 0.005555555555555556)));
}
public static double code(double a, double b, double angle) {
return 0.005555555555555556 * ((a * (angle * Math.PI)) * ((a * angle) * (Math.PI * 0.005555555555555556)));
}
def code(a, b, angle): return 0.005555555555555556 * ((a * (angle * math.pi)) * ((a * angle) * (math.pi * 0.005555555555555556)))
function code(a, b, angle) return Float64(0.005555555555555556 * Float64(Float64(a * Float64(angle * pi)) * Float64(Float64(a * angle) * Float64(pi * 0.005555555555555556)))) end
function tmp = code(a, b, angle) tmp = 0.005555555555555556 * ((a * (angle * pi)) * ((a * angle) * (pi * 0.005555555555555556))); end
code[a_, b_, angle_] := N[(0.005555555555555556 * N[(N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision] * N[(N[(a * angle), $MachinePrecision] * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
0.005555555555555556 \cdot \left(\left(a \cdot \left(angle \cdot \pi\right)\right) \cdot \left(\left(a \cdot angle\right) \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)
\end{array}
Initial program 74.6%
unpow274.6%
associate-*l/74.7%
associate-/l*74.7%
unpow274.7%
Simplified74.8%
Taylor expanded in a around inf 30.3%
unpow230.3%
*-commutative30.3%
associate-*r*30.3%
unpow230.3%
swap-sqr35.9%
unpow235.9%
associate-*r*35.9%
*-commutative35.9%
Simplified35.9%
Taylor expanded in angle around 0 37.6%
unpow237.6%
associate-*l*37.3%
*-commutative37.3%
associate-*l*37.3%
associate-*r*37.3%
Applied egg-rr37.3%
associate-*r*37.3%
*-commutative37.3%
Simplified37.3%
Final simplification37.3%
herbie shell --seed 2024157
(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)))