
(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}
(FPCore (a b angle) :precision binary64 (fma (* b (/ (+ 1.0 (cos (* 0.011111111111111112 (* angle PI)))) 2.0)) b (pow (* a (sin (* angle (/ PI 180.0)))) 2.0)))
double code(double a, double b, double angle) {
return fma((b * ((1.0 + cos((0.011111111111111112 * (angle * ((double) M_PI))))) / 2.0)), b, pow((a * sin((angle * (((double) M_PI) / 180.0)))), 2.0));
}
function code(a, b, angle) return fma(Float64(b * Float64(Float64(1.0 + cos(Float64(0.011111111111111112 * Float64(angle * pi)))) / 2.0)), b, (Float64(a * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0)) end
code[a_, b_, angle_] := N[(N[(b * N[(N[(1.0 + N[Cos[N[(0.011111111111111112 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] / 2.0), $MachinePrecision]), $MachinePrecision] * b + N[Power[N[(a * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b \cdot \frac{1 + \cos \left(0.011111111111111112 \cdot \left(angle \cdot \pi\right)\right)}{2}, b, {\left(a \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2}\right)
\end{array}
Initial program 82.7%
*-commutative82.7%
clear-num82.7%
un-div-inv82.8%
Applied egg-rr82.8%
Applied egg-rr82.9%
Simplified82.9%
unpow282.9%
cos-mult82.9%
Applied egg-rr82.9%
+-commutative82.9%
+-inverses82.9%
cos-082.9%
distribute-lft-out82.9%
distribute-lft-out82.9%
metadata-eval82.9%
Simplified82.9%
Taylor expanded in angle around inf 82.9%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* angle (/ PI 180.0)))) (+ (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 * (((double) M_PI) / 180.0);
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 * (Math.PI / 180.0);
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 * (math.pi / 180.0) 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(angle * Float64(pi / 180.0)) 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 * (pi / 180.0); tmp = ((a * sin(t_0)) ^ 2.0) + ((b * cos(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(Pi / 180.0), $MachinePrecision]), $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 := angle \cdot \frac{\pi}{180}\\
{\left(a \cdot \sin t\_0\right)}^{2} + {\left(b \cdot \cos t\_0\right)}^{2}
\end{array}
\end{array}
Initial program 82.7%
unpow282.7%
associate-*l/82.7%
associate-/l*82.8%
unpow282.8%
Simplified82.9%
(FPCore (a b angle) :precision binary64 (fma b b (pow (* a (sin (* angle (* PI 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return fma(b, b, pow((a * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0));
}
function code(a, b, angle) return fma(b, b, (Float64(a * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0)) end
code[a_, b_, angle_] := N[(b * b + N[Power[N[(a * N[Sin[N[(angle * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(b, b, {\left(a \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\right)
\end{array}
Initial program 82.7%
unpow282.7%
associate-*l/82.7%
associate-/l*82.8%
unpow282.8%
Simplified82.9%
+-commutative82.9%
associate-*r/82.9%
associate-*l/82.8%
unpow282.8%
*-commutative82.8%
associate-*r*82.8%
associate-*r/82.7%
associate-*l/82.7%
fma-define82.7%
Applied egg-rr82.9%
Taylor expanded in angle around 0 82.3%
(FPCore (a b angle) :precision binary64 (if (<= b 6.2e-84) (pow (* a (sin (* PI (* angle 0.005555555555555556)))) 2.0) (pow (* b (cos (* (* angle PI) 0.005555555555555556))) 2.0)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 6.2e-84) {
tmp = pow((a * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
} else {
tmp = pow((b * cos(((angle * ((double) M_PI)) * 0.005555555555555556))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 6.2e-84) {
tmp = Math.pow((a * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
} else {
tmp = Math.pow((b * Math.cos(((angle * Math.PI) * 0.005555555555555556))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 6.2e-84: tmp = math.pow((a * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0) else: tmp = math.pow((b * math.cos(((angle * math.pi) * 0.005555555555555556))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 6.2e-84) tmp = Float64(a * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0; else tmp = Float64(b * cos(Float64(Float64(angle * pi) * 0.005555555555555556))) ^ 2.0; end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 6.2e-84) tmp = (a * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0; else tmp = (b * cos(((angle * pi) * 0.005555555555555556))) ^ 2.0; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 6.2e-84], N[Power[N[(a * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[Power[N[(b * N[Cos[N[(N[(angle * Pi), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 6.2 \cdot 10^{-84}:\\
\;\;\;\;{\left(a \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(b \cdot \cos \left(\left(angle \cdot \pi\right) \cdot 0.005555555555555556\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 6.20000000000000003e-84Initial program 80.6%
unpow280.6%
associate-*l/80.6%
associate-/l*80.7%
unpow280.7%
Simplified80.8%
Taylor expanded in a around inf 40.8%
unpow240.8%
*-commutative40.8%
associate-*r*40.7%
unpow240.7%
swap-sqr46.8%
unpow246.8%
associate-*r*46.8%
*-commutative46.8%
associate-*r*46.8%
Simplified46.8%
if 6.20000000000000003e-84 < b Initial program 88.4%
unpow288.4%
associate-*l/88.4%
associate-/l*88.4%
unpow288.4%
Simplified88.4%
Taylor expanded in a around 0 79.9%
*-commutative79.9%
associate-*r*79.8%
unpow279.8%
unpow279.8%
swap-sqr79.8%
unpow279.8%
associate-*r*79.9%
*-commutative79.9%
Simplified79.9%
Final simplification55.8%
(FPCore (a b angle) :precision binary64 (if (<= b 2.7e-83) (pow (* a (sin (* PI (* angle 0.005555555555555556)))) 2.0) (* b b)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 2.7e-83) {
tmp = pow((a * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
} else {
tmp = b * b;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 2.7e-83) {
tmp = Math.pow((a * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
} else {
tmp = b * b;
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 2.7e-83: tmp = math.pow((a * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0) else: tmp = b * b return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 2.7e-83) tmp = Float64(a * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0; else tmp = Float64(b * b); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 2.7e-83) tmp = (a * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0; else tmp = b * b; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 2.7e-83], N[Power[N[(a * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(b * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.7 \cdot 10^{-83}:\\
\;\;\;\;{\left(a \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 2.69999999999999991e-83Initial program 80.6%
unpow280.6%
associate-*l/80.6%
associate-/l*80.7%
unpow280.7%
Simplified80.8%
Taylor expanded in a around inf 40.8%
unpow240.8%
*-commutative40.8%
associate-*r*40.7%
unpow240.7%
swap-sqr46.8%
unpow246.8%
associate-*r*46.8%
*-commutative46.8%
associate-*r*46.8%
Simplified46.8%
if 2.69999999999999991e-83 < b Initial program 88.4%
unpow288.4%
associate-*l/88.4%
associate-/l*88.4%
unpow288.4%
Simplified88.4%
Taylor expanded in angle around 0 78.7%
unpow278.7%
Applied egg-rr78.7%
Final simplification55.5%
(FPCore (a b angle) :precision binary64 (if (<= b 4.2e-84) (pow (* a (sin (* (* angle PI) 0.005555555555555556))) 2.0) (* b b)))
double code(double a, double b, double angle) {
double tmp;
if (b <= 4.2e-84) {
tmp = pow((a * sin(((angle * ((double) M_PI)) * 0.005555555555555556))), 2.0);
} else {
tmp = b * b;
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 4.2e-84) {
tmp = Math.pow((a * Math.sin(((angle * Math.PI) * 0.005555555555555556))), 2.0);
} else {
tmp = b * b;
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 4.2e-84: tmp = math.pow((a * math.sin(((angle * math.pi) * 0.005555555555555556))), 2.0) else: tmp = b * b return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 4.2e-84) tmp = Float64(a * sin(Float64(Float64(angle * pi) * 0.005555555555555556))) ^ 2.0; else tmp = Float64(b * b); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 4.2e-84) tmp = (a * sin(((angle * pi) * 0.005555555555555556))) ^ 2.0; else tmp = b * b; end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 4.2e-84], N[Power[N[(a * N[Sin[N[(N[(angle * Pi), $MachinePrecision] * 0.005555555555555556), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(b * b), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.2 \cdot 10^{-84}:\\
\;\;\;\;{\left(a \cdot \sin \left(\left(angle \cdot \pi\right) \cdot 0.005555555555555556\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b\\
\end{array}
\end{array}
if b < 4.19999999999999996e-84Initial program 80.6%
unpow280.6%
associate-*l/80.6%
associate-/l*80.7%
unpow280.7%
Simplified80.8%
Taylor expanded in a around inf 40.8%
unpow240.8%
*-commutative40.8%
associate-*r*40.7%
unpow240.7%
swap-sqr46.8%
unpow246.8%
associate-*r*46.8%
*-commutative46.8%
Simplified46.8%
if 4.19999999999999996e-84 < b Initial program 88.4%
unpow288.4%
associate-*l/88.4%
associate-/l*88.4%
unpow288.4%
Simplified88.4%
Taylor expanded in angle around 0 78.7%
unpow278.7%
Applied egg-rr78.7%
Final simplification55.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 82.7%
unpow282.7%
associate-*l/82.7%
associate-/l*82.8%
unpow282.8%
Simplified82.9%
Taylor expanded in angle around 0 59.3%
unpow259.3%
Applied egg-rr59.3%
herbie shell --seed 2024172
(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)))