
(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}
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* angle (/ PI 180.0)))) 2.0) (pow b 2.0)))
double code(double a, double b, double angle) {
return pow((a * sin((angle * (((double) M_PI) / 180.0)))), 2.0) + pow(b, 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((angle * (Math.PI / 180.0)))), 2.0) + Math.pow(b, 2.0);
}
def code(a, b, angle): return math.pow((a * math.sin((angle * (math.pi / 180.0)))), 2.0) + math.pow(b, 2.0)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0) + (b ^ 2.0)) end
function tmp = code(a, b, angle) tmp = ((a * sin((angle * (pi / 180.0)))) ^ 2.0) + (b ^ 2.0); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 76.1%
associate-*l/76.0%
associate-/l*76.1%
cos-neg76.1%
distribute-lft-neg-out76.1%
distribute-frac-neg76.1%
distribute-frac-neg76.1%
distribute-lft-neg-out76.1%
cos-neg76.1%
associate-*l/76.1%
associate-/l*76.1%
Simplified76.1%
Taylor expanded in angle around 0 76.8%
Taylor expanded in b around 0 76.8%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* angle (* PI 0.005555555555555556))))
(if (<= b 2e-160)
(pow (* a (sin t_0)) 2.0)
(+ (pow b 2.0) (pow (* a t_0) 2.0)))))
double code(double a, double b, double angle) {
double t_0 = angle * (((double) M_PI) * 0.005555555555555556);
double tmp;
if (b <= 2e-160) {
tmp = pow((a * sin(t_0)), 2.0);
} else {
tmp = pow(b, 2.0) + pow((a * t_0), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (Math.PI * 0.005555555555555556);
double tmp;
if (b <= 2e-160) {
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;
}
def code(a, b, angle): t_0 = angle * (math.pi * 0.005555555555555556) tmp = 0 if b <= 2e-160: 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
function code(a, b, angle) t_0 = Float64(angle * Float64(pi * 0.005555555555555556)) tmp = 0.0 if (b <= 2e-160) tmp = Float64(a * sin(t_0)) ^ 2.0; else tmp = Float64((b ^ 2.0) + (Float64(a * t_0) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = angle * (pi * 0.005555555555555556); tmp = 0.0; if (b <= 2e-160) tmp = (a * sin(t_0)) ^ 2.0; else tmp = (b ^ 2.0) + ((a * t_0) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 2e-160], 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}
\\
\begin{array}{l}
t_0 := angle \cdot \left(\pi \cdot 0.005555555555555556\right)\\
\mathbf{if}\;b \leq 2 \cdot 10^{-160}:\\
\;\;\;\;{\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 < 2e-160Initial program 76.2%
associate-*l/76.1%
associate-/l*76.3%
cos-neg76.3%
distribute-lft-neg-out76.3%
distribute-frac-neg76.3%
distribute-frac-neg76.3%
distribute-lft-neg-out76.3%
cos-neg76.3%
associate-*l/76.3%
associate-/l*76.3%
Simplified76.3%
Applied egg-rr75.2%
Taylor expanded in b around 0 30.6%
log1p-define35.4%
unpow235.4%
*-commutative35.4%
*-commutative35.4%
associate-*r*35.2%
unpow235.2%
swap-sqr41.4%
unpow241.4%
Simplified41.4%
Applied egg-rr41.9%
if 2e-160 < b Initial program 75.8%
associate-*l/75.8%
associate-/l*75.9%
cos-neg75.9%
distribute-lft-neg-out75.9%
distribute-frac-neg75.9%
distribute-frac-neg75.9%
distribute-lft-neg-out75.9%
cos-neg75.9%
associate-*l/75.7%
associate-/l*75.8%
Simplified75.8%
Taylor expanded in angle around 0 75.3%
Taylor expanded in b around 0 75.3%
Taylor expanded in angle around 0 71.9%
*-commutative71.9%
associate-*r*71.9%
Simplified71.9%
Final simplification53.4%
(FPCore (a b angle) :precision binary64 (if (<= b 2.05e-160) (pow (* a (sin (* angle (* PI 0.005555555555555556)))) 2.0) (+ (* b b) (pow (* 0.005555555555555556 (* a (* angle PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 2.05e-160) {
tmp = pow((a * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
} else {
tmp = (b * b) + pow((0.005555555555555556 * (a * (angle * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 2.05e-160) {
tmp = Math.pow((a * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
} else {
tmp = (b * b) + Math.pow((0.005555555555555556 * (a * (angle * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 2.05e-160: tmp = math.pow((a * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0) else: tmp = (b * b) + math.pow((0.005555555555555556 * (a * (angle * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 2.05e-160) tmp = Float64(a * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0; else tmp = Float64(Float64(b * b) + (Float64(0.005555555555555556 * Float64(a * Float64(angle * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 2.05e-160) tmp = (a * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0; else tmp = (b * b) + ((0.005555555555555556 * (a * (angle * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 2.05e-160], N[Power[N[(a * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.05 \cdot 10^{-160}:\\
\;\;\;\;{\left(a \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(0.005555555555555556 \cdot \left(a \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 2.05000000000000001e-160Initial program 76.2%
associate-*l/76.1%
associate-/l*76.3%
cos-neg76.3%
distribute-lft-neg-out76.3%
distribute-frac-neg76.3%
distribute-frac-neg76.3%
distribute-lft-neg-out76.3%
cos-neg76.3%
associate-*l/76.3%
associate-/l*76.3%
Simplified76.3%
Applied egg-rr75.2%
Taylor expanded in b around 0 30.6%
log1p-define35.4%
unpow235.4%
*-commutative35.4%
*-commutative35.4%
associate-*r*35.2%
unpow235.2%
swap-sqr41.4%
unpow241.4%
Simplified41.4%
Applied egg-rr41.9%
if 2.05000000000000001e-160 < b Initial program 75.8%
associate-*l/75.8%
associate-/l*75.9%
cos-neg75.9%
distribute-lft-neg-out75.9%
distribute-frac-neg75.9%
distribute-frac-neg75.9%
distribute-lft-neg-out75.9%
cos-neg75.9%
associate-*l/75.7%
associate-/l*75.8%
Simplified75.8%
Taylor expanded in angle around 0 75.3%
associate-*r/75.3%
associate-*l/75.3%
log1p-expm1-u75.3%
associate-*l/75.3%
associate-*r/75.3%
div-inv75.3%
metadata-eval75.3%
Applied egg-rr75.3%
*-rgt-identity75.3%
pow275.3%
Applied egg-rr75.3%
Taylor expanded in angle around 0 71.9%
Final simplification53.4%
(FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (* 0.005555555555555556 (* angle PI)))) 2.0) (* b b)))
double code(double a, double b, double angle) {
return pow((a * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0) + (b * b);
}
def code(a, b, angle): return math.pow((a * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) + (b * b)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0) + Float64(b * b)) end
function tmp = code(a, b, angle) tmp = ((a * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0) + (b * b); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 76.1%
associate-*l/76.0%
associate-/l*76.1%
cos-neg76.1%
distribute-lft-neg-out76.1%
distribute-frac-neg76.1%
distribute-frac-neg76.1%
distribute-lft-neg-out76.1%
cos-neg76.1%
associate-*l/76.1%
associate-/l*76.1%
Simplified76.1%
Taylor expanded in angle around 0 76.8%
associate-*r/76.7%
associate-*l/76.7%
log1p-expm1-u76.7%
associate-*l/76.7%
associate-*r/76.8%
div-inv76.8%
metadata-eval76.8%
Applied egg-rr76.8%
*-rgt-identity76.8%
pow276.8%
Applied egg-rr76.8%
Taylor expanded in a around 0 76.8%
(FPCore (a b angle) :precision binary64 (if (<= a 2.6e-84) (* b b) (+ (* b b) (pow (* 0.005555555555555556 (* a (* angle PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.6e-84) {
tmp = b * b;
} else {
tmp = (b * b) + pow((0.005555555555555556 * (a * (angle * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.6e-84) {
tmp = b * b;
} else {
tmp = (b * b) + Math.pow((0.005555555555555556 * (a * (angle * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 2.6e-84: tmp = b * b else: tmp = (b * b) + math.pow((0.005555555555555556 * (a * (angle * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 2.6e-84) tmp = Float64(b * b); else tmp = Float64(Float64(b * b) + (Float64(0.005555555555555556 * Float64(a * Float64(angle * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 2.6e-84) tmp = b * b; else tmp = (b * b) + ((0.005555555555555556 * (a * (angle * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 2.6e-84], N[(b * b), $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(a * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.6 \cdot 10^{-84}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(0.005555555555555556 \cdot \left(a \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 2.6e-84Initial program 74.5%
associate-*l/74.5%
associate-/l*74.6%
cos-neg74.6%
distribute-lft-neg-out74.6%
distribute-frac-neg74.6%
distribute-frac-neg74.6%
distribute-lft-neg-out74.6%
cos-neg74.6%
associate-*l/74.5%
associate-/l*74.6%
Simplified74.6%
Taylor expanded in angle around 0 57.7%
unpow257.7%
Applied egg-rr57.7%
if 2.6e-84 < a Initial program 78.9%
associate-*l/78.8%
associate-/l*79.0%
cos-neg79.0%
distribute-lft-neg-out79.0%
distribute-frac-neg79.0%
distribute-frac-neg79.0%
distribute-lft-neg-out79.0%
cos-neg79.0%
associate-*l/79.0%
associate-/l*79.0%
Simplified79.0%
Taylor expanded in angle around 0 78.2%
associate-*r/78.0%
associate-*l/78.2%
log1p-expm1-u78.2%
associate-*l/78.0%
associate-*r/78.2%
div-inv78.2%
metadata-eval78.2%
Applied egg-rr78.2%
*-rgt-identity78.2%
pow278.2%
Applied egg-rr78.2%
Taylor expanded in angle around 0 74.5%
Final simplification63.5%
(FPCore (a b angle) :precision binary64 (* b b))
double code(double a, double b, double angle) {
return b * b;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = b * b
end function
public static double code(double a, double b, double angle) {
return b * b;
}
def code(a, b, angle): return b * b
function code(a, b, angle) return Float64(b * b) end
function tmp = code(a, b, angle) tmp = b * b; end
code[a_, b_, angle_] := N[(b * b), $MachinePrecision]
\begin{array}{l}
\\
b \cdot b
\end{array}
Initial program 76.1%
associate-*l/76.0%
associate-/l*76.1%
cos-neg76.1%
distribute-lft-neg-out76.1%
distribute-frac-neg76.1%
distribute-frac-neg76.1%
distribute-lft-neg-out76.1%
cos-neg76.1%
associate-*l/76.1%
associate-/l*76.1%
Simplified76.1%
Taylor expanded in angle around 0 53.1%
unpow253.1%
Applied egg-rr53.1%
herbie shell --seed 2024114
(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)))