
(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 (cos y) x (* z (- (sin y)))))
double code(double x, double y, double z) {
return fma(cos(y), x, (z * -sin(y)));
}
function code(x, y, z) return fma(cos(y), x, Float64(z * Float64(-sin(y)))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, z \cdot \left(-\sin y\right)\right)
\end{array}
Initial program 99.8%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (- (* (cos y) x) (* z (sin y))))
double code(double x, double y, double z) {
return (cos(y) * x) - (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 = (cos(y) * x) - (z * sin(y))
end function
public static double code(double x, double y, double z) {
return (Math.cos(y) * x) - (z * Math.sin(y));
}
def code(x, y, z): return (math.cos(y) * x) - (z * math.sin(y))
function code(x, y, z) return Float64(Float64(cos(y) * x) - Float64(z * sin(y))) end
function tmp = code(x, y, z) tmp = (cos(y) * x) - (z * sin(y)); end
code[x_, y_, z_] := N[(N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision] - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\cos y \cdot x - z \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z)
:precision binary64
(if (or (<= x -1.1e-28)
(not (or (<= x 1.25e-93) (and (not (<= x 2e-73)) (<= x 4.9e-20)))))
(* (cos y) x)
(* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-28) || !((x <= 1.25e-93) || (!(x <= 2e-73) && (x <= 4.9e-20)))) {
tmp = cos(y) * x;
} else {
tmp = z * -sin(y);
}
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 <= (-1.1d-28)) .or. (.not. (x <= 1.25d-93) .or. (.not. (x <= 2d-73)) .and. (x <= 4.9d-20))) then
tmp = cos(y) * x
else
tmp = z * -sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -1.1e-28) || !((x <= 1.25e-93) || (!(x <= 2e-73) && (x <= 4.9e-20)))) {
tmp = Math.cos(y) * x;
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.1e-28) or not ((x <= 1.25e-93) or (not (x <= 2e-73) and (x <= 4.9e-20))): tmp = math.cos(y) * x else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.1e-28) || !((x <= 1.25e-93) || (!(x <= 2e-73) && (x <= 4.9e-20)))) tmp = Float64(cos(y) * x); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -1.1e-28) || ~(((x <= 1.25e-93) || (~((x <= 2e-73)) && (x <= 4.9e-20))))) tmp = cos(y) * x; else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.1e-28], N[Not[Or[LessEqual[x, 1.25e-93], And[N[Not[LessEqual[x, 2e-73]], $MachinePrecision], LessEqual[x, 4.9e-20]]]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{-28} \lor \neg \left(x \leq 1.25 \cdot 10^{-93} \lor \neg \left(x \leq 2 \cdot 10^{-73}\right) \land x \leq 4.9 \cdot 10^{-20}\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if x < -1.09999999999999998e-28 or 1.24999999999999999e-93 < x < 1.99999999999999999e-73 or 4.9000000000000002e-20 < x Initial program 99.8%
Taylor expanded in x around inf 83.8%
if -1.09999999999999998e-28 < x < 1.24999999999999999e-93 or 1.99999999999999999e-73 < x < 4.9000000000000002e-20Initial program 99.8%
Taylor expanded in x around 0 75.8%
mul-1-neg75.8%
*-commutative75.8%
distribute-rgt-neg-in75.8%
Simplified75.8%
Final simplification80.3%
(FPCore (x y z) :precision binary64 (if (or (<= z -2.6e-65) (not (<= z 3.4e-20))) (- x (* z (sin y))) (* (cos y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.6e-65) || !(z <= 3.4e-20)) {
tmp = x - (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 <= (-2.6d-65)) .or. (.not. (z <= 3.4d-20))) then
tmp = x - (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 <= -2.6e-65) || !(z <= 3.4e-20)) {
tmp = x - (z * Math.sin(y));
} else {
tmp = Math.cos(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.6e-65) or not (z <= 3.4e-20): tmp = x - (z * math.sin(y)) else: tmp = math.cos(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.6e-65) || !(z <= 3.4e-20)) tmp = Float64(x - 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 <= -2.6e-65) || ~((z <= 3.4e-20))) tmp = x - (z * sin(y)); else tmp = cos(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.6e-65], N[Not[LessEqual[z, 3.4e-20]], $MachinePrecision]], N[(x - 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 -2.6 \cdot 10^{-65} \lor \neg \left(z \leq 3.4 \cdot 10^{-20}\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot x\\
\end{array}
\end{array}
if z < -2.6000000000000001e-65 or 3.3999999999999997e-20 < z Initial program 99.8%
Taylor expanded in y around 0 90.7%
if -2.6000000000000001e-65 < z < 3.3999999999999997e-20Initial program 99.8%
Taylor expanded in x around inf 90.0%
Final simplification90.4%
(FPCore (x y z) :precision binary64 (if (or (<= y -32.0) (not (<= y 116000000.0))) (* (cos y) x) (+ x (* y (- (* y (* x -0.5)) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -32.0) || !(y <= 116000000.0)) {
tmp = cos(y) * x;
} else {
tmp = x + (y * ((y * (x * -0.5)) - 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 ((y <= (-32.0d0)) .or. (.not. (y <= 116000000.0d0))) then
tmp = cos(y) * x
else
tmp = x + (y * ((y * (x * (-0.5d0))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -32.0) || !(y <= 116000000.0)) {
tmp = Math.cos(y) * x;
} else {
tmp = x + (y * ((y * (x * -0.5)) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -32.0) or not (y <= 116000000.0): tmp = math.cos(y) * x else: tmp = x + (y * ((y * (x * -0.5)) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -32.0) || !(y <= 116000000.0)) tmp = Float64(cos(y) * x); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(x * -0.5)) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -32.0) || ~((y <= 116000000.0))) tmp = cos(y) * x; else tmp = x + (y * ((y * (x * -0.5)) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -32.0], N[Not[LessEqual[y, 116000000.0]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * x), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(x * -0.5), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -32 \lor \neg \left(y \leq 116000000\right):\\
\;\;\;\;\cos y \cdot x\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5\right) - z\right)\\
\end{array}
\end{array}
if y < -32 or 1.16e8 < y Initial program 99.7%
Taylor expanded in x around inf 50.7%
if -32 < y < 1.16e8Initial program 100.0%
Taylor expanded in y around 0 97.9%
+-commutative97.9%
mul-1-neg97.9%
unsub-neg97.9%
associate-*r*97.9%
unpow297.9%
associate-*r*97.9%
*-commutative97.9%
distribute-rgt-out--97.9%
*-commutative97.9%
Simplified97.9%
Final simplification73.9%
(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 51.3%
mul-1-neg51.3%
unsub-neg51.3%
Simplified51.3%
Final simplification51.3%
(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%
*-commutative99.8%
fma-neg99.8%
distribute-rgt-neg-in99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 37.1%
Final simplification37.1%
herbie shell --seed 2024044
(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))))