
(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 6 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 (* PI (expm1 (log1p (* 0.005555555555555556 angle_m)))))) 2.0) (pow b 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow((a * sin((((double) M_PI) * expm1(log1p((0.005555555555555556 * angle_m)))))), 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.PI * Math.expm1(Math.log1p((0.005555555555555556 * angle_m)))))), 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.pi * math.expm1(math.log1p((0.005555555555555556 * angle_m)))))), 2.0) + math.pow(b, 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((Float64(a * sin(Float64(pi * expm1(log1p(Float64(0.005555555555555556 * angle_m)))))) ^ 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[(Pi * N[(Exp[N[Log[1 + N[(0.005555555555555556 * angle$95$m), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $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(\pi \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(0.005555555555555556 \cdot angle\_m\right)\right)\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 83.1%
associate-*l/83.1%
associate-/l*83.1%
cos-neg83.1%
distribute-lft-neg-out83.1%
distribute-frac-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
cos-neg83.1%
associate-*l/83.1%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 83.3%
add-sqr-sqrt44.9%
pow244.9%
*-commutative44.9%
div-inv44.9%
metadata-eval44.9%
Applied egg-rr44.9%
Taylor expanded in angle around inf 83.3%
associate-*r*83.3%
*-commutative83.3%
Simplified83.3%
expm1-log1p-u64.2%
expm1-undefine51.4%
Applied egg-rr51.4%
expm1-define64.2%
Simplified64.2%
Final simplification64.2%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (* a (sin (* 0.005555555555555556 (* PI 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((0.005555555555555556 * (((double) M_PI) * 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((0.005555555555555556 * (Math.PI * 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((0.005555555555555556 * (math.pi * angle_m)))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(a * sin(Float64(0.005555555555555556 * Float64(pi * angle_m)))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (b ^ 2.0) + ((a * sin((0.005555555555555556 * (pi * 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[(0.005555555555555556 * N[(Pi * 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(0.005555555555555556 \cdot \left(\pi \cdot angle\_m\right)\right)\right)}^{2}
\end{array}
Initial program 83.1%
associate-*l/83.1%
associate-/l*83.1%
cos-neg83.1%
distribute-lft-neg-out83.1%
distribute-frac-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
cos-neg83.1%
associate-*l/83.1%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 83.3%
Taylor expanded in angle around inf 83.3%
Final simplification83.3%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (* 0.005555555555555556 (* angle_m (* a PI))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(b, 2.0) + pow((0.005555555555555556 * (angle_m * (a * ((double) M_PI)))), 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((0.005555555555555556 * (angle_m * (a * Math.PI))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(b, 2.0) + math.pow((0.005555555555555556 * (angle_m * (a * math.pi))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(0.005555555555555556 * Float64(angle_m * Float64(a * pi))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (b ^ 2.0) + ((0.005555555555555556 * (angle_m * (a * pi))) ^ 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[(0.005555555555555556 * N[(angle$95$m * N[(a * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2} + {\left(0.005555555555555556 \cdot \left(angle\_m \cdot \left(a \cdot \pi\right)\right)\right)}^{2}
\end{array}
Initial program 83.1%
associate-*l/83.1%
associate-/l*83.1%
cos-neg83.1%
distribute-lft-neg-out83.1%
distribute-frac-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
cos-neg83.1%
associate-*l/83.1%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 83.3%
Taylor expanded in angle around inf 83.3%
Taylor expanded in angle around 0 78.5%
*-commutative78.5%
associate-*l*78.5%
Simplified78.5%
Final simplification78.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (* 0.005555555555555556 (* a (* PI angle_m))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(b, 2.0) + pow((0.005555555555555556 * (a * (((double) M_PI) * 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((0.005555555555555556 * (a * (Math.PI * angle_m))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(b, 2.0) + math.pow((0.005555555555555556 * (a * (math.pi * angle_m))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(0.005555555555555556 * Float64(a * Float64(pi * angle_m))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (b ^ 2.0) + ((0.005555555555555556 * (a * (pi * 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[(0.005555555555555556 * N[(a * N[(Pi * angle$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2} + {\left(0.005555555555555556 \cdot \left(a \cdot \left(\pi \cdot angle\_m\right)\right)\right)}^{2}
\end{array}
Initial program 83.1%
associate-*l/83.1%
associate-/l*83.1%
cos-neg83.1%
distribute-lft-neg-out83.1%
distribute-frac-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
cos-neg83.1%
associate-*l/83.1%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 83.3%
Taylor expanded in angle around 0 78.5%
*-commutative78.5%
Simplified78.5%
Final simplification78.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (* PI (* angle_m (* a 0.005555555555555556))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(b, 2.0) + pow((((double) M_PI) * (angle_m * (a * 0.005555555555555556))), 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((Math.PI * (angle_m * (a * 0.005555555555555556))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(b, 2.0) + math.pow((math.pi * (angle_m * (a * 0.005555555555555556))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(pi * Float64(angle_m * Float64(a * 0.005555555555555556))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (b ^ 2.0) + ((pi * (angle_m * (a * 0.005555555555555556))) ^ 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[(Pi * N[(angle$95$m * N[(a * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2} + {\left(\pi \cdot \left(angle\_m \cdot \left(a \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 83.1%
associate-*l/83.1%
associate-/l*83.1%
cos-neg83.1%
distribute-lft-neg-out83.1%
distribute-frac-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
cos-neg83.1%
associate-*l/83.1%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 83.3%
Taylor expanded in angle around inf 83.3%
Taylor expanded in angle around 0 78.5%
*-commutative78.5%
associate-*l*78.5%
Simplified78.5%
Taylor expanded in angle around 0 78.5%
associate-*r*78.5%
*-commutative78.5%
associate-*r*78.5%
associate-*r*78.5%
*-commutative78.5%
associate-*r*78.5%
associate-*r*78.5%
Simplified78.5%
Final simplification78.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (/ (* a 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 * ((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.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.pi) / (180.0 / angle_m)), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(Float64(a * 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 * 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[(N[(a * Pi), $MachinePrecision] / N[(180.0 / angle$95$m), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2} + {\left(\frac{a \cdot \pi}{\frac{180}{angle\_m}}\right)}^{2}
\end{array}
Initial program 83.1%
associate-*l/83.1%
associate-/l*83.1%
cos-neg83.1%
distribute-lft-neg-out83.1%
distribute-frac-neg83.1%
distribute-frac-neg83.1%
distribute-lft-neg-out83.1%
cos-neg83.1%
associate-*l/83.1%
associate-/l*83.1%
Simplified83.1%
Taylor expanded in angle around 0 83.3%
Taylor expanded in angle around inf 83.3%
Taylor expanded in angle around 0 78.5%
*-commutative78.5%
associate-*l*78.5%
Simplified78.5%
associate-*r*78.5%
metadata-eval78.5%
associate-/r/78.5%
associate-*l/78.5%
*-un-lft-identity78.5%
Applied egg-rr78.5%
Final simplification78.5%
herbie shell --seed 2024077
(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)))