
(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 (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.8%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (fma (cos y) x (* (sin y) (- z))))
double code(double x, double y, double z) {
return fma(cos(y), x, (sin(y) * -z));
}
function code(x, y, z) return fma(cos(y), x, Float64(sin(y) * Float64(-z))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * x + N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, x, \sin y \cdot \left(-z\right)\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 99.8%
mul-1-neg99.8%
distribute-rgt-neg-out99.8%
+-commutative99.8%
fma-udef99.8%
distribute-rgt-neg-out99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= x -5.5e+140) (not (<= x 2.2e+112))) (* x (cos y)) (fma (sin y) (- z) x)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+140) || !(x <= 2.2e+112)) {
tmp = x * cos(y);
} else {
tmp = fma(sin(y), -z, x);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+140) || !(x <= 2.2e+112)) tmp = Float64(x * cos(y)); else tmp = fma(sin(y), Float64(-z), x); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+140], N[Not[LessEqual[x, 2.2e+112]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z) + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.5 \cdot 10^{+140} \lor \neg \left(x \leq 2.2 \cdot 10^{+112}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\sin y, -z, x\right)\\
\end{array}
\end{array}
if x < -5.5e140 or 2.1999999999999999e112 < 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 z around 0 90.8%
if -5.5e140 < x < 2.1999999999999999e112Initial 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 y around 0 88.0%
Final simplification88.7%
(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 (if (or (<= x -5.5e+140) (not (<= x 8.5e+113))) (* x (cos y)) (- x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -5.5e+140) || !(x <= 8.5e+113)) {
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 <= (-5.5d+140)) .or. (.not. (x <= 8.5d+113))) 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 <= -5.5e+140) || !(x <= 8.5e+113)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -5.5e+140) or not (x <= 8.5e+113): tmp = x * math.cos(y) else: tmp = x - (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -5.5e+140) || !(x <= 8.5e+113)) 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 <= -5.5e+140) || ~((x <= 8.5e+113))) tmp = x * cos(y); else tmp = x - (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -5.5e+140], N[Not[LessEqual[x, 8.5e+113]], $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 -5.5 \cdot 10^{+140} \lor \neg \left(x \leq 8.5 \cdot 10^{+113}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - \sin y \cdot z\\
\end{array}
\end{array}
if x < -5.5e140 or 8.5000000000000001e113 < 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 z around 0 90.8%
if -5.5e140 < x < 8.5000000000000001e113Initial program 99.8%
Taylor expanded in y around 0 87.9%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (<= y -65.0) (* x (cos y)) (if (<= y 0.000235) (- x (* y z)) (* (sin y) (- z)))))
double code(double x, double y, double z) {
double tmp;
if (y <= -65.0) {
tmp = x * cos(y);
} else if (y <= 0.000235) {
tmp = x - (y * z);
} 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 (y <= (-65.0d0)) then
tmp = x * cos(y)
else if (y <= 0.000235d0) then
tmp = x - (y * z)
else
tmp = sin(y) * -z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (y <= -65.0) {
tmp = x * Math.cos(y);
} else if (y <= 0.000235) {
tmp = x - (y * z);
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if y <= -65.0: tmp = x * math.cos(y) elif y <= 0.000235: tmp = x - (y * z) else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if (y <= -65.0) tmp = Float64(x * cos(y)); elseif (y <= 0.000235) tmp = Float64(x - Float64(y * z)); else tmp = Float64(sin(y) * Float64(-z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (y <= -65.0) tmp = x * cos(y); elseif (y <= 0.000235) tmp = x - (y * z); else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[y, -65.0], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.000235], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -65:\\
\;\;\;\;x \cdot \cos y\\
\mathbf{elif}\;y \leq 0.000235:\\
\;\;\;\;x - y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if y < -65Initial 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 57.4%
if -65 < y < 2.34999999999999993e-4Initial program 99.9%
Taylor expanded in y around 0 97.4%
+-commutative97.4%
mul-1-neg97.4%
unsub-neg97.4%
Simplified97.4%
if 2.34999999999999993e-4 < y Initial program 99.6%
Taylor expanded in x around 0 63.3%
mul-1-neg63.3%
*-commutative63.3%
distribute-rgt-neg-in63.3%
Simplified63.3%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (if (or (<= y -65.0) (not (<= y 1250000.0))) (* x (cos y)) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -65.0) || !(y <= 1250000.0)) {
tmp = x * cos(y);
} else {
tmp = x - (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 <= (-65.0d0)) .or. (.not. (y <= 1250000.0d0))) then
tmp = x * cos(y)
else
tmp = x - (y * z)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -65.0) || !(y <= 1250000.0)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -65.0) or not (y <= 1250000.0): tmp = x * math.cos(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -65.0) || !(y <= 1250000.0)) tmp = Float64(x * cos(y)); else tmp = Float64(x - Float64(y * z)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -65.0) || ~((y <= 1250000.0))) tmp = x * cos(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -65.0], N[Not[LessEqual[y, 1250000.0]], $MachinePrecision]], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x - N[(y * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -65 \lor \neg \left(y \leq 1250000\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -65 or 1.25e6 < 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 47.7%
if -65 < y < 1.25e6Initial program 99.9%
Taylor expanded in y around 0 95.6%
+-commutative95.6%
mul-1-neg95.6%
unsub-neg95.6%
Simplified95.6%
Final simplification71.8%
(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 50.9%
+-commutative50.9%
mul-1-neg50.9%
unsub-neg50.9%
Simplified50.9%
Final simplification50.9%
(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%
sub-neg99.8%
+-commutative99.8%
*-commutative99.8%
distribute-rgt-neg-in99.8%
fma-def99.8%
Applied egg-rr99.8%
Taylor expanded in y around 0 32.8%
Final simplification32.8%
herbie shell --seed 2023229
(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))))