
(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 (- (* 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}
Initial program 99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6e-46) (not (<= z 2.25e-68))) (- (* x 1.0) (* z (sin y))) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e-46) || !(z <= 2.25e-68)) {
tmp = (x * 1.0) - (z * sin(y));
} else {
tmp = cos(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 ((z <= (-6d-46)) .or. (.not. (z <= 2.25d-68))) then
tmp = (x * 1.0d0) - (z * sin(y))
else
tmp = cos(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6e-46) || !(z <= 2.25e-68)) {
tmp = (x * 1.0) - (z * Math.sin(y));
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e-46) or not (z <= 2.25e-68): tmp = (x * 1.0) - (z * math.sin(y)) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e-46) || !(z <= 2.25e-68)) tmp = Float64(Float64(x * 1.0) - Float64(z * sin(y))); else tmp = Float64(cos(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6e-46) || ~((z <= 2.25e-68))) tmp = (x * 1.0) - (z * sin(y)); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e-46], N[Not[LessEqual[z, 2.25e-68]], $MachinePrecision]], N[(N[(x * 1.0), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{-46} \lor \neg \left(z \leq 2.25 \cdot 10^{-68}\right):\\
\;\;\;\;x \cdot 1 - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -5.99999999999999975e-46 or 2.25e-68 < z Initial program 99.8%
Taylor expanded in y around 0
Applied rewrites90.0%
if -5.99999999999999975e-46 < z < 2.25e-68Initial program 99.8%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites99.7%
Taylor expanded in x around inf
Applied rewrites89.5%
Final simplification89.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -4.7e+160) (not (<= z 7.2e+87))) (* (- z) (sin y)) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -4.7e+160) || !(z <= 7.2e+87)) {
tmp = -z * sin(y);
} else {
tmp = cos(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 ((z <= (-4.7d+160)) .or. (.not. (z <= 7.2d+87))) then
tmp = -z * sin(y)
else
tmp = cos(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -4.7e+160) || !(z <= 7.2e+87)) {
tmp = -z * Math.sin(y);
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -4.7e+160) or not (z <= 7.2e+87): tmp = -z * math.sin(y) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -4.7e+160) || !(z <= 7.2e+87)) tmp = Float64(Float64(-z) * sin(y)); else tmp = Float64(cos(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -4.7e+160) || ~((z <= 7.2e+87))) tmp = -z * sin(y); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -4.7e+160], N[Not[LessEqual[z, 7.2e+87]], $MachinePrecision]], N[((-z) * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.7 \cdot 10^{+160} \lor \neg \left(z \leq 7.2 \cdot 10^{+87}\right):\\
\;\;\;\;\left(-z\right) \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -4.6999999999999997e160 or 7.19999999999999988e87 < z Initial program 99.8%
Taylor expanded in x around 0
mul-1-negN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
lower-neg.f64N/A
lower-sin.f6476.8
Applied rewrites76.8%
if -4.6999999999999997e160 < z < 7.19999999999999988e87Initial program 99.8%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites99.1%
Taylor expanded in x around inf
Applied rewrites80.6%
Final simplification79.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.042) (not (<= y 1.3e-7))) (* (cos y) x) (fma (- (* (fma 0.16666666666666666 (* z y) (* -0.5 x)) y) z) y x)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.042) || !(y <= 1.3e-7)) {
tmp = cos(y) * x;
} else {
tmp = fma(((fma(0.16666666666666666, (z * y), (-0.5 * x)) * y) - z), y, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -0.042) || !(y <= 1.3e-7)) tmp = Float64(cos(y) * x); else tmp = fma(Float64(Float64(fma(0.16666666666666666, Float64(z * y), Float64(-0.5 * x)) * y) - z), y, x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.042], N[Not[LessEqual[y, 1.3e-7]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(N[(0.16666666666666666 * N[(z * y), $MachinePrecision] + N[(-0.5 * x), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision] - z), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.042 \lor \neg \left(y \leq 1.3 \cdot 10^{-7}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\mathsf{fma}\left(0.16666666666666666, z \cdot y, -0.5 \cdot x\right) \cdot y - z, y, x\right)\\
\end{array}
\end{array}
if y < -0.0420000000000000026 or 1.29999999999999999e-7 < y Initial program 99.6%
Taylor expanded in x around inf
distribute-lft-inN/A
remove-double-negN/A
*-commutativeN/A
distribute-lft-neg-outN/A
mul-1-negN/A
*-commutativeN/A
mul-1-negN/A
distribute-lft-neg-outN/A
distribute-neg-inN/A
distribute-rgt-inN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-*.f64N/A
Applied rewrites87.6%
Taylor expanded in x around inf
Applied rewrites51.8%
if -0.0420000000000000026 < y < 1.29999999999999999e-7Initial program 100.0%
Taylor expanded in y around 0
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f64N/A
+-commutativeN/A
lower-fma.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower-*.f6499.8
Applied rewrites99.8%
Final simplification75.1%
(FPCore (x y z) :precision binary64 (if (<= z -5e+164) (* (- y) z) x))
double code(double x, double y, double z) {
double tmp;
if (z <= -5e+164) {
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 <= (-5d+164)) 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 <= -5e+164) {
tmp = -y * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5e+164: tmp = -y * z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5e+164) tmp = Float64(Float64(-y) * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5e+164) tmp = -y * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5e+164], N[((-y) * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{+164}:\\
\;\;\;\;\left(-y\right) \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -4.9999999999999995e164Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6449.7
Applied rewrites49.7%
Taylor expanded in x around 0
Applied rewrites44.8%
if -4.9999999999999995e164 < z Initial program 99.8%
Taylor expanded in y around 0
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6451.8
Applied rewrites51.8%
Applied rewrites5.9%
Taylor expanded in x around inf
Applied rewrites4.8%
Applied rewrites43.5%
(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(Float64(-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
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6451.6
Applied rewrites51.6%
(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
+-commutativeN/A
mul-1-negN/A
*-commutativeN/A
distribute-lft-neg-inN/A
lower-fma.f64N/A
lower-neg.f6451.6
Applied rewrites51.6%
Applied rewrites8.2%
Taylor expanded in x around inf
Applied rewrites4.5%
Applied rewrites39.8%
herbie shell --seed 2024320
(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))))