
(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 8 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 (- 0.0 (sin y)) z (* x (cos y))))
double code(double x, double y, double z) {
return fma((0.0 - sin(y)), z, (x * cos(y)));
}
function code(x, y, z) return fma(Float64(0.0 - sin(y)), z, Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[(0.0 - N[Sin[y], $MachinePrecision]), $MachinePrecision] * z + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(0 - \sin y, z, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
sub0-negN/A
neg-lowering-neg.f64N/A
sin-lowering-sin.f6499.8
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* x (cos y)) (* (sin y) z)))
double code(double x, double y, double z) {
return (x * cos(y)) - (sin(y) * z);
}
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)) - (sin(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.cos(y)) - (Math.sin(y) * z);
}
def code(x, y, z): return (x * math.cos(y)) - (math.sin(y) * z)
function code(x, y, z) return Float64(Float64(x * cos(y)) - Float64(sin(y) * z)) end
function tmp = code(x, y, z) tmp = (x * cos(y)) - (sin(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision] - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \cos y - \sin y \cdot z
\end{array}
Initial program 99.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 1.12e+111) (- x (* (sin y) z)) 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 <= 1.12e+111) {
tmp = x - (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 <= (-2.75d+104)) then
tmp = t_0
else if (x <= 1.12d+111) then
tmp = x - (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 <= -2.75e+104) {
tmp = t_0;
} else if (x <= 1.12e+111) {
tmp = x - (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 <= -2.75e+104: tmp = t_0 elif x <= 1.12e+111: tmp = x - (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 <= -2.75e+104) tmp = t_0; elseif (x <= 1.12e+111) tmp = Float64(x - 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 <= -2.75e+104) tmp = t_0; elseif (x <= 1.12e+111) tmp = x - (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, -2.75e+104], t$95$0, If[LessEqual[x, 1.12e+111], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $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 1.12 \cdot 10^{+111}:\\
\;\;\;\;x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -2.75000000000000008e104 or 1.11999999999999995e111 < x Initial program 99.8%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6493.2
Simplified93.2%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
cos-lowering-cos.f6493.2
Applied egg-rr93.2%
if -2.75000000000000008e104 < x < 1.11999999999999995e111Initial program 99.8%
Taylor expanded in y around 0
Simplified86.5%
Final simplification89.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -1.1e-48) t_0 (if (<= x 1.9e-77) (- 0.0 (* (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 = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (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 = 0.0 - (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(0.0 - 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 = 0.0 - (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[(0.0 - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $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}:\\
\;\;\;\;0 - \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.8%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6483.1
Simplified83.1%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
cos-lowering-cos.f6483.1
Applied egg-rr83.1%
if -1.10000000000000006e-48 < x < 1.8999999999999999e-77Initial program 99.7%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.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
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6473.9
Simplified73.9%
Final simplification80.0%
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* x (cos y))))
(if (<= y -0.024)
t_0
(if (<= y 0.026)
(fma y (- (* y (fma x -0.5 (* z (* y 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.024) {
tmp = t_0;
} else if (y <= 0.026) {
tmp = fma(y, ((y * fma(x, -0.5, (z * (y * 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.024) tmp = t_0; elseif (y <= 0.026) tmp = fma(y, Float64(Float64(y * fma(x, -0.5, Float64(z * Float64(y * 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.024], t$95$0, If[LessEqual[y, 0.026], N[(y * N[(N[(y * N[(x * -0.5 + N[(z * N[(y * 0.16666666666666666), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $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.024:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 0.026:\\
\;\;\;\;\mathsf{fma}\left(y, y \cdot \mathsf{fma}\left(x, -0.5, z \cdot \left(y \cdot 0.16666666666666666\right)\right) - z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -0.024 or 0.0259999999999999988 < y Initial program 99.6%
Taylor expanded in x around inf
+-rgt-identityN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f6452.8
Simplified52.8%
+-rgt-identityN/A
*-commutativeN/A
*-lowering-*.f64N/A
cos-lowering-cos.f6452.8
Applied egg-rr52.8%
if -0.024 < y < 0.0259999999999999988Initial program 100.0%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f64100.0
Applied egg-rr100.0%
sub0-negN/A
neg-lowering-neg.f64N/A
sin-lowering-sin.f64100.0
Applied egg-rr100.0%
+-commutativeN/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
cos-lowering-cos.f64N/A
distribute-lft-neg-outN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f64100.0
Applied egg-rr100.0%
Taylor expanded in y around 0
+-commutativeN/A
accelerator-lowering-fma.f64N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
*-commutativeN/A
accelerator-lowering-fma.f64N/A
associate-*r*N/A
*-commutativeN/A
*-lowering-*.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0
Simplified100.0%
Final simplification76.0%
(FPCore (x y z) :precision binary64 (if (<= z 4.6e+135) x (- 0.0 (* y z))))
double code(double x, double y, double z) {
double tmp;
if (z <= 4.6e+135) {
tmp = x;
} else {
tmp = 0.0 - (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 = 0.0d0 - (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 = 0.0 - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= 4.6e+135: tmp = x else: tmp = 0.0 - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if (z <= 4.6e+135) tmp = x; else tmp = Float64(0.0 - 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 = 0.0 - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, 4.6e+135], x, N[(0.0 - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq 4.6 \cdot 10^{+135}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;0 - 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%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f6453.1
Simplified53.1%
Taylor expanded in y around inf
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f6439.7
Simplified39.7%
(FPCore (x y z) :precision binary64 (fma y (- 0.0 z) x))
double code(double x, double y, double z) {
return fma(y, (0.0 - z), x);
}
function code(x, y, z) return fma(y, Float64(0.0 - z), x) end
code[x_, y_, z_] := N[(y * N[(0.0 - z), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, 0 - z, x\right)
\end{array}
Initial program 99.8%
sub-negN/A
+-commutativeN/A
*-commutativeN/A
distribute-lft-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f64N/A
sin-lowering-sin.f64N/A
*-lowering-*.f64N/A
cos-lowering-cos.f6499.8
Applied egg-rr99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
distribute-rgt-neg-inN/A
accelerator-lowering-fma.f64N/A
neg-sub0N/A
--lowering--.f6451.9
Simplified51.9%
sub0-negN/A
neg-lowering-neg.f6451.9
Applied egg-rr51.9%
Final simplification51.9%
(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.6%
herbie shell --seed 2024195
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, A"
:precision binary64
(- (* x (cos y)) (* z (sin y))))