
(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 10 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
(* (/ (pow PI 0.6666666666666666) 180.0) (/ (cbrt PI) (/ 1.0 angle)))))
2.0)
(* b b)))
double code(double a, double b, double angle) {
return pow((a * sin(((pow(((double) M_PI), 0.6666666666666666) / 180.0) * (cbrt(((double) M_PI)) / (1.0 / angle))))), 2.0) + (b * b);
}
public static double code(double a, double b, double angle) {
return Math.pow((a * Math.sin(((Math.pow(Math.PI, 0.6666666666666666) / 180.0) * (Math.cbrt(Math.PI) / (1.0 / angle))))), 2.0) + (b * b);
}
function code(a, b, angle) return Float64((Float64(a * sin(Float64(Float64((pi ^ 0.6666666666666666) / 180.0) * Float64(cbrt(pi) / Float64(1.0 / angle))))) ^ 2.0) + Float64(b * b)) end
code[a_, b_, angle_] := N[(N[Power[N[(a * N[Sin[N[(N[(N[Power[Pi, 0.6666666666666666], $MachinePrecision] / 180.0), $MachinePrecision] * N[(N[Power[Pi, 1/3], $MachinePrecision] / N[(1.0 / angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]], $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
{\left(a \cdot \sin \left(\frac{{\pi}^{0.6666666666666666}}{180} \cdot \frac{\sqrt[3]{\pi}}{\frac{1}{angle}}\right)\right)}^{2} + b \cdot b
\end{array}
Initial program 76.9%
Taylor expanded in angle around 0
Applied rewrites77.3%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-PI.f64N/A
pow1/3N/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f6477.3
Applied rewrites77.3%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6477.3
Applied rewrites77.3%
(FPCore (a b angle)
:precision binary64
(if (<= (/ angle 180.0) 5e-10)
(+
(pow (* 0.005555555555555556 (* a (* PI angle))) 2.0)
(pow (* b 1.0) 2.0))
(fma
a
(* a (- 0.5 (* 0.5 (cos (* (* PI angle) 0.011111111111111112)))))
(* b b))))
double code(double a, double b, double angle) {
double tmp;
if ((angle / 180.0) <= 5e-10) {
tmp = pow((0.005555555555555556 * (a * (((double) M_PI) * angle))), 2.0) + pow((b * 1.0), 2.0);
} else {
tmp = fma(a, (a * (0.5 - (0.5 * cos(((((double) M_PI) * angle) * 0.011111111111111112))))), (b * b));
}
return tmp;
}
function code(a, b, angle) tmp = 0.0 if (Float64(angle / 180.0) <= 5e-10) tmp = Float64((Float64(0.005555555555555556 * Float64(a * Float64(pi * angle))) ^ 2.0) + (Float64(b * 1.0) ^ 2.0)); else tmp = fma(a, Float64(a * Float64(0.5 - Float64(0.5 * cos(Float64(Float64(pi * angle) * 0.011111111111111112))))), Float64(b * b)); end return tmp end
code[a_, b_, angle_] := If[LessEqual[N[(angle / 180.0), $MachinePrecision], 5e-10], N[(N[Power[N[(0.005555555555555556 * N[(a * N[(Pi * angle), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 2.0], $MachinePrecision] + N[Power[N[(b * 1.0), $MachinePrecision], 2.0], $MachinePrecision]), $MachinePrecision], N[(a * N[(a * N[(0.5 - N[(0.5 * N[Cos[N[(N[(Pi * angle), $MachinePrecision] * 0.011111111111111112), $MachinePrecision]], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + N[(b * b), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{angle}{180} \leq 5 \cdot 10^{-10}:\\
\;\;\;\;{\left(0.005555555555555556 \cdot \left(a \cdot \left(\pi \cdot angle\right)\right)\right)}^{2} + {\left(b \cdot 1\right)}^{2}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(a, a \cdot \left(0.5 - 0.5 \cdot \cos \left(\left(\pi \cdot angle\right) \cdot 0.011111111111111112\right)\right), b \cdot b\right)\\
\end{array}
\end{array}
if (/.f64 angle #s(literal 180 binary64)) < 5.00000000000000031e-10Initial program 86.6%
Taylor expanded in angle around 0
Applied rewrites86.6%
Taylor expanded in angle around 0
lower-*.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f64N/A
lower-PI.f6483.4
Applied rewrites83.4%
if 5.00000000000000031e-10 < (/.f64 angle #s(literal 180 binary64)) Initial program 58.9%
Taylor expanded in angle around 0
Applied rewrites58.7%
lift-*.f64N/A
*-commutativeN/A
lift-/.f64N/A
clear-numN/A
un-div-invN/A
lift-PI.f64N/A
add-cube-cbrtN/A
div-invN/A
times-fracN/A
lower-*.f64N/A
lower-/.f64N/A
pow2N/A
lift-PI.f64N/A
pow1/3N/A
pow-powN/A
metadata-evalN/A
metadata-evalN/A
lower-pow.f64N/A
metadata-evalN/A
lower-/.f64N/A
lift-PI.f64N/A
lower-cbrt.f64N/A
lower-/.f6458.6
Applied rewrites58.6%
Taylor expanded in angle around 0
unpow2N/A
lower-*.f6458.6
Applied rewrites58.6%
Applied rewrites58.4%
Final simplification77.1%
herbie shell --seed 2024229
(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)))