
(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 6 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 -7.6e+245)
(- x)
(if (<= x -1.0)
(* x y)
(if (<= x 2.1e-24)
y
(if (or (<= x 8.5e+68) (not (<= x 5e+151))) (- x) (* x y))))))
double code(double x, double y) {
double tmp;
if (x <= -7.6e+245) {
tmp = -x;
} else if (x <= -1.0) {
tmp = x * y;
} else if (x <= 2.1e-24) {
tmp = y;
} else if ((x <= 8.5e+68) || !(x <= 5e+151)) {
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 <= (-7.6d+245)) then
tmp = -x
else if (x <= (-1.0d0)) then
tmp = x * y
else if (x <= 2.1d-24) then
tmp = y
else if ((x <= 8.5d+68) .or. (.not. (x <= 5d+151))) 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 <= -7.6e+245) {
tmp = -x;
} else if (x <= -1.0) {
tmp = x * y;
} else if (x <= 2.1e-24) {
tmp = y;
} else if ((x <= 8.5e+68) || !(x <= 5e+151)) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -7.6e+245: tmp = -x elif x <= -1.0: tmp = x * y elif x <= 2.1e-24: tmp = y elif (x <= 8.5e+68) or not (x <= 5e+151): tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -7.6e+245) tmp = Float64(-x); elseif (x <= -1.0) tmp = Float64(x * y); elseif (x <= 2.1e-24) tmp = y; elseif ((x <= 8.5e+68) || !(x <= 5e+151)) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -7.6e+245) tmp = -x; elseif (x <= -1.0) tmp = x * y; elseif (x <= 2.1e-24) tmp = y; elseif ((x <= 8.5e+68) || ~((x <= 5e+151))) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -7.6e+245], (-x), If[LessEqual[x, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[x, 2.1e-24], y, If[Or[LessEqual[x, 8.5e+68], N[Not[LessEqual[x, 5e+151]], $MachinePrecision]], (-x), N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -7.6 \cdot 10^{+245}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 2.1 \cdot 10^{-24}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 8.5 \cdot 10^{+68} \lor \neg \left(x \leq 5 \cdot 10^{+151}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -7.5999999999999999e245 or 2.0999999999999999e-24 < x < 8.49999999999999966e68 or 5.0000000000000002e151 < x Initial program 100.0%
Taylor expanded in y around 0 64.8%
neg-mul-164.8%
Simplified64.8%
if -7.5999999999999999e245 < x < -1 or 8.49999999999999966e68 < x < 5.0000000000000002e151Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 60.8%
if -1 < x < 2.0999999999999999e-24Initial program 100.0%
Taylor expanded in x around 0 80.3%
Final simplification70.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1.3e-65) (not (<= x 2.2e-24))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.3e-65) || !(x <= 2.2e-24)) {
tmp = x * (y + -1.0);
} 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 <= (-1.3d-65)) .or. (.not. (x <= 2.2d-24))) then
tmp = x * (y + (-1.0d0))
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.3e-65) || !(x <= 2.2e-24)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.3e-65) or not (x <= 2.2e-24): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.3e-65) || !(x <= 2.2e-24)) tmp = Float64(x * Float64(y + -1.0)); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.3e-65) || ~((x <= 2.2e-24))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.3e-65], N[Not[LessEqual[x, 2.2e-24]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-65} \lor \neg \left(x \leq 2.2 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.30000000000000005e-65 or 2.20000000000000002e-24 < x Initial program 100.0%
Taylor expanded in x around inf 95.0%
if -1.30000000000000005e-65 < x < 2.20000000000000002e-24Initial program 100.0%
Taylor expanded in x around 0 83.8%
Final simplification90.3%
(FPCore (x y) :precision binary64 (if (or (<= x -0.00029) (not (<= x 2.05e-24))) (* x (+ y -1.0)) (* (+ x 1.0) y)))
double code(double x, double y) {
double tmp;
if ((x <= -0.00029) || !(x <= 2.05e-24)) {
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.00029d0)) .or. (.not. (x <= 2.05d-24))) 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.00029) || !(x <= 2.05e-24)) {
tmp = x * (y + -1.0);
} else {
tmp = (x + 1.0) * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -0.00029) or not (x <= 2.05e-24): tmp = x * (y + -1.0) else: tmp = (x + 1.0) * y return tmp
function code(x, y) tmp = 0.0 if ((x <= -0.00029) || !(x <= 2.05e-24)) 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.00029) || ~((x <= 2.05e-24))) tmp = x * (y + -1.0); else tmp = (x + 1.0) * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -0.00029], N[Not[LessEqual[x, 2.05e-24]], $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.00029 \lor \neg \left(x \leq 2.05 \cdot 10^{-24}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\end{array}
\end{array}
if x < -2.9e-4 or 2.05000000000000007e-24 < x Initial program 100.0%
Taylor expanded in x around inf 98.2%
if -2.9e-4 < x < 2.05000000000000007e-24Initial program 100.0%
Taylor expanded in y around inf 81.0%
+-commutative81.0%
Simplified81.0%
Final simplification90.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.75e-65) (not (<= x 2.6e-24))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.75e-65) || !(x <= 2.6e-24)) {
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 <= (-1.75d-65)) .or. (.not. (x <= 2.6d-24))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.75e-65) || !(x <= 2.6e-24)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.75e-65) or not (x <= 2.6e-24): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.75e-65) || !(x <= 2.6e-24)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.75e-65) || ~((x <= 2.6e-24))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.75e-65], N[Not[LessEqual[x, 2.6e-24]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.75 \cdot 10^{-65} \lor \neg \left(x \leq 2.6 \cdot 10^{-24}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.75000000000000002e-65 or 2.6e-24 < x Initial program 100.0%
Taylor expanded in y around 0 54.2%
neg-mul-154.2%
Simplified54.2%
if -1.75000000000000002e-65 < x < 2.6e-24Initial program 100.0%
Taylor expanded in x around 0 83.8%
Final simplification66.6%
(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.8%
Final simplification38.8%
herbie shell --seed 2024077
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))