
(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 8 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 (hypot b (* a (sin (* 0.005555555555555556 (* angle PI))))) 2.0))
double code(double a, double b, double angle) {
return pow(hypot(b, (a * sin((0.005555555555555556 * (angle * ((double) M_PI)))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(Math.hypot(b, (a * Math.sin((0.005555555555555556 * (angle * Math.PI))))), 2.0);
}
def code(a, b, angle): return math.pow(math.hypot(b, (a * math.sin((0.005555555555555556 * (angle * math.pi))))), 2.0)
function code(a, b, angle) return hypot(b, Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi))))) ^ 2.0 end
function tmp = code(a, b, angle) tmp = hypot(b, (a * sin((0.005555555555555556 * (angle * pi))))) ^ 2.0; end
code[a_, b_, angle_] := N[Power[N[Sqrt[b ^ 2 + N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(b, a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)\right)}^{2}
\end{array}
Initial program 79.2%
unpow279.2%
associate-*l/79.2%
associate-/l*79.2%
unpow279.2%
Simplified79.2%
Taylor expanded in angle around 0 79.4%
Taylor expanded in a around 0 75.1%
unpow275.1%
*-commutative75.1%
associate-*r*75.0%
unpow275.0%
swap-sqr79.4%
unpow279.4%
rem-square-sqrt79.4%
hypot-undefine79.4%
hypot-undefine79.4%
unpow279.4%
Simplified79.5%
(FPCore (a b angle) :precision binary64 (if (<= b 9e-181) (pow (* a (sin (/ angle (/ 180.0 PI)))) 2.0) (pow (hypot b (* (* angle PI) (* a 0.005555555555555556))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 9e-181) {
tmp = pow((a * sin((angle / (180.0 / ((double) M_PI))))), 2.0);
} else {
tmp = pow(hypot(b, ((angle * ((double) M_PI)) * (a * 0.005555555555555556))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 9e-181) {
tmp = Math.pow((a * Math.sin((angle / (180.0 / Math.PI)))), 2.0);
} else {
tmp = Math.pow(Math.hypot(b, ((angle * Math.PI) * (a * 0.005555555555555556))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 9e-181: tmp = math.pow((a * math.sin((angle / (180.0 / math.pi)))), 2.0) else: tmp = math.pow(math.hypot(b, ((angle * math.pi) * (a * 0.005555555555555556))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 9e-181) tmp = Float64(a * sin(Float64(angle / Float64(180.0 / pi)))) ^ 2.0; else tmp = hypot(b, Float64(Float64(angle * pi) * Float64(a * 0.005555555555555556))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 9e-181) tmp = (a * sin((angle / (180.0 / pi)))) ^ 2.0; else tmp = hypot(b, ((angle * pi) * (a * 0.005555555555555556))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 9e-181], N[Power[N[(a * N[Sin[N[(angle / N[(180.0 / Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[N[Sqrt[b ^ 2 + N[(N[(angle * Pi), $MachinePrecision] * N[(a * 0.005555555555555556), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9 \cdot 10^{-181}:\\
\;\;\;\;{\left(a \cdot \sin \left(\frac{angle}{\frac{180}{\pi}}\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(b, \left(angle \cdot \pi\right) \cdot \left(a \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 8.9999999999999998e-181Initial program 79.8%
unpow279.8%
associate-*l/79.8%
associate-/l*79.7%
unpow279.7%
Simplified79.8%
Taylor expanded in a around inf 50.3%
unpow250.3%
*-commutative50.3%
associate-*r*50.2%
unpow250.2%
swap-sqr52.9%
unpow252.9%
associate-*r*52.9%
*-commutative52.9%
Simplified52.9%
*-commutative52.9%
associate-*r*52.9%
metadata-eval52.9%
div-inv52.9%
clear-num52.9%
un-div-inv52.9%
Applied egg-rr52.9%
if 8.9999999999999998e-181 < b Initial program 78.3%
unpow278.3%
associate-*l/78.4%
associate-/l*78.4%
unpow278.4%
Simplified78.5%
Taylor expanded in angle around 0 79.9%
Taylor expanded in a around 0 75.8%
unpow275.8%
*-commutative75.8%
associate-*r*75.7%
unpow275.7%
swap-sqr79.9%
unpow279.9%
rem-square-sqrt79.9%
hypot-undefine79.9%
hypot-undefine79.9%
unpow279.9%
Simplified79.9%
Taylor expanded in angle around 0 77.0%
associate-*r*77.0%
Simplified77.0%
Final simplification63.0%
(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(angle * Float64(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[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 79.2%
unpow279.2%
associate-*l/79.2%
associate-/l*79.2%
unpow279.2%
Simplified79.2%
Taylor expanded in angle around 0 79.4%
*-rgt-identity79.4%
unpow279.4%
Applied egg-rr79.4%
(FPCore (a b angle)
:precision binary64
(if (<= a 1.7e+115)
(pow b 2.0)
(*
0.005555555555555556
(* (* a (* angle (* 0.005555555555555556 PI))) (* a (* angle PI))))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.7e+115) {
tmp = pow(b, 2.0);
} else {
tmp = 0.005555555555555556 * ((a * (angle * (0.005555555555555556 * ((double) M_PI)))) * (a * (angle * ((double) M_PI))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.7e+115) {
tmp = Math.pow(b, 2.0);
} else {
tmp = 0.005555555555555556 * ((a * (angle * (0.005555555555555556 * Math.PI))) * (a * (angle * Math.PI)));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.7e+115: tmp = math.pow(b, 2.0) else: tmp = 0.005555555555555556 * ((a * (angle * (0.005555555555555556 * math.pi))) * (a * (angle * math.pi))) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.7e+115) tmp = b ^ 2.0; else tmp = Float64(0.005555555555555556 * Float64(Float64(a * Float64(angle * Float64(0.005555555555555556 * pi))) * Float64(a * Float64(angle * pi)))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.7e+115) tmp = b ^ 2.0; else tmp = 0.005555555555555556 * ((a * (angle * (0.005555555555555556 * pi))) * (a * (angle * pi))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.7e+115], N[Power[b, 2.0], $MachinePrecision], N[(0.005555555555555556 * N[(N[(a * N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.7 \cdot 10^{+115}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;0.005555555555555556 \cdot \left(\left(a \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right) \cdot \left(a \cdot \left(angle \cdot \pi\right)\right)\right)\\
\end{array}
\end{array}
if a < 1.7e115Initial program 78.2%
unpow278.2%
associate-*l/78.2%
associate-/l*78.2%
unpow278.2%
Simplified78.2%
Taylor expanded in angle around 0 59.0%
if 1.7e115 < a Initial program 85.4%
unpow285.4%
associate-*l/85.6%
associate-/l*85.6%
unpow285.6%
Simplified85.6%
Taylor expanded in a around inf 63.5%
unpow263.5%
*-commutative63.5%
associate-*r*63.6%
unpow263.6%
swap-sqr66.6%
unpow266.6%
associate-*r*66.6%
*-commutative66.6%
Simplified66.6%
Taylor expanded in angle around 0 67.8%
unpow267.8%
*-commutative67.8%
associate-*r*67.8%
*-commutative67.8%
associate-*l*67.8%
associate-*r*67.8%
Applied egg-rr67.8%
Final simplification60.2%
(FPCore (a b angle) :precision binary64 (* (* angle PI) (* (* a (* angle (* 0.005555555555555556 PI))) (* a 0.005555555555555556))))
double code(double a, double b, double angle) {
return (angle * ((double) M_PI)) * ((a * (angle * (0.005555555555555556 * ((double) M_PI)))) * (a * 0.005555555555555556));
}
public static double code(double a, double b, double angle) {
return (angle * Math.PI) * ((a * (angle * (0.005555555555555556 * Math.PI))) * (a * 0.005555555555555556));
}
def code(a, b, angle): return (angle * math.pi) * ((a * (angle * (0.005555555555555556 * math.pi))) * (a * 0.005555555555555556))
function code(a, b, angle) return Float64(Float64(angle * pi) * Float64(Float64(a * Float64(angle * Float64(0.005555555555555556 * pi))) * Float64(a * 0.005555555555555556))) end
function tmp = code(a, b, angle) tmp = (angle * pi) * ((a * (angle * (0.005555555555555556 * pi))) * (a * 0.005555555555555556)); end
code[a_, b_, angle_] := N[(N[(angle * Pi), $MachinePrecision] * N[(N[(a * N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(a * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(angle \cdot \pi\right) \cdot \left(\left(a \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right) \cdot \left(a \cdot 0.005555555555555556\right)\right)
\end{array}
Initial program 79.2%
unpow279.2%
associate-*l/79.2%
associate-/l*79.2%
unpow279.2%
Simplified79.2%
Taylor expanded in a around inf 40.0%
unpow240.0%
*-commutative40.0%
associate-*r*39.9%
unpow239.9%
swap-sqr41.9%
unpow241.9%
associate-*r*42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in angle around 0 39.6%
unpow239.6%
associate-*r*39.6%
associate-*r*39.9%
*-commutative39.9%
associate-*l*39.9%
associate-*r*39.9%
*-commutative39.9%
Applied egg-rr39.9%
Final simplification39.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* a (* angle (* 0.005555555555555556 PI))))) (* t_0 t_0)))
double code(double a, double b, double angle) {
double t_0 = a * (angle * (0.005555555555555556 * ((double) M_PI)));
return t_0 * t_0;
}
public static double code(double a, double b, double angle) {
double t_0 = a * (angle * (0.005555555555555556 * Math.PI));
return t_0 * t_0;
}
def code(a, b, angle): t_0 = a * (angle * (0.005555555555555556 * math.pi)) return t_0 * t_0
function code(a, b, angle) t_0 = Float64(a * Float64(angle * Float64(0.005555555555555556 * pi))) return Float64(t_0 * t_0) end
function tmp = code(a, b, angle) t_0 = a * (angle * (0.005555555555555556 * pi)); tmp = t_0 * t_0; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(a * N[(angle * N[(0.005555555555555556 * Pi), $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(0.005555555555555556 \cdot \pi\right)\right)\\
t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 79.2%
unpow279.2%
associate-*l/79.2%
associate-/l*79.2%
unpow279.2%
Simplified79.2%
Taylor expanded in a around inf 40.0%
unpow240.0%
*-commutative40.0%
associate-*r*39.9%
unpow239.9%
swap-sqr41.9%
unpow241.9%
associate-*r*42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in angle around 0 39.6%
unpow239.6%
*-commutative39.6%
associate-*l*39.6%
associate-*r*39.6%
*-commutative39.6%
associate-*l*39.6%
associate-*r*39.6%
Applied egg-rr39.6%
Final simplification39.6%
(FPCore (a b angle) :precision binary64 (* (* a (* angle PI)) (* a (* 0.005555555555555556 (* 0.005555555555555556 (* angle PI))))))
double code(double a, double b, double angle) {
return (a * (angle * ((double) M_PI))) * (a * (0.005555555555555556 * (0.005555555555555556 * (angle * ((double) M_PI)))));
}
public static double code(double a, double b, double angle) {
return (a * (angle * Math.PI)) * (a * (0.005555555555555556 * (0.005555555555555556 * (angle * Math.PI))));
}
def code(a, b, angle): return (a * (angle * math.pi)) * (a * (0.005555555555555556 * (0.005555555555555556 * (angle * math.pi))))
function code(a, b, angle) return Float64(Float64(a * Float64(angle * pi)) * Float64(a * Float64(0.005555555555555556 * Float64(0.005555555555555556 * Float64(angle * pi))))) end
function tmp = code(a, b, angle) tmp = (a * (angle * pi)) * (a * (0.005555555555555556 * (0.005555555555555556 * (angle * pi)))); end
code[a_, b_, angle_] := N[(N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision] * N[(a * N[(0.005555555555555556 * N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(a \cdot \left(angle \cdot \pi\right)\right) \cdot \left(a \cdot \left(0.005555555555555556 \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)\right)
\end{array}
Initial program 79.2%
unpow279.2%
associate-*l/79.2%
associate-/l*79.2%
unpow279.2%
Simplified79.2%
Taylor expanded in a around inf 40.0%
unpow240.0%
*-commutative40.0%
associate-*r*39.9%
unpow239.9%
swap-sqr41.9%
unpow241.9%
associate-*r*42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in angle around 0 39.6%
unpow239.6%
associate-*l*39.6%
*-commutative39.6%
associate-*l*39.6%
associate-*r*39.6%
Applied egg-rr39.6%
associate-*r*39.6%
*-commutative39.6%
associate-*r*39.6%
*-commutative39.6%
associate-*l*39.6%
associate-*r*39.6%
*-commutative39.6%
Simplified39.6%
Final simplification39.6%
(FPCore (a b angle) :precision binary64 (* (* a 0.005555555555555556) (* (* angle PI) (* a (* angle (* 0.005555555555555556 PI))))))
double code(double a, double b, double angle) {
return (a * 0.005555555555555556) * ((angle * ((double) M_PI)) * (a * (angle * (0.005555555555555556 * ((double) M_PI)))));
}
public static double code(double a, double b, double angle) {
return (a * 0.005555555555555556) * ((angle * Math.PI) * (a * (angle * (0.005555555555555556 * Math.PI))));
}
def code(a, b, angle): return (a * 0.005555555555555556) * ((angle * math.pi) * (a * (angle * (0.005555555555555556 * math.pi))))
function code(a, b, angle) return Float64(Float64(a * 0.005555555555555556) * Float64(Float64(angle * pi) * Float64(a * Float64(angle * Float64(0.005555555555555556 * pi))))) end
function tmp = code(a, b, angle) tmp = (a * 0.005555555555555556) * ((angle * pi) * (a * (angle * (0.005555555555555556 * pi)))); end
code[a_, b_, angle_] := N[(N[(a * 0.005555555555555556), $MachinePrecision] * N[(N[(angle * Pi), $MachinePrecision] * N[(a * N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(a \cdot 0.005555555555555556\right) \cdot \left(\left(angle \cdot \pi\right) \cdot \left(a \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)\right)
\end{array}
Initial program 79.2%
unpow279.2%
associate-*l/79.2%
associate-/l*79.2%
unpow279.2%
Simplified79.2%
Taylor expanded in a around inf 40.0%
unpow240.0%
*-commutative40.0%
associate-*r*39.9%
unpow239.9%
swap-sqr41.9%
unpow241.9%
associate-*r*42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in angle around 0 39.6%
unpow239.6%
associate-*r*39.6%
associate-*l*39.6%
*-commutative39.6%
*-commutative39.6%
associate-*l*39.6%
associate-*r*39.6%
Applied egg-rr39.6%
Final simplification39.6%
herbie shell --seed 2024165
(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)))