
(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 82.9%
associate-*l/82.6%
associate-/l*83.0%
cos-neg83.0%
distribute-lft-neg-out83.0%
distribute-frac-neg83.0%
distribute-frac-neg83.0%
distribute-lft-neg-out83.0%
cos-neg83.0%
associate-*l/82.5%
associate-/l*82.9%
Simplified82.9%
Taylor expanded in angle around 0 83.0%
Taylor expanded in angle around inf 82.6%
*-commutative82.6%
*-commutative82.6%
associate-*l*83.0%
*-commutative83.0%
Simplified83.0%
expm1-log1p-u64.0%
expm1-undefine56.7%
Applied egg-rr56.7%
expm1-define64.0%
Simplified64.0%
Final simplification64.0%
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 82.9%
associate-*l/82.6%
associate-/l*83.0%
cos-neg83.0%
distribute-lft-neg-out83.0%
distribute-frac-neg83.0%
distribute-frac-neg83.0%
distribute-lft-neg-out83.0%
cos-neg83.0%
associate-*l/82.5%
associate-/l*82.9%
Simplified82.9%
Taylor expanded in angle around 0 83.0%
Taylor expanded in angle around inf 82.6%
Final simplification82.6%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow b 2.0) (pow (* a (sin (* angle_m (/ PI 180.0)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(b, 2.0) + pow((a * sin((angle_m * (((double) M_PI) / 180.0)))), 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((angle_m * (Math.PI / 180.0)))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(b, 2.0) + math.pow((a * math.sin((angle_m * (math.pi / 180.0)))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((b ^ 2.0) + (Float64(a * sin(Float64(angle_m * Float64(pi / 180.0)))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (b ^ 2.0) + ((a * sin((angle_m * (pi / 180.0)))) ^ 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[(angle$95$m * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2} + {\left(a \cdot \sin \left(angle\_m \cdot \frac{\pi}{180}\right)\right)}^{2}
\end{array}
Initial program 82.9%
associate-*l/82.6%
associate-/l*83.0%
cos-neg83.0%
distribute-lft-neg-out83.0%
distribute-frac-neg83.0%
distribute-frac-neg83.0%
distribute-lft-neg-out83.0%
cos-neg83.0%
associate-*l/82.5%
associate-/l*82.9%
Simplified82.9%
Taylor expanded in angle around 0 83.0%
Final simplification83.0%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 6.3e-62)
(pow b 2.0)
(+
(pow b 2.0)
(*
(* PI 0.005555555555555556)
(* (* (* 0.005555555555555556 angle_m) (* a PI)) (* a angle_m))))))angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double tmp;
if (a <= 6.3e-62) {
tmp = pow(b, 2.0);
} else {
tmp = pow(b, 2.0) + ((((double) M_PI) * 0.005555555555555556) * (((0.005555555555555556 * angle_m) * (a * ((double) M_PI))) * (a * angle_m)));
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double tmp;
if (a <= 6.3e-62) {
tmp = Math.pow(b, 2.0);
} else {
tmp = Math.pow(b, 2.0) + ((Math.PI * 0.005555555555555556) * (((0.005555555555555556 * angle_m) * (a * Math.PI)) * (a * angle_m)));
}
return tmp;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): tmp = 0 if a <= 6.3e-62: tmp = math.pow(b, 2.0) else: tmp = math.pow(b, 2.0) + ((math.pi * 0.005555555555555556) * (((0.005555555555555556 * angle_m) * (a * math.pi)) * (a * angle_m))) return tmp
angle_m = abs(angle) function code(a, b, angle_m) tmp = 0.0 if (a <= 6.3e-62) tmp = b ^ 2.0; else tmp = Float64((b ^ 2.0) + Float64(Float64(pi * 0.005555555555555556) * Float64(Float64(Float64(0.005555555555555556 * angle_m) * Float64(a * pi)) * Float64(a * angle_m)))); end return tmp end
angle_m = abs(angle); function tmp_2 = code(a, b, angle_m) tmp = 0.0; if (a <= 6.3e-62) tmp = b ^ 2.0; else tmp = (b ^ 2.0) + ((pi * 0.005555555555555556) * (((0.005555555555555556 * angle_m) * (a * pi)) * (a * angle_m))); end tmp_2 = tmp; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := If[LessEqual[a, 6.3e-62], N[Power[b, 2.0], $MachinePrecision], N[(N[Power[b, 2.0], $MachinePrecision] + N[(N[(Pi * 0.005555555555555556), $MachinePrecision] * N[(N[(N[(0.005555555555555556 * angle$95$m), $MachinePrecision] * N[(a * Pi), $MachinePrecision]), $MachinePrecision] * N[(a * angle$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 6.3 \cdot 10^{-62}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2} + \left(\pi \cdot 0.005555555555555556\right) \cdot \left(\left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \left(a \cdot \pi\right)\right) \cdot \left(a \cdot angle\_m\right)\right)\\
\end{array}
\end{array}
if a < 6.2999999999999997e-62Initial program 82.6%
associate-*l/82.2%
associate-/l*82.6%
cos-neg82.6%
distribute-lft-neg-out82.6%
distribute-frac-neg82.6%
distribute-frac-neg82.6%
distribute-lft-neg-out82.6%
cos-neg82.6%
associate-*l/81.9%
associate-/l*82.6%
Simplified82.6%
Taylor expanded in angle around 0 82.6%
Taylor expanded in angle around 0 77.0%
*-commutative77.0%
*-commutative77.0%
associate-*l*77.0%
Simplified77.0%
Taylor expanded in angle around 0 70.6%
if 6.2999999999999997e-62 < a Initial program 83.7%
associate-*l/83.7%
associate-/l*83.9%
cos-neg83.9%
distribute-lft-neg-out83.9%
distribute-frac-neg83.9%
distribute-frac-neg83.9%
distribute-lft-neg-out83.9%
cos-neg83.9%
associate-*l/83.9%
associate-/l*83.9%
Simplified83.9%
Taylor expanded in angle around 0 84.0%
Taylor expanded in angle around 0 79.2%
*-commutative79.2%
*-commutative79.2%
associate-*l*79.1%
Simplified79.1%
unpow279.1%
associate-*r*79.2%
*-commutative79.2%
associate-*l*79.2%
*-commutative79.2%
associate-*l*79.2%
associate-*r*79.2%
associate-*l*79.2%
Applied egg-rr79.2%
Final simplification73.1%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(if (<= a 2.9e-62)
(pow b 2.0)
(+
(pow b 2.0)
(*
(* PI (* (* 0.005555555555555556 angle_m) (* a PI)))
(* 0.005555555555555556 (* a angle_m))))))angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double tmp;
if (a <= 2.9e-62) {
tmp = pow(b, 2.0);
} else {
tmp = pow(b, 2.0) + ((((double) M_PI) * ((0.005555555555555556 * angle_m) * (a * ((double) M_PI)))) * (0.005555555555555556 * (a * angle_m)));
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double tmp;
if (a <= 2.9e-62) {
tmp = Math.pow(b, 2.0);
} else {
tmp = Math.pow(b, 2.0) + ((Math.PI * ((0.005555555555555556 * angle_m) * (a * Math.PI))) * (0.005555555555555556 * (a * angle_m)));
}
return tmp;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): tmp = 0 if a <= 2.9e-62: tmp = math.pow(b, 2.0) else: tmp = math.pow(b, 2.0) + ((math.pi * ((0.005555555555555556 * angle_m) * (a * math.pi))) * (0.005555555555555556 * (a * angle_m))) return tmp
angle_m = abs(angle) function code(a, b, angle_m) tmp = 0.0 if (a <= 2.9e-62) tmp = b ^ 2.0; else tmp = Float64((b ^ 2.0) + Float64(Float64(pi * Float64(Float64(0.005555555555555556 * angle_m) * Float64(a * pi))) * Float64(0.005555555555555556 * Float64(a * angle_m)))); end return tmp end
angle_m = abs(angle); function tmp_2 = code(a, b, angle_m) tmp = 0.0; if (a <= 2.9e-62) tmp = b ^ 2.0; else tmp = (b ^ 2.0) + ((pi * ((0.005555555555555556 * angle_m) * (a * pi))) * (0.005555555555555556 * (a * angle_m))); end tmp_2 = tmp; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := If[LessEqual[a, 2.9e-62], N[Power[b, 2.0], $MachinePrecision], N[(N[Power[b, 2.0], $MachinePrecision] + N[(N[(Pi * N[(N[(0.005555555555555556 * angle$95$m), $MachinePrecision] * N[(a * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * N[(0.005555555555555556 * N[(a * angle$95$m), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.9 \cdot 10^{-62}:\\
\;\;\;\;{b}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2} + \left(\pi \cdot \left(\left(0.005555555555555556 \cdot angle\_m\right) \cdot \left(a \cdot \pi\right)\right)\right) \cdot \left(0.005555555555555556 \cdot \left(a \cdot angle\_m\right)\right)\\
\end{array}
\end{array}
if a < 2.89999999999999986e-62Initial program 82.6%
associate-*l/82.2%
associate-/l*82.6%
cos-neg82.6%
distribute-lft-neg-out82.6%
distribute-frac-neg82.6%
distribute-frac-neg82.6%
distribute-lft-neg-out82.6%
cos-neg82.6%
associate-*l/81.9%
associate-/l*82.6%
Simplified82.6%
Taylor expanded in angle around 0 82.6%
Taylor expanded in angle around 0 77.0%
*-commutative77.0%
*-commutative77.0%
associate-*l*77.0%
Simplified77.0%
Taylor expanded in angle around 0 70.6%
if 2.89999999999999986e-62 < a Initial program 83.7%
associate-*l/83.7%
associate-/l*83.9%
cos-neg83.9%
distribute-lft-neg-out83.9%
distribute-frac-neg83.9%
distribute-frac-neg83.9%
distribute-lft-neg-out83.9%
cos-neg83.9%
associate-*l/83.9%
associate-/l*83.9%
Simplified83.9%
Taylor expanded in angle around 0 84.0%
Taylor expanded in angle around 0 79.2%
*-commutative79.2%
*-commutative79.2%
associate-*l*79.1%
Simplified79.1%
unpow279.1%
*-commutative79.1%
associate-*l*79.2%
*-commutative79.2%
associate-*r*79.2%
*-commutative79.2%
associate-*l*79.2%
associate-*r*79.2%
associate-*l*79.3%
Applied egg-rr79.3%
Final simplification73.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (pow b 2.0))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(b, 2.0);
}
angle_m = abs(angle)
real(8) function code(a, b, angle_m)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle_m
code = b ** 2.0d0
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(b, 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(b, 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return b ^ 2.0 end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = b ^ 2.0; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[Power[b, 2.0], $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{b}^{2}
\end{array}
Initial program 82.9%
associate-*l/82.6%
associate-/l*83.0%
cos-neg83.0%
distribute-lft-neg-out83.0%
distribute-frac-neg83.0%
distribute-frac-neg83.0%
distribute-lft-neg-out83.0%
cos-neg83.0%
associate-*l/82.5%
associate-/l*82.9%
Simplified82.9%
Taylor expanded in angle around 0 83.0%
Taylor expanded in angle around 0 77.6%
*-commutative77.6%
*-commutative77.6%
associate-*l*77.6%
Simplified77.6%
Taylor expanded in angle around 0 64.2%
Final simplification64.2%
herbie shell --seed 2024046
(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)))