
(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 9 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 (sin y) z (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), z, Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * z + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) x (* (sin y) z)))
double code(double x, double y, double z) {
return fma(cos(y), x, (sin(y) * z));
}
function code(x, y, z) return fma(cos(y), x, Float64(sin(y) * z)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, \sin y \cdot z\right)
\end{array}
Initial program 99.8%
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.8
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= x -2.75e+104)
t_0
(if (<= x 2.3e+60) (fma (/ (sin y) x) (* z x) x) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -2.75e+104) {
tmp = t_0;
} else if (x <= 2.3e+60) {
tmp = fma((sin(y) / x), (z * x), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -2.75e+104) tmp = t_0; elseif (x <= 2.3e+60) tmp = fma(Float64(sin(y) / x), Float64(z * x), 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[x, -2.75e+104], t$95$0, If[LessEqual[x, 2.3e+60], N[(N[(N[Sin[y], $MachinePrecision] / x), $MachinePrecision] * N[(z * x), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -2.75 \cdot 10^{+104}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+60}:\\
\;\;\;\;\mathsf{fma}\left(\frac{\sin y}{x}, z \cdot x, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.75000000000000008e104 or 2.30000000000000017e60 < x Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6492.4
Simplified92.4%
if -2.75000000000000008e104 < x < 2.30000000000000017e60Initial program 99.8%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
+-commutativeN/A
associate-/l*N/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f64N/A
cos-lowering-cos.f6489.6
Simplified89.6%
distribute-rgt-inN/A
*-commutativeN/A
associate-*l*N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
/-lowering-/.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6490.4
Applied egg-rr90.4%
Taylor expanded in y around 0
Simplified77.6%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -1.1e-48) t_0 (if (<= x 1.9e-77) (* (sin y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.1e-48) {
tmp = t_0;
} else if (x <= 1.9e-77) {
tmp = sin(y) * z;
} 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 <= (-1.1d-48)) then
tmp = t_0
else if (x <= 1.9d-77) then
tmp = sin(y) * z
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 <= -1.1e-48) {
tmp = t_0;
} else if (x <= 1.9e-77) {
tmp = Math.sin(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if x <= -1.1e-48: tmp = t_0 elif x <= 1.9e-77: tmp = math.sin(y) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -1.1e-48) tmp = t_0; elseif (x <= 1.9e-77) tmp = Float64(sin(y) * z); 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 <= -1.1e-48) tmp = t_0; elseif (x <= 1.9e-77) tmp = sin(y) * z; 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, -1.1e-48], t$95$0, If[LessEqual[x, 1.9e-77], N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -1.1 \cdot 10^{-48}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.9 \cdot 10^{-77}:\\
\;\;\;\;\sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.10000000000000006e-48 or 1.8999999999999999e-77 < x Initial program 99.9%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.9
Applied egg-rr99.9%
Taylor expanded in z around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6483.3
Simplified83.3%
if -1.10000000000000006e-48 < x < 1.8999999999999999e-77Initial program 99.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.7
Applied egg-rr99.7%
Taylor expanded in z around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6474.0
Simplified74.0%
Final simplification80.1%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.0015)
t_0
(if (<= y 0.00375)
(fma y (fma y (* (* y z) -0.16666666666666666) z) x)
t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0015) {
tmp = t_0;
} else if (y <= 0.00375) {
tmp = fma(y, fma(y, ((y * z) * -0.16666666666666666), z), x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -0.0015) tmp = t_0; elseif (y <= 0.00375) tmp = fma(y, fma(y, Float64(Float64(y * z) * -0.16666666666666666), z), 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, -0.0015], t$95$0, If[LessEqual[y, 0.00375], N[(y * N[(y * N[(N[(y * z), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0015:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.00375:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(y, \left(y \cdot z\right) \cdot -0.16666666666666666, z\right), x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.0015 or 0.0037499999999999999 < y Initial program 99.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.7
Applied egg-rr99.7%
Taylor expanded in z around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6453.0
Simplified53.0%
if -0.0015 < y < 0.0037499999999999999Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0
Simplified100.0%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f64100.0
Simplified100.0%
(FPCore (x y z) :precision binary64 (fma y (fma y (* (* y z) -0.16666666666666666) z) x))
double code(double x, double y, double z) {
return fma(y, fma(y, ((y * z) * -0.16666666666666666), z), x);
}
function code(x, y, z) return fma(y, fma(y, Float64(Float64(y * z) * -0.16666666666666666), z), x) end
code[x_, y_, z_] := N[(y * N[(y * N[(N[(y * z), $MachinePrecision] * -0.16666666666666666), $MachinePrecision] + z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \mathsf{fma}\left(y, \left(y \cdot z\right) \cdot -0.16666666666666666, z\right), x\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f6450.9
Simplified50.9%
Taylor expanded in x around 0
*-commutativeN/A
*-lowering-*.f64N/A
*-lowering-*.f6451.6
Simplified51.6%
(FPCore (x y z) :precision binary64 (if (<= z 4.6e+135) x (* y z)))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.6e+135) {
tmp = x;
} else {
tmp = y * z;
}
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 (z <= 4.6d+135) then
tmp = x
else
tmp = y * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= 4.6e+135) {
tmp = x;
} else {
tmp = y * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.6e+135: tmp = x else: tmp = y * z return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.6e+135) tmp = x; else tmp = Float64(y * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= 4.6e+135) tmp = x; else tmp = y * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.6e+135], x, N[(y * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.6 \cdot 10^{+135}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;y \cdot z\\
\end{array}
\end{array}
if z < 4.6000000000000002e135Initial program 99.8%
Taylor expanded in y around 0
Simplified46.0%
if 4.6000000000000002e135 < z Initial program 99.7%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6452.3
Simplified52.3%
Taylor expanded in z around inf
*-lowering-*.f6439.2
Simplified39.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
accelerator-lowering-fma.f6451.5
Simplified51.5%
(FPCore (x y z) :precision binary64 x)
double code(double x, double y, double z) {
return x;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = x
end function
public static double code(double x, double y, double z) {
return x;
}
def code(x, y, z): return x
function code(x, y, z) return x end
function tmp = code(x, y, z) tmp = x; end
code[x_, y_, z_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Simplified41.8%
herbie shell --seed 2024195
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))