
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 8 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma (cos y) z (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
Initial program 99.8%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6499.8
Applied egg-rr99.8%
(FPCore (x y z) :precision binary64 (if (<= x -1.3e+81) (fma (sin y) x z) (if (<= x 1.12e-52) (* (cos y) z) (+ z (* x (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.3e+81) {
tmp = fma(sin(y), x, z);
} else if (x <= 1.12e-52) {
tmp = cos(y) * z;
} else {
tmp = z + (x * sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (x <= -1.3e+81) tmp = fma(sin(y), x, z); elseif (x <= 1.12e-52) tmp = Float64(cos(y) * z); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[x, -1.3e+81], N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision], If[LessEqual[x, 1.12e-52], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+81}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{elif}\;x \leq 1.12 \cdot 10^{-52}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if x < -1.29999999999999996e81Initial program 99.7%
*-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 y around 0
Simplified93.0%
if -1.29999999999999996e81 < x < 1.11999999999999994e-52Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6492.4
Simplified92.4%
if 1.11999999999999994e-52 < x Initial program 99.7%
Taylor expanded in y around 0
Simplified88.0%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (fma (sin y) x z))) (if (<= x -7.7e+83) t_0 (if (<= x 2.25e-52) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = fma(sin(y), x, z);
double tmp;
if (x <= -7.7e+83) {
tmp = t_0;
} else if (x <= 2.25e-52) {
tmp = cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = fma(sin(y), x, z) tmp = 0.0 if (x <= -7.7e+83) tmp = t_0; elseif (x <= 2.25e-52) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Sin[y], $MachinePrecision] * x + z), $MachinePrecision]}, If[LessEqual[x, -7.7e+83], t$95$0, If[LessEqual[x, 2.25e-52], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \mathsf{fma}\left(\sin y, x, z\right)\\
\mathbf{if}\;x \leq -7.7 \cdot 10^{+83}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 2.25 \cdot 10^{-52}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.6999999999999998e83 or 2.25e-52 < x Initial program 99.7%
*-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 y around 0
Simplified89.6%
if -7.6999999999999998e83 < x < 2.25e-52Initial program 99.9%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6492.4
Simplified92.4%
Final simplification91.0%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= x -7.6e+160) t_0 (if (<= x 1.7e+67) (* (cos y) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (x <= -7.6e+160) {
tmp = t_0;
} else if (x <= 1.7e+67) {
tmp = cos(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 * sin(y)
if (x <= (-7.6d+160)) then
tmp = t_0
else if (x <= 1.7d+67) then
tmp = cos(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.sin(y);
double tmp;
if (x <= -7.6e+160) {
tmp = t_0;
} else if (x <= 1.7e+67) {
tmp = Math.cos(y) * z;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.sin(y) tmp = 0 if x <= -7.6e+160: tmp = t_0 elif x <= 1.7e+67: tmp = math.cos(y) * z else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (x <= -7.6e+160) tmp = t_0; elseif (x <= 1.7e+67) tmp = Float64(cos(y) * z); else tmp = t_0; end return tmp end
function tmp_2 = code(x, y, z) t_0 = x * sin(y); tmp = 0.0; if (x <= -7.6e+160) tmp = t_0; elseif (x <= 1.7e+67) tmp = cos(y) * z; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -7.6e+160], t$95$0, If[LessEqual[x, 1.7e+67], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;x \leq -7.6 \cdot 10^{+160}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+67}:\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.60000000000000024e160 or 1.7000000000000001e67 < x Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6477.3
Simplified77.3%
if -7.60000000000000024e160 < x < 1.7000000000000001e67Initial program 99.8%
Taylor expanded in x around 0
*-lowering-*.f64N/A
cos-lowering-cos.f6486.1
Simplified86.1%
Final simplification82.8%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (sin y)))) (if (<= y -0.2) t_0 (if (<= y 0.19) (fma y (fma z (* y -0.5) x) z) t_0))))
double code(double x, double y, double z) {
double t_0 = x * sin(y);
double tmp;
if (y <= -0.2) {
tmp = t_0;
} else if (y <= 0.19) {
tmp = fma(y, fma(z, (y * -0.5), x), z);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * sin(y)) tmp = 0.0 if (y <= -0.2) tmp = t_0; elseif (y <= 0.19) tmp = fma(y, fma(z, Float64(y * -0.5), x), z); else tmp = t_0; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -0.2], t$95$0, If[LessEqual[y, 0.19], N[(y * N[(z * N[(y * -0.5), $MachinePrecision] + x), $MachinePrecision] + z), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \sin y\\
\mathbf{if}\;y \leq -0.2:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.19:\\
\;\;\;\;\mathsf{fma}\left(y, \mathsf{fma}\left(z, y \cdot -0.5, x\right), z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.20000000000000001 or 0.19 < y Initial program 99.6%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6455.4
Simplified55.4%
if -0.20000000000000001 < y < 0.19Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
associate-*r*N/A
accelerator-lowering-fma.f64N/A
+-commutativeN/A
*-commutativeN/A
associate-*l*N/A
accelerator-lowering-fma.f64N/A
*-commutativeN/A
*-lowering-*.f6499.2
Simplified99.2%
(FPCore (x y z) :precision binary64 (if (<= x -2.05e+167) (* y x) (if (<= x 1.8e+67) z (* y x))))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.05e+167) {
tmp = y * x;
} else if (x <= 1.8e+67) {
tmp = z;
} else {
tmp = y * 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 <= (-2.05d+167)) then
tmp = y * x
else if (x <= 1.8d+67) then
tmp = z
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -2.05e+167) {
tmp = y * x;
} else if (x <= 1.8e+67) {
tmp = z;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.05e+167: tmp = y * x elif x <= 1.8e+67: tmp = z else: tmp = y * x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.05e+167) tmp = Float64(y * x); elseif (x <= 1.8e+67) tmp = z; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.05e+167) tmp = y * x; elseif (x <= 1.8e+67) tmp = z; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.05e+167], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.8e+67], z, N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{+167}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.8 \cdot 10^{+67}:\\
\;\;\;\;z\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -2.05e167 or 1.7999999999999999e67 < x Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
sin-lowering-sin.f6476.8
Simplified76.8%
Taylor expanded in y around 0
*-lowering-*.f6429.6
Simplified29.6%
if -2.05e167 < x < 1.7999999999999999e67Initial program 99.8%
Taylor expanded in y around 0
Simplified58.3%
Final simplification47.8%
(FPCore (x y z) :precision binary64 (fma y x z))
double code(double x, double y, double z) {
return fma(y, x, z);
}
function code(x, y, z) return fma(y, x, z) end
code[x_, y_, z_] := N[(y * x + z), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, x, z\right)
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f6454.3
Simplified54.3%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
Simplified43.0%
herbie shell --seed 2024199
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))