
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* z (cos y))))
double code(double x, double y, double z) {
return (x * sin(y)) + (z * cos(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 * sin(y)) + (z * cos(y))
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (z * Math.cos(y));
}
def code(x, y, z): return (x * math.sin(y)) + (z * math.cos(y))
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(z * cos(y))) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (z * cos(y)); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + z \cdot \cos y
\end{array}
(FPCore (x y z) :precision binary64 (fma x (sin y) (* z (cos y))))
double code(double x, double y, double z) {
return fma(x, sin(y), (z * cos(y)));
}
function code(x, y, z) return fma(x, sin(y), Float64(z * cos(y))) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, z \cdot \cos y\right)
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.4e+81) (not (<= z 1.35e+19))) (* z (cos y)) (fma x (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.4e+81) || !(z <= 1.35e+19)) {
tmp = z * cos(y);
} else {
tmp = fma(x, sin(y), z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -5.4e+81) || !(z <= 1.35e+19)) tmp = Float64(z * cos(y)); else tmp = fma(x, sin(y), z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.4e+81], N[Not[LessEqual[z, 1.35e+19]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.4 \cdot 10^{+81} \lor \neg \left(z \leq 1.35 \cdot 10^{+19}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\end{array}
\end{array}
if z < -5.3999999999999999e81 or 1.35e19 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 88.5%
if -5.3999999999999999e81 < z < 1.35e19Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in y around 0 88.7%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (+ (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
return (z * cos(y)) + (x * 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 = (z * cos(y)) + (x * sin(y))
end function
public static double code(double x, double y, double z) {
return (z * Math.cos(y)) + (x * Math.sin(y));
}
def code(x, y, z): return (z * math.cos(y)) + (x * math.sin(y))
function code(x, y, z) return Float64(Float64(z * cos(y)) + Float64(x * sin(y))) end
function tmp = code(x, y, z) tmp = (z * cos(y)) + (x * sin(y)); end
code[x_, y_, z_] := N[(N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision] + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \cos y + x \cdot \sin y
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -5.2e+84) (not (<= z 2.5e+16))) (* z (cos y)) (+ z (* x (sin y)))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+84) || !(z <= 2.5e+16)) {
tmp = z * cos(y);
} else {
tmp = z + (x * 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 ((z <= (-5.2d+84)) .or. (.not. (z <= 2.5d+16))) then
tmp = z * cos(y)
else
tmp = z + (x * sin(y))
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -5.2e+84) || !(z <= 2.5e+16)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * Math.sin(y));
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -5.2e+84) or not (z <= 2.5e+16): tmp = z * math.cos(y) else: tmp = z + (x * math.sin(y)) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -5.2e+84) || !(z <= 2.5e+16)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * sin(y))); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -5.2e+84) || ~((z <= 2.5e+16))) tmp = z * cos(y); else tmp = z + (x * sin(y)); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -5.2e+84], N[Not[LessEqual[z, 2.5e+16]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.2 \cdot 10^{+84} \lor \neg \left(z \leq 2.5 \cdot 10^{+16}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot \sin y\\
\end{array}
\end{array}
if z < -5.2000000000000002e84 or 2.5e16 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 88.5%
if -5.2000000000000002e84 < z < 2.5e16Initial program 99.9%
Taylor expanded in y around 0 88.7%
Final simplification88.6%
(FPCore (x y z) :precision binary64 (if (or (<= z -1.15e-117) (not (<= z 5.8e-107))) (* z (cos y)) (* x (sin y))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-117) || !(z <= 5.8e-107)) {
tmp = z * cos(y);
} else {
tmp = x * 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 ((z <= (-1.15d-117)) .or. (.not. (z <= 5.8d-107))) then
tmp = z * cos(y)
else
tmp = x * sin(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -1.15e-117) || !(z <= 5.8e-107)) {
tmp = z * Math.cos(y);
} else {
tmp = x * Math.sin(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -1.15e-117) or not (z <= 5.8e-107): tmp = z * math.cos(y) else: tmp = x * math.sin(y) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -1.15e-117) || !(z <= 5.8e-107)) tmp = Float64(z * cos(y)); else tmp = Float64(x * sin(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -1.15e-117) || ~((z <= 5.8e-107))) tmp = z * cos(y); else tmp = x * sin(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -1.15e-117], N[Not[LessEqual[z, 5.8e-107]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.15 \cdot 10^{-117} \lor \neg \left(z \leq 5.8 \cdot 10^{-107}\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \sin y\\
\end{array}
\end{array}
if z < -1.14999999999999997e-117 or 5.7999999999999996e-107 < z Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in x around 0 81.7%
if -1.14999999999999997e-117 < z < 5.7999999999999996e-107Initial program 99.9%
fma-define99.9%
Simplified99.9%
Taylor expanded in x around inf 75.4%
Final simplification79.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.0012) (not (<= y 6.6e+23))) (* x (sin y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0012) || !(y <= 6.6e+23)) {
tmp = x * sin(y);
} else {
tmp = z + (x * 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 ((y <= (-0.0012d0)) .or. (.not. (y <= 6.6d+23))) then
tmp = x * sin(y)
else
tmp = z + (x * y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.0012) || !(y <= 6.6e+23)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.0012) or not (y <= 6.6e+23): tmp = x * math.sin(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.0012) || !(y <= 6.6e+23)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.0012) || ~((y <= 6.6e+23))) tmp = x * sin(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.0012], N[Not[LessEqual[y, 6.6e+23]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0012 \lor \neg \left(y \leq 6.6 \cdot 10^{+23}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -0.00119999999999999989 or 6.60000000000000059e23 < y Initial program 99.7%
fma-define99.7%
Simplified99.7%
Taylor expanded in x around inf 44.8%
if -0.00119999999999999989 < y < 6.60000000000000059e23Initial program 99.9%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 96.5%
+-commutative96.5%
Simplified96.5%
Final simplification68.6%
(FPCore (x y z) :precision binary64 (+ z (* x y)))
double code(double x, double y, double z) {
return z + (x * y);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (x * y)
end function
public static double code(double x, double y, double z) {
return z + (x * y);
}
def code(x, y, z): return z + (x * y)
function code(x, y, z) return Float64(z + Float64(x * y)) end
function tmp = code(x, y, z) tmp = z + (x * y); end
code[x_, y_, z_] := N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + x \cdot y
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 48.1%
+-commutative48.1%
Simplified48.1%
Final simplification48.1%
(FPCore (x y z) :precision binary64 (* x (/ z x)))
double code(double x, double y, double z) {
return x * (z / 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 * (z / x)
end function
public static double code(double x, double y, double z) {
return x * (z / x);
}
def code(x, y, z): return x * (z / x)
function code(x, y, z) return Float64(x * Float64(z / x)) end
function tmp = code(x, y, z) tmp = x * (z / x); end
code[x_, y_, z_] := N[(x * N[(z / x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \frac{z}{x}
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 48.1%
+-commutative48.1%
Simplified48.1%
Taylor expanded in x around inf 42.1%
Taylor expanded in y around 0 33.1%
(FPCore (x y z) :precision binary64 (* x y))
double code(double x, double y, double z) {
return x * 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 * y
end function
public static double code(double x, double y, double z) {
return x * y;
}
def code(x, y, z): return x * y
function code(x, y, z) return Float64(x * y) end
function tmp = code(x, y, z) tmp = x * y; end
code[x_, y_, z_] := N[(x * y), $MachinePrecision]
\begin{array}{l}
\\
x \cdot y
\end{array}
Initial program 99.8%
fma-define99.8%
Simplified99.8%
Taylor expanded in y around 0 48.1%
+-commutative48.1%
Simplified48.1%
Taylor expanded in x around inf 12.4%
*-commutative12.4%
Simplified12.4%
Final simplification12.4%
herbie shell --seed 2024157
(FPCore (x y z)
:name "Diagrams.ThreeD.Transform:aboutX from diagrams-lib-1.3.0.3, B"
:precision binary64
(+ (* x (sin y)) (* z (cos y))))