
(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 (* a (sin (* angle (/ (pow (sqrt PI) 2.0) 180.0)))) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
return pow((a * sin((angle * (pow(sqrt(((double) M_PI)), 2.0) / 180.0)))), 2.0) + pow(b, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((angle * (Math.pow(Math.sqrt(Math.PI), 2.0) / 180.0)))), 2.0) + Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow((a * math.sin((angle * (math.pow(math.sqrt(math.pi), 2.0) / 180.0)))), 2.0) + math.pow(b, 2.0)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(angle * Float64((sqrt(pi) ^ 2.0) / 180.0)))) ^ 2.0) + (b ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * sin((angle * ((sqrt(pi) ^ 2.0) / 180.0)))) ^ 2.0) + (b ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(angle * N[(N[Power[N[Sqrt[Pi], $MachinePrecision], 2.0], $MachinePrecision] / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(angle \cdot \frac{{\left(\sqrt{\pi}\right)}^{2}}{180}\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 74.0%
associate-*l/73.9%
associate-/l*74.0%
cos-neg74.0%
distribute-lft-neg-out74.0%
distribute-frac-neg74.0%
distribute-frac-neg74.0%
distribute-lft-neg-out74.0%
cos-neg74.0%
associate-*l/73.9%
associate-/l*73.7%
Simplified73.7%
Taylor expanded in angle around 0 74.4%
add-sqr-sqrt74.5%
pow274.5%
Applied egg-rr74.5%
Final simplification74.5%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* PI (/ angle 180.0)))) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
return pow((a * sin((((double) M_PI) * (angle / 180.0)))), 2.0) + pow(b, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((Math.PI * (angle / 180.0)))), 2.0) + Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow((a * math.sin((math.pi * (angle / 180.0)))), 2.0) + math.pow(b, 2.0)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + (b ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * sin((pi * (angle / 180.0)))) ^ 2.0) + (b ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 74.0%
associate-*l/74.0%
clear-num73.6%
Applied egg-rr73.6%
Taylor expanded in angle around 0 74.4%
Taylor expanded in b around 0 74.4%
Final simplification74.4%
(FPCore (a b angle) :precision binary64 (+ (pow b 2.0) (pow (* a (sin (* angle (/ PI 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return pow(b, 2.0) + pow((a * sin((angle * (((double) M_PI) / 180.0)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(b, 2.0) + Math.pow((a * Math.sin((angle * (Math.PI / 180.0)))), 2.0);
}
def code(a, b, angle): return math.pow(b, 2.0) + math.pow((a * math.sin((angle * (math.pi / 180.0)))), 2.0)
function code(a, b, angle) return Float64((b ^ 2.0) + (Float64(a * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (b ^ 2.0) + ((a * sin((angle * (pi / 180.0)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[b, 2.0], $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}^{2} + {\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2}
\end{array}
Initial program 74.0%
associate-*l/73.9%
associate-/l*74.0%
cos-neg74.0%
distribute-lft-neg-out74.0%
distribute-frac-neg74.0%
distribute-frac-neg74.0%
distribute-lft-neg-out74.0%
cos-neg74.0%
associate-*l/73.9%
associate-/l*73.7%
Simplified73.7%
Taylor expanded in angle around 0 74.4%
Taylor expanded in b around 0 74.4%
Final simplification74.4%
(FPCore (a b angle) :precision binary64 (if (<= b 9.2e-157) (pow (* a (sin (* PI (* angle 0.005555555555555556)))) 2.0) (+ (pow b 2.0) (pow (* angle (* a (* PI 0.005555555555555556))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 9.2e-157) {
tmp = pow((a * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
} else {
tmp = pow(b, 2.0) + pow((angle * (a * (((double) M_PI) * 0.005555555555555556))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 9.2e-157) {
tmp = Math.pow((a * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
} else {
tmp = Math.pow(b, 2.0) + Math.pow((angle * (a * (Math.PI * 0.005555555555555556))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 9.2e-157: tmp = math.pow((a * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0) else: tmp = math.pow(b, 2.0) + math.pow((angle * (a * (math.pi * 0.005555555555555556))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 9.2e-157) tmp = Float64(a * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0; else tmp = Float64((b ^ 2.0) + (Float64(angle * Float64(a * Float64(pi * 0.005555555555555556))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 9.2e-157) tmp = (a * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0; else tmp = (b ^ 2.0) + ((angle * (a * (pi * 0.005555555555555556))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 9.2e-157], N[Power[N[(a * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[Power[b, 2.0], $MachinePrecision] + N[Power[N[(angle * N[(a * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.2 \cdot 10^{-157}:\\
\;\;\;\;{\left(a \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2} + {\left(angle \cdot \left(a \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 9.19999999999999954e-157Initial program 72.8%
associate-*l/72.7%
associate-/l*72.8%
cos-neg72.8%
distribute-lft-neg-out72.8%
distribute-frac-neg72.8%
distribute-frac-neg72.8%
distribute-lft-neg-out72.8%
cos-neg72.8%
associate-*l/72.8%
associate-/l*72.3%
Simplified72.3%
Applied egg-rr70.3%
Taylor expanded in a around inf 34.9%
unpow234.9%
unpow234.9%
swap-sqr38.3%
unpow238.3%
*-commutative38.3%
associate-*r*38.5%
*-commutative38.5%
*-commutative38.5%
*-commutative38.5%
Simplified38.5%
if 9.19999999999999954e-157 < b Initial program 76.4%
associate-*l/76.5%
associate-/l*76.6%
cos-neg76.6%
distribute-lft-neg-out76.6%
distribute-frac-neg76.6%
distribute-frac-neg76.6%
distribute-lft-neg-out76.6%
cos-neg76.6%
associate-*l/76.5%
associate-/l*76.6%
Simplified76.6%
Taylor expanded in angle around 0 77.6%
Taylor expanded in angle around 0 75.1%
*-commutative75.1%
associate-*r*75.1%
associate-*l*75.1%
*-commutative75.1%
*-commutative75.1%
associate-*r*75.1%
Simplified75.1%
Final simplification49.9%
(FPCore (a b angle) :precision binary64 (if (<= a 1.65e+133) (* b b) (pow (* a (sin (* angle (* PI 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.65e+133) {
tmp = b * b;
} else {
tmp = pow((a * sin((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.65e+133) {
tmp = b * b;
} else {
tmp = Math.pow((a * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.65e+133: tmp = b * b else: tmp = math.pow((a * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.65e+133) tmp = Float64(b * b); else tmp = Float64(a * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.65e+133) tmp = b * b; else tmp = (a * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.65e+133], N[(b * b), $MachinePrecision], N[Power[N[(a * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.65 \cdot 10^{+133}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.65e133Initial program 70.7%
associate-*l/70.7%
associate-/l*70.8%
cos-neg70.8%
distribute-lft-neg-out70.8%
distribute-frac-neg70.8%
distribute-frac-neg70.8%
distribute-lft-neg-out70.8%
cos-neg70.8%
associate-*l/70.8%
associate-/l*70.4%
Simplified70.4%
Taylor expanded in angle around 0 58.9%
unpow258.9%
Applied egg-rr58.9%
if 1.65e133 < a Initial program 97.3%
associate-*l/97.0%
associate-/l*97.1%
cos-neg97.1%
distribute-lft-neg-out97.1%
distribute-frac-neg97.1%
distribute-frac-neg97.1%
distribute-lft-neg-out97.1%
cos-neg97.1%
associate-*l/97.1%
associate-/l*97.1%
Simplified97.1%
Applied egg-rr94.9%
Taylor expanded in a around inf 74.3%
rem-exp-log75.9%
add-sqr-sqrt75.9%
pow275.9%
unpow275.9%
sqrt-prod35.9%
add-sqr-sqrt75.9%
*-commutative75.9%
*-commutative75.9%
*-commutative75.9%
associate-*r*75.9%
Applied egg-rr75.9%
(FPCore (a b angle) :precision binary64 (if (<= a 9.5e+132) (* b b) (pow (* a (sin (* 0.005555555555555556 (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 9.5e+132) {
tmp = b * b;
} else {
tmp = pow((a * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 9.5e+132) {
tmp = b * b;
} else {
tmp = Math.pow((a * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 9.5e+132: tmp = b * b else: tmp = math.pow((a * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 9.5e+132) tmp = Float64(b * b); else tmp = Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 9.5e+132) tmp = b * b; else tmp = (a * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 9.5e+132], N[(b * b), $MachinePrecision], N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 9.5 \cdot 10^{+132}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 9.5000000000000005e132Initial program 70.7%
associate-*l/70.7%
associate-/l*70.8%
cos-neg70.8%
distribute-lft-neg-out70.8%
distribute-frac-neg70.8%
distribute-frac-neg70.8%
distribute-lft-neg-out70.8%
cos-neg70.8%
associate-*l/70.8%
associate-/l*70.4%
Simplified70.4%
Taylor expanded in angle around 0 58.9%
unpow258.9%
Applied egg-rr58.9%
if 9.5000000000000005e132 < a Initial program 97.3%
associate-*l/97.0%
associate-/l*97.1%
cos-neg97.1%
distribute-lft-neg-out97.1%
distribute-frac-neg97.1%
distribute-frac-neg97.1%
distribute-lft-neg-out97.1%
cos-neg97.1%
associate-*l/97.1%
associate-/l*97.1%
Simplified97.1%
Taylor expanded in angle around 0 97.1%
add-sqr-sqrt96.9%
pow296.9%
Applied egg-rr96.9%
Taylor expanded in a around inf 59.5%
*-commutative59.5%
*-commutative59.5%
*-commutative59.5%
associate-*r*59.5%
unpow259.5%
unpow259.5%
swap-sqr75.8%
unpow275.8%
*-commutative75.8%
*-commutative75.8%
associate-*r*75.9%
*-commutative75.9%
Simplified75.9%
(FPCore (a b angle) :precision binary64 (if (<= a 2.85e+206) (* b b) (cbrt (pow b 6.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.85e+206) {
tmp = b * b;
} else {
tmp = cbrt(pow(b, 6.0));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.85e+206) {
tmp = b * b;
} else {
tmp = Math.cbrt(Math.pow(b, 6.0));
}
return tmp;
}
function code(a, b, angle) tmp = 0.0 if (a <= 2.85e+206) tmp = Float64(b * b); else tmp = cbrt((b ^ 6.0)); end return tmp end
code[a_, b_, angle_] := If[LessEqual[a, 2.85e+206], N[(b * b), $MachinePrecision], N[Power[N[Power[b, 6.0], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.85 \cdot 10^{+206}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{b}^{6}}\\
\end{array}
\end{array}
if a < 2.8499999999999999e206Initial program 72.3%
associate-*l/72.3%
associate-/l*72.3%
cos-neg72.3%
distribute-lft-neg-out72.3%
distribute-frac-neg72.3%
distribute-frac-neg72.3%
distribute-lft-neg-out72.3%
cos-neg72.3%
associate-*l/72.3%
associate-/l*72.1%
Simplified72.1%
Taylor expanded in angle around 0 56.5%
unpow256.5%
Applied egg-rr56.5%
if 2.8499999999999999e206 < a Initial program 99.8%
associate-*l/99.6%
associate-/l*99.8%
cos-neg99.8%
distribute-lft-neg-out99.8%
distribute-frac-neg99.8%
distribute-frac-neg99.8%
distribute-lft-neg-out99.8%
cos-neg99.8%
associate-*l/99.8%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in angle around 0 42.9%
*-rgt-identity42.9%
add-cbrt-cube61.4%
pow361.3%
*-rgt-identity61.3%
pow-pow61.3%
metadata-eval61.3%
Applied egg-rr61.3%
(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 74.0%
associate-*l/73.9%
associate-/l*74.0%
cos-neg74.0%
distribute-lft-neg-out74.0%
distribute-frac-neg74.0%
distribute-frac-neg74.0%
distribute-lft-neg-out74.0%
cos-neg74.0%
associate-*l/73.9%
associate-/l*73.7%
Simplified73.7%
Taylor expanded in angle around 0 55.7%
unpow255.7%
Applied egg-rr55.7%
herbie shell --seed 2024113
(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)))