
(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 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.6%
unpow280.6%
swap-sqr71.9%
sqr-neg71.9%
swap-sqr80.6%
unpow280.6%
distribute-lft-neg-out80.6%
distribute-rgt-neg-in80.6%
sin-neg80.6%
distribute-rgt-neg-out80.6%
distribute-frac-neg80.6%
unpow280.6%
associate-*l*79.9%
Simplified80.6%
Taylor expanded in angle around 0 81.0%
Taylor expanded in angle around inf 81.0%
associate-*r*81.0%
*-commutative81.0%
*-commutative81.0%
unpow181.0%
sqr-pow42.1%
fabs-sqr42.1%
sqr-pow81.0%
unpow181.0%
associate-*r*81.0%
*-commutative81.0%
associate-*r*81.1%
fabs-mul81.1%
fabs-mul81.1%
metadata-eval81.1%
unpow181.1%
sqr-pow80.7%
fabs-sqr80.7%
sqr-pow81.1%
unpow181.1%
unpow181.1%
sqr-pow38.9%
fabs-sqr38.9%
sqr-pow81.1%
unpow181.1%
Simplified81.1%
Final simplification81.1%
(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.6%
Taylor expanded in angle around 0 81.0%
Taylor expanded in b around 0 81.0%
Final simplification81.0%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* 0.005555555555555556 (* (* PI (* angle (* b 0.005555555555555556))) (* angle (* b PI))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (0.005555555555555556 * ((((double) M_PI) * (angle * (b * 0.005555555555555556))) * (angle * (b * ((double) M_PI)))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (0.005555555555555556 * ((Math.PI * (angle * (b * 0.005555555555555556))) * (angle * (b * Math.PI))));
}
def code(a, b, angle): return math.pow(a, 2.0) + (0.005555555555555556 * ((math.pi * (angle * (b * 0.005555555555555556))) * (angle * (b * math.pi))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(0.005555555555555556 * Float64(Float64(pi * Float64(angle * Float64(b * 0.005555555555555556))) * Float64(angle * Float64(b * pi))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (0.005555555555555556 * ((pi * (angle * (b * 0.005555555555555556))) * (angle * (b * pi)))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(0.005555555555555556 * N[(N[(Pi * N[(angle * N[(b * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + 0.005555555555555556 \cdot \left(\left(\pi \cdot \left(angle \cdot \left(b \cdot 0.005555555555555556\right)\right)\right) \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)
\end{array}
Initial program 80.6%
Taylor expanded in angle around 0 81.0%
Taylor expanded in angle around 0 77.3%
associate-*r*77.3%
Simplified77.3%
unpow277.3%
*-commutative77.3%
associate-*r*77.3%
associate-*r*77.3%
*-commutative77.3%
*-commutative77.3%
associate-*r*77.3%
associate-*l*77.3%
*-commutative77.3%
Applied egg-rr77.3%
Final simplification77.3%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* angle (* b 0.005555555555555556)))) (+ (pow a 2.0) (* PI (* t_0 (* PI t_0))))))
double code(double a, double b, double angle) {
double t_0 = angle * (b * 0.005555555555555556);
return pow(a, 2.0) + (((double) M_PI) * (t_0 * (((double) M_PI) * t_0)));
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (b * 0.005555555555555556);
return Math.pow(a, 2.0) + (Math.PI * (t_0 * (Math.PI * t_0)));
}
def code(a, b, angle): t_0 = angle * (b * 0.005555555555555556) return math.pow(a, 2.0) + (math.pi * (t_0 * (math.pi * t_0)))
function code(a, b, angle) t_0 = Float64(angle * Float64(b * 0.005555555555555556)) return Float64((a ^ 2.0) + Float64(pi * Float64(t_0 * Float64(pi * t_0)))) end
function tmp = code(a, b, angle) t_0 = angle * (b * 0.005555555555555556); tmp = (a ^ 2.0) + (pi * (t_0 * (pi * t_0))); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(b * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[a, 2.0], $MachinePrecision] + N[(Pi * N[(t$95$0 * N[(Pi * t$95$0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := angle \cdot \left(b \cdot 0.005555555555555556\right)\\
{a}^{2} + \pi \cdot \left(t_0 \cdot \left(\pi \cdot t_0\right)\right)
\end{array}
\end{array}
Initial program 80.6%
Taylor expanded in angle around 0 81.0%
Taylor expanded in angle around 0 77.3%
associate-*r*77.3%
Simplified77.3%
unpow277.3%
associate-*r*77.3%
associate-*r*77.3%
associate-*r*77.3%
*-commutative77.3%
*-commutative77.3%
associate-*r*77.3%
*-commutative77.3%
associate-*r*77.3%
Applied egg-rr77.3%
Final simplification77.3%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* 3.08641975308642e-5 (pow (* PI (* b angle)) 2.0))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + (3.08641975308642e-5 * pow((((double) M_PI) * (b * angle)), 2.0));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + (3.08641975308642e-5 * Math.pow((Math.PI * (b * angle)), 2.0));
}
def code(a, b, angle): return math.pow(a, 2.0) + (3.08641975308642e-5 * math.pow((math.pi * (b * angle)), 2.0))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(3.08641975308642e-5 * (Float64(pi * Float64(b * angle)) ^ 2.0))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + (3.08641975308642e-5 * ((pi * (b * angle)) ^ 2.0)); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(3.08641975308642e-5 * N[Power[N[(Pi * N[(b * angle), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + 3.08641975308642 \cdot 10^{-5} \cdot {\left(\pi \cdot \left(b \cdot angle\right)\right)}^{2}
\end{array}
Initial program 80.6%
unpow280.6%
swap-sqr71.9%
sqr-neg71.9%
swap-sqr80.6%
unpow280.6%
distribute-lft-neg-out80.6%
distribute-rgt-neg-in80.6%
sin-neg80.6%
distribute-rgt-neg-out80.6%
distribute-frac-neg80.6%
unpow280.6%
associate-*l*79.9%
Simplified80.6%
Taylor expanded in angle around 0 81.0%
Taylor expanded in angle around inf 81.0%
associate-*r*81.0%
*-commutative81.0%
*-commutative81.0%
unpow181.0%
sqr-pow42.1%
fabs-sqr42.1%
sqr-pow81.0%
unpow181.0%
associate-*r*81.0%
*-commutative81.0%
associate-*r*81.1%
fabs-mul81.1%
fabs-mul81.1%
metadata-eval81.1%
unpow181.1%
sqr-pow80.7%
fabs-sqr80.7%
sqr-pow81.1%
unpow181.1%
unpow181.1%
sqr-pow38.9%
fabs-sqr38.9%
sqr-pow81.1%
unpow181.1%
Simplified81.1%
Taylor expanded in angle around 0 67.4%
unpow267.4%
unpow267.4%
*-commutative67.4%
unpow267.4%
unswap-sqr67.4%
swap-sqr77.3%
unpow277.3%
*-commutative77.3%
associate-*r*77.3%
*-commutative77.3%
*-commutative77.3%
Simplified77.3%
Final simplification77.3%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* PI (* 0.005555555555555556 (* b angle))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((((double) M_PI) * (0.005555555555555556 * (b * angle))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((Math.PI * (0.005555555555555556 * (b * angle))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((math.pi * (0.005555555555555556 * (b * angle))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(pi * Float64(0.005555555555555556 * Float64(b * angle))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((pi * (0.005555555555555556 * (b * angle))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(Pi * N[(0.005555555555555556 * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(\pi \cdot \left(0.005555555555555556 \cdot \left(b \cdot angle\right)\right)\right)}^{2}
\end{array}
Initial program 80.6%
Taylor expanded in angle around 0 81.0%
Taylor expanded in angle around 0 77.3%
associate-*r*77.3%
Simplified77.3%
expm1-log1p-u59.2%
expm1-udef54.4%
associate-*r*54.4%
*-commutative54.4%
*-commutative54.4%
associate-*r*54.4%
Applied egg-rr54.4%
expm1-def59.2%
expm1-log1p77.3%
associate-*l*77.3%
Simplified77.3%
Final simplification77.3%
herbie shell --seed 2023275
(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)))