
(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 7 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 (/ 180.0 angle_m)))) 2.0) (pow (* b (cos (expm1 (log1p (* PI (* angle_m 0.005555555555555556)))))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow((a * sin((((double) M_PI) / (180.0 / angle_m)))), 2.0) + pow((b * cos(expm1(log1p((((double) M_PI) * (angle_m * 0.005555555555555556)))))), 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 / (180.0 / angle_m)))), 2.0) + Math.pow((b * Math.cos(Math.expm1(Math.log1p((Math.PI * (angle_m * 0.005555555555555556)))))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow((a * math.sin((math.pi / (180.0 / angle_m)))), 2.0) + math.pow((b * math.cos(math.expm1(math.log1p((math.pi * (angle_m * 0.005555555555555556)))))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((Float64(a * sin(Float64(pi / Float64(180.0 / angle_m)))) ^ 2.0) + (Float64(b * cos(expm1(log1p(Float64(pi * Float64(angle_m * 0.005555555555555556)))))) ^ 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[(180.0 / angle$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Cos[N[(Exp[N[Log[1 + N[(Pi * N[(angle$95$m * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(a \cdot \sin \left(\frac{\pi}{\frac{180}{angle\_m}}\right)\right)}^{2} + {\left(b \cdot \cos \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\pi \cdot \left(angle\_m \cdot 0.005555555555555556\right)\right)\right)\right)\right)}^{2}
\end{array}
Initial program 77.7%
*-commutative77.7%
clear-num77.8%
un-div-inv77.8%
Applied egg-rr77.8%
expm1-log1p-u64.1%
expm1-undefine64.0%
associate-*l/64.0%
associate-*r/64.0%
div-inv64.0%
metadata-eval64.0%
Applied egg-rr64.0%
expm1-define64.1%
associate-*r*64.1%
*-commutative64.1%
associate-*r*64.1%
Simplified64.1%
Final simplification64.1%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow (* a (sin (/ PI (/ 180.0 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) / (180.0 / 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 / (180.0 / 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 / (180.0 / 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 / Float64(180.0 / angle_m)))) ^ 2.0) + (b ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = ((a * sin((pi / (180.0 / 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[(180.0 / angle$95$m), $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(\frac{\pi}{\frac{180}{angle\_m}}\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 77.7%
*-commutative77.7%
clear-num77.8%
un-div-inv77.8%
Applied egg-rr77.8%
expm1-log1p-u64.1%
expm1-undefine64.0%
associate-*l/64.0%
associate-*r/64.0%
div-inv64.0%
metadata-eval64.0%
Applied egg-rr64.0%
expm1-define64.1%
associate-*r*64.1%
*-commutative64.1%
associate-*r*64.1%
Simplified64.1%
Taylor expanded in angle around 0 77.9%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (pow (hypot b (* a (sin (* angle_m (* PI 0.005555555555555556))))) 2.0))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(hypot(b, (a * sin((angle_m * (((double) M_PI) * 0.005555555555555556))))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(Math.hypot(b, (a * Math.sin((angle_m * (Math.PI * 0.005555555555555556))))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(math.hypot(b, (a * math.sin((angle_m * (math.pi * 0.005555555555555556))))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return hypot(b, Float64(a * sin(Float64(angle_m * Float64(pi * 0.005555555555555556))))) ^ 2.0 end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = hypot(b, (a * sin((angle_m * (pi * 0.005555555555555556))))) ^ 2.0; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[Power[N[Sqrt[b ^ 2 + N[(a * N[Sin[N[(angle$95$m * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{\left(\mathsf{hypot}\left(b, a \cdot \sin \left(angle\_m \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)\right)}^{2}
\end{array}
Initial program 77.7%
*-commutative77.7%
clear-num77.8%
un-div-inv77.8%
Applied egg-rr77.8%
expm1-log1p-u64.1%
expm1-undefine64.0%
associate-*l/64.0%
associate-*r/64.0%
div-inv64.0%
metadata-eval64.0%
Applied egg-rr64.0%
expm1-define64.1%
associate-*r*64.1%
*-commutative64.1%
associate-*r*64.1%
Simplified64.1%
Taylor expanded in angle around 0 77.9%
Taylor expanded in a around 0 70.9%
+-commutative70.9%
unpow270.9%
unpow270.9%
unpow270.9%
swap-sqr77.7%
unpow277.7%
*-commutative77.7%
*-commutative77.7%
associate-*r*77.8%
unpow277.8%
rem-square-sqrt77.8%
Simplified77.8%
Final simplification77.8%
angle_m = (fabs.f64 angle)
(FPCore (a b angle_m)
:precision binary64
(let* ((t_0 (* 0.005555555555555556 (* PI angle_m))))
(if (<= b 1.2e-153)
(pow (* a (sin t_0)) 2.0)
(+ (pow b 2.0) (pow (* a t_0) 2.0)))))angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double t_0 = 0.005555555555555556 * (((double) M_PI) * angle_m);
double tmp;
if (b <= 1.2e-153) {
tmp = pow((a * sin(t_0)), 2.0);
} else {
tmp = pow(b, 2.0) + pow((a * t_0), 2.0);
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double t_0 = 0.005555555555555556 * (Math.PI * angle_m);
double tmp;
if (b <= 1.2e-153) {
tmp = Math.pow((a * Math.sin(t_0)), 2.0);
} else {
tmp = Math.pow(b, 2.0) + Math.pow((a * t_0), 2.0);
}
return tmp;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): t_0 = 0.005555555555555556 * (math.pi * angle_m) tmp = 0 if b <= 1.2e-153: tmp = math.pow((a * math.sin(t_0)), 2.0) else: tmp = math.pow(b, 2.0) + math.pow((a * t_0), 2.0) return tmp
angle_m = abs(angle) function code(a, b, angle_m) t_0 = Float64(0.005555555555555556 * Float64(pi * angle_m)) tmp = 0.0 if (b <= 1.2e-153) tmp = Float64(a * sin(t_0)) ^ 2.0; else tmp = Float64((b ^ 2.0) + (Float64(a * t_0) ^ 2.0)); end return tmp end
angle_m = abs(angle); function tmp_2 = code(a, b, angle_m) t_0 = 0.005555555555555556 * (pi * angle_m); tmp = 0.0; if (b <= 1.2e-153) tmp = (a * sin(t_0)) ^ 2.0; else tmp = (b ^ 2.0) + ((a * t_0) ^ 2.0); end tmp_2 = tmp; end
angle_m = N[Abs[angle], $MachinePrecision]
code[a_, b_, angle$95$m_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(Pi * angle$95$m), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.2e-153], N[Power[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[Power[b, 2.0], $MachinePrecision] + N[Power[N[(a * t$95$0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(\pi \cdot angle\_m\right)\\
\mathbf{if}\;b \leq 1.2 \cdot 10^{-153}:\\
\;\;\;\;{\left(a \cdot \sin t\_0\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{b}^{2} + {\left(a \cdot t\_0\right)}^{2}\\
\end{array}
\end{array}
if b < 1.2000000000000001e-153Initial program 76.4%
unpow276.4%
associate-*l/76.5%
associate-/l*76.5%
unpow276.5%
Simplified76.4%
Taylor expanded in a around inf 39.0%
unpow239.0%
*-commutative39.0%
associate-*r*39.0%
unpow239.0%
swap-sqr44.7%
unpow244.7%
associate-*r*44.8%
*-commutative44.8%
Simplified44.8%
if 1.2000000000000001e-153 < b Initial program 80.1%
*-commutative80.1%
clear-num80.4%
un-div-inv80.3%
Applied egg-rr80.3%
expm1-log1p-u61.9%
expm1-undefine61.8%
associate-*l/61.8%
associate-*r/61.8%
div-inv61.8%
metadata-eval61.8%
Applied egg-rr61.8%
expm1-define61.9%
associate-*r*61.9%
*-commutative61.9%
associate-*r*61.9%
Simplified61.9%
Taylor expanded in angle around 0 80.9%
Taylor expanded in angle around 0 77.7%
Final simplification56.0%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 1.65e+155) (* b b) (pow (* a (sin (* 0.005555555555555556 (* PI angle_m)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double tmp;
if (a <= 1.65e+155) {
tmp = b * b;
} else {
tmp = pow((a * sin((0.005555555555555556 * (((double) M_PI) * angle_m)))), 2.0);
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double tmp;
if (a <= 1.65e+155) {
tmp = b * b;
} else {
tmp = Math.pow((a * Math.sin((0.005555555555555556 * (Math.PI * angle_m)))), 2.0);
}
return tmp;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): tmp = 0 if a <= 1.65e+155: tmp = b * b else: tmp = math.pow((a * math.sin((0.005555555555555556 * (math.pi * angle_m)))), 2.0) return tmp
angle_m = abs(angle) function code(a, b, angle_m) tmp = 0.0 if (a <= 1.65e+155) tmp = Float64(b * b); else tmp = Float64(a * sin(Float64(0.005555555555555556 * Float64(pi * angle_m)))) ^ 2.0; end return tmp end
angle_m = abs(angle); function tmp_2 = code(a, b, angle_m) tmp = 0.0; if (a <= 1.65e+155) tmp = b * b; else tmp = (a * sin((0.005555555555555556 * (pi * angle_m)))) ^ 2.0; end tmp_2 = tmp; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := If[LessEqual[a, 1.65e+155], N[(b * b), $MachinePrecision], N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(Pi * angle$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.65 \cdot 10^{+155}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle\_m\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.6499999999999999e155Initial program 74.7%
unpow274.7%
associate-*l/74.7%
associate-/l*74.8%
unpow274.8%
Simplified74.7%
Taylor expanded in angle around 0 62.8%
unpow262.8%
Applied egg-rr62.8%
if 1.6499999999999999e155 < a Initial program 99.8%
unpow299.8%
associate-*l/99.8%
associate-/l*99.8%
unpow299.8%
Simplified99.8%
Taylor expanded in a around inf 80.2%
unpow280.2%
*-commutative80.2%
associate-*r*80.2%
unpow280.2%
swap-sqr94.9%
unpow294.9%
associate-*r*94.9%
*-commutative94.9%
Simplified94.9%
Final simplification66.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= a 3.85e+155) (* b b) (cbrt (pow b 6.0))))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double tmp;
if (a <= 3.85e+155) {
tmp = b * b;
} else {
tmp = cbrt(pow(b, 6.0));
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double tmp;
if (a <= 3.85e+155) {
tmp = b * b;
} else {
tmp = Math.cbrt(Math.pow(b, 6.0));
}
return tmp;
}
angle_m = abs(angle) function code(a, b, angle_m) tmp = 0.0 if (a <= 3.85e+155) tmp = Float64(b * b); else tmp = cbrt((b ^ 6.0)); end return tmp end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := If[LessEqual[a, 3.85e+155], N[(b * b), $MachinePrecision], N[Power[N[Power[b, 6.0], $MachinePrecision], 1/3], $MachinePrecision]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;a \leq 3.85 \cdot 10^{+155}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;\sqrt[3]{{b}^{6}}\\
\end{array}
\end{array}
if a < 3.8500000000000002e155Initial program 74.8%
unpow274.8%
associate-*l/74.8%
associate-/l*74.9%
unpow274.9%
Simplified74.9%
Taylor expanded in angle around 0 62.5%
unpow262.5%
Applied egg-rr62.5%
if 3.8500000000000002e155 < a Initial program 99.8%
*-commutative99.8%
clear-num99.8%
un-div-inv99.8%
Applied egg-rr99.8%
Applied egg-rr87.0%
Taylor expanded in angle around 0 26.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (* b b))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return b * b;
}
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 * b
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return b * b;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return b * b
angle_m = abs(angle) function code(a, b, angle_m) return Float64(b * b) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = b * b; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
b \cdot b
\end{array}
Initial program 77.7%
unpow277.7%
associate-*l/77.7%
associate-/l*77.7%
unpow277.7%
Simplified77.7%
Taylor expanded in angle around 0 57.0%
unpow257.0%
Applied egg-rr57.0%
herbie shell --seed 2024169
(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)))