
(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 7 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -0.27)
(- x)
(if (<= x 4.4e-85)
y
(if (<= x 1.6e+45)
(- x)
(if (or (<= x 1.25e+109) (and (not (<= x 4.8e+222)) (<= x 4.2e+248)))
(* x y)
(- x))))))
double code(double x, double y) {
double tmp;
if (x <= -0.27) {
tmp = -x;
} else if (x <= 4.4e-85) {
tmp = y;
} else if (x <= 1.6e+45) {
tmp = -x;
} else if ((x <= 1.25e+109) || (!(x <= 4.8e+222) && (x <= 4.2e+248))) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.27d0)) then
tmp = -x
else if (x <= 4.4d-85) then
tmp = y
else if (x <= 1.6d+45) then
tmp = -x
else if ((x <= 1.25d+109) .or. (.not. (x <= 4.8d+222)) .and. (x <= 4.2d+248)) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.27) {
tmp = -x;
} else if (x <= 4.4e-85) {
tmp = y;
} else if (x <= 1.6e+45) {
tmp = -x;
} else if ((x <= 1.25e+109) || (!(x <= 4.8e+222) && (x <= 4.2e+248))) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.27: tmp = -x elif x <= 4.4e-85: tmp = y elif x <= 1.6e+45: tmp = -x elif (x <= 1.25e+109) or (not (x <= 4.8e+222) and (x <= 4.2e+248)): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -0.27) tmp = Float64(-x); elseif (x <= 4.4e-85) tmp = y; elseif (x <= 1.6e+45) tmp = Float64(-x); elseif ((x <= 1.25e+109) || (!(x <= 4.8e+222) && (x <= 4.2e+248))) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.27) tmp = -x; elseif (x <= 4.4e-85) tmp = y; elseif (x <= 1.6e+45) tmp = -x; elseif ((x <= 1.25e+109) || (~((x <= 4.8e+222)) && (x <= 4.2e+248))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.27], (-x), If[LessEqual[x, 4.4e-85], y, If[LessEqual[x, 1.6e+45], (-x), If[Or[LessEqual[x, 1.25e+109], And[N[Not[LessEqual[x, 4.8e+222]], $MachinePrecision], LessEqual[x, 4.2e+248]]], N[(x * y), $MachinePrecision], (-x)]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.27:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-85}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+45}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 1.25 \cdot 10^{+109} \lor \neg \left(x \leq 4.8 \cdot 10^{+222}\right) \land x \leq 4.2 \cdot 10^{+248}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -0.27000000000000002 or 4.4e-85 < x < 1.6000000000000001e45 or 1.25e109 < x < 4.8000000000000002e222 or 4.19999999999999977e248 < x Initial program 100.0%
Taylor expanded in y around 0 62.1%
neg-mul-162.1%
Simplified62.1%
if -0.27000000000000002 < x < 4.4e-85Initial program 100.0%
Taylor expanded in x around 0 80.1%
if 1.6000000000000001e45 < x < 1.25e109 or 4.8000000000000002e222 < x < 4.19999999999999977e248Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 87.6%
Final simplification71.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.05e-82) (not (<= y 1.6e-12))) (* (+ x 1.0) y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.05e-82) || !(y <= 1.6e-12)) {
tmp = (x + 1.0) * y;
} else {
tmp = -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.05d-82)) .or. (.not. (y <= 1.6d-12))) then
tmp = (x + 1.0d0) * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.05e-82) || !(y <= 1.6e-12)) {
tmp = (x + 1.0) * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.05e-82) or not (y <= 1.6e-12): tmp = (x + 1.0) * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.05e-82) || !(y <= 1.6e-12)) tmp = Float64(Float64(x + 1.0) * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.05e-82) || ~((y <= 1.6e-12))) tmp = (x + 1.0) * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.05e-82], N[Not[LessEqual[y, 1.6e-12]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-82} \lor \neg \left(y \leq 1.6 \cdot 10^{-12}\right):\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1.05e-82 or 1.6e-12 < y Initial program 100.0%
Taylor expanded in y around inf 93.1%
if -1.05e-82 < y < 1.6e-12Initial program 100.0%
Taylor expanded in y around 0 77.9%
neg-mul-177.9%
Simplified77.9%
Final simplification86.0%
(FPCore (x y) :precision binary64 (if (or (<= x -0.36) (not (<= x 5.5e-110))) (* x (+ y -1.0)) (* (+ x 1.0) y)))
double code(double x, double y) {
double tmp;
if ((x <= -0.36) || !(x <= 5.5e-110)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-0.36d0)) .or. (.not. (x <= 5.5d-110))) then
tmp = x * (y + (-1.0d0))
else
tmp = (x + 1.0d0) * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -0.36) || !(x <= 5.5e-110)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.36) or not (x <= 5.5e-110): tmp = x * (y + -1.0) else: tmp = (x + 1.0) * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.36) || !(x <= 5.5e-110)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(Float64(x + 1.0) * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -0.36) || ~((x <= 5.5e-110))) tmp = x * (y + -1.0); else tmp = (x + 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.36], N[Not[LessEqual[x, 5.5e-110]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.36 \lor \neg \left(x \leq 5.5 \cdot 10^{-110}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if x < -0.35999999999999999 or 5.4999999999999998e-110 < x Initial program 100.0%
Taylor expanded in x around inf 92.9%
if -0.35999999999999999 < x < 5.4999999999999998e-110Initial program 100.0%
Taylor expanded in y around inf 81.8%
Final simplification88.0%
(FPCore (x y) :precision binary64 (if (<= x -390.0) (- (* x y) x) (if (<= x 5.5e-110) (* (+ x 1.0) y) (* x (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -390.0) {
tmp = (x * y) - x;
} else if (x <= 5.5e-110) {
tmp = (x + 1.0) * 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 <= (-390.0d0)) then
tmp = (x * y) - x
else if (x <= 5.5d-110) then
tmp = (x + 1.0d0) * 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 <= -390.0) {
tmp = (x * y) - x;
} else if (x <= 5.5e-110) {
tmp = (x + 1.0) * y;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -390.0: tmp = (x * y) - x elif x <= 5.5e-110: tmp = (x + 1.0) * y else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -390.0) tmp = Float64(Float64(x * y) - x); elseif (x <= 5.5e-110) tmp = Float64(Float64(x + 1.0) * y); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -390.0) tmp = (x * y) - x; elseif (x <= 5.5e-110) tmp = (x + 1.0) * y; else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -390.0], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 5.5e-110], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -390:\\
\;\;\;\;x \cdot y - x\\
\mathbf{elif}\;x \leq 5.5 \cdot 10^{-110}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if x < -390Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
distribute-lft-out--100.0%
*-commutative100.0%
cancel-sign-sub-inv100.0%
*-rgt-identity100.0%
sub-neg100.0%
Simplified100.0%
if -390 < x < 5.4999999999999998e-110Initial program 100.0%
Taylor expanded in y around inf 81.8%
if 5.4999999999999998e-110 < x Initial program 100.0%
Taylor expanded in x around inf 88.5%
Final simplification88.0%
(FPCore (x y) :precision binary64 (if (<= x -0.27) (- x) (if (<= x 4.4e-85) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -0.27) {
tmp = -x;
} else if (x <= 4.4e-85) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (x <= (-0.27d0)) then
tmp = -x
else if (x <= 4.4d-85) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -0.27) {
tmp = -x;
} else if (x <= 4.4e-85) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -0.27: tmp = -x elif x <= 4.4e-85: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -0.27) tmp = Float64(-x); elseif (x <= 4.4e-85) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -0.27) tmp = -x; elseif (x <= 4.4e-85) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -0.27], (-x), If[LessEqual[x, 4.4e-85], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -0.27:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{-85}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -0.27000000000000002 or 4.4e-85 < x Initial program 100.0%
Taylor expanded in y around 0 57.2%
neg-mul-157.2%
Simplified57.2%
if -0.27000000000000002 < x < 4.4e-85Initial program 100.0%
Taylor expanded in x around 0 80.1%
Final simplification67.7%
(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 41.3%
Final simplification41.3%
herbie shell --seed 2023182
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))