
(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 8 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 (let* ((t_0 (sin (* angle (* PI -0.005555555555555556))))) (+ (pow a 2.0) (* b (* t_0 (* t_0 b))))))
double code(double a, double b, double angle) {
double t_0 = sin((angle * (((double) M_PI) * -0.005555555555555556)));
return pow(a, 2.0) + (b * (t_0 * (t_0 * b)));
}
public static double code(double a, double b, double angle) {
double t_0 = Math.sin((angle * (Math.PI * -0.005555555555555556)));
return Math.pow(a, 2.0) + (b * (t_0 * (t_0 * b)));
}
def code(a, b, angle): t_0 = math.sin((angle * (math.pi * -0.005555555555555556))) return math.pow(a, 2.0) + (b * (t_0 * (t_0 * b)))
function code(a, b, angle) t_0 = sin(Float64(angle * Float64(pi * -0.005555555555555556))) return Float64((a ^ 2.0) + Float64(b * Float64(t_0 * Float64(t_0 * b)))) end
function tmp = code(a, b, angle) t_0 = sin((angle * (pi * -0.005555555555555556))); tmp = (a ^ 2.0) + (b * (t_0 * (t_0 * b))); end
code[a_, b_, angle_] := Block[{t$95$0 = N[Sin[N[(angle * N[(Pi * -0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[a, 2.0], $MachinePrecision] + N[(b * N[(t$95$0 * N[(t$95$0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(angle \cdot \left(\pi \cdot -0.005555555555555556\right)\right)\\
{a}^{2} + b \cdot \left(t_0 \cdot \left(t_0 \cdot b\right)\right)
\end{array}
\end{array}
Initial program 80.8%
Simplified80.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 81.8%
Final simplification81.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 80.8%
Simplified80.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 81.8%
Taylor expanded in angle around inf 70.5%
unpow270.5%
*-commutative70.5%
associate-*r*70.5%
unpow270.5%
swap-sqr81.8%
unpow281.8%
associate-*r*81.8%
*-commutative81.8%
Simplified81.8%
Final simplification81.8%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* (sin (* angle (* PI -0.005555555555555556))) b) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((sin((angle * (((double) M_PI) * -0.005555555555555556))) * b), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((Math.sin((angle * (Math.PI * -0.005555555555555556))) * b), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((math.sin((angle * (math.pi * -0.005555555555555556))) * b), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(sin(Float64(angle * Float64(pi * -0.005555555555555556))) * b) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((sin((angle * (pi * -0.005555555555555556))) * b) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(N[Sin[N[(angle * N[(Pi * -0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(\sin \left(angle \cdot \left(\pi \cdot -0.005555555555555556\right)\right) \cdot b\right)}^{2}
\end{array}
Initial program 80.8%
Simplified80.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 81.8%
associate-*l*81.8%
pow281.8%
*-commutative81.8%
Applied egg-rr81.8%
Final simplification81.8%
(FPCore (a b angle)
:precision binary64
(+
(pow a 2.0)
(*
angle
(*
-0.005555555555555556
(* PI (* b (* angle (* b (* PI -0.005555555555555556)))))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (angle * (-0.005555555555555556 * (((double) M_PI) * (b * (angle * (b * (((double) M_PI) * -0.005555555555555556)))))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (angle * (-0.005555555555555556 * (Math.PI * (b * (angle * (b * (Math.PI * -0.005555555555555556)))))));
}
def code(a, b, angle): return math.pow(a, 2.0) + (angle * (-0.005555555555555556 * (math.pi * (b * (angle * (b * (math.pi * -0.005555555555555556)))))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(angle * Float64(-0.005555555555555556 * Float64(pi * Float64(b * Float64(angle * Float64(b * Float64(pi * -0.005555555555555556)))))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (angle * (-0.005555555555555556 * (pi * (b * (angle * (b * (pi * -0.005555555555555556))))))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(angle * N[(-0.005555555555555556 * N[(Pi * N[(b * N[(angle * N[(b * N[(Pi * -0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + angle \cdot \left(-0.005555555555555556 \cdot \left(\pi \cdot \left(b \cdot \left(angle \cdot \left(b \cdot \left(\pi \cdot -0.005555555555555556\right)\right)\right)\right)\right)\right)
\end{array}
Initial program 80.8%
Simplified80.9%
Taylor expanded in angle around 0 76.6%
associate-*r*76.6%
*-commutative76.6%
associate-*l*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in angle around 0 77.3%
unpow277.3%
associate-*r*77.3%
metadata-eval77.3%
div-inv77.3%
associate-*l*74.9%
div-inv74.9%
metadata-eval74.9%
*-commutative74.9%
associate-*l*74.9%
Applied egg-rr74.9%
associate-*l*74.9%
associate-*l*74.9%
*-commutative74.9%
Simplified74.9%
Taylor expanded in b around 0 74.9%
*-commutative74.9%
associate-*r*74.9%
*-commutative74.9%
Simplified74.9%
Final simplification74.9%
(FPCore (a b angle)
:precision binary64
(+
(pow a 2.0)
(*
angle
(*
-0.005555555555555556
(* PI (* (* angle b) (* -0.005555555555555556 (* PI b))))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (angle * (-0.005555555555555556 * (((double) M_PI) * ((angle * b) * (-0.005555555555555556 * (((double) M_PI) * b))))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (angle * (-0.005555555555555556 * (Math.PI * ((angle * b) * (-0.005555555555555556 * (Math.PI * b))))));
}
def code(a, b, angle): return math.pow(a, 2.0) + (angle * (-0.005555555555555556 * (math.pi * ((angle * b) * (-0.005555555555555556 * (math.pi * b))))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(angle * Float64(-0.005555555555555556 * Float64(pi * Float64(Float64(angle * b) * Float64(-0.005555555555555556 * Float64(pi * b))))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (angle * (-0.005555555555555556 * (pi * ((angle * b) * (-0.005555555555555556 * (pi * b)))))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(angle * N[(-0.005555555555555556 * N[(Pi * N[(N[(angle * b), $MachinePrecision] * N[(-0.005555555555555556 * N[(Pi * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + angle \cdot \left(-0.005555555555555556 \cdot \left(\pi \cdot \left(\left(angle \cdot b\right) \cdot \left(-0.005555555555555556 \cdot \left(\pi \cdot b\right)\right)\right)\right)\right)
\end{array}
Initial program 80.8%
Simplified80.9%
Taylor expanded in angle around 0 76.6%
associate-*r*76.6%
*-commutative76.6%
associate-*l*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in angle around 0 77.3%
unpow277.3%
associate-*r*77.3%
metadata-eval77.3%
div-inv77.3%
associate-*l*74.9%
div-inv74.9%
metadata-eval74.9%
*-commutative74.9%
associate-*l*74.9%
Applied egg-rr74.9%
associate-*l*74.9%
associate-*l*74.9%
*-commutative74.9%
Simplified74.9%
add-log-exp67.2%
exp-prod67.2%
associate-*r*67.2%
*-commutative67.2%
associate-*r*67.2%
associate-*l*67.2%
Applied egg-rr67.2%
log-pow74.5%
rem-log-exp74.9%
*-commutative74.9%
associate-*l*74.9%
associate-*r*75.0%
*-commutative75.0%
associate-*r*74.9%
*-commutative74.9%
Simplified74.9%
Final simplification74.9%
(FPCore (a b angle)
:precision binary64
(+
(pow a 2.0)
(*
angle
(*
PI
(*
-0.005555555555555556
(* b (* (* PI -0.005555555555555556) (* angle b))))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (angle * (((double) M_PI) * (-0.005555555555555556 * (b * ((((double) M_PI) * -0.005555555555555556) * (angle * b))))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (angle * (Math.PI * (-0.005555555555555556 * (b * ((Math.PI * -0.005555555555555556) * (angle * b))))));
}
def code(a, b, angle): return math.pow(a, 2.0) + (angle * (math.pi * (-0.005555555555555556 * (b * ((math.pi * -0.005555555555555556) * (angle * b))))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(angle * Float64(pi * Float64(-0.005555555555555556 * Float64(b * Float64(Float64(pi * -0.005555555555555556) * Float64(angle * b))))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (angle * (pi * (-0.005555555555555556 * (b * ((pi * -0.005555555555555556) * (angle * b)))))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(angle * N[(Pi * N[(-0.005555555555555556 * N[(b * N[(N[(Pi * -0.005555555555555556), $MachinePrecision] * N[(angle * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + angle \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot \left(b \cdot \left(\left(\pi \cdot -0.005555555555555556\right) \cdot \left(angle \cdot b\right)\right)\right)\right)\right)
\end{array}
Initial program 80.8%
Simplified80.9%
Taylor expanded in angle around 0 76.6%
associate-*r*76.6%
*-commutative76.6%
associate-*l*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in angle around 0 77.3%
unpow277.3%
associate-*r*77.3%
metadata-eval77.3%
div-inv77.3%
associate-*l*74.9%
div-inv74.9%
metadata-eval74.9%
*-commutative74.9%
associate-*l*74.9%
Applied egg-rr74.9%
associate-*l*74.9%
associate-*l*74.9%
*-commutative74.9%
Simplified74.9%
expm1-log1p-u57.2%
expm1-udef57.3%
associate-*r*57.3%
*-commutative57.3%
associate-*l*57.3%
*-commutative57.3%
associate-*r*57.3%
associate-*l*57.3%
Applied egg-rr57.3%
expm1-def57.2%
expm1-log1p75.0%
*-commutative75.0%
Simplified75.0%
Final simplification75.0%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* angle (* PI (* -0.005555555555555556 b))))) (+ (pow a 2.0) (* t_0 t_0))))
double code(double a, double b, double angle) {
double t_0 = angle * (((double) M_PI) * (-0.005555555555555556 * b));
return pow(a, 2.0) + (t_0 * t_0);
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (Math.PI * (-0.005555555555555556 * b));
return Math.pow(a, 2.0) + (t_0 * t_0);
}
def code(a, b, angle): t_0 = angle * (math.pi * (-0.005555555555555556 * b)) return math.pow(a, 2.0) + (t_0 * t_0)
function code(a, b, angle) t_0 = Float64(angle * Float64(pi * Float64(-0.005555555555555556 * b))) return Float64((a ^ 2.0) + Float64(t_0 * t_0)) end
function tmp = code(a, b, angle) t_0 = angle * (pi * (-0.005555555555555556 * b)); tmp = (a ^ 2.0) + (t_0 * t_0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(Pi * N[(-0.005555555555555556 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[a, 2.0], $MachinePrecision] + N[(t$95$0 * t$95$0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := angle \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot b\right)\right)\\
{a}^{2} + t_0 \cdot t_0
\end{array}
\end{array}
Initial program 80.8%
Simplified80.9%
Taylor expanded in angle around 0 76.6%
associate-*r*76.6%
*-commutative76.6%
associate-*l*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in angle around 0 77.3%
unpow-prod-down66.7%
add-sqr-sqrt66.7%
unpow-prod-down66.7%
sqrt-pow156.8%
metadata-eval56.8%
pow156.8%
*-commutative56.8%
associate-*l*56.8%
unpow-prod-down63.8%
sqrt-pow177.3%
metadata-eval77.3%
pow177.3%
*-commutative77.3%
associate-*l*77.3%
Applied egg-rr77.3%
Final simplification77.3%
(FPCore (a b angle)
:precision binary64
(+
(pow a 2.0)
(*
(*
(* angle (* PI (* -0.005555555555555556 b)))
(* angle -0.005555555555555556))
(* PI b))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (((angle * (((double) M_PI) * (-0.005555555555555556 * b))) * (angle * -0.005555555555555556)) * (((double) M_PI) * b));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (((angle * (Math.PI * (-0.005555555555555556 * b))) * (angle * -0.005555555555555556)) * (Math.PI * b));
}
def code(a, b, angle): return math.pow(a, 2.0) + (((angle * (math.pi * (-0.005555555555555556 * b))) * (angle * -0.005555555555555556)) * (math.pi * b))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(Float64(Float64(angle * Float64(pi * Float64(-0.005555555555555556 * b))) * Float64(angle * -0.005555555555555556)) * Float64(pi * b))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (((angle * (pi * (-0.005555555555555556 * b))) * (angle * -0.005555555555555556)) * (pi * b)); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(N[(angle * N[(Pi * N[(-0.005555555555555556 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(angle * -0.005555555555555556), $MachinePrecision]), $MachinePrecision] * N[(Pi * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + \left(\left(angle \cdot \left(\pi \cdot \left(-0.005555555555555556 \cdot b\right)\right)\right) \cdot \left(angle \cdot -0.005555555555555556\right)\right) \cdot \left(\pi \cdot b\right)
\end{array}
Initial program 80.8%
Simplified80.9%
Taylor expanded in angle around 0 76.6%
associate-*r*76.6%
*-commutative76.6%
associate-*l*76.7%
*-commutative76.7%
Simplified76.7%
Taylor expanded in angle around 0 77.3%
unpow277.3%
associate-*r*77.3%
metadata-eval77.3%
div-inv77.3%
associate-*r*77.3%
*-commutative77.3%
associate-*l*77.3%
div-inv77.3%
metadata-eval77.3%
Applied egg-rr77.3%
Final simplification77.3%
herbie shell --seed 2024024
(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)))