
(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 (<= y -1.04e-10)
y
(if (<= y 3.25e-21)
(- x)
(if (or (<= y 2.05e+84) (and (not (<= y 1.45e+149)) (<= y 1.12e+229)))
y
(* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.04e-10) {
tmp = y;
} else if (y <= 3.25e-21) {
tmp = -x;
} else if ((y <= 2.05e+84) || (!(y <= 1.45e+149) && (y <= 1.12e+229))) {
tmp = y;
} 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 (y <= (-1.04d-10)) then
tmp = y
else if (y <= 3.25d-21) then
tmp = -x
else if ((y <= 2.05d+84) .or. (.not. (y <= 1.45d+149)) .and. (y <= 1.12d+229)) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.04e-10) {
tmp = y;
} else if (y <= 3.25e-21) {
tmp = -x;
} else if ((y <= 2.05e+84) || (!(y <= 1.45e+149) && (y <= 1.12e+229))) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.04e-10: tmp = y elif y <= 3.25e-21: tmp = -x elif (y <= 2.05e+84) or (not (y <= 1.45e+149) and (y <= 1.12e+229)): tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.04e-10) tmp = y; elseif (y <= 3.25e-21) tmp = Float64(-x); elseif ((y <= 2.05e+84) || (!(y <= 1.45e+149) && (y <= 1.12e+229))) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.04e-10) tmp = y; elseif (y <= 3.25e-21) tmp = -x; elseif ((y <= 2.05e+84) || (~((y <= 1.45e+149)) && (y <= 1.12e+229))) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.04e-10], y, If[LessEqual[y, 3.25e-21], (-x), If[Or[LessEqual[y, 2.05e+84], And[N[Not[LessEqual[y, 1.45e+149]], $MachinePrecision], LessEqual[y, 1.12e+229]]], y, N[(x * y), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.04 \cdot 10^{-10}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.25 \cdot 10^{-21}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 2.05 \cdot 10^{+84} \lor \neg \left(y \leq 1.45 \cdot 10^{+149}\right) \land y \leq 1.12 \cdot 10^{+229}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.04e-10 or 3.24999999999999993e-21 < y < 2.05000000000000015e84 or 1.4500000000000001e149 < y < 1.12e229Initial 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%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 59.7%
if -1.04e-10 < y < 3.24999999999999993e-21Initial program 100.0%
Taylor expanded in y around 0 86.3%
neg-mul-186.3%
Simplified86.3%
if 2.05000000000000015e84 < y < 1.4500000000000001e149 or 1.12e229 < y 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%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 70.8%
*-commutative70.8%
Simplified70.8%
Final simplification74.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4e-7))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4e-7)) {
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 <= 4d-7))) 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 <= 4e-7)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4e-7): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4e-7)) 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 <= 4e-7))) 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, 4e-7]], $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 4 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 3.9999999999999998e-7 < x Initial program 100.0%
Taylor expanded in x around inf 98.7%
if -1 < x < 3.9999999999999998e-7Initial program 100.0%
Taylor expanded in x around 0 99.7%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x (+ y -1.0)) (if (<= x 4e-7) (- 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 <= 4e-7) {
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 <= 4d-7) 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 <= 4e-7) {
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 <= 4e-7: 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 <= 4e-7) 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 <= 4e-7) 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, 4e-7], 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 4 \cdot 10^{-7}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 98.5%
if -1 < x < 3.9999999999999998e-7Initial program 100.0%
Taylor expanded in x around 0 99.7%
if 3.9999999999999998e-7 < x Initial program 100.0%
Taylor expanded in x around inf 99.0%
*-commutative99.0%
Simplified99.0%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= y -2.65e-17) y (if (<= y 2.2e-26) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -2.65e-17) {
tmp = y;
} else if (y <= 2.2e-26) {
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 <= (-2.65d-17)) then
tmp = y
else if (y <= 2.2d-26) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.65e-17) {
tmp = y;
} else if (y <= 2.2e-26) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.65e-17: tmp = y elif y <= 2.2e-26: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.65e-17) tmp = y; elseif (y <= 2.2e-26) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.65e-17) tmp = y; elseif (y <= 2.2e-26) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.65e-17], y, If[LessEqual[y, 2.2e-26], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{-17}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-26}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.6499999999999999e-17 or 2.2000000000000001e-26 < y 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%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 52.9%
if -2.6499999999999999e-17 < y < 2.2000000000000001e-26Initial program 100.0%
Taylor expanded in y around 0 86.3%
neg-mul-186.3%
Simplified86.3%
(FPCore (x y) :precision binary64 (if (<= x -2.6e+72) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if (x <= -2.6e+72) {
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.6d+72)) 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.6e+72) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.6e+72: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.6e+72) 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.6e+72) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.6e+72], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.6 \cdot 10^{+72}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2.59999999999999981e72Initial 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%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 54.8%
Taylor expanded in x around inf 54.8%
*-commutative54.8%
Simplified54.8%
if -2.59999999999999981e72 < x Initial program 100.0%
Taylor expanded in x around 0 85.7%
Final simplification79.3%
(FPCore (x y) :precision binary64 (+ y (* x (+ y -1.0))))
double code(double x, double y) {
return y + (x * (y + -1.0));
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + (x * (y + (-1.0d0)))
end function
public static double code(double x, double y) {
return y + (x * (y + -1.0));
}
def code(x, y): return y + (x * (y + -1.0))
function code(x, y) return Float64(y + Float64(x * Float64(y + -1.0))) end
function tmp = code(x, y) tmp = y + (x * (y + -1.0)); end
code[x_, y_] := N[(y + N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + x \cdot \left(y + -1\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%
fma-undefine100.0%
Applied egg-rr100.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%
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%
fma-undefine100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 34.7%
herbie shell --seed 2024108
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))