
(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 (- 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%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -4e+60) t_0 (if (<= x 9e+69) (fma (- 0.0 (sin y)) z x) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -4e+60) {
tmp = t_0;
} else if (x <= 9e+69) {
tmp = fma((0.0 - sin(y)), z, x);
} else {
tmp = t_0;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (x <= -4e+60) tmp = t_0; elseif (x <= 9e+69) tmp = fma(Float64(0.0 - sin(y)), 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[x, -4e+60], t$95$0, If[LessEqual[x, 9e+69], N[(N[(0.0 - N[Sin[y], $MachinePrecision]), $MachinePrecision] * z + x), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;x \leq -4 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 9 \cdot 10^{+69}:\\
\;\;\;\;\mathsf{fma}\left(0 - \sin y, z, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -3.9999999999999998e60 or 8.9999999999999999e69 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6491.5%
Simplified91.5%
if -3.9999999999999998e60 < x < 8.9999999999999999e69Initial 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
Simplified88.0%
(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 -1.7e+60) t_0 (if (<= x 1.18e+70) (- x (* (sin y) z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (x <= -1.7e+60) {
tmp = t_0;
} else if (x <= 1.18e+70) {
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 <= (-1.7d+60)) then
tmp = t_0
else if (x <= 1.18d+70) 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 <= -1.7e+60) {
tmp = t_0;
} else if (x <= 1.18e+70) {
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 <= -1.7e+60: tmp = t_0 elif x <= 1.18e+70: 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 <= -1.7e+60) tmp = t_0; elseif (x <= 1.18e+70) 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 <= -1.7e+60) tmp = t_0; elseif (x <= 1.18e+70) 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, -1.7e+60], t$95$0, If[LessEqual[x, 1.18e+70], 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 -1.7 \cdot 10^{+60}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 1.18 \cdot 10^{+70}:\\
\;\;\;\;x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -1.7e60 or 1.18000000000000001e70 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6491.5%
Simplified91.5%
if -1.7e60 < x < 1.18000000000000001e70Initial program 99.8%
Taylor expanded in y around 0
Simplified88.0%
Final simplification89.4%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= x -8e-39) t_0 (if (<= x 3.8e-69) (- 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 <= -8e-39) {
tmp = t_0;
} else if (x <= 3.8e-69) {
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 <= (-8d-39)) then
tmp = t_0
else if (x <= 3.8d-69) 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 <= -8e-39) {
tmp = t_0;
} else if (x <= 3.8e-69) {
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 <= -8e-39: tmp = t_0 elif x <= 3.8e-69: 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 <= -8e-39) tmp = t_0; elseif (x <= 3.8e-69) 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 <= -8e-39) tmp = t_0; elseif (x <= 3.8e-69) 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, -8e-39], t$95$0, If[LessEqual[x, 3.8e-69], 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 -8 \cdot 10^{-39}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq 3.8 \cdot 10^{-69}:\\
\;\;\;\;0 - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -7.99999999999999943e-39 or 3.7999999999999998e-69 < x Initial program 99.8%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6482.6%
Simplified82.6%
if -7.99999999999999943e-39 < x < 3.7999999999999998e-69Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6479.4%
Simplified79.4%
sub0-negN/A
neg-lowering-neg.f64N/A
*-lowering-*.f64N/A
sin-lowering-sin.f6479.4%
Applied egg-rr79.4%
Final simplification81.3%
(FPCore (x y z) :precision binary64 (let* ((t_0 (* x (cos y)))) (if (<= y -1.35e-7) t_0 (if (<= y 3e-18) (- x (* y z)) t_0))))
double code(double x, double y, double z) {
double t_0 = x * cos(y);
double tmp;
if (y <= -1.35e-7) {
tmp = t_0;
} else if (y <= 3e-18) {
tmp = x - (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 (y <= (-1.35d-7)) then
tmp = t_0
else if (y <= 3d-18) then
tmp = x - (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 (y <= -1.35e-7) {
tmp = t_0;
} else if (y <= 3e-18) {
tmp = x - (y * z);
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y, z): t_0 = x * math.cos(y) tmp = 0 if y <= -1.35e-7: tmp = t_0 elif y <= 3e-18: tmp = x - (y * z) else: tmp = t_0 return tmp
function code(x, y, z) t_0 = Float64(x * cos(y)) tmp = 0.0 if (y <= -1.35e-7) tmp = t_0; elseif (y <= 3e-18) tmp = Float64(x - Float64(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 (y <= -1.35e-7) tmp = t_0; elseif (y <= 3e-18) tmp = x - (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[y, -1.35e-7], t$95$0, If[LessEqual[y, 3e-18], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision], t$95$0]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \cos y\\
\mathbf{if}\;y \leq -1.35 \cdot 10^{-7}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-18}:\\
\;\;\;\;x - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if y < -1.35000000000000004e-7 or 2.99999999999999983e-18 < y Initial program 99.7%
Taylor expanded in x around inf
*-lowering-*.f64N/A
cos-lowering-cos.f6455.2%
Simplified55.2%
if -1.35000000000000004e-7 < y < 2.99999999999999983e-18Initial program 100.0%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f64100.0%
Simplified100.0%
Final simplification75.9%
(FPCore (x y z) :precision binary64 (if (<= x -7.5e-97) x (if (<= x 3.2e-109) (- 0.0 (* y z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e-97) {
tmp = x;
} else if (x <= 3.2e-109) {
tmp = 0.0 - (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 (x <= (-7.5d-97)) then
tmp = x
else if (x <= 3.2d-109) then
tmp = 0.0d0 - (y * z)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (x <= -7.5e-97) {
tmp = x;
} else if (x <= 3.2e-109) {
tmp = 0.0 - (y * z);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -7.5e-97: tmp = x elif x <= 3.2e-109: tmp = 0.0 - (y * z) else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -7.5e-97) tmp = x; elseif (x <= 3.2e-109) tmp = Float64(0.0 - Float64(y * z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -7.5e-97) tmp = x; elseif (x <= 3.2e-109) tmp = 0.0 - (y * z); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -7.5e-97], x, If[LessEqual[x, 3.2e-109], N[(0.0 - N[(y * z), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.5 \cdot 10^{-97}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 3.2 \cdot 10^{-109}:\\
\;\;\;\;0 - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -7.5e-97 or 3.2000000000000002e-109 < x Initial program 99.9%
Taylor expanded in y around 0
Simplified44.6%
if -7.5e-97 < x < 3.2000000000000002e-109Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6453.3%
Simplified53.3%
Taylor expanded in x around 0
mul-1-negN/A
neg-sub0N/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6443.3%
Simplified43.3%
sub0-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
*-lowering-*.f64N/A
neg-lowering-neg.f6443.3%
Applied egg-rr43.3%
Final simplification44.2%
(FPCore (x y z) :precision binary64 (- x (* y z)))
double code(double x, double y, double z) {
return x - (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 - (y * z)
end function
public static double code(double x, double y, double z) {
return x - (y * z);
}
def code(x, y, z): return x - (y * z)
function code(x, y, z) return Float64(x - Float64(y * z)) end
function tmp = code(x, y, z) tmp = x - (y * z); end
code[x_, y_, z_] := N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - y \cdot z
\end{array}
Initial program 99.8%
Taylor expanded in y around 0
mul-1-negN/A
unsub-negN/A
--lowering--.f64N/A
*-commutativeN/A
*-lowering-*.f6451.0%
Simplified51.0%
Final simplification51.0%
(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
Simplified33.6%
herbie shell --seed 2024191
(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))))