
(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 9 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 (cos (pow (/ 1.0 (/ (cbrt (/ 180.0 PI)) (cbrt angle))) 3.0))) 2.0) (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * cos(pow((1.0 / (cbrt((180.0 / ((double) M_PI))) / cbrt(angle))), 3.0))), 2.0) + pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos(Math.pow((1.0 / (Math.cbrt((180.0 / Math.PI)) / Math.cbrt(angle))), 3.0))), 2.0) + Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
}
function code(a, b, angle) return Float64((Float64(a * cos((Float64(1.0 / Float64(cbrt(Float64(180.0 / pi)) / cbrt(angle))) ^ 3.0))) ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[Power[N[(1.0 / N[(N[Power[N[(180.0 / Pi), $MachinePrecision], 1/3], $MachinePrecision] / N[Power[angle, 1/3], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left({\left(\frac{1}{\frac{\sqrt[3]{\frac{180}{\pi}}}{\sqrt[3]{angle}}}\right)}^{3}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 81.0%
Simplified81.0%
metadata-eval81.0%
div-inv81.0%
add-cube-cbrt81.0%
pow381.0%
div-inv80.9%
metadata-eval80.9%
associate-*r*81.0%
*-commutative81.0%
Applied egg-rr81.0%
metadata-eval81.0%
associate-/r/81.0%
cbrt-div81.1%
metadata-eval81.1%
Applied egg-rr81.1%
associate-/r*81.1%
cbrt-div81.1%
Applied egg-rr81.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0) (pow (* a (cos (pow (/ 1.0 (cbrt (/ 180.0 (* PI angle)))) 3.0))) 2.0)))
double code(double a, double b, double angle) {
return pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0) + pow((a * cos(pow((1.0 / cbrt((180.0 / (((double) M_PI) * angle)))), 3.0))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0) + Math.pow((a * Math.cos(Math.pow((1.0 / Math.cbrt((180.0 / (Math.PI * angle)))), 3.0))), 2.0);
}
function code(a, b, angle) return Float64((Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0) + (Float64(a * cos((Float64(1.0 / cbrt(Float64(180.0 / Float64(pi * angle)))) ^ 3.0))) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(a * N[Cos[N[Power[N[(1.0 / N[Power[N[(180.0 / N[(Pi * angle), $MachinePrecision]), $MachinePrecision], 1/3], $MachinePrecision]), $MachinePrecision], 3.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2} + {\left(a \cdot \cos \left({\left(\frac{1}{\sqrt[3]{\frac{180}{\pi \cdot angle}}}\right)}^{3}\right)\right)}^{2}
\end{array}
Initial program 81.0%
Simplified81.0%
metadata-eval81.0%
div-inv81.0%
add-cube-cbrt81.0%
pow381.0%
div-inv80.9%
metadata-eval80.9%
associate-*r*81.0%
*-commutative81.0%
Applied egg-rr81.0%
metadata-eval81.0%
associate-/r/81.0%
cbrt-div81.1%
metadata-eval81.1%
Applied egg-rr81.1%
Final simplification81.1%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0) (pow (* a (pow (cbrt (cos (* 0.005555555555555556 (* PI angle)))) 3.0)) 2.0)))
double code(double a, double b, double angle) {
return pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0) + pow((a * pow(cbrt(cos((0.005555555555555556 * (((double) M_PI) * angle)))), 3.0)), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0) + Math.pow((a * Math.pow(Math.cbrt(Math.cos((0.005555555555555556 * (Math.PI * angle)))), 3.0)), 2.0);
}
function code(a, b, angle) return Float64((Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0) + (Float64(a * (cbrt(cos(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 3.0)) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(a * N[Power[N[Power[N[Cos[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 1/3], $MachinePrecision], 3.0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2} + {\left(a \cdot {\left(\sqrt[3]{\cos \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)}\right)}^{3}\right)}^{2}
\end{array}
Initial program 81.0%
Simplified81.0%
metadata-eval81.0%
div-inv81.0%
add-cube-cbrt81.0%
pow381.0%
div-inv81.0%
metadata-eval81.0%
associate-*r*81.1%
*-commutative81.1%
Applied egg-rr81.1%
Final simplification81.1%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (cos (* 0.005555555555555556 (* PI angle)))))
(+
(pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0)
(* a (* t_0 (* a t_0))))))
double code(double a, double b, double angle) {
double t_0 = cos((0.005555555555555556 * (((double) M_PI) * angle)));
return pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0) + (a * (t_0 * (a * t_0)));
}
public static double code(double a, double b, double angle) {
double t_0 = Math.cos((0.005555555555555556 * (Math.PI * angle)));
return Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0) + (a * (t_0 * (a * t_0)));
}
def code(a, b, angle): t_0 = math.cos((0.005555555555555556 * (math.pi * angle))) return math.pow((b * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0) + (a * (t_0 * (a * t_0)))
function code(a, b, angle) t_0 = cos(Float64(0.005555555555555556 * Float64(pi * angle))) return Float64((Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0) + Float64(a * Float64(t_0 * Float64(a * t_0)))) end
function tmp = code(a, b, angle) t_0 = cos((0.005555555555555556 * (pi * angle))); tmp = ((b * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0) + (a * (t_0 * (a * t_0))); end
code[a_, b_, angle_] := Block[{t$95$0 = N[Cos[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(a * N[(t$95$0 * N[(a * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\\
{\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2} + a \cdot \left(t\_0 \cdot \left(a \cdot t\_0\right)\right)
\end{array}
\end{array}
Initial program 81.0%
Simplified81.0%
metadata-eval81.0%
div-inv81.0%
unpow281.0%
*-commutative81.0%
associate-*r*81.0%
Applied egg-rr81.1%
Final simplification81.1%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* angle (/ PI 180.0)))) (pow (hypot (* b (sin t_0)) (* a (cos t_0))) 2.0)))
double code(double a, double b, double angle) {
double t_0 = angle * (((double) M_PI) / 180.0);
return pow(hypot((b * sin(t_0)), (a * cos(t_0))), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (Math.PI / 180.0);
return Math.pow(Math.hypot((b * Math.sin(t_0)), (a * Math.cos(t_0))), 2.0);
}
def code(a, b, angle): t_0 = angle * (math.pi / 180.0) return math.pow(math.hypot((b * math.sin(t_0)), (a * math.cos(t_0))), 2.0)
function code(a, b, angle) t_0 = Float64(angle * Float64(pi / 180.0)) return hypot(Float64(b * sin(t_0)), Float64(a * cos(t_0))) ^ 2.0 end
function tmp = code(a, b, angle) t_0 = angle * (pi / 180.0); tmp = hypot((b * sin(t_0)), (a * cos(t_0))) ^ 2.0; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]}, N[Power[N[Sqrt[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := angle \cdot \frac{\pi}{180}\\
{\left(\mathsf{hypot}\left(b \cdot \sin t\_0, a \cdot \cos t\_0\right)\right)}^{2}
\end{array}
\end{array}
Initial program 81.0%
Simplified81.0%
metadata-eval81.0%
div-inv81.0%
add-cube-cbrt81.0%
pow381.0%
div-inv81.0%
metadata-eval81.0%
associate-*r*81.1%
*-commutative81.1%
Applied egg-rr81.1%
Applied egg-rr81.0%
*-lft-identity81.0%
Simplified81.0%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* 0.005555555555555556 (* PI angle)))) (pow (hypot (* a (cos t_0)) (* b (sin t_0))) 2.0)))
double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (((double) M_PI) * angle);
return pow(hypot((a * cos(t_0)), (b * sin(t_0))), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (Math.PI * angle);
return Math.pow(Math.hypot((a * Math.cos(t_0)), (b * Math.sin(t_0))), 2.0);
}
def code(a, b, angle): t_0 = 0.005555555555555556 * (math.pi * angle) return math.pow(math.hypot((a * math.cos(t_0)), (b * math.sin(t_0))), 2.0)
function code(a, b, angle) t_0 = Float64(0.005555555555555556 * Float64(pi * angle)) return hypot(Float64(a * cos(t_0)), Float64(b * sin(t_0))) ^ 2.0 end
function tmp = code(a, b, angle) t_0 = 0.005555555555555556 * (pi * angle); tmp = hypot((a * cos(t_0)), (b * sin(t_0))) ^ 2.0; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]}, N[Power[N[Sqrt[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(\pi \cdot angle\right)\\
{\left(\mathsf{hypot}\left(a \cdot \cos t\_0, b \cdot \sin t\_0\right)\right)}^{2}
\end{array}
\end{array}
Initial program 81.0%
Simplified81.0%
metadata-eval81.0%
div-inv81.0%
unpow281.0%
metadata-eval81.0%
div-inv81.0%
unpow281.0%
unpow281.0%
unpow281.0%
Applied egg-rr80.9%
(FPCore (a b angle) :precision binary64 (+ (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0) (pow a 2.0)))
double code(double a, double b, double angle) {
return pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0) + pow(a, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0) + Math.pow(a, 2.0);
}
def code(a, b, angle): return math.pow((b * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0) + math.pow(a, 2.0)
function code(a, b, angle) return Float64((Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0) + (a ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((b * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0) + (a ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2} + {a}^{2}
\end{array}
Initial program 81.0%
Simplified81.0%
Taylor expanded in angle around 0 80.9%
Final simplification80.9%
(FPCore (a b angle) :precision binary64 (if (<= a 1.75e-121) (pow (* b (sin (* 0.005555555555555556 (* PI angle)))) 2.0) (* a a)))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.75e-121) {
tmp = pow((b * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 2.0);
} else {
tmp = a * a;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.75e-121) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (Math.PI * angle)))), 2.0);
} else {
tmp = a * a;
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.75e-121: tmp = math.pow((b * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0) else: tmp = a * a return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.75e-121) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0; else tmp = Float64(a * a); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.75e-121) tmp = (b * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0; else tmp = a * a; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.75e-121], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(a * a), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.75 \cdot 10^{-121}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a\\
\end{array}
\end{array}
if a < 1.74999999999999996e-121Initial program 81.4%
Simplified81.4%
Taylor expanded in a around 0 37.4%
*-commutative37.4%
unpow237.4%
unpow237.4%
swap-sqr41.3%
unpow241.3%
*-commutative41.3%
Simplified41.3%
if 1.74999999999999996e-121 < a Initial program 80.3%
Simplified80.2%
Taylor expanded in angle around 0 71.8%
unpow271.8%
Applied egg-rr71.8%
Final simplification52.3%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 81.0%
Simplified81.0%
Taylor expanded in angle around 0 62.1%
unpow262.1%
Applied egg-rr62.1%
herbie shell --seed 2024144
(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)))