
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 7 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (cos y)) (* z (sin y))))
double code(double x, double y, double z) {
return (x * cos(y)) + (z * sin(y));
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = (x * cos(y)) + (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) + (z * Math.sin(y));
}
def code(x, y, z): return (x * math.cos(y)) + (z * math.sin(y))
function code(x, y, z) return Float64(Float64(x * cos(y)) + Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (x * cos(y)) + (z * sin(y)); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y + z \cdot \sin y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) x (* z (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), x, (z * sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(z * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, z \cdot \sin y\right)
\end{array}
Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma 1.0 x (* z (sin y))))) (if (<= z -5.7e-105) t_0 (if (<= z 53000000.0) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(1.0, x, (z * sin(y)));
double tmp;
if (z <= -5.7e-105) {
tmp = t_0;
} else if (z <= 53000000.0) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(1.0, x, Float64(z * sin(y))) tmp = 0.0 if (z <= -5.7e-105) tmp = t_0; elseif (z <= 53000000.0) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(1.0 * x + N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -5.7e-105], t$95$0, If[LessEqual[z, 53000000.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(1, x, z \cdot \sin y\right)\\
\mathbf{if}\;z \leq -5.7 \cdot 10^{-105}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 53000000:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -5.69999999999999963e-105 or 5.3e7 < z Initial program 99.8%
lift-+.f64N/A
lift-*.f64N/A
*-commutativeN/A
lower-fma.f6499.8
lift-*.f64N/A
*-commutativeN/A
lower-*.f6499.8
Applied rewrites99.8%
Taylor expanded in y around 0
Applied rewrites87.1%
if -5.69999999999999963e-105 < z < 5.3e7Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6491.8
Applied rewrites91.8%
Final simplification89.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -2.3e-77) t_0 (if (<= x 3.7e-71) (* z (sin y)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -2.3e-77) {
tmp = t_0;
} else if (x <= 3.7e-71) {
tmp = z * sin(y);
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: t_0
real(8) :: tmp
t_0 = x * cos(y)
if (x <= (-2.3d-77)) then
tmp = t_0
else if (x <= 3.7d-71) then
tmp = z * sin(y)
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = x * Math.cos(y);
double tmp;
if (x <= -2.3e-77) {
tmp = t_0;
} else if (x <= 3.7e-71) {
tmp = z * Math.sin(y);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -2.3e-77: tmp = t_0 elif x <= 3.7e-71: tmp = z * math.sin(y) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -2.3e-77) tmp = t_0; elseif (x <= 3.7e-71) tmp = Float64(z * sin(y)); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * cos(y); tmp = 0.0; if (x <= -2.3e-77) tmp = t_0; elseif (x <= 3.7e-71) tmp = z * sin(y); else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -2.3e-77], t$95$0, If[LessEqual[x, 3.7e-71], N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -2.3 \cdot 10^{-77}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.7 \cdot 10^{-71}:\\
\;\;\;\;z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.29999999999999999e-77 or 3.6999999999999996e-71 < x Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6482.8
Applied rewrites82.8%
if -2.29999999999999999e-77 < x < 3.6999999999999996e-71Initial program 99.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f64N/A
lower-sin.f6478.7
Applied rewrites78.7%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= y -4e-5) t_0 (if (<= y 7.2e-12) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -4e-5) {
tmp = t_0;
} else if (y <= 7.2e-12) {
tmp = fma(z, y, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -4e-5) tmp = t_0; elseif (y <= 7.2e-12) tmp = fma(z, y, x); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4e-5], t$95$0, If[LessEqual[y, 7.2e-12], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -4 \cdot 10^{-5}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 7.2 \cdot 10^{-12}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -4.00000000000000033e-5 or 7.2e-12 < y Initial program 99.7%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6451.4
Applied rewrites51.4%
if -4.00000000000000033e-5 < y < 7.2e-12Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64100.0
Applied rewrites100.0%
Final simplification76.8%
(FPCore (x y z) :precision binary64 (if (<= x -4.4e-79) (* 1.0 x) (if (<= x 1.7e-85) (* z y) (* 1.0 x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e-79) {
tmp = 1.0 * x;
} else if (x <= 1.7e-85) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8) :: tmp
if (x <= (-4.4d-79)) then
tmp = 1.0d0 * x
else if (x <= 1.7d-85) then
tmp = z * y
else
tmp = 1.0d0 * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -4.4e-79) {
tmp = 1.0 * x;
} else if (x <= 1.7e-85) {
tmp = z * y;
} else {
tmp = 1.0 * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -4.4e-79: tmp = 1.0 * x elif x <= 1.7e-85: tmp = z * y else: tmp = 1.0 * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -4.4e-79) tmp = Float64(1.0 * x); elseif (x <= 1.7e-85) tmp = Float64(z * y); else tmp = Float64(1.0 * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -4.4e-79) tmp = 1.0 * x; elseif (x <= 1.7e-85) tmp = z * y; else tmp = 1.0 * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -4.4e-79], N[(1.0 * x), $MachinePrecision], If[LessEqual[x, 1.7e-85], N[(z * y), $MachinePrecision], N[(1.0 * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{-79}:\\
\;\;\;\;1 \cdot x\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{-85}:\\
\;\;\;\;z \cdot y\\
\mathbf{else}:\\
\;\;\;\;1 \cdot x\\
\end{array}
\end{array}
if x < -4.3999999999999998e-79 or 1.7e-85 < x Initial program 99.9%
Taylor expanded in z around 0
*-commutativeN/A
lower-*.f64N/A
lower-cos.f6482.4
Applied rewrites82.4%
Taylor expanded in y around 0
Applied rewrites55.3%
if -4.3999999999999998e-79 < x < 1.7e-85Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6448.4
Applied rewrites48.4%
Taylor expanded in z around inf
Applied rewrites36.2%
(FPCore (x y z) :precision binary64 (fma z y x))
double code(double x, double y, double z) {
return fma(z, y, x);
}
function code(x, y, z) return fma(z, y, x) end
code[x_, y_, z_] := N[(z * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, y, x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6456.1
Applied rewrites56.1%
(FPCore (x y z) :precision binary64 (* z y))
double code(double x, double y, double z) {
return z * y;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z * y
end function
public static double code(double x, double y, double z) {
return z * y;
}
def code(x, y, z): return z * y
function code(x, y, z) return Float64(z * y) end
function tmp = code(x, y, z) tmp = z * y; end
code[x_, y_, z_] := N[(z * y), $MachinePrecision]
\begin{array}{l}
\\
z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f6456.1
Applied rewrites56.1%
Taylor expanded in z around inf
Applied rewrites18.1%
herbie shell --seed 2024251
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))