
(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 180.0) PI))) 2.0) (* b b)))
double code(double a, double b, double angle) {
return pow((a * sin(((angle / 180.0) * ((double) M_PI)))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(((angle / 180.0) * Math.PI))), 2.0) + (b * b);
}
def code(a, b, angle): return math.pow((a * math.sin(((angle / 180.0) * math.pi))), 2.0) + (b * b)
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64(angle / 180.0) * pi))) ^ 2.0) + Float64(b * b)) end
function tmp = code(a, b, angle) tmp = ((a * sin(((angle / 180.0) * pi))) ^ 2.0) + (b * b); end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(angle / 180.0), $MachinePrecision] * Pi), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{angle}{180} \cdot \pi\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 77.9%
associate-*l/77.7%
associate-/l*77.8%
cos-neg77.8%
distribute-lft-neg-out77.8%
distribute-frac-neg77.8%
distribute-frac-neg77.8%
distribute-lft-neg-out77.8%
cos-neg77.8%
associate-*l/77.8%
associate-/l*77.8%
Simplified77.8%
Taylor expanded in angle around 0 78.0%
clear-num78.0%
un-div-inv78.0%
Applied egg-rr78.0%
associate-/r/78.1%
Simplified78.1%
*-rgt-identity78.1%
pow278.1%
Applied egg-rr78.1%
(FPCore (a b angle) :precision binary64 (if (<= b 1.18e-157) (pow (* a (sin (* angle (* PI 0.005555555555555556)))) 2.0) (+ (* b b) (pow (* (* a 0.005555555555555556) (* angle PI)) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 1.18e-157) {
tmp = pow((a * sin((angle * (((double) M_PI) * 0.005555555555555556)))), 2.0);
} else {
tmp = (b * b) + pow(((a * 0.005555555555555556) * (angle * ((double) M_PI))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 1.18e-157) {
tmp = Math.pow((a * Math.sin((angle * (Math.PI * 0.005555555555555556)))), 2.0);
} else {
tmp = (b * b) + Math.pow(((a * 0.005555555555555556) * (angle * Math.PI)), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 1.18e-157: tmp = math.pow((a * math.sin((angle * (math.pi * 0.005555555555555556)))), 2.0) else: tmp = (b * b) + math.pow(((a * 0.005555555555555556) * (angle * math.pi)), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 1.18e-157) tmp = Float64(a * sin(Float64(angle * Float64(pi * 0.005555555555555556)))) ^ 2.0; else tmp = Float64(Float64(b * b) + (Float64(Float64(a * 0.005555555555555556) * Float64(angle * pi)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 1.18e-157) tmp = (a * sin((angle * (pi * 0.005555555555555556)))) ^ 2.0; else tmp = (b * b) + (((a * 0.005555555555555556) * (angle * pi)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 1.18e-157], 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[(N[(a * 0.005555555555555556), $MachinePrecision] * N[(angle * Pi), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 1.18 \cdot 10^{-157}:\\
\;\;\;\;{\left(a \cdot \sin \left(angle \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(\left(a \cdot 0.005555555555555556\right) \cdot \left(angle \cdot \pi\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 1.18e-157Initial program 78.9%
associate-*l/78.8%
associate-/l*78.8%
cos-neg78.8%
distribute-lft-neg-out78.8%
distribute-frac-neg78.8%
distribute-frac-neg78.8%
distribute-lft-neg-out78.8%
cos-neg78.8%
associate-*l/78.8%
associate-/l*78.8%
Simplified78.8%
Applied egg-rr63.3%
Applied egg-rr53.2%
Taylor expanded in b around 0 45.5%
unpow245.5%
*-commutative45.5%
associate-*r*45.5%
unpow245.5%
swap-sqr49.5%
unpow249.5%
*-commutative49.5%
Simplified49.5%
if 1.18e-157 < b Initial program 76.3%
associate-*l/76.0%
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.2%
associate-/l*76.3%
Simplified76.3%
Taylor expanded in angle around 0 76.2%
clear-num76.2%
un-div-inv76.2%
Applied egg-rr76.2%
associate-/r/76.2%
Simplified76.2%
*-rgt-identity76.2%
pow276.2%
Applied egg-rr76.2%
Taylor expanded in angle around 0 73.0%
associate-*r*73.0%
Simplified73.0%
Final simplification58.9%
(FPCore (a b angle) :precision binary64 (if (<= b 4.4e-160) (pow (* a (sin (* 0.005555555555555556 (* angle PI)))) 2.0) (+ (* b b) (pow (* (* a 0.005555555555555556) (* angle PI)) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (b <= 4.4e-160) {
tmp = pow((a * sin((0.005555555555555556 * (angle * ((double) M_PI))))), 2.0);
} else {
tmp = (b * b) + pow(((a * 0.005555555555555556) * (angle * ((double) M_PI))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 4.4e-160) {
tmp = Math.pow((a * Math.sin((0.005555555555555556 * (angle * Math.PI)))), 2.0);
} else {
tmp = (b * b) + Math.pow(((a * 0.005555555555555556) * (angle * Math.PI)), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if b <= 4.4e-160: tmp = math.pow((a * math.sin((0.005555555555555556 * (angle * math.pi)))), 2.0) else: tmp = (b * b) + math.pow(((a * 0.005555555555555556) * (angle * math.pi)), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (b <= 4.4e-160) tmp = Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi)))) ^ 2.0; else tmp = Float64(Float64(b * b) + (Float64(Float64(a * 0.005555555555555556) * Float64(angle * pi)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 4.4e-160) tmp = (a * sin((0.005555555555555556 * (angle * pi)))) ^ 2.0; else tmp = (b * b) + (((a * 0.005555555555555556) * (angle * pi)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[b, 4.4e-160], N[Power[N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(N[(a * 0.005555555555555556), $MachinePrecision] * N[(angle * Pi), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;b \leq 4.4 \cdot 10^{-160}:\\
\;\;\;\;{\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right)\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(\left(a \cdot 0.005555555555555556\right) \cdot \left(angle \cdot \pi\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 4.4e-160Initial program 78.9%
associate-*l/78.8%
associate-/l*78.8%
cos-neg78.8%
distribute-lft-neg-out78.8%
distribute-frac-neg78.8%
distribute-frac-neg78.8%
distribute-lft-neg-out78.8%
cos-neg78.8%
associate-*l/78.8%
associate-/l*78.8%
Simplified78.8%
Applied egg-rr63.3%
Applied egg-rr53.2%
Taylor expanded in b around 0 45.5%
unpow245.5%
*-commutative45.5%
associate-*r*45.5%
unpow245.5%
swap-sqr49.5%
unpow249.5%
associate-*r*49.5%
*-commutative49.5%
Simplified49.5%
if 4.4e-160 < b Initial program 76.3%
associate-*l/76.0%
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.2%
associate-/l*76.3%
Simplified76.3%
Taylor expanded in angle around 0 76.2%
clear-num76.2%
un-div-inv76.2%
Applied egg-rr76.2%
associate-/r/76.2%
Simplified76.2%
*-rgt-identity76.2%
pow276.2%
Applied egg-rr76.2%
Taylor expanded in angle around 0 73.0%
associate-*r*73.0%
Simplified73.0%
Final simplification58.8%
(FPCore (a b angle) :precision binary64 (if (<= a 1.45e-112) (* b b) (+ (* b b) (pow (* (* a 0.005555555555555556) (* angle PI)) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.45e-112) {
tmp = b * b;
} else {
tmp = (b * b) + pow(((a * 0.005555555555555556) * (angle * ((double) M_PI))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.45e-112) {
tmp = b * b;
} else {
tmp = (b * b) + Math.pow(((a * 0.005555555555555556) * (angle * Math.PI)), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.45e-112: tmp = b * b else: tmp = (b * b) + math.pow(((a * 0.005555555555555556) * (angle * math.pi)), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.45e-112) tmp = Float64(b * b); else tmp = Float64(Float64(b * b) + (Float64(Float64(a * 0.005555555555555556) * Float64(angle * pi)) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.45e-112) tmp = b * b; else tmp = (b * b) + (((a * 0.005555555555555556) * (angle * pi)) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.45e-112], N[(b * b), $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(N[(a * 0.005555555555555556), $MachinePrecision] * N[(angle * Pi), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.45 \cdot 10^{-112}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(\left(a \cdot 0.005555555555555556\right) \cdot \left(angle \cdot \pi\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.44999999999999996e-112Initial program 76.1%
associate-*l/75.7%
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.8%
associate-/l*75.9%
Simplified75.9%
Taylor expanded in angle around 0 57.3%
unpow257.3%
Applied egg-rr57.3%
if 1.44999999999999996e-112 < a Initial program 80.8%
associate-*l/80.8%
associate-/l*80.8%
cos-neg80.8%
distribute-lft-neg-out80.8%
distribute-frac-neg80.8%
distribute-frac-neg80.8%
distribute-lft-neg-out80.8%
cos-neg80.8%
associate-*l/80.9%
associate-/l*80.8%
Simplified80.8%
Taylor expanded in angle around 0 80.7%
clear-num80.7%
un-div-inv80.7%
Applied egg-rr80.7%
associate-/r/80.7%
Simplified80.7%
*-rgt-identity80.7%
pow280.7%
Applied egg-rr80.7%
Taylor expanded in angle around 0 76.9%
associate-*r*77.0%
Simplified77.0%
Final simplification64.8%
(FPCore (a b angle) :precision binary64 (if (<= a 1.05e-114) (* b b) (+ (* b b) (pow (* a (* PI (* angle 0.005555555555555556))) 2.0))))
double code(double a, double b, double angle) {
double tmp;
if (a <= 1.05e-114) {
tmp = b * b;
} else {
tmp = (b * b) + pow((a * (((double) M_PI) * (angle * 0.005555555555555556))), 2.0);
}
return tmp;
}
public static double code(double a, double b, double angle) {
double tmp;
if (a <= 1.05e-114) {
tmp = b * b;
} else {
tmp = (b * b) + Math.pow((a * (Math.PI * (angle * 0.005555555555555556))), 2.0);
}
return tmp;
}
def code(a, b, angle): tmp = 0 if a <= 1.05e-114: tmp = b * b else: tmp = (b * b) + math.pow((a * (math.pi * (angle * 0.005555555555555556))), 2.0) return tmp
function code(a, b, angle) tmp = 0.0 if (a <= 1.05e-114) tmp = Float64(b * b); else tmp = Float64(Float64(b * b) + (Float64(a * Float64(pi * Float64(angle * 0.005555555555555556))) ^ 2.0)); end return tmp end
function tmp_2 = code(a, b, angle) tmp = 0.0; if (a <= 1.05e-114) tmp = b * b; else tmp = (b * b) + ((a * (pi * (angle * 0.005555555555555556))) ^ 2.0); end tmp_2 = tmp; end
code[a_, b_, angle_] := If[LessEqual[a, 1.05e-114], N[(b * b), $MachinePrecision], N[(N[(b * b), $MachinePrecision] + N[Power[N[(a * N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.05 \cdot 10^{-114}:\\
\;\;\;\;b \cdot b\\
\mathbf{else}:\\
\;\;\;\;b \cdot b + {\left(a \cdot \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if a < 1.04999999999999996e-114Initial program 76.1%
associate-*l/75.7%
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.8%
associate-/l*75.9%
Simplified75.9%
Taylor expanded in angle around 0 57.3%
unpow257.3%
Applied egg-rr57.3%
if 1.04999999999999996e-114 < a Initial program 80.8%
associate-*l/80.8%
associate-/l*80.8%
cos-neg80.8%
distribute-lft-neg-out80.8%
distribute-frac-neg80.8%
distribute-frac-neg80.8%
distribute-lft-neg-out80.8%
cos-neg80.8%
associate-*l/80.9%
associate-/l*80.8%
Simplified80.8%
Taylor expanded in angle around 0 80.7%
clear-num80.7%
un-div-inv80.7%
Applied egg-rr80.7%
associate-/r/80.7%
Simplified80.7%
*-rgt-identity80.7%
pow280.7%
Applied egg-rr80.7%
Taylor expanded in angle around 0 76.9%
*-commutative76.9%
associate-*r*77.0%
*-commutative77.0%
associate-*l*77.0%
Simplified77.0%
Final simplification64.8%
(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 77.9%
associate-*l/77.7%
associate-/l*77.8%
cos-neg77.8%
distribute-lft-neg-out77.8%
distribute-frac-neg77.8%
distribute-frac-neg77.8%
distribute-lft-neg-out77.8%
cos-neg77.8%
associate-*l/77.8%
associate-/l*77.8%
Simplified77.8%
Taylor expanded in angle around 0 53.5%
unpow253.5%
Applied egg-rr53.5%
herbie shell --seed 2024121
(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)))