
(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 (- (+ y (* y x)) x))
double code(double x, double y) {
return (y + (y * x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (y * x)) - x
end function
public static double code(double x, double y) {
return (y + (y * x)) - x;
}
def code(x, y): return (y + (y * x)) - x
function code(x, y) return Float64(Float64(y + Float64(y * x)) - x) end
function tmp = code(x, y) tmp = (y + (y * x)) - x; end
code[x_, y_] := N[(N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + y \cdot x\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= x -1.5e+284)
(not
(or (<= x 2.35e+104) (and (not (<= x 1.65e+139)) (<= x 8.5e+260)))))
(* y x)
(- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.5e+284) || !((x <= 2.35e+104) || (!(x <= 1.65e+139) && (x <= 8.5e+260)))) {
tmp = y * x;
} 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.5d+284)) .or. (.not. (x <= 2.35d+104) .or. (.not. (x <= 1.65d+139)) .and. (x <= 8.5d+260))) then
tmp = y * x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.5e+284) || !((x <= 2.35e+104) || (!(x <= 1.65e+139) && (x <= 8.5e+260)))) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.5e+284) or not ((x <= 2.35e+104) or (not (x <= 1.65e+139) and (x <= 8.5e+260))): tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.5e+284) || !((x <= 2.35e+104) || (!(x <= 1.65e+139) && (x <= 8.5e+260)))) tmp = Float64(y * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.5e+284) || ~(((x <= 2.35e+104) || (~((x <= 1.65e+139)) && (x <= 8.5e+260))))) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.5e+284], N[Not[Or[LessEqual[x, 2.35e+104], And[N[Not[LessEqual[x, 1.65e+139]], $MachinePrecision], LessEqual[x, 8.5e+260]]]], $MachinePrecision]], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.5 \cdot 10^{+284} \lor \neg \left(x \leq 2.35 \cdot 10^{+104} \lor \neg \left(x \leq 1.65 \cdot 10^{+139}\right) \land x \leq 8.5 \cdot 10^{+260}\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.50000000000000004e284 or 2.35000000000000008e104 < x < 1.6500000000000001e139 or 8.5e260 < 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 76.7%
Taylor expanded in x around inf 76.7%
*-commutative76.7%
Simplified76.7%
if -1.50000000000000004e284 < x < 2.35000000000000008e104 or 1.6500000000000001e139 < x < 8.5e260Initial program 100.0%
Taylor expanded in x around 0 85.1%
Final simplification83.8%
(FPCore (x y) :precision binary64 (if (or (<= x -10000000000000.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -10000000000000.0) || !(x <= 1.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 <= (-10000000000000.0d0)) .or. (.not. (x <= 1.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 <= -10000000000000.0) || !(x <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -10000000000000.0) or not (x <= 1.0): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -10000000000000.0) || !(x <= 1.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 <= -10000000000000.0) || ~((x <= 1.0))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -10000000000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10000000000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1e13 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.8%
if -1e13 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.9%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= x -10000000000000.0) (- (* y x) x) (if (<= x 1.0) (- y x) (* x (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -10000000000000.0) {
tmp = (y * x) - x;
} else if (x <= 1.0) {
tmp = y - x;
} 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 <= (-10000000000000.0d0)) then
tmp = (y * x) - x
else if (x <= 1.0d0) then
tmp = y - x
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -10000000000000.0) {
tmp = (y * x) - x;
} else if (x <= 1.0) {
tmp = y - x;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -10000000000000.0: tmp = (y * x) - x elif x <= 1.0: tmp = y - x else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -10000000000000.0) tmp = Float64(Float64(y * x) - x); elseif (x <= 1.0) tmp = Float64(y - x); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -10000000000000.0) tmp = (y * x) - x; elseif (x <= 1.0) tmp = y - x; else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -10000000000000.0], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 1.0], N[(y - x), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -10000000000000:\\
\;\;\;\;y \cdot x - x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if x < -1e13Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
if -1e13 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.9%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.7%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (<= y -1e-15) y (if (<= y 1.0) (- x) (* y x))))
double code(double x, double y) {
double tmp;
if (y <= -1e-15) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} 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 (y <= (-1d-15)) then
tmp = y
else if (y <= 1.0d0) then
tmp = -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1e-15) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e-15: tmp = y elif y <= 1.0: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1e-15) tmp = y; elseif (y <= 1.0) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e-15) tmp = y; elseif (y <= 1.0) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e-15], y, If[LessEqual[y, 1.0], (-x), N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-15}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.0000000000000001e-15Initial 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 59.1%
if -1.0000000000000001e-15 < y < 1Initial program 100.0%
Taylor expanded in y around 0 82.6%
neg-mul-182.6%
Simplified82.6%
if 1 < y Initial program 99.9%
*-commutative99.9%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Taylor expanded in y around inf 96.3%
Taylor expanded in x around inf 49.7%
*-commutative49.7%
Simplified49.7%
Final simplification67.7%
(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 (if (<= y -2.5e-16) y (if (<= y 6.1e-6) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -2.5e-16) {
tmp = y;
} else if (y <= 6.1e-6) {
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.5d-16)) then
tmp = y
else if (y <= 6.1d-6) 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.5e-16) {
tmp = y;
} else if (y <= 6.1e-6) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.5e-16: tmp = y elif y <= 6.1e-6: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.5e-16) tmp = y; elseif (y <= 6.1e-6) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.5e-16) tmp = y; elseif (y <= 6.1e-6) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.5e-16], y, If[LessEqual[y, 6.1e-6], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.5 \cdot 10^{-16}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.1 \cdot 10^{-6}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.5000000000000002e-16 or 6.10000000000000004e-6 < y 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 54.7%
if -2.5000000000000002e-16 < y < 6.10000000000000004e-6Initial program 100.0%
Taylor expanded in y around 0 82.6%
neg-mul-182.6%
Simplified82.6%
Final simplification67.4%
(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 38.2%
Final simplification38.2%
herbie shell --seed 2024011
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))