
(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 (let* ((t_0 (sin (* PI (* angle 0.005555555555555556))))) (+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (* b (* t_0 (* t_0 b))))))
double code(double a, double b, double angle) {
double t_0 = sin((((double) M_PI) * (angle * 0.005555555555555556)));
return pow((a * cos((((double) M_PI) * (angle / 180.0)))), 2.0) + (b * (t_0 * (t_0 * b)));
}
public static double code(double a, double b, double angle) {
double t_0 = Math.sin((Math.PI * (angle * 0.005555555555555556)));
return Math.pow((a * Math.cos((Math.PI * (angle / 180.0)))), 2.0) + (b * (t_0 * (t_0 * b)));
}
def code(a, b, angle): t_0 = math.sin((math.pi * (angle * 0.005555555555555556))) return math.pow((a * math.cos((math.pi * (angle / 180.0)))), 2.0) + (b * (t_0 * (t_0 * b)))
function code(a, b, angle) t_0 = sin(Float64(pi * Float64(angle * 0.005555555555555556))) return Float64((Float64(a * cos(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + Float64(b * Float64(t_0 * Float64(t_0 * b)))) end
function tmp = code(a, b, angle) t_0 = sin((pi * (angle * 0.005555555555555556))); tmp = ((a * cos((pi * (angle / 180.0)))) ^ 2.0) + (b * (t_0 * (t_0 * b))); end
code[a_, b_, angle_] := Block[{t$95$0 = N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 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(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\\
{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + b \cdot \left(t_0 \cdot \left(t_0 \cdot b\right)\right)
\end{array}
\end{array}
Initial program 80.2%
unpow280.2%
*-commutative80.2%
associate-*r*80.3%
*-commutative80.3%
div-inv79.4%
metadata-eval79.4%
div-inv80.3%
metadata-eval80.3%
Applied egg-rr80.3%
Final simplification80.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* angle (/ PI 180.0)))) 2.0) (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * cos((angle * (((double) M_PI) / 180.0)))), 2.0) + pow((b * sin((((double) M_PI) * (angle / 180.0)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos((angle * (Math.PI / 180.0)))), 2.0) + Math.pow((b * Math.sin((Math.PI * (angle / 180.0)))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.cos((angle * (math.pi / 180.0)))), 2.0) + math.pow((b * math.sin((math.pi * (angle / 180.0)))), 2.0)
function code(a, b, angle) return Float64((Float64(a * cos(Float64(angle * Float64(pi / 180.0)))) ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(angle / 180.0)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * cos((angle * (pi / 180.0)))) ^ 2.0) + ((b * sin((pi * (angle / 180.0)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2}
\end{array}
Initial program 80.2%
Taylor expanded in angle around inf 79.9%
metadata-eval79.9%
*-commutative79.9%
associate-/r/79.9%
associate-/l*79.9%
*-commutative79.9%
associate-/l*79.9%
metadata-eval79.9%
*-commutative79.9%
associate-*r/80.3%
Simplified80.3%
Final simplification80.3%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (/ PI (/ 180.0 angle)))) 2.0)))
double code(double a, double b, double angle) {
return pow((a * cos((((double) M_PI) * (angle / 180.0)))), 2.0) + pow((b * sin((((double) M_PI) / (180.0 / angle)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.cos((Math.PI * (angle / 180.0)))), 2.0) + Math.pow((b * Math.sin((Math.PI / (180.0 / angle)))), 2.0);
}
def code(a, b, angle): return math.pow((a * math.cos((math.pi * (angle / 180.0)))), 2.0) + math.pow((b * math.sin((math.pi / (180.0 / angle)))), 2.0)
function code(a, b, angle) return Float64((Float64(a * cos(Float64(pi * Float64(angle / 180.0)))) ^ 2.0) + (Float64(b * sin(Float64(pi / Float64(180.0 / angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * cos((pi * (angle / 180.0)))) ^ 2.0) + ((b * sin((pi / (180.0 / angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Cos[N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi / N[(180.0 / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \cos \left(\pi \cdot \frac{angle}{180}\right)\right)}^{2} + {\left(b \cdot \sin \left(\frac{\pi}{\frac{180}{angle}}\right)\right)}^{2}
\end{array}
Initial program 80.2%
clear-num80.3%
un-div-inv80.3%
Applied egg-rr80.3%
Final simplification80.3%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (sin (* PI (* angle 0.005555555555555556))))) (+ (* b (* t_0 (* t_0 b))) (pow a 2.0))))
double code(double a, double b, double angle) {
double t_0 = sin((((double) M_PI) * (angle * 0.005555555555555556)));
return (b * (t_0 * (t_0 * b))) + pow(a, 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.sin((Math.PI * (angle * 0.005555555555555556)));
return (b * (t_0 * (t_0 * b))) + Math.pow(a, 2.0);
}
def code(a, b, angle): t_0 = math.sin((math.pi * (angle * 0.005555555555555556))) return (b * (t_0 * (t_0 * b))) + math.pow(a, 2.0)
function code(a, b, angle) t_0 = sin(Float64(pi * Float64(angle * 0.005555555555555556))) return Float64(Float64(b * Float64(t_0 * Float64(t_0 * b))) + (a ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = sin((pi * (angle * 0.005555555555555556))); tmp = (b * (t_0 * (t_0 * b))) + (a ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]}, N[(N[(b * N[(t$95$0 * N[(t$95$0 * b), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[Power[a, 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\\
b \cdot \left(t_0 \cdot \left(t_0 \cdot b\right)\right) + {a}^{2}
\end{array}
\end{array}
Initial program 80.2%
unpow280.2%
*-commutative80.2%
associate-*r*80.3%
*-commutative80.3%
div-inv79.4%
metadata-eval79.4%
div-inv80.3%
metadata-eval80.3%
Applied egg-rr80.3%
Taylor expanded in angle around 0 80.2%
Final simplification80.2%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* 0.005555555555555556 (* PI angle)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((0.005555555555555556 * (((double) M_PI) * angle)))), 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 * (Math.PI * angle)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((0.005555555555555556 * (math.pi * angle)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(0.005555555555555556 * Float64(pi * angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((0.005555555555555556 * (pi * angle)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 80.2%
Taylor expanded in angle around 0 80.1%
Taylor expanded in angle around inf 79.7%
Final simplification79.7%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* angle (/ PI 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((angle * (((double) M_PI) / 180.0)))), 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 / 180.0)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((angle * (math.pi / 180.0)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((angle * (pi / 180.0)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2}
\end{array}
Initial program 80.2%
Taylor expanded in angle around 0 80.1%
Taylor expanded in angle around inf 79.7%
metadata-eval79.7%
*-commutative79.7%
associate-/r/79.7%
associate-/l*79.7%
*-commutative79.7%
associate-/l*79.7%
metadata-eval79.7%
*-commutative79.7%
associate-*r/80.2%
Simplified80.2%
Final simplification80.2%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* (sin (* PI (* angle 0.005555555555555556))) b) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((sin((((double) M_PI) * (angle * 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((Math.PI * (angle * 0.005555555555555556))) * b), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((math.sin((math.pi * (angle * 0.005555555555555556))) * b), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(sin(Float64(pi * Float64(angle * 0.005555555555555556))) * b) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((sin((pi * (angle * 0.005555555555555556))) * b) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision] * b), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(\sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right) \cdot b\right)}^{2}
\end{array}
Initial program 80.2%
Taylor expanded in angle around 0 80.1%
add-exp-log40.3%
div-inv41.6%
metadata-eval41.6%
Applied egg-rr41.6%
Taylor expanded in angle around inf 79.7%
associate-*r*80.2%
*-commutative80.2%
*-commutative80.2%
Simplified80.2%
Final simplification80.2%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (pow (* PI (* angle b)) 2.0) 3.08641975308642e-5)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (pow((((double) M_PI) * (angle * b)), 2.0) * 3.08641975308642e-5);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (Math.pow((Math.PI * (angle * b)), 2.0) * 3.08641975308642e-5);
}
def code(a, b, angle): return math.pow(a, 2.0) + (math.pow((math.pi * (angle * b)), 2.0) * 3.08641975308642e-5)
function code(a, b, angle) return Float64((a ^ 2.0) + Float64((Float64(pi * Float64(angle * b)) ^ 2.0) * 3.08641975308642e-5)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (((pi * (angle * b)) ^ 2.0) * 3.08641975308642e-5); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[Power[N[(Pi * N[(angle * b), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 3.08641975308642e-5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(\pi \cdot \left(angle \cdot b\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}
\end{array}
Initial program 80.2%
Taylor expanded in angle around 0 80.1%
Taylor expanded in angle around 0 72.0%
Taylor expanded in b around 0 72.0%
associate-*r*72.0%
Simplified72.0%
*-commutative72.0%
unpow-prod-down72.0%
*-commutative72.0%
metadata-eval72.0%
Applied egg-rr72.0%
Final simplification72.0%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (* 0.005555555555555556 (* PI angle))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * (0.005555555555555556 * (((double) M_PI) * angle))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * (0.005555555555555556 * (Math.PI * angle))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * (0.005555555555555556 * (math.pi * angle))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * Float64(0.005555555555555556 * Float64(pi * angle))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * (0.005555555555555556 * (pi * angle))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 80.2%
Taylor expanded in angle around 0 80.1%
Taylor expanded in angle around 0 72.0%
Final simplification72.0%
herbie shell --seed 2023182
(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)))