
(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 9 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 (<= y -1.5e+240)
y
(if (<= y -4.5e+52)
(* y x)
(if (<= y -3.2e-17)
y
(if (<= y 9.5e-91) (- x) (if (<= y 3.5e+233) y (* y x)))))))
double code(double x, double y) {
double tmp;
if (y <= -1.5e+240) {
tmp = y;
} else if (y <= -4.5e+52) {
tmp = y * x;
} else if (y <= -3.2e-17) {
tmp = y;
} else if (y <= 9.5e-91) {
tmp = -x;
} else if (y <= 3.5e+233) {
tmp = 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 (y <= (-1.5d+240)) then
tmp = y
else if (y <= (-4.5d+52)) then
tmp = y * x
else if (y <= (-3.2d-17)) then
tmp = y
else if (y <= 9.5d-91) then
tmp = -x
else if (y <= 3.5d+233) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.5e+240) {
tmp = y;
} else if (y <= -4.5e+52) {
tmp = y * x;
} else if (y <= -3.2e-17) {
tmp = y;
} else if (y <= 9.5e-91) {
tmp = -x;
} else if (y <= 3.5e+233) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.5e+240: tmp = y elif y <= -4.5e+52: tmp = y * x elif y <= -3.2e-17: tmp = y elif y <= 9.5e-91: tmp = -x elif y <= 3.5e+233: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.5e+240) tmp = y; elseif (y <= -4.5e+52) tmp = Float64(y * x); elseif (y <= -3.2e-17) tmp = y; elseif (y <= 9.5e-91) tmp = Float64(-x); elseif (y <= 3.5e+233) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.5e+240) tmp = y; elseif (y <= -4.5e+52) tmp = y * x; elseif (y <= -3.2e-17) tmp = y; elseif (y <= 9.5e-91) tmp = -x; elseif (y <= 3.5e+233) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.5e+240], y, If[LessEqual[y, -4.5e+52], N[(y * x), $MachinePrecision], If[LessEqual[y, -3.2e-17], y, If[LessEqual[y, 9.5e-91], (-x), If[LessEqual[y, 3.5e+233], y, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.5 \cdot 10^{+240}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -4.5 \cdot 10^{+52}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -3.2 \cdot 10^{-17}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 9.5 \cdot 10^{-91}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+233}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.4999999999999999e240 or -4.5e52 < y < -3.2000000000000002e-17 or 9.5e-91 < y < 3.4999999999999998e233Initial program 100.0%
Taylor expanded in x around 0 64.5%
if -1.4999999999999999e240 < y < -4.5e52 or 3.4999999999999998e233 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 69.9%
if -3.2000000000000002e-17 < y < 9.5e-91Initial program 100.0%
Taylor expanded in y around 0 82.1%
neg-mul-182.1%
Simplified82.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.4e+231) (and (not (<= y -5.8e+51)) (<= y 1.25e+233))) (- y x) (* y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.4e+231) || (!(y <= -5.8e+51) && (y <= 1.25e+233))) {
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 ((y <= (-1.4d+231)) .or. (.not. (y <= (-5.8d+51))) .and. (y <= 1.25d+233)) 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 ((y <= -1.4e+231) || (!(y <= -5.8e+51) && (y <= 1.25e+233))) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.4e+231) or (not (y <= -5.8e+51) and (y <= 1.25e+233)): tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.4e+231) || (!(y <= -5.8e+51) && (y <= 1.25e+233))) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.4e+231) || (~((y <= -5.8e+51)) && (y <= 1.25e+233))) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.4e+231], And[N[Not[LessEqual[y, -5.8e+51]], $MachinePrecision], LessEqual[y, 1.25e+233]]], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.4 \cdot 10^{+231} \lor \neg \left(y \leq -5.8 \cdot 10^{+51}\right) \land y \leq 1.25 \cdot 10^{+233}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.4e231 or -5.7999999999999997e51 < y < 1.25000000000000002e233Initial program 100.0%
Taylor expanded in x around 0 87.8%
Taylor expanded in y around 0 87.8%
if -1.4e231 < y < -5.7999999999999997e51 or 1.25000000000000002e233 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 71.5%
Final simplification84.8%
(FPCore (x y) :precision binary64 (if (or (<= x -210000000.0) (not (<= x 1.0))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -210000000.0) || !(x <= 1.0)) {
tmp = (y * x) - 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 <= (-210000000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (y * x) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -210000000.0) || !(x <= 1.0)) {
tmp = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -210000000.0) or not (x <= 1.0): tmp = (y * x) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -210000000.0) || !(x <= 1.0)) tmp = Float64(Float64(y * x) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -210000000.0) || ~((x <= 1.0))) tmp = (y * x) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -210000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -210000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2.1e8 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.5%
if -2.1e8 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in y around 0 99.0%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (or (<= y -3500000000.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -3500000000.0) || !(y <= 1.0)) {
tmp = y * (x + 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 ((y <= (-3500000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + 1.0d0)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3500000000.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3500000000.0) or not (y <= 1.0): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3500000000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3500000000.0) || ~((y <= 1.0))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3500000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3500000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -3.5e9 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
if -3.5e9 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.2%
Taylor expanded in y around 0 98.2%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (<= y -3500000000.0) (+ y (* y x)) (if (<= y 1.0) (- y x) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -3500000000.0) {
tmp = y + (y * x);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-3500000000.0d0)) then
tmp = y + (y * x)
else if (y <= 1.0d0) then
tmp = y - x
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -3500000000.0) {
tmp = y + (y * x);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3500000000.0: tmp = y + (y * x) elif y <= 1.0: tmp = y - x else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -3500000000.0) tmp = Float64(y + Float64(y * x)); elseif (y <= 1.0) tmp = Float64(y - x); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3500000000.0) tmp = y + (y * x); elseif (y <= 1.0) tmp = y - x; else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3500000000.0], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(y - x), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3500000000:\\
\;\;\;\;y + y \cdot x\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -3.5e9Initial program 100.0%
Taylor expanded in y around inf 100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
*-commutative100.0%
+-commutative100.0%
Applied egg-rr100.0%
if -3.5e9 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.2%
Taylor expanded in y around 0 98.2%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.8%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (<= y -1.3e-16) y (if (<= y 8e-91) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.3e-16) {
tmp = y;
} else if (y <= 8e-91) {
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 <= (-1.3d-16)) then
tmp = y
else if (y <= 8d-91) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.3e-16) {
tmp = y;
} else if (y <= 8e-91) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.3e-16: tmp = y elif y <= 8e-91: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.3e-16) tmp = y; elseif (y <= 8e-91) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.3e-16) tmp = y; elseif (y <= 8e-91) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.3e-16], y, If[LessEqual[y, 8e-91], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{-16}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 8 \cdot 10^{-91}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.2999999999999999e-16 or 8.00000000000000018e-91 < y Initial program 100.0%
Taylor expanded in x around 0 52.8%
if -1.2999999999999999e-16 < y < 8.00000000000000018e-91Initial program 100.0%
Taylor expanded in y around 0 82.1%
neg-mul-182.1%
Simplified82.1%
(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%
Taylor expanded in x around 0 38.2%
herbie shell --seed 2024170
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))