
(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 z (- (sin y)) (* x (cos y))))
double code(double x, double y, double z) {
return fma(z, -sin(y), (x * cos(y)));
}
function code(x, y, z) return fma(z, Float64(-sin(y)), Float64(x * cos(y))) end
code[x_, y_, z_] := N[(z * (-N[Sin[y], $MachinePrecision]) + N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(z, -\sin y, x \cdot \cos y\right)
\end{array}
Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-define99.9%
sin-neg99.9%
Simplified99.9%
(FPCore (x y z) :precision binary64 (if (<= z -6.4e-107) (fma (- z) (sin y) x) (if (<= z 6e-64) (* x (cos y)) (- x (* z (sin y))))))
double code(double x, double y, double z) {
double tmp;
if (z <= -6.4e-107) {
tmp = fma(-z, sin(y), x);
} else if (z <= 6e-64) {
tmp = x * cos(y);
} else {
tmp = x - (z * sin(y));
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if (z <= -6.4e-107) tmp = fma(Float64(-z), sin(y), x); elseif (z <= 6e-64) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(z * sin(y))); end return tmp end
code[x_, y_, z_] := If[LessEqual[z, -6.4e-107], N[((-z) * N[Sin[y], $MachinePrecision] + x), $MachinePrecision], If[LessEqual[z, 6e-64], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.4 \cdot 10^{-107}:\\
\;\;\;\;\mathsf{fma}\left(-z, \sin y, x\right)\\
\mathbf{elif}\;z \leq 6 \cdot 10^{-64}:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - z \cdot \sin y\\
\end{array}
\end{array}
if z < -6.40000000000000025e-107Initial program 99.8%
cancel-sign-sub-inv99.8%
+-commutative99.8%
distribute-lft-neg-out99.8%
distribute-rgt-neg-in99.8%
sin-neg99.8%
fma-define99.9%
sin-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 86.4%
Taylor expanded in z around 0 86.3%
+-commutative86.3%
associate-*r*86.3%
neg-mul-186.3%
fma-define86.4%
Simplified86.4%
if -6.40000000000000025e-107 < z < 6.0000000000000001e-64Initial program 99.8%
Taylor expanded in x around inf 93.0%
if 6.0000000000000001e-64 < z Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
sin-neg99.9%
fma-define99.9%
sin-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 88.5%
Taylor expanded in z around 0 88.5%
+-commutative88.5%
associate-*r*88.5%
neg-mul-188.5%
Simplified88.5%
Taylor expanded in z around 0 88.5%
neg-mul-188.5%
sub-neg88.5%
Simplified88.5%
(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 -2.8e-104) (not (<= z 2.9e-65))) (- x (* z (sin y))) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-104) || !(z <= 2.9e-65)) {
tmp = x - (z * sin(y));
} else {
tmp = x * cos(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 ((z <= (-2.8d-104)) .or. (.not. (z <= 2.9d-65))) then
tmp = x - (z * sin(y))
else
tmp = x * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -2.8e-104) || !(z <= 2.9e-65)) {
tmp = x - (z * Math.sin(y));
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -2.8e-104) or not (z <= 2.9e-65): tmp = x - (z * math.sin(y)) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -2.8e-104) || !(z <= 2.9e-65)) tmp = Float64(x - Float64(z * sin(y))); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -2.8e-104) || ~((z <= 2.9e-65))) tmp = x - (z * sin(y)); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -2.8e-104], N[Not[LessEqual[z, 2.9e-65]], $MachinePrecision]], N[(x - N[(z * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.8 \cdot 10^{-104} \lor \neg \left(z \leq 2.9 \cdot 10^{-65}\right):\\
\;\;\;\;x - z \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -2.8e-104 or 2.8999999999999998e-65 < z Initial program 99.9%
cancel-sign-sub-inv99.9%
+-commutative99.9%
distribute-lft-neg-out99.9%
distribute-rgt-neg-in99.9%
sin-neg99.9%
fma-define99.9%
sin-neg99.9%
Simplified99.9%
Taylor expanded in y around 0 87.3%
Taylor expanded in z around 0 87.2%
+-commutative87.2%
associate-*r*87.2%
neg-mul-187.2%
Simplified87.2%
Taylor expanded in z around 0 87.2%
neg-mul-187.2%
sub-neg87.2%
Simplified87.2%
if -2.8e-104 < z < 2.8999999999999998e-65Initial program 99.8%
Taylor expanded in x around inf 93.0%
Final simplification89.1%
(FPCore (x y z) :precision binary64 (if (or (<= x -3.8e-82) (not (<= x 4.5e-132))) (* x (cos y)) (* z (- (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -3.8e-82) || !(x <= 4.5e-132)) {
tmp = x * cos(y);
} 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 <= (-3.8d-82)) .or. (.not. (x <= 4.5d-132))) then
tmp = x * cos(y)
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 <= -3.8e-82) || !(x <= 4.5e-132)) {
tmp = x * Math.cos(y);
} else {
tmp = z * -Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -3.8e-82) or not (x <= 4.5e-132): tmp = x * math.cos(y) else: tmp = z * -math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -3.8e-82) || !(x <= 4.5e-132)) tmp = Float64(x * cos(y)); else tmp = Float64(z * Float64(-sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -3.8e-82) || ~((x <= 4.5e-132))) tmp = x * cos(y); else tmp = z * -sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -3.8e-82], N[Not[LessEqual[x, 4.5e-132]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z * (-N[Sin[y], $MachinePrecision])), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.8 \cdot 10^{-82} \lor \neg \left(x \leq 4.5 \cdot 10^{-132}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \left(-\sin y\right)\\
\end{array}
\end{array}
if x < -3.8000000000000002e-82 or 4.4999999999999999e-132 < x Initial program 99.9%
Taylor expanded in x around inf 80.2%
if -3.8000000000000002e-82 < x < 4.4999999999999999e-132Initial program 99.8%
Taylor expanded in x around 0 82.0%
neg-mul-182.0%
*-commutative82.0%
distribute-rgt-neg-in82.0%
Simplified82.0%
Final simplification80.8%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.00028) (not (<= y 48.0))) (* x (cos y)) (+ x (* y (- (* y (+ (* x -0.5) (* 0.16666666666666666 (* z y)))) z)))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00028) || !(y <= 48.0)) {
tmp = x * cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * 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.00028d0)) .or. (.not. (y <= 48.0d0))) then
tmp = x * cos(y)
else
tmp = x + (y * ((y * ((x * (-0.5d0)) + (0.16666666666666666d0 * (z * y)))) - z))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.00028) || !(y <= 48.0)) {
tmp = x * Math.cos(y);
} else {
tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.00028) or not (y <= 48.0): tmp = x * math.cos(y) else: tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z)) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.00028) || !(y <= 48.0)) tmp = Float64(x * cos(y)); else tmp = Float64(x + Float64(y * Float64(Float64(y * Float64(Float64(x * -0.5) + Float64(0.16666666666666666 * Float64(z * y)))) - z))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.00028) || ~((y <= 48.0))) tmp = x * cos(y); else tmp = x + (y * ((y * ((x * -0.5) + (0.16666666666666666 * (z * y)))) - z)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.00028], N[Not[LessEqual[y, 48.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(N[(y * N[(N[(x * -0.5), $MachinePrecision] + N[(0.16666666666666666 * N[(z * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00028 \lor \neg \left(y \leq 48\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \left(y \cdot \left(x \cdot -0.5 + 0.16666666666666666 \cdot \left(z \cdot y\right)\right) - z\right)\\
\end{array}
\end{array}
if y < -2.7999999999999998e-4 or 48 < y Initial program 99.7%
Taylor expanded in x around inf 50.7%
if -2.7999999999999998e-4 < y < 48Initial program 100.0%
Taylor expanded in y around 0 98.8%
Final simplification76.3%
(FPCore (x y z) :precision binary64 (if (<= x -1.05e-94) x (if (<= x 1.2e-192) (* z (- y)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -1.05e-94) {
tmp = x;
} else if (x <= 1.2e-192) {
tmp = z * -y;
} 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-94)) then
tmp = x
else if (x <= 1.2d-192) then
tmp = z * -y
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-94) {
tmp = x;
} else if (x <= 1.2e-192) {
tmp = z * -y;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -1.05e-94: tmp = x elif x <= 1.2e-192: tmp = z * -y else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -1.05e-94) tmp = x; elseif (x <= 1.2e-192) tmp = Float64(z * Float64(-y)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -1.05e-94) tmp = x; elseif (x <= 1.2e-192) tmp = z * -y; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -1.05e-94], x, If[LessEqual[x, 1.2e-192], N[(z * (-y)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \cdot 10^{-94}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 1.2 \cdot 10^{-192}:\\
\;\;\;\;z \cdot \left(-y\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -1.05e-94 or 1.2e-192 < x Initial program 99.9%
Taylor expanded in y around 0 49.7%
if -1.05e-94 < x < 1.2e-192Initial program 99.7%
Taylor expanded in y around 0 54.8%
mul-1-neg54.8%
unsub-neg54.8%
*-commutative54.8%
Simplified54.8%
Taylor expanded in x around 0 45.7%
neg-mul-145.7%
distribute-rgt-neg-in45.7%
Simplified45.7%
Final simplification48.6%
(FPCore (x y z) :precision binary64 (- x (* z y)))
double code(double x, double y, double z) {
return x - (z * 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 - (z * y)
end function
public static double code(double x, double y, double z) {
return x - (z * y);
}
def code(x, y, z): return x - (z * y)
function code(x, y, z) return Float64(x - Float64(z * y)) end
function tmp = code(x, y, z) tmp = x - (z * y); end
code[x_, y_, z_] := N[(x - N[(z * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - z \cdot y
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 55.6%
mul-1-neg55.6%
unsub-neg55.6%
*-commutative55.6%
Simplified55.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 39.5%
herbie shell --seed 2024185
(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))))