
(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 (cos y) z (* (sin y) x)))
double code(double x, double y, double z) {
return fma(cos(y), z, (sin(y) * x));
}
function code(x, y, z) return fma(cos(y), z, Float64(sin(y) * x)) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, \sin y \cdot x\right)
\end{array}
Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (fma x (sin y) (* (cos y) z)))
double code(double x, double y, double z) {
return fma(x, sin(y), (cos(y) * z));
}
function code(x, y, z) return fma(x, sin(y), Float64(cos(y) * z)) end
code[x_, y_, z_] := N[(x * N[Sin[y], $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, \sin y, \cos y \cdot z\right)
\end{array}
Initial program 99.8%
fma-def99.8%
Simplified99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6e+57) (not (<= z 2.7e+29))) (* (cos y) z) (fma x (sin y) z)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+57) || !(z <= 2.7e+29)) {
tmp = cos(y) * z;
} else {
tmp = fma(x, sin(y), z);
}
return tmp;
}
function code(x, y, z) tmp = 0.0 if ((z <= -6e+57) || !(z <= 2.7e+29)) tmp = Float64(cos(y) * z); else tmp = fma(x, sin(y), z); end return tmp end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e+57], N[Not[LessEqual[z, 2.7e+29]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(x * N[Sin[y], $MachinePrecision] + z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+57} \lor \neg \left(z \leq 2.7 \cdot 10^{+29}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(x, \sin y, z\right)\\
\end{array}
\end{array}
if z < -5.9999999999999999e57 or 2.7e29 < z Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 89.7%
if -5.9999999999999999e57 < z < 2.7e29Initial program 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 87.5%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (+ (* (sin y) x) (* (cos y) z)))
double code(double x, double y, double z) {
return (sin(y) * x) + (cos(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 = (sin(y) * x) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (Math.sin(y) * x) + (Math.cos(y) * z);
}
def code(x, y, z): return (math.sin(y) * x) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(sin(y) * x) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (sin(y) * x) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\sin y \cdot x + \cos y \cdot z
\end{array}
Initial program 99.8%
Final simplification99.8%
(FPCore (x y z) :precision binary64 (if (or (<= z -6e+57) (not (<= z 2.2e+27))) (* (cos y) z) (+ z (* (sin y) x))))
double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+57) || !(z <= 2.2e+27)) {
tmp = cos(y) * z;
} else {
tmp = z + (sin(y) * 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 ((z <= (-6d+57)) .or. (.not. (z <= 2.2d+27))) then
tmp = cos(y) * z
else
tmp = z + (sin(y) * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -6e+57) || !(z <= 2.2e+27)) {
tmp = Math.cos(y) * z;
} else {
tmp = z + (Math.sin(y) * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -6e+57) or not (z <= 2.2e+27): tmp = math.cos(y) * z else: tmp = z + (math.sin(y) * x) return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -6e+57) || !(z <= 2.2e+27)) tmp = Float64(cos(y) * z); else tmp = Float64(z + Float64(sin(y) * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -6e+57) || ~((z <= 2.2e+27))) tmp = cos(y) * z; else tmp = z + (sin(y) * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -6e+57], N[Not[LessEqual[z, 2.2e+27]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6 \cdot 10^{+57} \lor \neg \left(z \leq 2.2 \cdot 10^{+27}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + \sin y \cdot x\\
\end{array}
\end{array}
if z < -5.9999999999999999e57 or 2.1999999999999999e27 < z Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 89.7%
if -5.9999999999999999e57 < z < 2.1999999999999999e27Initial program 99.8%
Taylor expanded in y around 0 87.5%
Final simplification88.5%
(FPCore (x y z) :precision binary64 (if (or (<= y -0.004) (not (<= y 0.43))) (* (cos y) z) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -0.004) || !(y <= 0.43)) {
tmp = cos(y) * z;
} else {
tmp = z + (y * 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 ((y <= (-0.004d0)) .or. (.not. (y <= 0.43d0))) then
tmp = cos(y) * z
else
tmp = z + (y * x)
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((y <= -0.004) || !(y <= 0.43)) {
tmp = Math.cos(y) * z;
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -0.004) or not (y <= 0.43): tmp = math.cos(y) * z else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -0.004) || !(y <= 0.43)) tmp = Float64(cos(y) * z); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -0.004) || ~((y <= 0.43))) tmp = cos(y) * z; else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -0.004], N[Not[LessEqual[y, 0.43]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.004 \lor \neg \left(y \leq 0.43\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
if y < -0.0040000000000000001 or 0.429999999999999993 < y Initial program 99.6%
Taylor expanded in x around 0 99.6%
fma-def99.6%
Simplified99.6%
Taylor expanded in z around inf 53.0%
if -0.0040000000000000001 < y < 0.429999999999999993Initial program 100.0%
Taylor expanded in y around 0 99.4%
Final simplification75.7%
(FPCore (x y z) :precision binary64 (if (or (<= z -7e-99) (not (<= z 5e-144))) (* (cos y) z) (* (sin y) x)))
double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-99) || !(z <= 5e-144)) {
tmp = cos(y) * z;
} else {
tmp = sin(y) * 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 ((z <= (-7d-99)) .or. (.not. (z <= 5d-144))) then
tmp = cos(y) * z
else
tmp = sin(y) * x
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((z <= -7e-99) || !(z <= 5e-144)) {
tmp = Math.cos(y) * z;
} else {
tmp = Math.sin(y) * x;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (z <= -7e-99) or not (z <= 5e-144): tmp = math.cos(y) * z else: tmp = math.sin(y) * x return tmp
function code(x, y, z) tmp = 0.0 if ((z <= -7e-99) || !(z <= 5e-144)) tmp = Float64(cos(y) * z); else tmp = Float64(sin(y) * x); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((z <= -7e-99) || ~((z <= 5e-144))) tmp = cos(y) * z; else tmp = sin(y) * x; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[z, -7e-99], N[Not[LessEqual[z, 5e-144]], $MachinePrecision]], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision], N[(N[Sin[y], $MachinePrecision] * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7 \cdot 10^{-99} \lor \neg \left(z \leq 5 \cdot 10^{-144}\right):\\
\;\;\;\;\cos y \cdot z\\
\mathbf{else}:\\
\;\;\;\;\sin y \cdot x\\
\end{array}
\end{array}
if z < -6.9999999999999997e-99 or 4.9999999999999998e-144 < z Initial program 99.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in z around inf 82.6%
if -6.9999999999999997e-99 < z < 4.9999999999999998e-144Initial program 99.7%
Taylor expanded in x around 0 99.7%
fma-def99.7%
Simplified99.7%
Taylor expanded in z around 0 70.0%
Final simplification78.6%
(FPCore (x y z) :precision binary64 (+ z (* y x)))
double code(double x, double y, double z) {
return z + (y * x);
}
real(8) function code(x, y, z)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
code = z + (y * x)
end function
public static double code(double x, double y, double z) {
return z + (y * x);
}
def code(x, y, z): return z + (y * x)
function code(x, y, z) return Float64(z + Float64(y * x)) end
function tmp = code(x, y, z) tmp = z + (y * x); end
code[x_, y_, z_] := N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z + y \cdot x
\end{array}
Initial program 99.8%
Taylor expanded in y around 0 51.5%
Final simplification51.5%
(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.8%
Taylor expanded in x around 0 99.8%
fma-def99.8%
Simplified99.8%
Taylor expanded in y around 0 43.1%
Final simplification43.1%
herbie shell --seed 2023196
(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))))