
(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.7%
Applied egg-rr99.7%
Final simplification99.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.7%
Final simplification99.7%
(FPCore (x y z)
:precision binary64
(if (or (<= z -3.7e+105)
(not (or (<= z -1e+31) (and (not (<= z -1.2e-14)) (<= z 9e+55)))))
(* (sin y) (- z))
(* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -3.7e+105) || !((z <= -1e+31) || (!(z <= -1.2e-14) && (z <= 9e+55)))) {
tmp = sin(y) * -z;
} 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 <= (-3.7d+105)) .or. (.not. (z <= (-1d+31)) .or. (.not. (z <= (-1.2d-14))) .and. (z <= 9d+55))) then
tmp = sin(y) * -z
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 <= -3.7e+105) || !((z <= -1e+31) || (!(z <= -1.2e-14) && (z <= 9e+55)))) {
tmp = Math.sin(y) * -z;
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -3.7e+105) or not ((z <= -1e+31) or (not (z <= -1.2e-14) and (z <= 9e+55))): tmp = math.sin(y) * -z else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -3.7e+105) || !((z <= -1e+31) || (!(z <= -1.2e-14) && (z <= 9e+55)))) tmp = Float64(sin(y) * Float64(-z)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -3.7e+105) || ~(((z <= -1e+31) || (~((z <= -1.2e-14)) && (z <= 9e+55))))) tmp = sin(y) * -z; else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -3.7e+105], N[Not[Or[LessEqual[z, -1e+31], And[N[Not[LessEqual[z, -1.2e-14]], $MachinePrecision], LessEqual[z, 9e+55]]]], $MachinePrecision]], N[(N[Sin[y], $MachinePrecision] * (-z)), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.7 \cdot 10^{+105} \lor \neg \left(z \leq -1 \cdot 10^{+31} \lor \neg \left(z \leq -1.2 \cdot 10^{-14}\right) \land z \leq 9 \cdot 10^{+55}\right):\\
\;\;\;\;\sin y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -3.69999999999999985e105 or -9.9999999999999996e30 < z < -1.2e-14 or 8.99999999999999996e55 < z Initial program 99.6%
Taylor expanded in x around 0 78.9%
mul-1-neg78.9%
*-commutative78.9%
distribute-rgt-neg-in78.9%
Simplified78.9%
if -3.69999999999999985e105 < z < -9.9999999999999996e30 or -1.2e-14 < z < 8.99999999999999996e55Initial program 99.8%
Taylor expanded in x around inf 84.5%
Final simplification82.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -9e-46) (not (<= z 2.2e-106))) (- x (* (sin y) z)) (* x (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -9e-46) || !(z <= 2.2e-106)) {
tmp = x - (sin(y) * z);
} 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 <= (-9d-46)) .or. (.not. (z <= 2.2d-106))) then
tmp = x - (sin(y) * z)
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 <= -9e-46) || !(z <= 2.2e-106)) {
tmp = x - (Math.sin(y) * z);
} else {
tmp = x * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -9e-46) or not (z <= 2.2e-106): tmp = x - (math.sin(y) * z) else: tmp = x * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -9e-46) || !(z <= 2.2e-106)) tmp = Float64(x - Float64(sin(y) * z)); else tmp = Float64(x * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -9e-46) || ~((z <= 2.2e-106))) tmp = x - (sin(y) * z); else tmp = x * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -9e-46], N[Not[LessEqual[z, 2.2e-106]], $MachinePrecision]], N[(x - N[(N[Sin[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(x * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9 \cdot 10^{-46} \lor \neg \left(z \leq 2.2 \cdot 10^{-106}\right):\\
\;\;\;\;x - \sin y \cdot z\\
\mathbf{else}:\\
\;\;\;\;x \cdot \cos y\\
\end{array}
\end{array}
if z < -9.00000000000000001e-46 or 2.19999999999999994e-106 < z Initial program 99.7%
Taylor expanded in y around 0 85.6%
if -9.00000000000000001e-46 < z < 2.19999999999999994e-106Initial program 99.8%
Taylor expanded in x around inf 92.6%
Final simplification88.7%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.3e-6) (not (<= y 0.00095))) (* x (cos y)) (- x (* y z))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.3e-6) || !(y <= 0.00095)) {
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 <= (-1.3d-6)) .or. (.not. (y <= 0.00095d0))) 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 <= -1.3e-6) || !(y <= 0.00095)) {
tmp = x * Math.cos(y);
} else {
tmp = x - (y * z);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.3e-6) or not (y <= 0.00095): tmp = x * math.cos(y) else: tmp = x - (y * z) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.3e-6) || !(y <= 0.00095)) 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 <= -1.3e-6) || ~((y <= 0.00095))) tmp = x * cos(y); else tmp = x - (y * z); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.3e-6], N[Not[LessEqual[y, 0.00095]], $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 -1.3 \cdot 10^{-6} \lor \neg \left(y \leq 0.00095\right):\\
\;\;\;\;x \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot z\\
\end{array}
\end{array}
if y < -1.30000000000000005e-6 or 9.49999999999999998e-4 < y Initial program 99.5%
Taylor expanded in x around inf 54.5%
if -1.30000000000000005e-6 < y < 9.49999999999999998e-4Initial program 100.0%
Taylor expanded in y around 0 99.8%
mul-1-neg99.8%
unsub-neg99.8%
Simplified99.8%
Final simplification74.3%
(FPCore (x y z) :precision binary64 (if (<= x -3.1e-187) x (if (<= x 7.1e-159) (* y (- z)) x)))
double code(double x, double y, double z) {
double tmp;
if (x <= -3.1e-187) {
tmp = x;
} else if (x <= 7.1e-159) {
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 <= (-3.1d-187)) then
tmp = x
else if (x <= 7.1d-159) 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 <= -3.1e-187) {
tmp = x;
} else if (x <= 7.1e-159) {
tmp = y * -z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if x <= -3.1e-187: tmp = x elif x <= 7.1e-159: tmp = y * -z else: tmp = x return tmp
function code(x, y, z) tmp = 0.0 if (x <= -3.1e-187) tmp = x; elseif (x <= 7.1e-159) tmp = Float64(y * Float64(-z)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (x <= -3.1e-187) tmp = x; elseif (x <= 7.1e-159) tmp = y * -z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[x, -3.1e-187], x, If[LessEqual[x, 7.1e-159], N[(y * (-z)), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.1 \cdot 10^{-187}:\\
\;\;\;\;x\\
\mathbf{elif}\;x \leq 7.1 \cdot 10^{-159}:\\
\;\;\;\;y \cdot \left(-z\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if x < -3.10000000000000019e-187 or 7.10000000000000024e-159 < 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 42.1%
if -3.10000000000000019e-187 < x < 7.10000000000000024e-159Initial program 99.7%
*-commutative99.7%
add-sqr-sqrt52.4%
associate-*r*52.4%
fma-neg52.3%
distribute-rgt-neg-in52.3%
Applied egg-rr52.3%
Taylor expanded in y around 0 25.1%
mul-1-neg25.1%
distribute-rgt-neg-in25.1%
Simplified25.1%
Taylor expanded in y around inf 37.9%
Final simplification41.1%
(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 46.9%
mul-1-neg46.9%
unsub-neg46.9%
Simplified46.9%
Final simplification46.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.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 37.3%
Final simplification37.3%
herbie shell --seed 2023331
(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))))