
(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 2 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 (hypot (* a (sin (* 0.005555555555555556 (* angle PI)))) (* b (cos (/ PI (/ 180.0 angle))))) 2.0))
double code(double a, double b, double angle) {
return pow(hypot((a * sin((0.005555555555555556 * (angle * ((double) M_PI))))), (b * cos((((double) M_PI) / (180.0 / angle))))), 2.0);
}
public static double code(double a, double b, double angle) {
return Math.pow(Math.hypot((a * Math.sin((0.005555555555555556 * (angle * Math.PI)))), (b * Math.cos((Math.PI / (180.0 / angle))))), 2.0);
}
def code(a, b, angle): return math.pow(math.hypot((a * math.sin((0.005555555555555556 * (angle * math.pi)))), (b * math.cos((math.pi / (180.0 / angle))))), 2.0)
function code(a, b, angle) return hypot(Float64(a * sin(Float64(0.005555555555555556 * Float64(angle * pi)))), Float64(b * cos(Float64(pi / Float64(180.0 / angle))))) ^ 2.0 end
function tmp = code(a, b, angle) tmp = hypot((a * sin((0.005555555555555556 * (angle * pi)))), (b * cos((pi / (180.0 / angle))))) ^ 2.0; end
code[a_, b_, angle_] := N[Power[N[Sqrt[N[(a * N[Sin[N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(b * N[Cos[N[(Pi / N[(180.0 / angle), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]
\begin{array}{l}
\\
{\left(\mathsf{hypot}\left(a \cdot \sin \left(0.005555555555555556 \cdot \left(angle \cdot \pi\right)\right), b \cdot \cos \left(\frac{\pi}{\frac{180}{angle}}\right)\right)\right)}^{2}
\end{array}
Initial program 83.1%
unpow283.1%
associate-*l/83.0%
associate-/l*83.1%
unpow283.1%
Simplified83.1%
Taylor expanded in a around 0 74.0%
*-commutative74.0%
*-commutative74.0%
associate-*r*74.0%
*-commutative74.0%
unpow274.0%
unpow274.0%
swap-sqr83.1%
unpow283.1%
*-commutative83.1%
associate-*r*83.1%
unpow283.1%
Simplified83.2%
associate-*r*83.1%
metadata-eval83.1%
associate-/r/83.1%
associate-*l/83.3%
*-un-lft-identity83.3%
Applied egg-rr83.3%
(FPCore (a b angle) :precision binary64 (let* ((t_0 (* 0.005555555555555556 (* angle PI)))) (pow (hypot (* a (sin t_0)) (* b (cos t_0))) 2.0)))
double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (angle * ((double) M_PI));
return pow(hypot((a * sin(t_0)), (b * cos(t_0))), 2.0);
}
public static double code(double a, double b, double angle) {
double t_0 = 0.005555555555555556 * (angle * Math.PI);
return Math.pow(Math.hypot((a * Math.sin(t_0)), (b * Math.cos(t_0))), 2.0);
}
def code(a, b, angle): t_0 = 0.005555555555555556 * (angle * math.pi) return math.pow(math.hypot((a * math.sin(t_0)), (b * math.cos(t_0))), 2.0)
function code(a, b, angle) t_0 = Float64(0.005555555555555556 * Float64(angle * pi)) return hypot(Float64(a * sin(t_0)), Float64(b * cos(t_0))) ^ 2.0 end
function tmp = code(a, b, angle) t_0 = 0.005555555555555556 * (angle * pi); tmp = hypot((a * sin(t_0)), (b * cos(t_0))) ^ 2.0; end
code[a_, b_, angle_] := Block[{t$95$0 = N[(0.005555555555555556 * N[(angle * Pi), $MachinePrecision]), $MachinePrecision]}, N[Power[N[Sqrt[N[(a * N[Sin[t$95$0], $MachinePrecision]), $MachinePrecision] ^ 2 + N[(b * N[Cos[t$95$0], $MachinePrecision]), $MachinePrecision] ^ 2], $MachinePrecision], 2.0], $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := 0.005555555555555556 \cdot \left(angle \cdot \pi\right)\\
{\left(\mathsf{hypot}\left(a \cdot \sin t\_0, b \cdot \cos t\_0\right)\right)}^{2}
\end{array}
\end{array}
Initial program 83.1%
unpow283.1%
associate-*l/83.0%
associate-/l*83.1%
unpow283.1%
Simplified83.1%
Taylor expanded in a around 0 74.0%
*-commutative74.0%
*-commutative74.0%
associate-*r*74.0%
*-commutative74.0%
unpow274.0%
unpow274.0%
swap-sqr83.1%
unpow283.1%
*-commutative83.1%
associate-*r*83.1%
unpow283.1%
Simplified83.2%
herbie shell --seed 2024179
(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)))