
(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.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -1.95e-181) (not (<= x 2.7e-16))) (fma x (sin y) z) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -1.95e-181) || !(x <= 2.7e-16)) {
tmp = fma(x, sin(y), z);
} else {
tmp = z * cos(y);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((x <= -1.95e-181) || !(x <= 2.7e-16)) tmp = fma(x, sin(y), z); else tmp = Float64(z * cos(y)); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[x, -1.95e-181], N[Not[LessEqual[x, 2.7e-16]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-181} \lor \neg \left(x \leq 2.7 \cdot 10^{-16}\right):\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -1.95e-181 or 2.69999999999999999e-16 < x Initial program 99.9%
fma-def99.9%
Simplified99.9%
Taylor expanded in y around 0 86.5%
if -1.95e-181 < x < 2.69999999999999999e-16Initial program 99.9%
add-sqr-sqrt51.7%
associate-*r*51.7%
fma-def51.7%
Applied egg-rr51.7%
Taylor expanded in x around 0 90.6%
Final simplification87.9%
(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}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z) :precision binary64 (if (or (<= x -4.9e-181) (not (<= x 2.25e-13))) (+ z (* x (sin y))) (* z (cos y))))
double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-181) || !(x <= 2.25e-13)) {
tmp = z + (x * sin(y));
} else {
tmp = z * 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 ((x <= (-4.9d-181)) .or. (.not. (x <= 2.25d-13))) then
tmp = z + (x * sin(y))
else
tmp = z * cos(y)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -4.9e-181) || !(x <= 2.25e-13)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = z * Math.cos(y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -4.9e-181) or not (x <= 2.25e-13): tmp = z + (x * math.sin(y)) else: tmp = z * math.cos(y) return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -4.9e-181) || !(x <= 2.25e-13)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(z * cos(y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -4.9e-181) || ~((x <= 2.25e-13))) tmp = z + (x * sin(y)); else tmp = z * cos(y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -4.9e-181], N[Not[LessEqual[x, 2.25e-13]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-181} \lor \neg \left(x \leq 2.25 \cdot 10^{-13}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z \cdot \cos y\\
\end{array}
\end{array}
if x < -4.89999999999999963e-181 or 2.25e-13 < x Initial program 99.9%
Taylor expanded in y around 0 86.5%
if -4.89999999999999963e-181 < x < 2.25e-13Initial program 99.9%
add-sqr-sqrt51.7%
associate-*r*51.7%
fma-def51.7%
Applied egg-rr51.7%
Taylor expanded in x around 0 90.6%
Final simplification87.9%
(FPCore (x y z) :precision binary64 (if (or (<= y -1.8e-5) (not (<= y 0.0027))) (* z (cos y)) (+ z (* x y))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -1.8e-5) || !(y <= 0.0027)) {
tmp = z * cos(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 <= (-1.8d-5)) .or. (.not. (y <= 0.0027d0))) then
tmp = z * cos(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 <= -1.8e-5) || !(y <= 0.0027)) {
tmp = z * Math.cos(y);
} else {
tmp = z + (x * y);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -1.8e-5) or not (y <= 0.0027): tmp = z * math.cos(y) else: tmp = z + (x * y) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -1.8e-5) || !(y <= 0.0027)) tmp = Float64(z * cos(y)); else tmp = Float64(z + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -1.8e-5) || ~((y <= 0.0027))) tmp = z * cos(y); else tmp = z + (x * y); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -1.8e-5], N[Not[LessEqual[y, 0.0027]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.8 \cdot 10^{-5} \lor \neg \left(y \leq 0.0027\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;z + x \cdot y\\
\end{array}
\end{array}
if y < -1.80000000000000005e-5 or 0.0027000000000000001 < y Initial program 99.7%
add-sqr-sqrt45.2%
associate-*r*45.3%
fma-def45.3%
Applied egg-rr45.3%
Taylor expanded in x around 0 54.8%
if -1.80000000000000005e-5 < y < 0.0027000000000000001Initial program 100.0%
Taylor expanded in y around 0 99.9%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -2.4e-5) (not (<= y 0.00021))) (* z (cos y)) (fma y x z)))
double code(double x, double y, double z) {
double tmp;
if ((y <= -2.4e-5) || !(y <= 0.00021)) {
tmp = z * cos(y);
} else {
tmp = fma(y, x, z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((y <= -2.4e-5) || !(y <= 0.00021)) tmp = Float64(z * cos(y)); else tmp = fma(y, x, z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[y, -2.4e-5], N[Not[LessEqual[y, 0.00021]], $MachinePrecision]], N[(z * N[Cos[y], $MachinePrecision]), $MachinePrecision], N[(y * x + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{-5} \lor \neg \left(y \leq 0.00021\right):\\
\;\;\;\;z \cdot \cos y\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\end{array}
\end{array}
if y < -2.4000000000000001e-5 or 2.1000000000000001e-4 < y Initial program 99.7%
add-sqr-sqrt45.2%
associate-*r*45.3%
fma-def45.3%
Applied egg-rr45.3%
Taylor expanded in x around 0 54.8%
if -2.4000000000000001e-5 < y < 2.1000000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 99.9%
fma-def99.9%
Simplified99.9%
Final simplification78.5%
(FPCore (x y z) :precision binary64 (if (<= z -1.9e-137) z (if (<= z 4.4e-204) (* x y) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-137) {
tmp = z;
} else if (z <= 4.4e-204) {
tmp = x * y;
} else {
tmp = 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 (z <= (-1.9d-137)) then
tmp = z
else if (z <= 4.4d-204) then
tmp = x * y
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -1.9e-137) {
tmp = z;
} else if (z <= 4.4e-204) {
tmp = x * y;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -1.9e-137: tmp = z elif z <= 4.4e-204: tmp = x * y else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -1.9e-137) tmp = z; elseif (z <= 4.4e-204) tmp = Float64(x * y); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -1.9e-137) tmp = z; elseif (z <= 4.4e-204) tmp = x * y; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -1.9e-137], z, If[LessEqual[z, 4.4e-204], N[(x * y), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.9 \cdot 10^{-137}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 4.4 \cdot 10^{-204}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
if z < -1.89999999999999999e-137 or 4.3999999999999997e-204 < z Initial program 99.9%
Taylor expanded in y around 0 55.8%
Taylor expanded in y around 0 48.5%
if -1.89999999999999999e-137 < z < 4.3999999999999997e-204Initial program 99.8%
Taylor expanded in y around 0 54.8%
Taylor expanded in y around inf 47.1%
Final simplification48.2%
(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.9%
Taylor expanded in y around 0 55.6%
Final simplification55.6%
(FPCore (x y z) :precision binary64 z)
double code(double x, double y, double z) {
return z;
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z
end function
public static double code(double x, double y, double z) {
return z;
}
def code(x, y, z): return z
function code(x, y, z) return z end
function tmp = code(x, y, z) tmp = z; end
code[x_, y_, z_] := z
\begin{array}{l}
\\
z
\end{array}
Initial program 99.9%
Taylor expanded in y around 0 55.6%
Taylor expanded in y around 0 40.2%
Final simplification40.2%
herbie shell --seed 2023221
(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))))