
(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 (- (* 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 -1.85e+244)
(* x y)
(if (<= y -6.6e+152)
y
(if (<= y -1.0)
(* x y)
(if (<= y 4.3e-78)
(- x)
(if (or (<= y 1.46e+113) (and (not (<= y 2.9e+200)) (<= y 5.4e+262)))
y
(* x y)))))))
double code(double x, double y) {
double tmp;
if (y <= -1.85e+244) {
tmp = x * y;
} else if (y <= -6.6e+152) {
tmp = y;
} else if (y <= -1.0) {
tmp = x * y;
} else if (y <= 4.3e-78) {
tmp = -x;
} else if ((y <= 1.46e+113) || (!(y <= 2.9e+200) && (y <= 5.4e+262))) {
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.85d+244)) then
tmp = x * y
else if (y <= (-6.6d+152)) then
tmp = y
else if (y <= (-1.0d0)) then
tmp = x * y
else if (y <= 4.3d-78) then
tmp = -x
else if ((y <= 1.46d+113) .or. (.not. (y <= 2.9d+200)) .and. (y <= 5.4d+262)) 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.85e+244) {
tmp = x * y;
} else if (y <= -6.6e+152) {
tmp = y;
} else if (y <= -1.0) {
tmp = x * y;
} else if (y <= 4.3e-78) {
tmp = -x;
} else if ((y <= 1.46e+113) || (!(y <= 2.9e+200) && (y <= 5.4e+262))) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.85e+244: tmp = x * y elif y <= -6.6e+152: tmp = y elif y <= -1.0: tmp = x * y elif y <= 4.3e-78: tmp = -x elif (y <= 1.46e+113) or (not (y <= 2.9e+200) and (y <= 5.4e+262)): tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.85e+244) tmp = Float64(x * y); elseif (y <= -6.6e+152) tmp = y; elseif (y <= -1.0) tmp = Float64(x * y); elseif (y <= 4.3e-78) tmp = Float64(-x); elseif ((y <= 1.46e+113) || (!(y <= 2.9e+200) && (y <= 5.4e+262))) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.85e+244) tmp = x * y; elseif (y <= -6.6e+152) tmp = y; elseif (y <= -1.0) tmp = x * y; elseif (y <= 4.3e-78) tmp = -x; elseif ((y <= 1.46e+113) || (~((y <= 2.9e+200)) && (y <= 5.4e+262))) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.85e+244], N[(x * y), $MachinePrecision], If[LessEqual[y, -6.6e+152], y, If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 4.3e-78], (-x), If[Or[LessEqual[y, 1.46e+113], And[N[Not[LessEqual[y, 2.9e+200]], $MachinePrecision], LessEqual[y, 5.4e+262]]], y, N[(x * y), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.85 \cdot 10^{+244}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -6.6 \cdot 10^{+152}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-78}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1.46 \cdot 10^{+113} \lor \neg \left(y \leq 2.9 \cdot 10^{+200}\right) \land y \leq 5.4 \cdot 10^{+262}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.8500000000000001e244 or -6.6000000000000003e152 < y < -1 or 1.46e113 < y < 2.8999999999999999e200 or 5.4000000000000002e262 < y Initial program 100.0%
Taylor expanded in x around inf 74.1%
*-commutative74.1%
Simplified74.1%
Taylor expanded in y around inf 70.0%
if -1.8500000000000001e244 < y < -6.6000000000000003e152 or 4.29999999999999994e-78 < y < 1.46e113 or 2.8999999999999999e200 < y < 5.4000000000000002e262Initial program 100.0%
Taylor expanded in x around 0 64.8%
if -1 < y < 4.29999999999999994e-78Initial program 100.0%
Taylor expanded in y around 0 85.2%
neg-mul-185.2%
Simplified85.2%
Final simplification75.0%
(FPCore (x y)
:precision binary64
(if (or (<= x -2.7e-70)
(not (or (<= x 1.4e-122) (and (not (<= x 7.8e-104)) (<= x 3.6e-19)))))
(* x (+ y -1.0))
y))
double code(double x, double y) {
double tmp;
if ((x <= -2.7e-70) || !((x <= 1.4e-122) || (!(x <= 7.8e-104) && (x <= 3.6e-19)))) {
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 <= (-2.7d-70)) .or. (.not. (x <= 1.4d-122) .or. (.not. (x <= 7.8d-104)) .and. (x <= 3.6d-19))) 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 <= -2.7e-70) || !((x <= 1.4e-122) || (!(x <= 7.8e-104) && (x <= 3.6e-19)))) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.7e-70) or not ((x <= 1.4e-122) or (not (x <= 7.8e-104) and (x <= 3.6e-19))): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.7e-70) || !((x <= 1.4e-122) || (!(x <= 7.8e-104) && (x <= 3.6e-19)))) 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 <= -2.7e-70) || ~(((x <= 1.4e-122) || (~((x <= 7.8e-104)) && (x <= 3.6e-19))))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.7e-70], N[Not[Or[LessEqual[x, 1.4e-122], And[N[Not[LessEqual[x, 7.8e-104]], $MachinePrecision], LessEqual[x, 3.6e-19]]]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.7 \cdot 10^{-70} \lor \neg \left(x \leq 1.4 \cdot 10^{-122} \lor \neg \left(x \leq 7.8 \cdot 10^{-104}\right) \land x \leq 3.6 \cdot 10^{-19}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.7000000000000001e-70 or 1.3999999999999999e-122 < x < 7.8000000000000004e-104 or 3.6000000000000001e-19 < x Initial program 100.0%
Taylor expanded in x around inf 96.4%
if -2.7000000000000001e-70 < x < 1.3999999999999999e-122 or 7.8000000000000004e-104 < x < 3.6000000000000001e-19Initial program 100.0%
Taylor expanded in x around 0 85.3%
Final simplification92.5%
(FPCore (x y) :precision binary64 (if (or (<= y -41000.0) (not (<= y 4.3e-78))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -41000.0) || !(y <= 4.3e-78)) {
tmp = y * (x + 1.0);
} 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 ((y <= (-41000.0d0)) .or. (.not. (y <= 4.3d-78))) then
tmp = y * (x + 1.0d0)
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -41000.0) || !(y <= 4.3e-78)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -41000.0) or not (y <= 4.3e-78): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -41000.0) || !(y <= 4.3e-78)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -41000.0) || ~((y <= 4.3e-78))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -41000.0], N[Not[LessEqual[y, 4.3e-78]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -41000 \lor \neg \left(y \leq 4.3 \cdot 10^{-78}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -41000 or 4.29999999999999994e-78 < y Initial program 100.0%
Taylor expanded in y around inf 93.3%
if -41000 < y < 4.29999999999999994e-78Initial program 100.0%
Taylor expanded in x around inf 87.0%
Final simplification90.4%
(FPCore (x y) :precision binary64 (if (or (<= y -44000.0) (not (<= y 4.3e-78))) (* y (+ x 1.0)) (- (* x y) x)))
double code(double x, double y) {
double tmp;
if ((y <= -44000.0) || !(y <= 4.3e-78)) {
tmp = y * (x + 1.0);
} 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 ((y <= (-44000.0d0)) .or. (.not. (y <= 4.3d-78))) then
tmp = y * (x + 1.0d0)
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -44000.0) || !(y <= 4.3e-78)) {
tmp = y * (x + 1.0);
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -44000.0) or not (y <= 4.3e-78): tmp = y * (x + 1.0) else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -44000.0) || !(y <= 4.3e-78)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -44000.0) || ~((y <= 4.3e-78))) tmp = y * (x + 1.0); else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -44000.0], N[Not[LessEqual[y, 4.3e-78]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -44000 \lor \neg \left(y \leq 4.3 \cdot 10^{-78}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if y < -44000 or 4.29999999999999994e-78 < y Initial program 100.0%
Taylor expanded in y around inf 93.3%
if -44000 < y < 4.29999999999999994e-78Initial program 100.0%
Taylor expanded in x around inf 87.0%
*-commutative87.0%
Simplified87.0%
Final simplification90.4%
(FPCore (x y) :precision binary64 (if (<= y -41000.0) y (if (<= y 4.3e-78) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -41000.0) {
tmp = y;
} else if (y <= 4.3e-78) {
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 <= (-41000.0d0)) then
tmp = y
else if (y <= 4.3d-78) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -41000.0) {
tmp = y;
} else if (y <= 4.3e-78) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -41000.0: tmp = y elif y <= 4.3e-78: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -41000.0) tmp = y; elseif (y <= 4.3e-78) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -41000.0) tmp = y; elseif (y <= 4.3e-78) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -41000.0], y, If[LessEqual[y, 4.3e-78], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -41000:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.3 \cdot 10^{-78}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -41000 or 4.29999999999999994e-78 < y Initial program 100.0%
Taylor expanded in x around 0 49.1%
if -41000 < y < 4.29999999999999994e-78Initial program 100.0%
Taylor expanded in y around 0 82.7%
neg-mul-182.7%
Simplified82.7%
Final simplification64.3%
(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 33.6%
Final simplification33.6%
herbie shell --seed 2024034
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))