
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* PI (/ angle 180.0)))) (+ (pow (* a (cos t_0)) 2.0) (pow (* b (sin t_0)) 2.0))))
double code(double a, double b, double angle) {
double t_0 = ((double) M_PI) * (angle / 180.0);
return pow((a * cos(t_0)), 2.0) + pow((b * sin(t_0)), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = Math.PI * (angle / 180.0);
return Math.pow((a * Math.cos(t_0)), 2.0) + Math.pow((b * Math.sin(t_0)), 2.0);
}
def code(a, b, angle): t_0 = math.pi * (angle / 180.0) return math.pow((a * math.cos(t_0)), 2.0) + math.pow((b * math.sin(t_0)), 2.0)
function code(a, b, angle) t_0 = Float64(pi * Float64(angle / 180.0)) return Float64((Float64(a * cos(t_0)) ^ 2.0) + (Float64(b * sin(t_0)) ^ 2.0)) end
function tmp = code(a, b, angle) t_0 = pi * (angle / 180.0); tmp = ((a * cos(t_0)) ^ 2.0) + ((b * sin(t_0)) ^ 2.0); end
code[a_, b_, angle_] := Block[{t$95$0 = N[(Pi * N[(angle / 180.0), $MachinePrecision]), $MachinePrecision]}, N[(N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \pi \cdot \frac{angle}{180}\\
{\left(a \cdot \cos t\_0\right)}^{2} + {\left(b \cdot \sin t\_0\right)}^{2}
\end{array}
\end{array}
(FPCore (a b angle) :precision binary64 (fma a a (pow (* b (sin (* angle (* 0.005555555555555556 PI)))) 2.0)))
double code(double a, double b, double angle) {
return fma(a, a, pow((b * sin((angle * (0.005555555555555556 * ((double) M_PI))))), 2.0));
}
function code(a, b, angle) return fma(a, a, (Float64(b * sin(Float64(angle * Float64(0.005555555555555556 * pi)))) ^ 2.0)) end
code[a_, b_, angle_] := N[(a * a + N[Power[N[(b * N[Sin[N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(a, a, {\left(b \cdot \sin \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)}^{2}\right)
\end{array}
Initial program 80.5%
Simplified80.5%
Taylor expanded in angle around 0 80.6%
unpow280.6%
fma-define80.6%
add-sqr-sqrt80.6%
pow280.6%
sqrt-pow180.6%
metadata-eval80.6%
pow180.6%
*-commutative80.6%
associate-*r*80.6%
Applied egg-rr80.6%
(FPCore (a b angle) :precision binary64 (if (<= a 2.8e-160) (pow (* b (sin (* 0.005555555555555556 (* angle PI)))) 2.0) (+ (* a a) (pow (* b (* angle (* 0.005555555555555556 PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 2.8e-160) {
tmp = pow((b * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
} else {
tmp = (a * a) + pow((b * (angle * (0.005555555555555556 * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 2.8e-160) {
tmp = Math.pow((b * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
} else {
tmp = (a * a) + Math.pow((b * (angle * (0.005555555555555556 * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 2.8e-160: tmp = math.pow((b * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) else: tmp = (a * a) + math.pow((b * (angle * (0.005555555555555556 * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 2.8e-160) tmp = Float64(b * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; else tmp = Float64(Float64(a * a) + (Float64(b * Float64(angle * Float64(0.005555555555555556 * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 2.8e-160) tmp = (b * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0; else tmp = (a * a) + ((b * (angle * (0.005555555555555556 * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 2.8e-160], N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 2.8 \cdot 10^{-160}:\\
\;\;\;\;{\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(b \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 2.80000000000000016e-160Initial program 80.7%
Simplified80.7%
Taylor expanded in angle around 0 80.8%
Taylor expanded in a around 0 44.7%
unpow244.7%
*-commutative44.7%
associate-*l*44.7%
*-commutative44.7%
unpow244.7%
swap-sqr51.0%
unpow251.0%
*-commutative51.0%
associate-*l*51.0%
*-commutative51.0%
Simplified51.0%
if 2.80000000000000016e-160 < a Initial program 80.1%
Simplified80.2%
Taylor expanded in angle around 0 80.3%
unpow280.3%
Applied egg-rr80.3%
Taylor expanded in angle around 0 77.9%
associate-*r*77.9%
*-commutative77.9%
associate-*r*77.9%
*-commutative77.9%
Simplified77.9%
Final simplification61.2%
(FPCore (a b angle)
:precision binary64
(let* ((t_0 (* angle (* 0.005555555555555556 PI))))
(if (<= b 1.2e-90)
(pow (* a (cos t_0)) 2.0)
(+ (* a a) (pow (* b t_0) 2.0)))))
double code(double a, double b, double angle) {
double t_0 = angle * (0.005555555555555556 * ((double) M_PI));
double tmp;
if (b <= 1.2e-90) {
tmp = pow((a * cos(t_0)), 2.0);
} else {
tmp = (a * a) + pow((b * t_0), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double t_0 = angle * (0.005555555555555556 * Math.PI);
double tmp;
if (b <= 1.2e-90) {
tmp = Math.pow((a * Math.cos(t_0)), 2.0);
} else {
tmp = (a * a) + Math.pow((b * t_0), 2.0);
}
return tmp;
}
def code(a, b, angle): t_0 = angle * (0.005555555555555556 * math.pi) tmp = 0 if b <= 1.2e-90: tmp = math.pow((a * math.cos(t_0)), 2.0) else: tmp = (a * a) + math.pow((b * t_0), 2.0) return tmp
function code(a, b, angle) t_0 = Float64(angle * Float64(0.005555555555555556 * pi)) tmp = 0.0 if (b <= 1.2e-90) tmp = Float64(a * cos(t_0)) ^ 2.0; else tmp = Float64(Float64(a * a) + (Float64(b * t_0) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) t_0 = angle * (0.005555555555555556 * pi); tmp = 0.0; if (b <= 1.2e-90) tmp = (a * cos(t_0)) ^ 2.0; else tmp = (a * a) + ((b * t_0) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[b, 1.2e-90], N[Power[N[(a * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * t$95$0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := angle \cdot \left(0.005555555555555556 \cdot \pi\right)\\
\mathbf{if}\;b \leq 1.2 \cdot 10^{-90}:\\
\;\;\;\;{\left(a \cdot \cos t\_0\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(b \cdot t\_0\right)}^{2}\\
\end{array}
\end{array}
if b < 1.2000000000000001e-90Initial program 80.8%
Simplified80.8%
Taylor expanded in a around inf 59.8%
*-commutative59.8%
associate-*r*59.9%
*-commutative59.9%
associate-*r*59.9%
unpow259.9%
unpow259.9%
swap-sqr59.9%
unpow259.9%
Simplified59.9%
if 1.2000000000000001e-90 < b Initial program 79.9%
Simplified79.9%
Taylor expanded in angle around 0 80.9%
unpow280.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 78.2%
associate-*r*78.2%
*-commutative78.2%
associate-*r*78.2%
*-commutative78.2%
Simplified78.2%
Final simplification66.1%
(FPCore (a b angle) :precision binary64 (+ (* a a) (pow (* b (sin (* PI (* angle 0.005555555555555556)))) 2.0)))
double code(double a, double b, double angle) {
return (a * a) + pow((b * sin((((double) M_PI) * (angle * 0.005555555555555556)))), 2.0);
}
public static double code(double a, double b, double angle) {
return (a * a) + Math.pow((b * Math.sin((Math.PI * (angle * 0.005555555555555556)))), 2.0);
}
def code(a, b, angle): return (a * a) + math.pow((b * math.sin((math.pi * (angle * 0.005555555555555556)))), 2.0)
function code(a, b, angle) return Float64(Float64(a * a) + (Float64(b * sin(Float64(pi * Float64(angle * 0.005555555555555556)))) ^ 2.0)) end
function tmp = code(a, b, angle) tmp = (a * a) + ((b * sin((pi * (angle * 0.005555555555555556)))) ^ 2.0); end
code[a_, b_, angle_] := N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a + {\left(b \cdot \sin \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 80.5%
Simplified80.5%
Taylor expanded in angle around 0 80.6%
unpow280.6%
Applied egg-rr80.6%
(FPCore (a b angle) :precision binary64 (if (<= b 4.5e-90) (* a a) (+ (* a a) (pow (* b (* angle (* 0.005555555555555556 PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 4.5e-90) {
tmp = a * a;
} else {
tmp = (a * a) + pow((b * (angle * (0.005555555555555556 * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 4.5e-90) {
tmp = a * a;
} else {
tmp = (a * a) + Math.pow((b * (angle * (0.005555555555555556 * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 4.5e-90: tmp = a * a else: tmp = (a * a) + math.pow((b * (angle * (0.005555555555555556 * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 4.5e-90) tmp = Float64(a * a); else tmp = Float64(Float64(a * a) + (Float64(b * Float64(angle * Float64(0.005555555555555556 * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 4.5e-90) tmp = a * a; else tmp = (a * a) + ((b * (angle * (0.005555555555555556 * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 4.5e-90], N[(a * a), $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(b * N[(angle * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.5 \cdot 10^{-90}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(b \cdot \left(angle \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 4.50000000000000009e-90Initial program 80.8%
Simplified80.8%
Taylor expanded in angle around 0 60.0%
unpow280.5%
Applied egg-rr60.0%
if 4.50000000000000009e-90 < b Initial program 79.9%
Simplified79.9%
Taylor expanded in angle around 0 80.9%
unpow280.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 78.2%
associate-*r*78.2%
*-commutative78.2%
associate-*r*78.2%
*-commutative78.2%
Simplified78.2%
Final simplification66.2%
(FPCore (a b angle) :precision binary64 (if (<= b 5e-91) (* a a) (+ (* a a) (pow (* angle (* b (* 0.005555555555555556 PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 5e-91) {
tmp = a * a;
} else {
tmp = (a * a) + pow((angle * (b * (0.005555555555555556 * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 5e-91) {
tmp = a * a;
} else {
tmp = (a * a) + Math.pow((angle * (b * (0.005555555555555556 * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 5e-91: tmp = a * a else: tmp = (a * a) + math.pow((angle * (b * (0.005555555555555556 * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 5e-91) tmp = Float64(a * a); else tmp = Float64(Float64(a * a) + (Float64(angle * Float64(b * Float64(0.005555555555555556 * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 5e-91) tmp = a * a; else tmp = (a * a) + ((angle * (b * (0.005555555555555556 * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 5e-91], N[(a * a), $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(angle * N[(b * N[(0.005555555555555556 * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5 \cdot 10^{-91}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(angle \cdot \left(b \cdot \left(0.005555555555555556 \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 4.99999999999999997e-91Initial program 80.8%
Simplified80.8%
Taylor expanded in angle around 0 60.0%
unpow280.5%
Applied egg-rr60.0%
if 4.99999999999999997e-91 < b Initial program 79.9%
Simplified79.9%
Taylor expanded in angle around 0 80.9%
unpow280.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 78.2%
associate-*r*78.1%
*-commutative78.1%
associate-*r*78.1%
*-commutative78.1%
associate-*r*78.2%
*-commutative78.2%
Simplified78.2%
Final simplification66.2%
(FPCore (a b angle) :precision binary64 (if (<= b 8.5e-92) (* a a) (+ (* a a) (pow (* 0.005555555555555556 (* angle (* b PI))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 8.5e-92) {
tmp = a * a;
} else {
tmp = (a * a) + pow((0.005555555555555556 * (angle * (b * ((double) M_PI)))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 8.5e-92) {
tmp = a * a;
} else {
tmp = (a * a) + Math.pow((0.005555555555555556 * (angle * (b * Math.PI))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 8.5e-92: tmp = a * a else: tmp = (a * a) + math.pow((0.005555555555555556 * (angle * (b * math.pi))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 8.5e-92) tmp = Float64(a * a); else tmp = Float64(Float64(a * a) + (Float64(0.005555555555555556 * Float64(angle * Float64(b * pi))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 8.5e-92) tmp = a * a; else tmp = (a * a) + ((0.005555555555555556 * (angle * (b * pi))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 8.5e-92], N[(a * a), $MachinePrecision], N[(N[(a * a), $MachinePrecision] + N[Power[N[(0.005555555555555556 * N[(angle * N[(b * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 8.5 \cdot 10^{-92}:\\
\;\;\;\;a \cdot a\\
\mathbf{else}:\\
\;\;\;\;a \cdot a + {\left(0.005555555555555556 \cdot \left(angle \cdot \left(b \cdot \pi\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 8.50000000000000067e-92Initial program 80.8%
Simplified80.8%
Taylor expanded in angle around 0 60.0%
unpow280.5%
Applied egg-rr60.0%
if 8.50000000000000067e-92 < b Initial program 79.9%
Simplified79.9%
Taylor expanded in angle around 0 80.9%
unpow280.9%
Applied egg-rr80.9%
Taylor expanded in angle around 0 78.2%
*-commutative78.2%
Simplified78.2%
Final simplification66.2%
(FPCore (a b angle) :precision binary64 (* a a))
double code(double a, double b, double angle) {
return a * a;
}
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a * a
end function
public static double code(double a, double b, double angle) {
return a * a;
}
def code(a, b, angle): return a * a
function code(a, b, angle) return Float64(a * a) end
function tmp = code(a, b, angle) tmp = a * a; end
code[a_, b_, angle_] := N[(a * a), $MachinePrecision]
\begin{array}{l}
\\
a \cdot a
\end{array}
Initial program 80.5%
Simplified80.5%
Taylor expanded in angle around 0 58.9%
unpow280.6%
Applied egg-rr58.9%
herbie shell --seed 2024123
(FPCore (a b angle)
:name "ab-angle->ABCF C"
:precision binary64
(+ (pow (* a (cos (* PI (/ angle 180.0)))) 2.0) (pow (* b (sin (* PI (/ angle 180.0)))) 2.0)))