
(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 7 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 (/ 0.005555555555555556 (/ (/ 1.0 PI) angle)))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((0.005555555555555556 / ((1.0 / ((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 / ((1.0 / Math.PI) / angle)))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((0.005555555555555556 / ((1.0 / math.pi) / angle)))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(0.005555555555555556 / Float64(Float64(1.0 / pi) / angle)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((0.005555555555555556 / ((1.0 / 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[(N[(1.0 / Pi), $MachinePrecision] / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(b \cdot \sin \left(\frac{0.005555555555555556}{\frac{\frac{1}{\pi}}{angle}}\right)\right)}^{2}
\end{array}
Initial program 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
add-exp-log40.6%
metadata-eval40.6%
div-inv40.6%
*-commutative40.6%
div-inv40.6%
metadata-eval40.6%
associate-*l*40.6%
Applied egg-rr40.6%
rem-exp-log79.3%
*-commutative79.3%
associate-*r*79.3%
metadata-eval79.3%
associate-/r/79.3%
div-inv79.3%
associate-/r*79.3%
metadata-eval79.3%
associate-/r*79.3%
Applied egg-rr79.3%
Final simplification79.3%
(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 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
Taylor expanded in b around 0 79.3%
Final simplification79.3%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* 0.005555555555555556 (* angle (* b PI))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((0.005555555555555556 * (angle * (b * ((double) M_PI)))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((0.005555555555555556 * (angle * (b * Math.PI))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((0.005555555555555556 * (angle * (b * math.pi))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(0.005555555555555556 * Float64(angle * Float64(b * pi))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((0.005555555555555556 * (angle * (b * pi))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
Taylor expanded in angle around 0 73.3%
Final simplification73.3%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* angle (* PI (* b 0.005555555555555556))) 2.0)))
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((angle * (((double) M_PI) * (b * 0.005555555555555556))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((angle * (Math.PI * (b * 0.005555555555555556))), 2.0);
}
def code(a, b, angle): return math.pow(a, 2.0) + math.pow((angle * (math.pi * (b * 0.005555555555555556))), 2.0)
function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(angle * Float64(pi * Float64(b * 0.005555555555555556))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((angle * (pi * (b * 0.005555555555555556))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(angle * N[(Pi * N[(b * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + {\left(angle \cdot \left(\pi \cdot \left(b \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
add-exp-log40.6%
metadata-eval40.6%
div-inv40.6%
*-commutative40.6%
div-inv40.6%
metadata-eval40.6%
associate-*l*40.6%
Applied egg-rr40.6%
Taylor expanded in angle around 0 73.3%
associate-*r*73.3%
*-commutative73.3%
*-commutative73.3%
*-commutative73.3%
associate-*r*73.3%
*-commutative73.3%
associate-*r*73.3%
associate-*l*73.3%
*-commutative73.3%
Simplified73.3%
Final simplification73.3%
(FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (* (* 0.005555555555555556 (* b PI)) (/ (* angle (* b PI)) (/ 180.0 angle)))))
double code(double a, double b, double angle) {
return pow(a, 2.0) + ((0.005555555555555556 * (b * ((double) M_PI))) * ((angle * (b * ((double) M_PI))) / (180.0 / angle)));
}
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + ((0.005555555555555556 * (b * Math.PI)) * ((angle * (b * Math.PI)) / (180.0 / angle)));
}
def code(a, b, angle): return math.pow(a, 2.0) + ((0.005555555555555556 * (b * math.pi)) * ((angle * (b * math.pi)) / (180.0 / angle)))
function code(a, b, angle) return Float64((a ^ 2.0) + Float64(Float64(0.005555555555555556 * Float64(b * pi)) * Float64(Float64(angle * Float64(b * pi)) / Float64(180.0 / angle)))) end
function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((0.005555555555555556 * (b * pi)) * ((angle * (b * pi)) / (180.0 / angle))); end
code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[(N[(0.005555555555555556 * N[(b * Pi), $MachinePrecision]), $MachinePrecision] * N[(N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision] / N[(180.0 / angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{a}^{2} + \left(0.005555555555555556 \cdot \left(b \cdot \pi\right)\right) \cdot \frac{angle \cdot \left(b \cdot \pi\right)}{\frac{180}{angle}}
\end{array}
Initial program 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
Taylor expanded in angle around 0 73.3%
unpow273.3%
associate-*r*73.3%
associate-*l*72.6%
*-commutative72.6%
*-commutative72.6%
*-commutative72.6%
associate-*l*72.6%
*-commutative72.6%
Applied egg-rr72.6%
metadata-eval72.6%
div-inv72.6%
*-commutative72.6%
clear-num72.6%
un-div-inv72.6%
associate-*r*72.6%
*-commutative72.6%
associate-*l*72.6%
*-commutative72.6%
associate-*l*72.6%
Applied egg-rr72.6%
associate-/l*72.8%
*-commutative72.8%
associate-*r*72.8%
*-commutative72.8%
associate-*r*72.8%
*-commutative72.8%
Simplified72.8%
Final simplification72.8%
(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 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
Taylor expanded in angle around 0 73.3%
unpow273.3%
*-commutative73.3%
associate-*l*73.3%
*-commutative73.3%
*-commutative73.3%
associate-*l*73.3%
*-commutative73.3%
Applied egg-rr73.3%
Final simplification73.3%
(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 79.0%
Simplified79.0%
Taylor expanded in angle around 0 79.3%
Taylor expanded in angle around 0 73.3%
unpow273.3%
associate-*r*73.3%
*-commutative73.3%
associate-*l*73.3%
*-commutative73.3%
associate-*r*73.3%
*-commutative73.3%
Applied egg-rr73.3%
Final simplification73.3%
herbie shell --seed 2024076
(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)))