
(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.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 (- (* 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 -4.7e+178) (not (<= x 2e+34))) (* x (cos y)) (- x (* (sin y) z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.7e+178) || !(x <= 2e+34)) {
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 <= (-4.7d+178)) .or. (.not. (x <= 2d+34))) 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 <= -4.7e+178) || !(x <= 2e+34)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (Math.sin(y) * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.7e+178) or not (x <= 2e+34): tmp = x * math.cos(y) else: tmp = x - (math.sin(y) * z) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.7e+178) || !(x <= 2e+34)) 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 <= -4.7e+178) || ~((x <= 2e+34))) tmp = x * cos(y); else tmp = x - (sin(y) * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.7e+178], N[Not[LessEqual[x, 2e+34]], $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 -4.7 \cdot 10^{+178} \lor \neg \left(x \leq 2 \cdot 10^{+34}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - \sin y \cdot z\\
\end{array}
\end{array}
if x < -4.69999999999999992e178 or 1.99999999999999989e34 < 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 92.4%
if -4.69999999999999992e178 < x < 1.99999999999999989e34Initial program 99.8%
Taylor expanded in y around 0 87.2%
Final simplification88.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.85e-72) (not (<= x 7.2e-35))) (* x (cos y)) (* (sin y) (- z))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.85e-72) || !(x <= 7.2e-35)) {
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 <= (-1.85d-72)) .or. (.not. (x <= 7.2d-35))) 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 <= -1.85e-72) || !(x <= 7.2e-35)) {
tmp = x * Math.cos(y);
} else {
tmp = Math.sin(y) * -z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -1.85e-72) or not (x <= 7.2e-35): tmp = x * math.cos(y) else: tmp = math.sin(y) * -z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -1.85e-72) || !(x <= 7.2e-35)) 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 <= -1.85e-72) || ~((x <= 7.2e-35))) tmp = x * cos(y); else tmp = sin(y) * -z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.85e-72], N[Not[LessEqual[x, 7.2e-35]], $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 -1.85 \cdot 10^{-72} \lor \neg \left(x \leq 7.2 \cdot 10^{-35}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\end{array}
\end{array}
if x < -1.8499999999999999e-72 or 7.20000000000000038e-35 < 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 84.3%
if -1.8499999999999999e-72 < x < 7.20000000000000038e-35Initial program 99.8%
Taylor expanded in x around 0 75.5%
associate-*r*75.5%
neg-mul-175.5%
Simplified75.5%
Final simplification80.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -28.5) (not (<= y 3.3e+22))) (* x (cos y)) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -28.5) || !(y <= 3.3e+22)) {
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 <= (-28.5d0)) .or. (.not. (y <= 3.3d+22))) 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 <= -28.5) || !(y <= 3.3e+22)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -28.5) or not (y <= 3.3e+22): tmp = x * math.cos(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -28.5) || !(y <= 3.3e+22)) 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 <= -28.5) || ~((y <= 3.3e+22))) tmp = x * cos(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -28.5], N[Not[LessEqual[y, 3.3e+22]], $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 -28.5 \lor \neg \left(y \leq 3.3 \cdot 10^{+22}\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -28.5 or 3.2999999999999998e22 < 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 48.5%
if -28.5 < y < 3.2999999999999998e22Initial program 100.0%
Taylor expanded in y around 0 96.7%
+-commutative96.7%
mul-1-neg96.7%
unsub-neg96.7%
Simplified96.7%
Final simplification72.8%
(FPCore (x y z) :precision binary64 (if (<= x -2.15e-215) x (if (<= x 4.2e-133) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -2.15e-215) {
tmp = x;
} else if (x <= 4.2e-133) {
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 <= (-2.15d-215)) then
tmp = x
else if (x <= 4.2d-133) 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 <= -2.15e-215) {
tmp = x;
} else if (x <= 4.2e-133) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -2.15e-215: tmp = x elif x <= 4.2e-133: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -2.15e-215) tmp = x; elseif (x <= 4.2e-133) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -2.15e-215) tmp = x; elseif (x <= 4.2e-133) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -2.15e-215], x, If[LessEqual[x, 4.2e-133], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.15 \cdot 10^{-215}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{-133}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -2.15000000000000012e-215 or 4.2000000000000002e-133 < 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 y around 0 49.7%
if -2.15000000000000012e-215 < x < 4.2000000000000002e-133Initial program 99.8%
Taylor expanded in y around 0 43.5%
+-commutative43.5%
mul-1-neg43.5%
unsub-neg43.5%
fma-def43.5%
unpow243.5%
associate-*l*43.7%
Simplified43.7%
Taylor expanded in x around 0 32.4%
mul-1-neg32.4%
*-commutative32.4%
distribute-rgt-neg-in32.4%
Simplified32.4%
Final simplification45.3%
(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.5%
+-commutative51.5%
mul-1-neg51.5%
unsub-neg51.5%
Simplified51.5%
Final simplification51.5%
(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 41.1%
Final simplification41.1%
herbie shell --seed 2023173
(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))))