
(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 4 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}
NOTE: angle should be positive before calling this function
(FPCore (a b angle)
:precision binary64
(+
(pow
(*
a
(sin
(expm1 (log1p (* 0.005555555555555556 (expm1 (log1p (* angle PI))))))))
2.0)
(pow b 2.0)))angle = abs(angle);
double code(double a, double b, double angle) {
return pow((a * sin(expm1(log1p((0.005555555555555556 * expm1(log1p((angle * ((double) M_PI))))))))), 2.0) + pow(b, 2.0);
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(Math.expm1(Math.log1p((0.005555555555555556 * Math.expm1(Math.log1p((angle * Math.PI)))))))), 2.0) + Math.pow(b, 2.0);
}
angle = abs(angle) def code(a, b, angle): return math.pow((a * math.sin(math.expm1(math.log1p((0.005555555555555556 * math.expm1(math.log1p((angle * math.pi)))))))), 2.0) + math.pow(b, 2.0)
angle = abs(angle) function code(a, b, angle) return Float64((Float64(a * sin(expm1(log1p(Float64(0.005555555555555556 * expm1(log1p(Float64(angle * pi)))))))) ^ 2.0) + (b ^ 2.0)) end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(Exp[N[Log[1 + N[(0.005555555555555556 * N[(Exp[N[Log[1 + N[(angle * Pi), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]] - 1), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[b, 2.0], $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{\left(a \cdot \sin \left(\mathsf{expm1}\left(\mathsf{log1p}\left(0.005555555555555556 \cdot \mathsf{expm1}\left(\mathsf{log1p}\left(angle \cdot \pi\right)\right)\right)\right)\right)\right)}^{2} + {b}^{2}
\end{array}
Initial program 81.2%
associate-*l/81.3%
associate-*r/81.2%
associate-*l/81.2%
associate-*r/81.2%
Simplified81.2%
Taylor expanded in angle around 0 81.8%
Taylor expanded in angle around inf 81.8%
expm1-log1p-u64.6%
Applied egg-rr64.6%
expm1-log1p-u64.3%
Applied egg-rr64.3%
Final simplification64.3%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (+ (pow (* a (sin (/ 1.0 (/ 180.0 (* angle PI))))) 2.0) (* b b)))
angle = abs(angle);
double code(double a, double b, double angle) {
return pow((a * sin((1.0 / (180.0 / (angle * ((double) M_PI)))))), 2.0) + (b * b);
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin((1.0 / (180.0 / (angle * Math.PI))))), 2.0) + (b * b);
}
angle = abs(angle) def code(a, b, angle): return math.pow((a * math.sin((1.0 / (180.0 / (angle * math.pi))))), 2.0) + (b * b)
angle = abs(angle) function code(a, b, angle) return Float64((Float64(a * sin(Float64(1.0 / Float64(180.0 / Float64(angle * pi))))) ^ 2.0) + Float64(b * b)) end
angle = abs(angle) function tmp = code(a, b, angle) tmp = ((a * sin((1.0 / (180.0 / (angle * pi))))) ^ 2.0) + (b * b); end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(1.0 / N[(180.0 / N[(angle * Pi), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{\left(a \cdot \sin \left(\frac{1}{\frac{180}{angle \cdot \pi}}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 81.2%
associate-*l/81.3%
associate-*r/81.2%
associate-*l/81.2%
associate-*r/81.2%
Simplified81.2%
Taylor expanded in angle around 0 81.8%
Taylor expanded in angle around inf 81.8%
*-commutative81.8%
metadata-eval81.8%
div-inv81.8%
clear-num81.8%
Applied egg-rr81.8%
Taylor expanded in b around 0 81.8%
unpow277.7%
Simplified81.8%
Final simplification81.8%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (+ (pow b 2.0) (* (pow (* angle (* a PI)) 2.0) 3.08641975308642e-5)))
angle = abs(angle);
double code(double a, double b, double angle) {
return pow(b, 2.0) + (pow((angle * (a * ((double) M_PI))), 2.0) * 3.08641975308642e-5);
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return Math.pow(b, 2.0) + (Math.pow((angle * (a * Math.PI)), 2.0) * 3.08641975308642e-5);
}
angle = abs(angle) def code(a, b, angle): return math.pow(b, 2.0) + (math.pow((angle * (a * math.pi)), 2.0) * 3.08641975308642e-5)
angle = abs(angle) function code(a, b, angle) return Float64((b ^ 2.0) + Float64((Float64(angle * Float64(a * pi)) ^ 2.0) * 3.08641975308642e-5)) end
angle = abs(angle) function tmp = code(a, b, angle) tmp = (b ^ 2.0) + (((angle * (a * pi)) ^ 2.0) * 3.08641975308642e-5); end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[Power[b, 2.0], $MachinePrecision] + N[(N[Power[N[(angle * N[(a * Pi), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] * 3.08641975308642e-5), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
{b}^{2} + {\left(angle \cdot \left(a \cdot \pi\right)\right)}^{2} \cdot 3.08641975308642 \cdot 10^{-5}
\end{array}
Initial program 81.2%
associate-*l/81.3%
associate-*r/81.2%
associate-*l/81.2%
associate-*r/81.2%
Simplified81.2%
Taylor expanded in angle around 0 81.8%
Taylor expanded in angle around 0 77.6%
*-commutative77.6%
Simplified77.6%
*-commutative77.6%
unpow-prod-down77.7%
metadata-eval77.7%
Applied egg-rr77.7%
Final simplification77.7%
NOTE: angle should be positive before calling this function (FPCore (a b angle) :precision binary64 (+ (* b b) (* 3.08641975308642e-5 (pow (* PI (* a angle)) 2.0))))
angle = abs(angle);
double code(double a, double b, double angle) {
return (b * b) + (3.08641975308642e-5 * pow((((double) M_PI) * (a * angle)), 2.0));
}
angle = Math.abs(angle);
public static double code(double a, double b, double angle) {
return (b * b) + (3.08641975308642e-5 * Math.pow((Math.PI * (a * angle)), 2.0));
}
angle = abs(angle) def code(a, b, angle): return (b * b) + (3.08641975308642e-5 * math.pow((math.pi * (a * angle)), 2.0))
angle = abs(angle) function code(a, b, angle) return Float64(Float64(b * b) + Float64(3.08641975308642e-5 * (Float64(pi * Float64(a * angle)) ^ 2.0))) end
angle = abs(angle) function tmp = code(a, b, angle) tmp = (b * b) + (3.08641975308642e-5 * ((pi * (a * angle)) ^ 2.0)); end
NOTE: angle should be positive before calling this function code[a_, b_, angle_] := N[(N[(b * b), $MachinePrecision] + N[(3.08641975308642e-5 * N[Power[N[(Pi * N[(a * angle), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
angle = |angle|\\
\\
b \cdot b + 3.08641975308642 \cdot 10^{-5} \cdot {\left(\pi \cdot \left(a \cdot angle\right)\right)}^{2}
\end{array}
Initial program 81.2%
associate-*l/81.3%
associate-*r/81.2%
associate-*l/81.2%
associate-*r/81.2%
Simplified81.2%
Taylor expanded in angle around 0 81.8%
Taylor expanded in angle around inf 81.8%
Taylor expanded in angle around 0 66.7%
associate-*r*66.7%
*-commutative66.7%
unpow266.7%
unpow266.7%
swap-sqr66.7%
unpow266.7%
associate-*l*66.7%
unpow266.7%
unpow266.7%
swap-sqr77.7%
unpow277.7%
associate-*r*77.7%
*-commutative77.7%
associate-*l*77.7%
Simplified77.7%
Taylor expanded in b around 0 77.7%
unpow277.7%
Simplified77.7%
Final simplification77.7%
herbie shell --seed 2023217
(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)))