
(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 (sin y) (- z) (* x (cos y))))
double code(double x, double y, double z) {
return fma(sin(y), -z, (x * cos(y)));
}
function code(x, y, z) return fma(sin(y), Float64(-z), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(N[Sin[y], $MachinePrecision] * (-z) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\sin y, -z, x \cdot \cos y\right)
\end{array}
Initial program 99.7%
sub-neg99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
fma-def99.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.7%
Final simplification99.7%
(FPCore (x y z) :precision binary64 (if (or (<= x -6.2e-31) (not (<= x 9.5e+66))) (* x (cos y)) (- x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-31) || !(x <= 9.5e+66)) {
tmp = x * cos(y);
} else {
tmp = x - (sin(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 ((x <= (-6.2d-31)) .or. (.not. (x <= 9.5d+66))) then
tmp = x * cos(y)
else
tmp = x - (sin(y) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -6.2e-31) || !(x <= 9.5e+66)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -6.2e-31) or not (x <= 9.5e+66): tmp = x * math.cos(y) else: tmp = x - (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -6.2e-31) || !(x <= 9.5e+66)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(sin(y) * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -6.2e-31) || ~((x <= 9.5e+66))) tmp = x * cos(y); else tmp = x - (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -6.2e-31], N[Not[LessEqual[x, 9.5e+66]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.2 \cdot 10^{-31} \lor \neg \left(x \leq 9.5 \cdot 10^{+66}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - \sin y \cdot z\\
\end{array}
\end{array}
if x < -6.19999999999999999e-31 or 9.50000000000000051e66 < x Initial program 99.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 88.9%
if -6.19999999999999999e-31 < x < 9.50000000000000051e66Initial program 99.7%
Taylor expanded in y around 0 86.4%
Final simplification87.6%
(FPCore (x y z) :precision binary64 (if (or (<= x -9e-100) (not (<= x 7.2e-68))) (* x (cos y)) (* (sin y) (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-100) || !(x <= 7.2e-68)) {
tmp = x * cos(y);
} else {
tmp = sin(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 ((x <= (-9d-100)) .or. (.not. (x <= 7.2d-68))) then
tmp = x * cos(y)
else
tmp = sin(y) * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -9e-100) || !(x <= 7.2e-68)) {
tmp = x * Math.cos(y);
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -9e-100) or not (x <= 7.2e-68): tmp = x * math.cos(y) else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -9e-100) || !(x <= 7.2e-68)) tmp = Float64(x * cos(y)); else tmp = Float64(sin(y) * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -9e-100) || ~((x <= 7.2e-68))) tmp = x * cos(y); else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -9e-100], N[Not[LessEqual[x, 7.2e-68]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9 \cdot 10^{-100} \lor \neg \left(x \leq 7.2 \cdot 10^{-68}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -9.0000000000000002e-100 or 7.20000000000000015e-68 < x Initial program 99.7%
sub-neg99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in z around 0 82.9%
if -9.0000000000000002e-100 < x < 7.20000000000000015e-68Initial program 99.8%
Taylor expanded in x around 0 80.1%
mul-1-neg80.1%
*-commutative80.1%
distribute-rgt-neg-in80.1%
Simplified80.1%
Final simplification82.0%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.185) (not (<= y 1.16e-14))) (* x (cos y)) (- (* x (+ 1.0 (* -0.5 (* y y)))) (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.185) || !(y <= 1.16e-14)) {
tmp = x * cos(y);
} else {
tmp = (x * (1.0 + (-0.5 * (y * y)))) - (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 ((y <= (-0.185d0)) .or. (.not. (y <= 1.16d-14))) then
tmp = x * cos(y)
else
tmp = (x * (1.0d0 + ((-0.5d0) * (y * y)))) - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.185) || !(y <= 1.16e-14)) {
tmp = x * Math.cos(y);
} else {
tmp = (x * (1.0 + (-0.5 * (y * y)))) - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.185) or not (y <= 1.16e-14): tmp = x * math.cos(y) else: tmp = (x * (1.0 + (-0.5 * (y * y)))) - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.185) || !(y <= 1.16e-14)) tmp = Float64(x * cos(y)); else tmp = Float64(Float64(x * Float64(1.0 + Float64(-0.5 * Float64(y * y)))) - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.185) || ~((y <= 1.16e-14))) tmp = x * cos(y); else tmp = (x * (1.0 + (-0.5 * (y * y)))) - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.185], N[Not[LessEqual[y, 1.16e-14]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[(x * N[(1.0 + N[(-0.5 * N[(y * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.185 \lor \neg \left(y \leq 1.16 \cdot 10^{-14}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 + -0.5 \cdot \left(y \cdot y\right)\right) - y \cdot z\\
\end{array}
\end{array}
if y < -0.185 or 1.16000000000000007e-14 < y Initial program 99.6%
sub-neg99.6%
+-commutative99.6%
*-commutative99.6%
distribute-rgt-neg-in99.6%
fma-def99.6%
Applied egg-rr99.6%
Taylor expanded in z around 0 56.9%
if -0.185 < y < 1.16000000000000007e-14Initial program 100.0%
Taylor expanded in y around 0 100.0%
unpow2100.0%
Simplified100.0%
Taylor expanded in y around 0 99.4%
Final simplification75.0%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e-271) x (if (<= x 4.8e-82) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e-271) {
tmp = x;
} else if (x <= 4.8e-82) {
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 (x <= (-1.05d-271)) then
tmp = x
else if (x <= 4.8d-82) 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 (x <= -1.05e-271) {
tmp = x;
} else if (x <= 4.8e-82) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e-271: tmp = x elif x <= 4.8e-82: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e-271) tmp = x; elseif (x <= 4.8e-82) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.05e-271) tmp = x; elseif (x <= 4.8e-82) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e-271], x, If[LessEqual[x, 4.8e-82], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-271}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-82}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.05e-271 or 4.80000000000000017e-82 < x Initial program 99.7%
sub-neg99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
fma-def99.7%
Applied egg-rr99.7%
Taylor expanded in y around 0 44.2%
if -1.05e-271 < x < 4.80000000000000017e-82Initial program 99.8%
Taylor expanded in y around 0 70.8%
unpow270.8%
Simplified70.8%
Taylor expanded in y around 0 48.6%
Taylor expanded in x around 0 43.1%
associate-*r*43.1%
neg-mul-143.1%
Simplified43.1%
Final simplification44.0%
(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.7%
Taylor expanded in y around 0 47.3%
+-commutative47.3%
mul-1-neg47.3%
unsub-neg47.3%
Simplified47.3%
Final simplification47.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.7%
sub-neg99.7%
+-commutative99.7%
*-commutative99.7%
distribute-rgt-neg-in99.7%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 37.5%
Final simplification37.5%
herbie shell --seed 2023207
(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))))