
(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 (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
(let* ((t_0 (* (sin y) z)))
(if (<= y -375.0)
t_0
(if (<= y 3.4e-21) (fma z y x) (if (<= y 4.8e+200) (* x (cos y)) t_0)))))
double code(double x, double y, double z) {
double t_0 = sin(y) * z;
double tmp;
if (y <= -375.0) {
tmp = t_0;
} else if (y <= 3.4e-21) {
tmp = fma(z, y, x);
} else if (y <= 4.8e+200) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(sin(y) * z) tmp = 0.0 if (y <= -375.0) tmp = t_0; elseif (y <= 3.4e-21) tmp = fma(z, y, x); elseif (y <= 4.8e+200) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]}, If[LessEqual[y, -375.0], t$95$0, If[LessEqual[y, 3.4e-21], N[(z * y + x), $MachinePrecision], If[LessEqual[y, 4.8e+200], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \sin y \cdot z\\
\mathbf{if}\;y \leq -375:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{elif}\;y \leq 4.8 \cdot 10^{+200}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -375 or 4.8000000000000001e200 < y Initial program 99.6%
Taylor expanded in x around 0
*-lowering-*.f64N/A
sin-lowering-sin.f6458.2
Simplified58.2%
if -375 < y < 3.4e-21Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6499.4
Simplified99.4%
if 3.4e-21 < y < 4.8000000000000001e200Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6469.8
Simplified69.8%
Final simplification80.5%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) z x))) (if (<= z -1.1e-45) t_0 (if (<= z 1.1e-127) (* x (cos y)) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), z, x);
double tmp;
if (z <= -1.1e-45) {
tmp = t_0;
} else if (z <= 1.1e-127) {
tmp = x * cos(y);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), z, x) tmp = 0.0 if (z <= -1.1e-45) tmp = t_0; elseif (z <= 1.1e-127) tmp = Float64(x * cos(y)); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * z + x), $MachinePrecision]}, If[LessEqual[z, -1.1e-45], t$95$0, If[LessEqual[z, 1.1e-127], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, z, x\right)\\
\mathbf{if}\;z \leq -1.1 \cdot 10^{-45}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;z \leq 1.1 \cdot 10^{-127}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if z < -1.09999999999999997e-45 or 1.1000000000000001e-127 < z Initial program 99.8%
Taylor expanded in y around 0
Simplified82.7%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
sin-lowering-sin.f6482.7
Applied egg-rr82.7%
if -1.09999999999999997e-45 < z < 1.1000000000000001e-127Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6496.2
Simplified96.2%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= y -0.0044) t_0 (if (<= y 3.4e-21) (fma z y x) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -0.0044) {
tmp = t_0;
} else if (y <= 3.4e-21) {
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 <= -0.0044) tmp = t_0; elseif (y <= 3.4e-21) 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, -0.0044], t$95$0, If[LessEqual[y, 3.4e-21], N[(z * y + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -0.0044:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3.4 \cdot 10^{-21}:\\
\;\;\;\;\mathsf{fma}\left(z, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.00440000000000000027 or 3.4e-21 < y Initial program 99.6%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6455.7
Simplified55.7%
if -0.00440000000000000027 < y < 3.4e-21Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64100.0
Simplified100.0%
(FPCore (x y z) :precision binary64 (if (<= z -1.85e+134) (* y z) x))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+134) {
tmp = y * z;
} else {
tmp = 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 (z <= (-1.85d+134)) then
tmp = y * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.85e+134) {
tmp = y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.85e+134: tmp = y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.85e+134) tmp = Float64(y * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.85e+134) tmp = y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.85e+134], N[(y * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{+134}:\\
\;\;\;\;y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -1.85000000000000007e134Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6446.4
Simplified46.4%
Taylor expanded in z around inf
*-lowering-*.f6437.9
Simplified37.9%
if -1.85000000000000007e134 < z Initial program 99.8%
Taylor expanded in y around 0
Simplified44.7%
(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.f6452.1
Simplified52.1%
(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
Simplified40.3%
herbie shell --seed 2024204
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutY from diagrams-lib-1.3.0.3"
:precision binary64
(+ (* x (cos y)) (* z (sin y))))