
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* (/ angle 180.0) PI))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos 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 (* (/ angle 180.0) PI))) (+ (pow (* a (sin t_0)) 2.0) (pow (* b (cos t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * ((double) M_PI);
return pow((a * sin(t_0)), 2.0) + pow((b * cos(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = (angle / 180.0) * Math.PI;
return Math.pow((a * Math.sin(t_0)), 2.0) + Math.pow((b * Math.cos(t_0)), 2.0);
}
def code(a, b, angle): t_0 = (angle / 180.0) * math.pi return math.pow((a * math.sin(t_0)), 2.0) + math.pow((b * math.cos(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(Float64(angle / 180.0) * pi) return Float64((Float64(a * sin(t_0)) ^ 2.0) + (Float64(b * cos(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = (angle / 180.0) * pi; tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]}, N[(N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \frac{angle}{180} \cdot \pi\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (pow (sqrt (* angle_m (* PI 0.005555555555555556))) 2.0))) 2.0) (pow b 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow((a * sin(pow(sqrt((angle_m * (((double) M_PI) * 0.005555555555555556))), 2.0))), 2.0) + pow(b, 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow((a * Math.sin(Math.pow(Math.sqrt((angle_m * (Math.PI * 0.005555555555555556))), 2.0))), 2.0) + Math.pow(b, 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow((a * math.sin(math.pow(math.sqrt((angle_m * (math.pi * 0.005555555555555556))), 2.0))), 2.0) + math.pow(b, 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((Float64(a * sin((sqrt(Float64(angle_m * Float64(pi * 0.005555555555555556))) ^ 2.0))) ^ 2.0) + (b ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = ((a * sin((sqrt((angle_m * (pi * 0.005555555555555556))) ^ 2.0))) ^ 2.0) + (b ^ 2.0); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[N[(a * N[Sin[N[Power[N[Sqrt[N[(angle$95$m * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left({\left(\sqrt{angle\_m \cdot \left(\pi \cdot 0.005555555555555556\right)}\right)}^{2}\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 82.0%
unpow282.0%
associate-*l/81.8%
associate-/l*82.0%
unpow282.0%
Simplified82.0%
Taylor expanded in angle around 0 82.4%
associate-*r/82.1%
associate-*l/82.4%
add-sqr-sqrt45.6%
pow245.6%
associate-*l/45.3%
associate-*r/45.6%
div-inv45.6%
metadata-eval45.6%
Applied egg-rr45.6%
Final simplification45.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (* a (sin (/ PI (/ 180.0 angle_m)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(b, 2.0) + pow((a * sin((((double) M_PI) / (180.0 / angle_m)))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(b, 2.0) + Math.pow((a * Math.sin((Math.PI / (180.0 / angle_m)))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(b, 2.0) + math.pow((a * math.sin((math.pi / (180.0 / angle_m)))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(a * sin(Float64(pi / Float64(180.0 / angle_m)))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (b ^ 2.0) + ((a * sin((pi / (180.0 / angle_m)))) ^ 2.0); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[b, 2.0], $MachinePrecision] + N[Power[N[(a * N[Sin[N[(Pi / N[(180.0 / angle$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2} + {\left(a \cdot \sin \left(\frac{\pi}{\frac{180}{angle\_m}}\right)\right)}^{2}
\end{array}
Initial program 82.0%
unpow282.0%
associate-*l/81.8%
associate-/l*82.0%
unpow282.0%
Simplified82.0%
Taylor expanded in angle around 0 82.4%
*-commutative82.4%
associate-/r/82.4%
Applied egg-rr82.4%
Final simplification82.4%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (* angle_m (/ PI 180.0)))) 2.0) (* b b)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow((a * sin((angle_m * (((double) M_PI) / 180.0)))), 2.0) + (b * b);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow((a * Math.sin((angle_m * (Math.PI / 180.0)))), 2.0) + (b * b);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow((a * math.sin((angle_m * (math.pi / 180.0)))), 2.0) + (b * b)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((Float64(a * sin(Float64(angle_m * Float64(pi / 180.0)))) ^ 2.0) + Float64(b * b)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = ((a * sin((angle_m * (pi / 180.0)))) ^ 2.0) + (b * b); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[N[(a * N[Sin[N[(angle$95$m * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(angle\_m \cdot \frac{\pi}{180}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 82.0%
unpow282.0%
associate-*l/81.8%
associate-/l*82.0%
unpow282.0%
Simplified82.0%
Taylor expanded in angle around 0 82.4%
*-rgt-identity82.4%
unpow282.4%
Applied egg-rr82.4%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 8.2e+182) (pow b 2.0) (* 3.08641975308642e-5 (* (* a angle_m) (* PI (* a (* angle_m PI)))))))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double tmp;
if (a <= 8.2e+182) {
tmp = pow(b, 2.0);
} else {
tmp = 3.08641975308642e-5 * ((a * angle_m) * (((double) M_PI) * (a * (angle_m * ((double) M_PI)))));
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double tmp;
if (a <= 8.2e+182) {
tmp = Math.pow(b, 2.0);
} else {
tmp = 3.08641975308642e-5 * ((a * angle_m) * (Math.PI * (a * (angle_m * Math.PI))));
}
return tmp;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): tmp = 0 if a <= 8.2e+182: tmp = math.pow(b, 2.0) else: tmp = 3.08641975308642e-5 * ((a * angle_m) * (math.pi * (a * (angle_m * math.pi)))) return tmp
angle_m = abs(angle) function code(a, b, angle_m) tmp = 0.0 if (a <= 8.2e+182) tmp = b ^ 2.0; else tmp = Float64(3.08641975308642e-5 * Float64(Float64(a * angle_m) * Float64(pi * Float64(a * Float64(angle_m * pi))))); end return tmp end
angle_m = abs(angle); function tmp_2 = code(a, b, angle_m) tmp = 0.0; if (a <= 8.2e+182) tmp = b ^ 2.0; else tmp = 3.08641975308642e-5 * ((a * angle_m) * (pi * (a * (angle_m * pi)))); end tmp_2 = tmp; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := If[LessEqual[a, 8.2e+182], N[Power[b, 2.0], $MachinePrecision], N[(3.08641975308642e-5 * N[(N[(a * angle$95$m), $MachinePrecision] * N[(Pi * N[(a * N[(angle$95$m * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 8.2 \cdot 10^{+182}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;3.08641975308642 \cdot 10^{-5} \cdot \left(\left(a \cdot angle\_m\right) \cdot \left(\pi \cdot \left(a \cdot \left(angle\_m \cdot \pi\right)\right)\right)\right)\\
\end{array}
\end{array}
if a < 8.20000000000000006e182Initial program 80.0%
unpow280.0%
associate-*l/79.7%
associate-/l*80.0%
unpow280.0%
Simplified80.0%
Taylor expanded in angle around 0 66.5%
if 8.20000000000000006e182 < a Initial program 99.9%
unpow299.9%
associate-*l/99.9%
associate-/l*99.9%
unpow299.9%
Simplified99.9%
Taylor expanded in a around inf 77.7%
unpow277.7%
*-commutative77.7%
associate-*r*77.7%
unpow277.7%
swap-sqr81.4%
unpow281.4%
associate-*r*81.4%
*-commutative81.4%
Simplified81.4%
Taylor expanded in angle around 0 77.7%
unpow277.7%
unpow277.7%
unpow277.7%
swap-sqr77.7%
swap-sqr81.3%
unpow281.3%
Simplified81.3%
unpow281.3%
associate-*r*81.4%
associate-*l*81.3%
*-commutative81.3%
Applied egg-rr81.3%
Final simplification68.0%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (* 3.08641975308642e-5 (* (* a angle_m) (* PI (* a (* angle_m PI))))))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return 3.08641975308642e-5 * ((a * angle_m) * (((double) M_PI) * (a * (angle_m * ((double) M_PI)))));
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return 3.08641975308642e-5 * ((a * angle_m) * (Math.PI * (a * (angle_m * Math.PI))));
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return 3.08641975308642e-5 * ((a * angle_m) * (math.pi * (a * (angle_m * math.pi))))
angle_m = abs(angle) function code(a, b, angle_m) return Float64(3.08641975308642e-5 * Float64(Float64(a * angle_m) * Float64(pi * Float64(a * Float64(angle_m * pi))))) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = 3.08641975308642e-5 * ((a * angle_m) * (pi * (a * (angle_m * pi)))); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(3.08641975308642e-5 * N[(N[(a * angle$95$m), $MachinePrecision] * N[(Pi * N[(a * N[(angle$95$m * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
3.08641975308642 \cdot 10^{-5} \cdot \left(\left(a \cdot angle\_m\right) \cdot \left(\pi \cdot \left(a \cdot \left(angle\_m \cdot \pi\right)\right)\right)\right)
\end{array}
Initial program 82.0%
unpow282.0%
associate-*l/81.8%
associate-/l*82.0%
unpow282.0%
Simplified82.0%
Taylor expanded in a around inf 34.5%
unpow234.5%
*-commutative34.5%
associate-*r*34.8%
unpow234.8%
swap-sqr36.8%
unpow236.8%
associate-*r*36.5%
*-commutative36.5%
Simplified36.5%
Taylor expanded in angle around 0 33.4%
unpow233.4%
unpow233.4%
unpow233.4%
swap-sqr33.4%
swap-sqr34.7%
unpow234.7%
Simplified34.7%
unpow234.7%
associate-*r*34.7%
associate-*l*34.7%
*-commutative34.7%
Applied egg-rr34.7%
Final simplification34.7%
herbie shell --seed 2024173
(FPCore (a b angle)
:name "ab-angle->ABCF A"
:precision binary64
(+ (pow (* a (sin (* (/ angle 180.0) PI))) 2.0) (pow (* b (cos (* (/ angle 180.0) PI))) 2.0)))