
(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 6 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}
NOTE: angle should be positive before calling this function
(FPCore (a b angle)
:precision binary64
(+
(pow a 2.0)
(pow
(*
b
(sin
(expm1 (log1p (* PI (expm1 (log1p (* angle 0.005555555555555556))))))))
2.0)))angle = abs(angle);
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin(expm1(log1p((((double) M_PI) * expm1(log1p((angle * 0.005555555555555556)))))))), 2.0);
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin(Math.expm1(Math.log1p((Math.PI * Math.expm1(Math.log1p((angle * 0.005555555555555556)))))))), 2.0);
}
angle = abs(angle) def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin(math.expm1(math.log1p((math.pi * math.expm1(math.log1p((angle * 0.005555555555555556)))))))), 2.0)
angle = abs(angle) function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(expm1(log1p(Float64(pi * expm1(log1p(Float64(angle * 0.005555555555555556)))))))) ^ 2.0)) end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Exp[N[Log[1 + N[(Pi * N[(Exp[N[Log[1 + N[(angle * 0.005555555555555556), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{a}^{2} + {\left(b \cdot \sin \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\pi \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(angle \cdot 0.005555555555555556\right)\right)\right)\right)\right)\right)}^{2}
\end{array}
Initial program 76.6%
Taylor expanded in angle around 0 76.9%
add-sqr-sqrt39.9%
sqrt-unprod60.6%
associate-*r/60.6%
associate-*r/60.6%
frac-times60.5%
metadata-eval60.5%
metadata-eval60.5%
frac-times60.6%
associate-*l/60.6%
associate-*l/60.6%
sqrt-unprod37.0%
add-sqr-sqrt77.0%
expm1-log1p-u63.9%
add-sqr-sqrt37.0%
sqrt-unprod60.7%
associate-*l/60.7%
associate-*l/60.7%
frac-times60.6%
Applied egg-rr64.6%
expm1-log1p-u64.6%
Applied egg-rr64.6%
Final simplification64.6%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (expm1 (log1p (* PI (* angle 0.005555555555555556)))))) 2.0)))
angle = abs(angle);
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin(expm1(log1p((((double) M_PI) * (angle * 0.005555555555555556)))))), 2.0);
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin(Math.expm1(Math.log1p((Math.PI * (angle * 0.005555555555555556)))))), 2.0);
}
angle = abs(angle) def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin(math.expm1(math.log1p((math.pi * (angle * 0.005555555555555556)))))), 2.0)
angle = abs(angle) function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(expm1(log1p(Float64(pi * Float64(angle * 0.005555555555555556)))))) ^ 2.0)) end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Exp[N[Log[1 + N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{a}^{2} + {\left(b \cdot \sin \left(\mathsf{expm1}\left(\mathsf{log1p}\left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)\right)\right)}^{2}
\end{array}
Initial program 76.6%
Taylor expanded in angle around 0 76.9%
add-sqr-sqrt39.9%
sqrt-unprod60.6%
associate-*r/60.6%
associate-*r/60.6%
frac-times60.5%
metadata-eval60.5%
metadata-eval60.5%
frac-times60.6%
associate-*l/60.6%
associate-*l/60.6%
sqrt-unprod37.0%
add-sqr-sqrt77.0%
expm1-log1p-u63.9%
add-sqr-sqrt37.0%
sqrt-unprod60.7%
associate-*l/60.7%
associate-*l/60.7%
frac-times60.6%
Applied egg-rr64.6%
Final simplification64.6%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* angle (/ PI 180.0)))) 2.0)))
angle = abs(angle);
double code(double a, double b, double angle) {
return pow(a, 2.0) + pow((b * sin((angle * (((double) M_PI) / 180.0)))), 2.0);
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((angle * (Math.PI / 180.0)))), 2.0);
}
angle = abs(angle) def code(a, b, angle): return math.pow(a, 2.0) + math.pow((b * math.sin((angle * (math.pi / 180.0)))), 2.0)
angle = abs(angle) function code(a, b, angle) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(angle * Float64(pi / 180.0)))) ^ 2.0)) end
angle = abs(angle) function tmp = code(a, b, angle) tmp = (a ^ 2.0) + ((b * sin((angle * (pi / 180.0)))) ^ 2.0); end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(angle * N[(Pi / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{a}^{2} + {\left(b \cdot \sin \left(angle \cdot \frac{\pi}{180}\right)\right)}^{2}
\end{array}
Initial program 76.6%
Taylor expanded in angle around 0 76.9%
Taylor expanded in angle around inf 76.9%
*-commutative76.9%
associate-*r*77.0%
metadata-eval77.0%
associate-/r/77.0%
associate-*l/77.0%
*-lft-identity77.0%
associate-/l*77.0%
associate-*r/77.0%
Simplified77.0%
Final simplification77.0%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (if (<= b 9.2e-68) (pow a 2.0) (+ (pow a 2.0) (pow (* b (* 0.005555555555555556 (* PI angle))) 2.0))))
angle = abs(angle);
double code(double a, double b, double angle) {
double tmp;
if (b <= 9.2e-68) {
tmp = pow(a, 2.0);
} else {
tmp = pow(a, 2.0) + pow((b * (0.005555555555555556 * (((double) M_PI) * angle))), 2.0);
}
return tmp;
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 9.2e-68) {
tmp = Math.pow(a, 2.0);
} else {
tmp = Math.pow(a, 2.0) + Math.pow((b * (0.005555555555555556 * (Math.PI * angle))), 2.0);
}
return tmp;
}
angle = abs(angle) def code(a, b, angle): tmp = 0 if b <= 9.2e-68: tmp = math.pow(a, 2.0) else: tmp = math.pow(a, 2.0) + math.pow((b * (0.005555555555555556 * (math.pi * angle))), 2.0) return tmp
angle = abs(angle) function code(a, b, angle) tmp = 0.0 if (b <= 9.2e-68) tmp = a ^ 2.0; else tmp = Float64((a ^ 2.0) + (Float64(b * Float64(0.005555555555555556 * Float64(pi * angle))) ^ 2.0)); end return tmp end
angle = abs(angle) function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 9.2e-68) tmp = a ^ 2.0; else tmp = (a ^ 2.0) + ((b * (0.005555555555555556 * (pi * angle))) ^ 2.0); end tmp_2 = tmp; end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := If[LessEqual[b, 9.2e-68], N[Power[a, 2.0], $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[(0.005555555555555556 * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
angle = |angle|\\
\\
\begin{array}{l}
\mathbf{if}\;b \leq 9.2 \cdot 10^{-68}:\\
\;\;\;\;{a}^{2}\\
\mathbf{else}:\\
\;\;\;\;{a}^{2} + {\left(b \cdot \left(0.005555555555555556 \cdot \left(\pi \cdot angle\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 9.19999999999999987e-68Initial program 75.2%
Applied egg-rr59.7%
*-commutative59.7%
associate-/l*59.7%
+-inverses59.7%
div063.2%
Simplified63.2%
Taylor expanded in angle around 0 63.5%
if 9.19999999999999987e-68 < b Initial program 80.0%
Taylor expanded in angle around 0 80.3%
Taylor expanded in angle around 0 77.2%
Final simplification67.6%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (if (<= b 2.6e-67) (pow a 2.0) (+ (pow a 2.0) (pow (* b (* PI (* angle 0.005555555555555556))) 2.0))))
angle = abs(angle);
double code(double a, double b, double angle) {
double tmp;
if (b <= 2.6e-67) {
tmp = pow(a, 2.0);
} else {
tmp = pow(a, 2.0) + pow((b * (((double) M_PI) * (angle * 0.005555555555555556))), 2.0);
}
return tmp;
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
double tmp;
if (b <= 2.6e-67) {
tmp = Math.pow(a, 2.0);
} else {
tmp = Math.pow(a, 2.0) + Math.pow((b * (Math.PI * (angle * 0.005555555555555556))), 2.0);
}
return tmp;
}
angle = abs(angle) def code(a, b, angle): tmp = 0 if b <= 2.6e-67: tmp = math.pow(a, 2.0) else: tmp = math.pow(a, 2.0) + math.pow((b * (math.pi * (angle * 0.005555555555555556))), 2.0) return tmp
angle = abs(angle) function code(a, b, angle) tmp = 0.0 if (b <= 2.6e-67) tmp = a ^ 2.0; else tmp = Float64((a ^ 2.0) + (Float64(b * Float64(pi * Float64(angle * 0.005555555555555556))) ^ 2.0)); end return tmp end
angle = abs(angle) function tmp_2 = code(a, b, angle) tmp = 0.0; if (b <= 2.6e-67) tmp = a ^ 2.0; else tmp = (a ^ 2.0) + ((b * (pi * (angle * 0.005555555555555556))) ^ 2.0); end tmp_2 = tmp; end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := If[LessEqual[b, 2.6e-67], N[Power[a, 2.0], $MachinePrecision], N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[(Pi * N[(angle * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
angle = |angle|\\
\\
\begin{array}{l}
\mathbf{if}\;b \leq 2.6 \cdot 10^{-67}:\\
\;\;\;\;{a}^{2}\\
\mathbf{else}:\\
\;\;\;\;{a}^{2} + {\left(b \cdot \left(\pi \cdot \left(angle \cdot 0.005555555555555556\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 2.5999999999999999e-67Initial program 75.2%
Applied egg-rr59.7%
*-commutative59.7%
associate-/l*59.7%
+-inverses59.7%
div063.2%
Simplified63.2%
Taylor expanded in angle around 0 63.5%
if 2.5999999999999999e-67 < b Initial program 80.0%
Taylor expanded in angle around 0 80.3%
Taylor expanded in angle around 0 77.2%
associate-*r*77.2%
*-commutative77.2%
*-commutative77.2%
*-commutative77.2%
Simplified77.2%
Final simplification67.6%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (pow a 2.0))
angle = abs(angle);
double code(double a, double b, double angle) {
return pow(a, 2.0);
}
NOTE: angle should be positive before calling this function
real(8) function code(a, b, angle)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle
code = a ** 2.0d0
end function
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow(a, 2.0);
}
angle = abs(angle) def code(a, b, angle): return math.pow(a, 2.0)
angle = abs(angle) function code(a, b, angle) return a ^ 2.0 end
angle = abs(angle) function tmp = code(a, b, angle) tmp = a ^ 2.0; end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[Power[a, 2.0], $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{a}^{2}
\end{array}
Initial program 76.6%
Applied egg-rr51.3%
*-commutative51.3%
associate-/l*51.3%
+-inverses51.3%
div058.7%
Simplified58.7%
Taylor expanded in angle around 0 58.9%
Final simplification58.9%
herbie shell --seed 2023301
(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)))