
(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 8 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 (fma x (+ y -1.0) y))
double code(double x, double y) {
return fma(x, (y + -1.0), y);
}
function code(x, y) return fma(x, Float64(y + -1.0), y) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, y\right)
\end{array}
Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x y) (if (<= x 9.2e-26) y (if (<= x 1.7e+148) (- x) (* x y)))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * y;
} else if (x <= 9.2e-26) {
tmp = y;
} else if (x <= 1.7e+148) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = x * y
else if (x <= 9.2d-26) then
tmp = y
else if (x <= 1.7d+148) then
tmp = -x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * y;
} else if (x <= 9.2e-26) {
tmp = y;
} else if (x <= 1.7e+148) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * y elif x <= 9.2e-26: tmp = y elif x <= 1.7e+148: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * y); elseif (x <= 9.2e-26) tmp = y; elseif (x <= 1.7e+148) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x * y; elseif (x <= 9.2e-26) tmp = y; elseif (x <= 1.7e+148) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 9.2e-26], y, If[LessEqual[x, 1.7e+148], (-x), N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 9.2 \cdot 10^{-26}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.7 \cdot 10^{+148}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -1 or 1.7000000000000001e148 < x Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 55.6%
Taylor expanded in x around inf 55.4%
*-commutative55.4%
Simplified55.4%
if -1 < x < 9.20000000000000035e-26Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 77.1%
if 9.20000000000000035e-26 < x < 1.7000000000000001e148Initial program 100.0%
Taylor expanded in y around 0 61.8%
neg-mul-161.8%
Simplified61.8%
Final simplification66.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 3.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 3.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-1.0d0)) .or. (.not. (x <= 3.0d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 3.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 3.0): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 3.0)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 3.0))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 3.0]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 3\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 3 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
if -1 < x < 3Initial program 100.0%
Taylor expanded in x around 0 98.2%
Final simplification98.1%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x (+ y -1.0)) (if (<= x 3.0) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 3.0) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-1.0d0)) then
tmp = x * (y + (-1.0d0))
else if (x <= 3.0d0) then
tmp = y - x
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 3.0) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * (y + -1.0) elif x <= 3.0: tmp = y - x else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * Float64(y + -1.0)); elseif (x <= 3.0) tmp = Float64(y - x); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x * (y + -1.0); elseif (x <= 3.0) tmp = y - x; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 3.0], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{elif}\;x \leq 3:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 99.8%
if -1 < x < 3Initial program 100.0%
Taylor expanded in x around 0 98.2%
if 3 < x Initial program 100.0%
Taylor expanded in x around inf 96.1%
*-commutative96.1%
Simplified96.1%
Final simplification98.1%
(FPCore (x y) :precision binary64 (if (or (<= x -2.1e+81) (not (<= x 6.5e+147))) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -2.1e+81) || !(x <= 6.5e+147)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-2.1d+81)) .or. (.not. (x <= 6.5d+147))) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.1e+81) || !(x <= 6.5e+147)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.1e+81) or not (x <= 6.5e+147): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.1e+81) || !(x <= 6.5e+147)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.1e+81) || ~((x <= 6.5e+147))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.1e+81], N[Not[LessEqual[x, 6.5e+147]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.1 \cdot 10^{+81} \lor \neg \left(x \leq 6.5 \cdot 10^{+147}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2.0999999999999999e81 or 6.5e147 < x Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 57.4%
Taylor expanded in x around inf 57.4%
*-commutative57.4%
Simplified57.4%
if -2.0999999999999999e81 < x < 6.5e147Initial program 100.0%
Taylor expanded in x around 0 87.8%
Final simplification78.2%
(FPCore (x y) :precision binary64 (if (or (<= x -9.5e-5) (not (<= x 2.6e-21))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -9.5e-5) || !(x <= 2.6e-21)) {
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 ((x <= (-9.5d-5)) .or. (.not. (x <= 2.6d-21))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -9.5e-5) || !(x <= 2.6e-21)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -9.5e-5) or not (x <= 2.6e-21): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -9.5e-5) || !(x <= 2.6e-21)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -9.5e-5) || ~((x <= 2.6e-21))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -9.5e-5], N[Not[LessEqual[x, 2.6e-21]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-5} \lor \neg \left(x \leq 2.6 \cdot 10^{-21}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -9.5000000000000005e-5 or 2.60000000000000017e-21 < x Initial program 100.0%
Taylor expanded in y around 0 48.7%
neg-mul-148.7%
Simplified48.7%
if -9.5000000000000005e-5 < x < 2.60000000000000017e-21Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 77.1%
Final simplification62.5%
(FPCore (x y) :precision binary64 (- (* y (+ x 1.0)) x))
double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y * (x + 1.0d0)) - x
end function
public static double code(double x, double y) {
return (y * (x + 1.0)) - x;
}
def code(x, y): return (y * (x + 1.0)) - x
function code(x, y) return Float64(Float64(y * Float64(x + 1.0)) - x) end
function tmp = code(x, y) tmp = (y * (x + 1.0)) - x; end
code[x_, y_] := N[(N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
y \cdot \left(x + 1\right) - x
\end{array}
Initial program 100.0%
Final simplification100.0%
(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}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 39.2%
herbie shell --seed 2024103
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))