
(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 6 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 (* (* PI 0.005555555555555556) (pow (/ 1.0 angle) -1.0)))) 2.0) (* b b)))
double code(double a, double b, double angle) {
return pow((a * sin(((((double) M_PI) * 0.005555555555555556) * pow((1.0 / angle), -1.0)))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(((Math.PI * 0.005555555555555556) * Math.pow((1.0 / angle), -1.0)))), 2.0) + (b * b);
}
def code(a, b, angle): return math.pow((a * math.sin(((math.pi * 0.005555555555555556) * math.pow((1.0 / angle), -1.0)))), 2.0) + (b * b)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64(pi * 0.005555555555555556) * (Float64(1.0 / angle) ^ -1.0)))) ^ 2.0) + Float64(b * b)) end
function tmp = code(a, b, angle) tmp = ((a * sin(((pi * 0.005555555555555556) * ((1.0 / angle) ^ -1.0)))) ^ 2.0) + (b * b); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(Pi * 0.005555555555555556), $MachinePrecision] * N[Power[N[(1.0 / angle), $MachinePrecision], -1.0], $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\left(\pi \cdot 0.005555555555555556\right) \cdot {\left(\frac{1}{angle}\right)}^{-1}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 82.1%
unpow282.1%
associate-*l/82.0%
associate-/l*82.1%
unpow282.1%
Simplified82.2%
Taylor expanded in angle around 0 82.4%
*-rgt-identity82.4%
unpow282.4%
Applied egg-rr82.4%
associate-*r/82.2%
clear-num82.2%
*-commutative82.2%
associate-/r*82.3%
Applied egg-rr82.3%
inv-pow82.3%
div-inv82.2%
unpow-prod-down82.4%
inv-pow82.4%
clear-num82.4%
div-inv82.4%
metadata-eval82.4%
Applied egg-rr82.4%
(FPCore (a b angle) :precision binary64 (if (<= b 9.5e-149) (pow (* a (sin (* 0.005555555555555556 (* PI angle)))) 2.0) (+ (* b b) (pow (* angle (* PI (* a 0.005555555555555556))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 9.5e-149) {
tmp = pow((a * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
} else {
tmp = (b * b) + pow((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 <= 9.5e-149) {
tmp = Math.pow((a * Math.sin((0.005555555555555556 * (Math.PI * angle)))), 2.0);
} else {
tmp = (b * b) + Math.pow((angle * (Math.PI * (a * 0.005555555555555556))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 9.5e-149: tmp = math.pow((a * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0) else: tmp = (b * b) + math.pow((angle * (math.pi * (a * 0.005555555555555556))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 9.5e-149) tmp = Float64(a * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0; else tmp = Float64(Float64(b * b) + (Float64(angle * Float64(pi * Float64(a * 0.005555555555555556))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 9.5e-149) tmp = (a * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0; else tmp = (b * b) + ((angle * (pi * (a * 0.005555555555555556))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 9.5e-149], N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(angle * N[(Pi * N[(a * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.5 \cdot 10^{-149}:\\
\;\;\;\;{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(angle \cdot \left(\pi \cdot \left(a \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 9.50000000000000034e-149Initial program 79.1%
unpow279.1%
associate-*l/78.9%
associate-/l*79.1%
unpow279.1%
Simplified79.1%
Taylor expanded in a around inf 43.8%
unpow243.8%
*-commutative43.8%
associate-*r*43.8%
unpow243.8%
swap-sqr49.1%
unpow249.1%
associate-*r*49.1%
*-commutative49.1%
Simplified49.1%
if 9.50000000000000034e-149 < b Initial program 86.9%
unpow286.9%
associate-*l/86.9%
associate-/l*87.0%
unpow287.0%
Simplified87.0%
Taylor expanded in angle around 0 87.6%
*-rgt-identity87.6%
unpow287.6%
Applied egg-rr87.6%
Taylor expanded in angle around 0 86.1%
*-commutative86.1%
associate-*r*86.0%
associate-*l*86.1%
*-commutative86.1%
associate-*r*86.1%
*-commutative86.1%
Simplified86.1%
Final simplification63.4%
(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 82.1%
unpow282.1%
associate-*l/82.0%
associate-/l*82.1%
unpow282.1%
Simplified82.2%
Taylor expanded in angle around 0 82.4%
*-rgt-identity82.4%
unpow282.4%
Applied egg-rr82.4%
Final simplification82.4%
(FPCore (a b angle) :precision binary64 (if (<= a 6.9e-99) (pow b 2.0) (+ (* b b) (pow (* angle (* PI (* a 0.005555555555555556))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 6.9e-99) {
tmp = pow(b, 2.0);
} else {
tmp = (b * b) + pow((angle * (((double) M_PI) * (a * 0.005555555555555556))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 6.9e-99) {
tmp = Math.pow(b, 2.0);
} else {
tmp = (b * b) + Math.pow((angle * (Math.PI * (a * 0.005555555555555556))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 6.9e-99: tmp = math.pow(b, 2.0) else: tmp = (b * b) + math.pow((angle * (math.pi * (a * 0.005555555555555556))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 6.9e-99) tmp = b ^ 2.0; else tmp = Float64(Float64(b * b) + (Float64(angle * Float64(pi * Float64(a * 0.005555555555555556))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 6.9e-99) tmp = b ^ 2.0; else tmp = (b * b) + ((angle * (pi * (a * 0.005555555555555556))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 6.9e-99], N[Power[b, 2.0], $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(angle * N[(Pi * N[(a * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 6.9 \cdot 10^{-99}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(angle \cdot \left(\pi \cdot \left(a \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 6.9000000000000003e-99Initial program 82.2%
unpow282.2%
associate-*l/82.2%
associate-/l*82.3%
unpow282.3%
Simplified82.3%
Taylor expanded in angle around 0 60.3%
if 6.9000000000000003e-99 < a Initial program 81.9%
unpow281.9%
associate-*l/81.6%
associate-/l*81.9%
unpow281.9%
Simplified81.9%
Taylor expanded in angle around 0 82.0%
*-rgt-identity82.0%
unpow282.0%
Applied egg-rr82.0%
Taylor expanded in angle around 0 78.1%
*-commutative78.1%
associate-*r*78.1%
associate-*l*78.0%
*-commutative78.0%
associate-*r*78.0%
*-commutative78.0%
Simplified78.0%
Final simplification66.3%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* 0.005555555555555556 (* a (* PI angle))))) (if (<= a 1.6e+69) (pow b 2.0) (* t_0 t_0))))
double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (a * (((double) M_PI) * angle));
double tmp;
if (a <= 1.6e+69) {
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 = 0.005555555555555556 * (a * (Math.PI * angle));
double tmp;
if (a <= 1.6e+69) {
tmp = Math.pow(b, 2.0);
} else {
tmp = t_0 * t_0;
}
return tmp;
}
def code(a, b, angle): t_0 = 0.005555555555555556 * (a * (math.pi * angle)) tmp = 0 if a <= 1.6e+69: tmp = math.pow(b, 2.0) else: tmp = t_0 * t_0 return tmp
function code(a, b, angle) t_0 = Float64(0.005555555555555556 * Float64(a * Float64(pi * angle))) tmp = 0.0 if (a <= 1.6e+69) tmp = b ^ 2.0; else tmp = Float64(t_0 * t_0); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = 0.005555555555555556 * (a * (pi * angle)); tmp = 0.0; if (a <= 1.6e+69) tmp = b ^ 2.0; else tmp = t_0 * t_0; end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(a * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[a, 1.6e+69], N[Power[b, 2.0], $MachinePrecision], N[(t$95$0 * t$95$0), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(a \cdot \left(\pi \cdot angle\right)\right)\\
\mathbf{if}\;a \leq 1.6 \cdot 10^{+69}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;t\_0 \cdot t\_0\\
\end{array}
\end{array}
if a < 1.59999999999999992e69Initial program 79.7%
unpow279.7%
associate-*l/79.7%
associate-/l*79.8%
unpow279.8%
Simplified79.8%
Taylor expanded in angle around 0 60.6%
if 1.59999999999999992e69 < a Initial program 91.6%
unpow291.6%
associate-*l/91.3%
associate-/l*91.7%
unpow291.7%
Simplified91.7%
Taylor expanded in a around inf 59.4%
unpow259.4%
*-commutative59.4%
associate-*r*59.8%
unpow259.8%
swap-sqr67.3%
unpow267.3%
associate-*r*67.0%
*-commutative67.0%
Simplified67.0%
Taylor expanded in angle around 0 72.0%
associate-*r*72.0%
*-commutative72.0%
*-commutative72.0%
Simplified72.0%
unpow-prod-down70.3%
add-sqr-sqrt70.3%
unpow-prod-down70.3%
sqrt-pow127.2%
metadata-eval27.2%
pow127.2%
associate-*r*27.2%
unpow-prod-down28.9%
sqrt-pow172.0%
metadata-eval72.0%
pow172.0%
associate-*r*72.0%
Applied egg-rr72.0%
Final simplification62.8%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* 0.005555555555555556 (* a (* PI angle))))) (* t_0 t_0)))
double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (a * (((double) M_PI) * angle));
return t_0 * t_0;
}
public static double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (a * (Math.PI * angle));
return t_0 * t_0;
}
def code(a, b, angle): t_0 = 0.005555555555555556 * (a * (math.pi * angle)) return t_0 * t_0
function code(a, b, angle) t_0 = Float64(0.005555555555555556 * Float64(a * Float64(pi * angle))) return Float64(t_0 * t_0) end
function tmp = code(a, b, angle) t_0 = 0.005555555555555556 * (a * (pi * angle)); tmp = t_0 * t_0; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(a * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(t$95$0 * t$95$0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(a \cdot \left(\pi \cdot angle\right)\right)\\
t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 82.1%
unpow282.1%
associate-*l/82.0%
associate-/l*82.1%
unpow282.1%
Simplified82.2%
Taylor expanded in a around inf 36.4%
unpow236.4%
*-commutative36.4%
associate-*r*36.5%
unpow236.5%
swap-sqr41.6%
unpow241.6%
associate-*r*41.6%
*-commutative41.6%
Simplified41.6%
Taylor expanded in angle around 0 40.4%
associate-*r*40.4%
*-commutative40.4%
*-commutative40.4%
Simplified40.4%
unpow-prod-down39.8%
add-sqr-sqrt39.8%
unpow-prod-down39.8%
sqrt-pow119.6%
metadata-eval19.6%
pow119.6%
associate-*r*19.6%
unpow-prod-down20.2%
sqrt-pow140.5%
metadata-eval40.5%
pow140.5%
associate-*r*40.4%
Applied egg-rr40.4%
Final simplification40.4%
herbie shell --seed 2024186
(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)))