
(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 10 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 (* x (sin y))))
double code(double x, double y, double z) {
return fma(cos(y), z, (x * sin(y)));
}
function code(x, y, z) return fma(cos(y), z, Float64(x * sin(y))) end
code[x_, y_, z_] := N[(N[Cos[y], $MachinePrecision] * z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\cos y, z, x \cdot \sin y\right)
\end{array}
(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}
(FPCore (x y z) :precision binary64 (+ (* x (sin y)) (* (cos y) z)))
double code(double x, double y, double z) {
return (x * sin(y)) + (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 = (x * sin(y)) + (cos(y) * z)
end function
public static double code(double x, double y, double z) {
return (x * Math.sin(y)) + (Math.cos(y) * z);
}
def code(x, y, z): return (x * math.sin(y)) + (math.cos(y) * z)
function code(x, y, z) return Float64(Float64(x * sin(y)) + Float64(cos(y) * z)) end
function tmp = code(x, y, z) tmp = (x * sin(y)) + (cos(y) * z); end
code[x_, y_, z_] := N[(N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision] + N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \sin y + \cos y \cdot z
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)) (t_1 (* x (sin y))))
(if (<= y -2.8e+176)
t_0
(if (<= y -3e+106)
t_1
(if (<= y -6.2e-5) t_0 (if (<= y 4.2e-6) (+ z (* y x)) t_1))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double t_1 = x * sin(y);
double tmp;
if (y <= -2.8e+176) {
tmp = t_0;
} else if (y <= -3e+106) {
tmp = t_1;
} else if (y <= -6.2e-5) {
tmp = t_0;
} else if (y <= 4.2e-6) {
tmp = z + (y * x);
} else {
tmp = t_1;
}
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) :: t_0
real(8) :: t_1
real(8) :: tmp
t_0 = cos(y) * z
t_1 = x * sin(y)
if (y <= (-2.8d+176)) then
tmp = t_0
else if (y <= (-3d+106)) then
tmp = t_1
else if (y <= (-6.2d-5)) then
tmp = t_0
else if (y <= 4.2d-6) then
tmp = z + (y * x)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double t_0 = Math.cos(y) * z;
double t_1 = x * Math.sin(y);
double tmp;
if (y <= -2.8e+176) {
tmp = t_0;
} else if (y <= -3e+106) {
tmp = t_1;
} else if (y <= -6.2e-5) {
tmp = t_0;
} else if (y <= 4.2e-6) {
tmp = z + (y * x);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z): t_0 = math.cos(y) * z t_1 = x * math.sin(y) tmp = 0 if y <= -2.8e+176: tmp = t_0 elif y <= -3e+106: tmp = t_1 elif y <= -6.2e-5: tmp = t_0 elif y <= 4.2e-6: tmp = z + (y * x) else: tmp = t_1 return tmp
function code(x, y, z) t_0 = Float64(cos(y) * z) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -2.8e+176) tmp = t_0; elseif (y <= -3e+106) tmp = t_1; elseif (y <= -6.2e-5) tmp = t_0; elseif (y <= 4.2e-6) tmp = Float64(z + Float64(y * x)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z) t_0 = cos(y) * z; t_1 = x * sin(y); tmp = 0.0; if (y <= -2.8e+176) tmp = t_0; elseif (y <= -3e+106) tmp = t_1; elseif (y <= -6.2e-5) tmp = t_0; elseif (y <= 4.2e-6) tmp = z + (y * x); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -2.8e+176], t$95$0, If[LessEqual[y, -3e+106], t$95$1, If[LessEqual[y, -6.2e-5], t$95$0, If[LessEqual[y, 4.2e-6], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -2.8 \cdot 10^{+176}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -3 \cdot 10^{+106}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -6.2 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-6}:\\
\;\;\;\;z + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z)
:precision binary64
(let* ((t_0 (* (cos y) z)) (t_1 (* x (sin y))))
(if (<= y -6.6e+176)
t_0
(if (<= y -1.5e+106)
t_1
(if (<= y -9.8e-5) t_0 (if (<= y 4.2e-6) (fma y x z) t_1))))))
double code(double x, double y, double z) {
double t_0 = cos(y) * z;
double t_1 = x * sin(y);
double tmp;
if (y <= -6.6e+176) {
tmp = t_0;
} else if (y <= -1.5e+106) {
tmp = t_1;
} else if (y <= -9.8e-5) {
tmp = t_0;
} else if (y <= 4.2e-6) {
tmp = fma(y, x, z);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z) t_0 = Float64(cos(y) * z) t_1 = Float64(x * sin(y)) tmp = 0.0 if (y <= -6.6e+176) tmp = t_0; elseif (y <= -1.5e+106) tmp = t_1; elseif (y <= -9.8e-5) tmp = t_0; elseif (y <= 4.2e-6) tmp = fma(y, x, z); else tmp = t_1; end return tmp end
code[x_, y_, z_] := Block[{t$95$0 = N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]}, Block[{t$95$1 = N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -6.6e+176], t$95$0, If[LessEqual[y, -1.5e+106], t$95$1, If[LessEqual[y, -9.8e-5], t$95$0, If[LessEqual[y, 4.2e-6], N[(y * x + z), $MachinePrecision], t$95$1]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := \cos y \cdot z\\
t_1 := x \cdot \sin y\\
\mathbf{if}\;y \leq -6.6 \cdot 10^{+176}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq -1.5 \cdot 10^{+106}:\\
\;\;\;\;t_1\\
\mathbf{elif}\;y \leq -9.8 \cdot 10^{-5}:\\
\;\;\;\;t_0\\
\mathbf{elif}\;y \leq 4.2 \cdot 10^{-6}:\\
\;\;\;\;\mathsf{fma}\left(y, x, z\right)\\
\mathbf{else}:\\
\;\;\;\;t_1\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= x -2.5e-85) (not (<= x 3.7e-139))) (+ z (* x (sin y))) (* (cos y) z)))
double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-85) || !(x <= 3.7e-139)) {
tmp = z + (x * sin(y));
} else {
tmp = cos(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 <= (-2.5d-85)) .or. (.not. (x <= 3.7d-139))) then
tmp = z + (x * sin(y))
else
tmp = cos(y) * z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if ((x <= -2.5e-85) || !(x <= 3.7e-139)) {
tmp = z + (x * Math.sin(y));
} else {
tmp = Math.cos(y) * z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if (x <= -2.5e-85) or not (x <= 3.7e-139): tmp = z + (x * math.sin(y)) else: tmp = math.cos(y) * z return tmp
function code(x, y, z) tmp = 0.0 if ((x <= -2.5e-85) || !(x <= 3.7e-139)) tmp = Float64(z + Float64(x * sin(y))); else tmp = Float64(cos(y) * z); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((x <= -2.5e-85) || ~((x <= 3.7e-139))) tmp = z + (x * sin(y)); else tmp = cos(y) * z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[x, -2.5e-85], N[Not[LessEqual[x, 3.7e-139]], $MachinePrecision]], N[(z + N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[Cos[y], $MachinePrecision] * z), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-85} \lor \neg \left(x \leq 3.7 \cdot 10^{-139}\right):\\
\;\;\;\;z + x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;\cos y \cdot z\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (or (<= y -650000000.0) (not (<= y 4.2e-6))) (* x (sin y)) (+ z (* y x))))
double code(double x, double y, double z) {
double tmp;
if ((y <= -650000000.0) || !(y <= 4.2e-6)) {
tmp = x * sin(y);
} 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 <= (-650000000.0d0)) .or. (.not. (y <= 4.2d-6))) then
tmp = x * sin(y)
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 <= -650000000.0) || !(y <= 4.2e-6)) {
tmp = x * Math.sin(y);
} else {
tmp = z + (y * x);
}
return tmp;
}
def code(x, y, z): tmp = 0 if (y <= -650000000.0) or not (y <= 4.2e-6): tmp = x * math.sin(y) else: tmp = z + (y * x) return tmp
function code(x, y, z) tmp = 0.0 if ((y <= -650000000.0) || !(y <= 4.2e-6)) tmp = Float64(x * sin(y)); else tmp = Float64(z + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if ((y <= -650000000.0) || ~((y <= 4.2e-6))) tmp = x * sin(y); else tmp = z + (y * x); end tmp_2 = tmp; end
code[x_, y_, z_] := If[Or[LessEqual[y, -650000000.0], N[Not[LessEqual[y, 4.2e-6]], $MachinePrecision]], N[(x * N[Sin[y], $MachinePrecision]), $MachinePrecision], N[(z + N[(y * x), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -650000000 \lor \neg \left(y \leq 4.2 \cdot 10^{-6}\right):\\
\;\;\;\;x \cdot \sin y\\
\mathbf{else}:\\
\;\;\;\;z + y \cdot x\\
\end{array}
\end{array}
(FPCore (x y z) :precision binary64 (if (<= z -5.1e-165) z (if (<= z 1.46e-154) (* y x) z)))
double code(double x, double y, double z) {
double tmp;
if (z <= -5.1e-165) {
tmp = z;
} else if (z <= 1.46e-154) {
tmp = y * x;
} 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 <= (-5.1d-165)) then
tmp = z
else if (z <= 1.46d-154) then
tmp = y * x
else
tmp = z
end if
code = tmp
end function
public static double code(double x, double y, double z) {
double tmp;
if (z <= -5.1e-165) {
tmp = z;
} else if (z <= 1.46e-154) {
tmp = y * x;
} else {
tmp = z;
}
return tmp;
}
def code(x, y, z): tmp = 0 if z <= -5.1e-165: tmp = z elif z <= 1.46e-154: tmp = y * x else: tmp = z return tmp
function code(x, y, z) tmp = 0.0 if (z <= -5.1e-165) tmp = z; elseif (z <= 1.46e-154) tmp = Float64(y * x); else tmp = z; end return tmp end
function tmp_2 = code(x, y, z) tmp = 0.0; if (z <= -5.1e-165) tmp = z; elseif (z <= 1.46e-154) tmp = y * x; else tmp = z; end tmp_2 = tmp; end
code[x_, y_, z_] := If[LessEqual[z, -5.1e-165], z, If[LessEqual[z, 1.46e-154], N[(y * x), $MachinePrecision], z]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5.1 \cdot 10^{-165}:\\
\;\;\;\;z\\
\mathbf{elif}\;z \leq 1.46 \cdot 10^{-154}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;z\\
\end{array}
\end{array}
(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}
(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}
herbie shell --seed 2023364
(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))))