
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 5 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
(FPCore (x y) :precision binary64 (- (* (+ x 1.0) y) x))
double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x + 1.0d0) * y) - x
end function
public static double code(double x, double y) {
return ((x + 1.0) * y) - x;
}
def code(x, y): return ((x + 1.0) * y) - x
function code(x, y) return Float64(Float64(Float64(x + 1.0) * y) - x) end
function tmp = code(x, y) tmp = ((x + 1.0) * y) - x; end
code[x_, y_] := N[(N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(x + 1\right) \cdot y - x
\end{array}
(FPCore (x y) :precision binary64 (if (or (<= x -7.3e-25) (not (<= x 2.7e-22))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -7.3e-25) || !(x <= 2.7e-22)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-7.3d-25)) .or. (.not. (x <= 2.7d-22))) then
tmp = x * (y + (-1.0d0))
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -7.3e-25) || !(x <= 2.7e-22)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -7.3e-25) or not (x <= 2.7e-22): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -7.3e-25) || !(x <= 2.7e-22)) tmp = Float64(x * Float64(y + -1.0)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -7.3e-25) || ~((x <= 2.7e-22))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -7.3e-25], N[Not[LessEqual[x, 2.7e-22]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.3 \cdot 10^{-25} \lor \neg \left(x \leq 2.7 \cdot 10^{-22}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= x -1.6e-24) (- (* x y) x) (if (<= x 5.2e-21) y (* x (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.6e-24) {
tmp = (x * y) - x;
} else if (x <= 5.2e-21) {
tmp = y;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.6d-24)) then
tmp = (x * y) - x
else if (x <= 5.2d-21) then
tmp = y
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.6e-24) {
tmp = (x * y) - x;
} else if (x <= 5.2e-21) {
tmp = y;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.6e-24: tmp = (x * y) - x elif x <= 5.2e-21: tmp = y else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.6e-24) tmp = Float64(Float64(x * y) - x); elseif (x <= 5.2e-21) tmp = y; else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.6e-24) tmp = (x * y) - x; elseif (x <= 5.2e-21) tmp = y; else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.6e-24], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 5.2e-21], y, N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.6 \cdot 10^{-24}:\\
\;\;\;\;x \cdot y - x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-21}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 (if (<= y -0.0535) y (if (<= y 8.5e-39) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -0.0535) {
tmp = y;
} else if (y <= 8.5e-39) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-0.0535d0)) then
tmp = y
else if (y <= 8.5d-39) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -0.0535) {
tmp = y;
} else if (y <= 8.5e-39) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.0535: tmp = y elif y <= 8.5e-39: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -0.0535) tmp = y; elseif (y <= 8.5e-39) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -0.0535) tmp = y; elseif (y <= 8.5e-39) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.0535], y, If[LessEqual[y, 8.5e-39], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.0535:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{-39}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
(FPCore (x y) :precision binary64 y)
double code(double x, double y) {
return y;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y
end function
public static double code(double x, double y) {
return y;
}
def code(x, y): return y
function code(x, y) return y end
function tmp = code(x, y) tmp = y; end
code[x_, y_] := y
\begin{array}{l}
\\
y
\end{array}
herbie shell --seed 2024008
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))