
(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 5 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 (* 0.005555555555555556 PI)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((angle * (0.005555555555555556 * ((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((angle * (0.005555555555555556 * Math.PI)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((angle * (0.005555555555555556 * math.pi)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(angle * Float64(0.005555555555555556 * pi)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((angle * (0.005555555555555556 * pi)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 80.6%
Simplified80.6%
Taylor expanded in angle around 0 80.7%
Taylor expanded in angle around inf 80.7%
associate-*r*80.7%
*-commutative80.7%
associate-*r*80.8%
Simplified80.8%
Final simplification80.8%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (* 0.005555555555555556 (* angle (* 0.005555555555555556 (* b PI)))) (* PI (* b angle)))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + ((0.005555555555555556 * (angle * (0.005555555555555556 * (b * ((double) M_PI))))) * (((double) M_PI) * (b * angle)));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + ((0.005555555555555556 * (angle * (0.005555555555555556 * (b * Math.PI)))) * (Math.PI * (b * angle)));
}
def code(a, b, angle): return math.pow(a, 2.0) + ((0.005555555555555556 * (angle * (0.005555555555555556 * (b * math.pi)))) * (math.pi * (b * angle)))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(Float64(0.005555555555555556 * Float64(angle * Float64(0.005555555555555556 * Float64(b * pi)))) * Float64(pi * Float64(b * angle)))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((0.005555555555555556 * (angle * (0.005555555555555556 * (b * pi)))) * (pi * (b * angle))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(0.005555555555555556 * N[(angle * N[(0.005555555555555556 * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(Pi * N[(b * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + \left(0.005555555555555556 \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \left(b \cdot \pi\right)\right)\right)\right) \cdot \left(\pi \cdot \left(b \cdot angle\right)\right)
\end{array}
Initial program 80.6%
Simplified80.6%
Taylor expanded in angle around 0 80.7%
Taylor expanded in angle around 0 74.5%
*-commutative74.5%
Simplified74.5%
unpow274.5%
associate-*r*74.5%
*-commutative74.5%
associate-*l*74.5%
*-commutative74.5%
associate-*r*74.6%
Applied egg-rr74.6%
Final simplification74.6%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* angle (* 0.005555555555555556 (* b PI))))) (+ (pow a 2.0) (* t_0 t_0))))
double code(double a, double b, double angle) {
double t_0 = angle * (0.005555555555555556 * (b * ((double) M_PI)));
return pow(a, 2.0) + (t_0 * t_0);
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (0.005555555555555556 * (b * Math.PI));
return Math.pow(a, 2.0) + (t_0 * t_0);
}
def code(a, b, angle): t_0 = angle * (0.005555555555555556 * (b * math.pi)) return math.pow(a, 2.0) + (t_0 * t_0)
function code(a, b, angle) t_0 = Float64(angle * Float64(0.005555555555555556 * Float64(b * pi))) return Float64((a ^ 2.0) + Float64(t_0 * t_0)) end
function tmp = code(a, b, angle) t_0 = angle * (0.005555555555555556 * (b * pi)); tmp = (a ^ 2.0) + (t_0 * t_0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(0.005555555555555556 * N[(b * Pi), $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(0.005555555555555556 \cdot \left(b \cdot \pi\right)\right)\\
{a}^{2} + t\_0 \cdot t\_0
\end{array}
\end{array}
Initial program 80.6%
Simplified80.6%
Taylor expanded in angle around 0 80.7%
Taylor expanded in angle around 0 74.5%
*-commutative74.5%
Simplified74.5%
unpow274.5%
*-commutative74.5%
associate-*l*74.6%
*-commutative74.6%
associate-*l*74.5%
Applied egg-rr74.5%
Final simplification74.5%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (* angle 0.005555555555555556) (* (* b PI) (* angle (* PI (* b 0.005555555555555556)))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + ((angle * 0.005555555555555556) * ((b * ((double) M_PI)) * (angle * (((double) M_PI) * (b * 0.005555555555555556)))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + ((angle * 0.005555555555555556) * ((b * Math.PI) * (angle * (Math.PI * (b * 0.005555555555555556)))));
}
def code(a, b, angle): return math.pow(a, 2.0) + ((angle * 0.005555555555555556) * ((b * math.pi) * (angle * (math.pi * (b * 0.005555555555555556)))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(Float64(angle * 0.005555555555555556) * Float64(Float64(b * pi) * Float64(angle * Float64(pi * Float64(b * 0.005555555555555556)))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((angle * 0.005555555555555556) * ((b * pi) * (angle * (pi * (b * 0.005555555555555556))))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(angle * 0.005555555555555556), $MachinePrecision] * N[(N[(b * Pi), $MachinePrecision] * N[(angle * N[(Pi * N[(b * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + \left(angle \cdot 0.005555555555555556\right) \cdot \left(\left(b \cdot \pi\right) \cdot \left(angle \cdot \left(\pi \cdot \left(b \cdot 0.005555555555555556\right)\right)\right)\right)
\end{array}
Initial program 80.6%
Simplified80.6%
Taylor expanded in angle around 0 80.7%
Taylor expanded in angle around 0 74.5%
*-commutative74.5%
Simplified74.5%
unpow274.5%
associate-*r*74.5%
*-commutative74.5%
associate-*l*72.1%
*-commutative72.1%
associate-*l*72.1%
Applied egg-rr72.1%
Taylor expanded in b around 0 72.1%
associate-*r*72.1%
*-commutative72.1%
*-commutative72.1%
Simplified72.1%
Final simplification72.1%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (* angle 0.005555555555555556) (* (* b PI) (* 0.005555555555555556 (* angle (* b PI)))))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + ((angle * 0.005555555555555556) * ((b * ((double) M_PI)) * (0.005555555555555556 * (angle * (b * ((double) M_PI))))));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + ((angle * 0.005555555555555556) * ((b * Math.PI) * (0.005555555555555556 * (angle * (b * Math.PI)))));
}
def code(a, b, angle): return math.pow(a, 2.0) + ((angle * 0.005555555555555556) * ((b * math.pi) * (0.005555555555555556 * (angle * (b * math.pi)))))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(Float64(angle * 0.005555555555555556) * Float64(Float64(b * pi) * Float64(0.005555555555555556 * Float64(angle * Float64(b * pi)))))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((angle * 0.005555555555555556) * ((b * pi) * (0.005555555555555556 * (angle * (b * pi))))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(angle * 0.005555555555555556), $MachinePrecision] * N[(N[(b * Pi), $MachinePrecision] * N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + \left(angle \cdot 0.005555555555555556\right) \cdot \left(\left(b \cdot \pi\right) \cdot \left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)\right)
\end{array}
Initial program 80.6%
Simplified80.6%
Taylor expanded in angle around 0 80.7%
Taylor expanded in angle around 0 74.5%
*-commutative74.5%
Simplified74.5%
unpow274.5%
associate-*r*74.5%
*-commutative74.5%
associate-*l*72.1%
*-commutative72.1%
associate-*l*72.1%
Applied egg-rr72.1%
Taylor expanded in angle around 0 72.1%
Final simplification72.1%
herbie shell --seed 2024108
(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)))