
(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 6 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 (+ (pow a 2.0) (pow (* b (sin (* angle (* PI -0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((angle * (((double) M_PI) * -0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((angle * (Math.PI * -0.005555555555555556)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((angle * (math.pi * -0.005555555555555556)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(angle * Float64(pi * -0.005555555555555556)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((angle * (pi * -0.005555555555555556)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $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}^{2} + {\left(b \cdot \sin \left(angle \cdot \left(\pi \cdot -0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 78.3%
Simplified78.3%
Applied egg-rr77.2%
Taylor expanded in angle around 0 77.7%
associate-*l*78.8%
pow278.8%
*-commutative78.8%
Applied egg-rr78.8%
Final simplification78.8%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* -0.005555555555555556 (* angle PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((-0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((-0.005555555555555556 * (angle * Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((-0.005555555555555556 * (angle * math.pi)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(-0.005555555555555556 * Float64(angle * pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((-0.005555555555555556 * (angle * pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(-0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(-0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 78.3%
Simplified78.3%
Applied egg-rr77.2%
Taylor expanded in angle around 0 77.7%
Taylor expanded in angle around inf 65.2%
unpow265.2%
*-commutative65.2%
associate-*r*65.3%
unpow265.3%
swap-sqr78.8%
unpow278.8%
associate-*r*78.7%
*-commutative78.7%
Simplified78.7%
Final simplification78.7%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.1e-51)
(+ (pow a 2.0) (pow (* b 0.0) 2.0))
(+
(pow (* a (cos (* angle (/ PI -180.0)))) 2.0)
(*
(* -0.005555555555555556 (* PI (* -0.005555555555555556 (* b angle))))
(* angle (* b PI))))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 3.1e-51) {
tmp = pow(a, 2.0) + pow((b * 0.0), 2.0);
} else {
tmp = pow((a * cos((angle * (((double) M_PI) / -180.0)))), 2.0) + ((-0.005555555555555556 * (((double) M_PI) * (-0.005555555555555556 * (b * angle)))) * (angle * (b * ((double) M_PI))));
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 3.1e-51) {
tmp = Math.pow(a, 2.0) + Math.pow((b * 0.0), 2.0);
} else {
tmp = Math.pow((a * Math.cos((angle * (Math.PI / -180.0)))), 2.0) + ((-0.005555555555555556 * (Math.PI * (-0.005555555555555556 * (b * angle)))) * (angle * (b * Math.PI)));
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 3.1e-51: tmp = math.pow(a, 2.0) + math.pow((b * 0.0), 2.0) else: tmp = math.pow((a * math.cos((angle * (math.pi / -180.0)))), 2.0) + ((-0.005555555555555556 * (math.pi * (-0.005555555555555556 * (b * angle)))) * (angle * (b * math.pi))) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 3.1e-51) tmp = Float64((a ^ 2.0) + (Float64(b * 0.0) ^ 2.0)); else tmp = Float64((Float64(a * cos(Float64(angle * Float64(pi / -180.0)))) ^ 2.0) + Float64(Float64(-0.005555555555555556 * Float64(pi * Float64(-0.005555555555555556 * Float64(b * angle)))) * Float64(angle * Float64(b * pi)))); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 3.1e-51) tmp = (a ^ 2.0) + ((b * 0.0) ^ 2.0); else tmp = ((a * cos((angle * (pi / -180.0)))) ^ 2.0) + ((-0.005555555555555556 * (pi * (-0.005555555555555556 * (b * angle)))) * (angle * (b * pi))); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 3.1e-51], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * 0.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[Power[N[(a * N[Cos[N[(angle * N[(Pi / -180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(N[(-0.005555555555555556 * N[(Pi * N[(-0.005555555555555556 * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.1 \cdot 10^{-51}:\\
\;\;\;\;{a}^{2} + {\left(b \cdot 0\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \cos \left(angle \cdot \frac{\pi}{-180}\right)\right)}^{2} + \left(-0.005555555555555556 \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot \left(b \cdot angle\right)\right)\right)\right) \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\\
\end{array}
\end{array}
if b < 3.0999999999999997e-51Initial program 77.4%
Simplified77.4%
Taylor expanded in angle around 0 78.0%
div-inv78.0%
metadata-eval78.0%
rem-cube-cbrt77.7%
Applied egg-rr77.7%
Taylor expanded in angle around 0 60.7%
if 3.0999999999999997e-51 < b Initial program 80.5%
Simplified80.5%
Taylor expanded in angle around 0 77.5%
associate-*r*77.5%
*-commutative77.5%
Simplified77.5%
unpow277.5%
associate-*r*77.6%
*-commutative77.6%
associate-*l*77.6%
*-commutative77.6%
associate-*l*77.6%
Applied egg-rr77.6%
Final simplification65.8%
(FPCore (a b angle)
:precision binary64
(if (<= b 3.9e-51)
(+ (pow a 2.0) (pow (* b 0.0) 2.0))
(+
(*
(* -0.005555555555555556 (* PI (* -0.005555555555555556 (* b angle))))
(* angle (* b PI)))
(* a a))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 3.9e-51) {
tmp = pow(a, 2.0) + pow((b * 0.0), 2.0);
} else {
tmp = ((-0.005555555555555556 * (((double) M_PI) * (-0.005555555555555556 * (b * angle)))) * (angle * (b * ((double) M_PI)))) + (a * a);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 3.9e-51) {
tmp = Math.pow(a, 2.0) + Math.pow((b * 0.0), 2.0);
} else {
tmp = ((-0.005555555555555556 * (Math.PI * (-0.005555555555555556 * (b * angle)))) * (angle * (b * Math.PI))) + (a * a);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 3.9e-51: tmp = math.pow(a, 2.0) + math.pow((b * 0.0), 2.0) else: tmp = ((-0.005555555555555556 * (math.pi * (-0.005555555555555556 * (b * angle)))) * (angle * (b * math.pi))) + (a * a) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 3.9e-51) tmp = Float64((a ^ 2.0) + (Float64(b * 0.0) ^ 2.0)); else tmp = Float64(Float64(Float64(-0.005555555555555556 * Float64(pi * Float64(-0.005555555555555556 * Float64(b * angle)))) * Float64(angle * Float64(b * pi))) + Float64(a * a)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 3.9e-51) tmp = (a ^ 2.0) + ((b * 0.0) ^ 2.0); else tmp = ((-0.005555555555555556 * (pi * (-0.005555555555555556 * (b * angle)))) * (angle * (b * pi))) + (a * a); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 3.9e-51], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * 0.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(N[(N[(-0.005555555555555556 * N[(Pi * N[(-0.005555555555555556 * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 3.9 \cdot 10^{-51}:\\
\;\;\;\;{a}^{2} + {\left(b \cdot 0\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\left(-0.005555555555555556 \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot \left(b \cdot angle\right)\right)\right)\right) \cdot \left(angle \cdot \left(b \cdot \pi\right)\right) + a \cdot a\\
\end{array}
\end{array}
if b < 3.8999999999999997e-51Initial program 77.4%
Simplified77.4%
Taylor expanded in angle around 0 78.0%
div-inv78.0%
metadata-eval78.0%
rem-cube-cbrt77.7%
Applied egg-rr77.7%
Taylor expanded in angle around 0 60.7%
if 3.8999999999999997e-51 < b Initial program 80.5%
Simplified80.5%
Taylor expanded in angle around 0 77.5%
associate-*r*77.5%
*-commutative77.5%
Simplified77.5%
Taylor expanded in angle around 0 77.5%
unpow277.5%
Applied egg-rr77.5%
unpow277.5%
associate-*r*77.6%
*-commutative77.6%
associate-*l*77.6%
*-commutative77.6%
associate-*l*77.6%
Applied egg-rr77.6%
Final simplification65.8%
(FPCore (a b angle) :precision binary64 (+ (* a a) (* (* PI -0.005555555555555556) (* (* b angle) (* PI (* -0.005555555555555556 (* b angle)))))))
double code(double a, double b, double angle) {
return (a * a) + ((((double) M_PI) * -0.005555555555555556) * ((b * angle) * (((double) M_PI) * (-0.005555555555555556 * (b * angle)))));
}
public static double code(double a, double b, double angle) {
return (a * a) + ((Math.PI * -0.005555555555555556) * ((b * angle) * (Math.PI * (-0.005555555555555556 * (b * angle)))));
}
def code(a, b, angle): return (a * a) + ((math.pi * -0.005555555555555556) * ((b * angle) * (math.pi * (-0.005555555555555556 * (b * angle)))))
function code(a, b, angle) return Float64(Float64(a * a) + Float64(Float64(pi * -0.005555555555555556) * Float64(Float64(b * angle) * Float64(pi * Float64(-0.005555555555555556 * Float64(b * angle)))))) end
function tmp = code(a, b, angle) tmp = (a * a) + ((pi * -0.005555555555555556) * ((b * angle) * (pi * (-0.005555555555555556 * (b * angle))))); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[(N[(Pi * -0.005555555555555556), $MachinePrecision] * N[(N[(b * angle), $MachinePrecision] * N[(Pi * N[(-0.005555555555555556 * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + \left(\pi \cdot -0.005555555555555556\right) \cdot \left(\left(b \cdot angle\right) \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot \left(b \cdot angle\right)\right)\right)\right)
\end{array}
Initial program 78.3%
Simplified78.3%
Taylor expanded in angle around 0 72.6%
associate-*r*72.6%
*-commutative72.6%
Simplified72.6%
Taylor expanded in angle around 0 72.9%
unpow272.9%
Applied egg-rr72.9%
unpow272.9%
associate-*r*72.9%
*-commutative72.9%
metadata-eval72.9%
div-inv72.9%
associate-*l*73.0%
div-inv73.0%
metadata-eval73.0%
*-commutative73.0%
associate-*l*72.9%
Applied egg-rr72.9%
Final simplification72.9%
(FPCore (a b angle) :precision binary64 (+ (* (* -0.005555555555555556 (* PI (* -0.005555555555555556 (* b angle)))) (* angle (* b PI))) (* a a)))
double code(double a, double b, double angle) {
return ((-0.005555555555555556 * (((double) M_PI) * (-0.005555555555555556 * (b * angle)))) * (angle * (b * ((double) M_PI)))) + (a * a);
}
public static double code(double a, double b, double angle) {
return ((-0.005555555555555556 * (Math.PI * (-0.005555555555555556 * (b * angle)))) * (angle * (b * Math.PI))) + (a * a);
}
def code(a, b, angle): return ((-0.005555555555555556 * (math.pi * (-0.005555555555555556 * (b * angle)))) * (angle * (b * math.pi))) + (a * a)
function code(a, b, angle) return Float64(Float64(Float64(-0.005555555555555556 * Float64(pi * Float64(-0.005555555555555556 * Float64(b * angle)))) * Float64(angle * Float64(b * pi))) + Float64(a * a)) end
function tmp = code(a, b, angle) tmp = ((-0.005555555555555556 * (pi * (-0.005555555555555556 * (b * angle)))) * (angle * (b * pi))) + (a * a); end
code[a_, b_, angle_] := N[(N[(N[(-0.005555555555555556 * N[(Pi * N[(-0.005555555555555556 * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(a * a), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(-0.005555555555555556 \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot \left(b \cdot angle\right)\right)\right)\right) \cdot \left(angle \cdot \left(b \cdot \pi\right)\right) + a \cdot a
\end{array}
Initial program 78.3%
Simplified78.3%
Taylor expanded in angle around 0 72.6%
associate-*r*72.6%
*-commutative72.6%
Simplified72.6%
Taylor expanded in angle around 0 72.9%
unpow272.9%
Applied egg-rr72.9%
unpow272.9%
associate-*r*73.0%
*-commutative73.0%
associate-*l*73.0%
*-commutative73.0%
associate-*l*73.0%
Applied egg-rr73.0%
Final simplification73.0%
herbie shell --seed 2024043
(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)))