
(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}
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (pow (sqrt (* PI (* angle_m 0.005555555555555556))) 2.0))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0) + pow((b * sin(pow(sqrt((((double) M_PI) * (angle_m * 0.005555555555555556))), 2.0))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin(Math.pow(Math.sqrt((Math.PI * (angle_m * 0.005555555555555556))), 2.0))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0) + math.pow((b * math.sin(math.pow(math.sqrt((math.pi * (angle_m * 0.005555555555555556))), 2.0))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((a ^ 2.0) + (Float64(b * sin((sqrt(Float64(pi * Float64(angle_m * 0.005555555555555556))) ^ 2.0))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (a ^ 2.0) + ((b * sin((sqrt((pi * (angle_m * 0.005555555555555556))) ^ 2.0))) ^ 2.0); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[Power[N[Sqrt[N[(Pi * N[(angle$95$m * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision], 2.0], $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2} + {\left(b \cdot \sin \left({\left(\sqrt{\pi \cdot \left(angle_m \cdot 0.005555555555555556\right)}\right)}^{2}\right)\right)}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
add-sqr-sqrt39.0%
pow239.0%
div-inv39.0%
metadata-eval39.0%
Applied egg-rr39.0%
Final simplification39.0%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow a 2.0) (pow (* b (expm1 (log1p (sin (* angle_m (* PI -0.005555555555555556)))))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0) + pow((b * expm1(log1p(sin((angle_m * (((double) M_PI) * -0.005555555555555556)))))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0) + Math.pow((b * Math.expm1(Math.log1p(Math.sin((angle_m * (Math.PI * -0.005555555555555556)))))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0) + math.pow((b * math.expm1(math.log1p(math.sin((angle_m * (math.pi * -0.005555555555555556)))))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((a ^ 2.0) + (Float64(b * expm1(log1p(sin(Float64(angle_m * Float64(pi * -0.005555555555555556)))))) ^ 2.0)) end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[(Exp[N[Log[1 + N[Sin[N[(angle$95$m * N[(Pi * -0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2} + {\left(b \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(\sin \left(angle_m \cdot \left(\pi \cdot -0.005555555555555556\right)\right)\right)\right)\right)}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
add-sqr-sqrt39.0%
pow239.0%
div-inv39.0%
metadata-eval39.0%
Applied egg-rr39.0%
add-sqr-sqrt39.0%
sqrt-unprod30.2%
sqrt-pow230.2%
metadata-eval30.2%
pow130.2%
associate-*r*30.2%
sqrt-pow261.7%
metadata-eval61.7%
pow161.7%
associate-*r*61.7%
swap-sqr61.3%
*-commutative61.3%
*-commutative61.3%
metadata-eval61.3%
metadata-eval61.3%
swap-sqr61.7%
associate-*r*61.7%
Applied egg-rr76.5%
Final simplification76.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow a 2.0) (pow (* b (log1p (expm1 (sin (* angle_m (* PI -0.005555555555555556)))))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0) + pow((b * log1p(expm1(sin((angle_m * (((double) M_PI) * -0.005555555555555556)))))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0) + Math.pow((b * Math.log1p(Math.expm1(Math.sin((angle_m * (Math.PI * -0.005555555555555556)))))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0) + math.pow((b * math.log1p(math.expm1(math.sin((angle_m * (math.pi * -0.005555555555555556)))))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((a ^ 2.0) + (Float64(b * log1p(expm1(sin(Float64(angle_m * Float64(pi * -0.005555555555555556)))))) ^ 2.0)) end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Log[1 + N[(Exp[N[Sin[N[(angle$95$m * N[(Pi * -0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2} + {\left(b \cdot \mathsf{log1p}\left(\mathsf{expm1}\left(\sin \left(angle_m \cdot \left(\pi \cdot -0.005555555555555556\right)\right)\right)\right)\right)}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
add-sqr-sqrt39.0%
pow239.0%
div-inv39.0%
metadata-eval39.0%
Applied egg-rr39.0%
add-sqr-sqrt39.0%
sqrt-unprod30.2%
sqrt-pow230.2%
metadata-eval30.2%
pow130.2%
associate-*r*30.2%
sqrt-pow261.7%
metadata-eval61.7%
pow161.7%
associate-*r*61.7%
swap-sqr61.3%
*-commutative61.3%
*-commutative61.3%
metadata-eval61.3%
metadata-eval61.3%
swap-sqr61.7%
associate-*r*61.7%
Applied egg-rr76.5%
Final simplification76.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* 0.005555555555555556 (* PI angle_m)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0) + pow((b * sin((0.005555555555555556 * (((double) M_PI) * angle_m)))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((0.005555555555555556 * (Math.PI * angle_m)))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0) + math.pow((b * math.sin((0.005555555555555556 * (math.pi * angle_m)))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(0.005555555555555556 * Float64(pi * angle_m)))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (a ^ 2.0) + ((b * sin((0.005555555555555556 * (pi * angle_m)))) ^ 2.0); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(0.005555555555555556 * N[(Pi * angle$95$m), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2} + {\left(b \cdot \sin \left(0.005555555555555556 \cdot \left(\pi \cdot angle_m\right)\right)\right)}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
Taylor expanded in b around 0 76.0%
Final simplification76.0%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* PI (* angle_m 0.005555555555555556)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0) + pow((b * sin((((double) M_PI) * (angle_m * 0.005555555555555556)))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((Math.PI * (angle_m * 0.005555555555555556)))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0) + math.pow((b * math.sin((math.pi * (angle_m * 0.005555555555555556)))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(angle_m * 0.005555555555555556)))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (a ^ 2.0) + ((b * sin((pi * (angle_m * 0.005555555555555556)))) ^ 2.0); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle$95$m * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2} + {\left(b \cdot \sin \left(\pi \cdot \left(angle_m \cdot 0.005555555555555556\right)\right)\right)}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
Taylor expanded in angle around inf 76.0%
associate-*r*76.4%
*-commutative76.4%
*-commutative76.4%
*-commutative76.4%
Simplified76.4%
Final simplification76.4%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (+ (pow a 2.0) (pow (* b (sin (* PI (/ angle_m 180.0)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0) + pow((b * sin((((double) M_PI) * (angle_m / 180.0)))), 2.0);
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0) + Math.pow((b * Math.sin((Math.PI * (angle_m / 180.0)))), 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0) + math.pow((b * math.sin((math.pi * (angle_m / 180.0)))), 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return Float64((a ^ 2.0) + (Float64(b * sin(Float64(pi * Float64(angle_m / 180.0)))) ^ 2.0)) end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = (a ^ 2.0) + ((b * sin((pi * (angle_m / 180.0)))) ^ 2.0); end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[(N[Power[a, 2.0], $MachinePrecision] + N[Power[N[(b * N[Sin[N[(Pi * N[(angle$95$m / 180.0), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2} + {\left(b \cdot \sin \left(\pi \cdot \frac{angle_m}{180}\right)\right)}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
Final simplification76.5%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (if (<= b 5.9e-21) (pow a 2.0) (pow (hypot a (* b (* angle_m (* PI 0.005555555555555556)))) 2.0)))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
double tmp;
if (b <= 5.9e-21) {
tmp = pow(a, 2.0);
} else {
tmp = pow(hypot(a, (b * (angle_m * (((double) M_PI) * 0.005555555555555556)))), 2.0);
}
return tmp;
}
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
double tmp;
if (b <= 5.9e-21) {
tmp = Math.pow(a, 2.0);
} else {
tmp = Math.pow(Math.hypot(a, (b * (angle_m * (Math.PI * 0.005555555555555556)))), 2.0);
}
return tmp;
}
angle_m = math.fabs(angle) def code(a, b, angle_m): tmp = 0 if b <= 5.9e-21: tmp = math.pow(a, 2.0) else: tmp = math.pow(math.hypot(a, (b * (angle_m * (math.pi * 0.005555555555555556)))), 2.0) return tmp
angle_m = abs(angle) function code(a, b, angle_m) tmp = 0.0 if (b <= 5.9e-21) tmp = a ^ 2.0; else tmp = hypot(a, Float64(b * Float64(angle_m * Float64(pi * 0.005555555555555556)))) ^ 2.0; end return tmp end
angle_m = abs(angle); function tmp_2 = code(a, b, angle_m) tmp = 0.0; if (b <= 5.9e-21) tmp = a ^ 2.0; else tmp = hypot(a, (b * (angle_m * (pi * 0.005555555555555556)))) ^ 2.0; end tmp_2 = tmp; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := If[LessEqual[b, 5.9e-21], N[Power[a, 2.0], $MachinePrecision], N[Power[N[Sqrt[a ^ 2 + N[(b * N[(angle$95$m * N[(Pi * 0.005555555555555556), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
angle_m = \left|angle\right|
\\
\begin{array}{l}
\mathbf{if}\;b \leq 5.9 \cdot 10^{-21}:\\
\;\;\;\;{a}^{2}\\
\mathbf{else}:\\
\;\;\;\;{\left(\mathsf{hypot}\left(a, b \cdot \left(angle_m \cdot \left(\pi \cdot 0.005555555555555556\right)\right)\right)\right)}^{2}\\
\end{array}
\end{array}
if b < 5.9000000000000003e-21Initial program 75.2%
Taylor expanded in angle around 0 75.4%
Taylor expanded in angle around 0 70.8%
*-commutative70.8%
unpow-prod-down70.4%
associate-*r*70.4%
*-commutative70.4%
metadata-eval70.4%
Applied egg-rr70.4%
Taylor expanded in a around inf 63.1%
if 5.9000000000000003e-21 < b Initial program 80.2%
Taylor expanded in angle around 0 80.1%
Taylor expanded in angle around 0 75.1%
*-commutative75.1%
unpow-prod-down75.0%
associate-*r*75.0%
*-commutative75.0%
metadata-eval75.0%
Applied egg-rr75.0%
expm1-log1p-u73.1%
expm1-udef61.8%
Applied egg-rr61.8%
expm1-def73.2%
expm1-log1p75.1%
associate-*l*75.0%
remove-double-div75.0%
associate-*l/75.0%
*-lft-identity75.0%
associate-/r/75.0%
associate-/l*74.9%
associate-/r/75.2%
/-rgt-identity75.2%
*-commutative75.2%
Simplified75.2%
Final simplification65.9%
angle_m = (fabs.f64 angle) (FPCore (a b angle_m) :precision binary64 (pow a 2.0))
angle_m = fabs(angle);
double code(double a, double b, double angle_m) {
return pow(a, 2.0);
}
angle_m = abs(angle)
real(8) function code(a, b, angle_m)
real(8), intent (in) :: a
real(8), intent (in) :: b
real(8), intent (in) :: angle_m
code = a ** 2.0d0
end function
angle_m = Math.abs(angle);
public static double code(double a, double b, double angle_m) {
return Math.pow(a, 2.0);
}
angle_m = math.fabs(angle) def code(a, b, angle_m): return math.pow(a, 2.0)
angle_m = abs(angle) function code(a, b, angle_m) return a ^ 2.0 end
angle_m = abs(angle); function tmp = code(a, b, angle_m) tmp = a ^ 2.0; end
angle_m = N[Abs[angle], $MachinePrecision] code[a_, b_, angle$95$m_] := N[Power[a, 2.0], $MachinePrecision]
\begin{array}{l}
angle_m = \left|angle\right|
\\
{a}^{2}
\end{array}
Initial program 76.4%
Taylor expanded in angle around 0 76.5%
Taylor expanded in angle around 0 71.8%
*-commutative71.8%
unpow-prod-down71.4%
associate-*r*71.4%
*-commutative71.4%
metadata-eval71.4%
Applied egg-rr71.4%
Taylor expanded in a around inf 58.9%
Final simplification58.9%
herbie shell --seed 2023332
(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)))