
(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 (- (* 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 -6e+14)
(* x y)
(if (<= y -3e-31)
y
(if (<= y 1.0)
(- x)
(if (or (<= y 7.6e+92) (not (<= y 6.7e+162))) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -6e+14) {
tmp = x * y;
} else if (y <= -3e-31) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} else if ((y <= 7.6e+92) || !(y <= 6.7e+162)) {
tmp = x * y;
} 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 <= (-6d+14)) then
tmp = x * y
else if (y <= (-3d-31)) then
tmp = y
else if (y <= 1.0d0) then
tmp = -x
else if ((y <= 7.6d+92) .or. (.not. (y <= 6.7d+162))) then
tmp = x * y
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -6e+14) {
tmp = x * y;
} else if (y <= -3e-31) {
tmp = y;
} else if (y <= 1.0) {
tmp = -x;
} else if ((y <= 7.6e+92) || !(y <= 6.7e+162)) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -6e+14: tmp = x * y elif y <= -3e-31: tmp = y elif y <= 1.0: tmp = -x elif (y <= 7.6e+92) or not (y <= 6.7e+162): tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -6e+14) tmp = Float64(x * y); elseif (y <= -3e-31) tmp = y; elseif (y <= 1.0) tmp = Float64(-x); elseif ((y <= 7.6e+92) || !(y <= 6.7e+162)) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -6e+14) tmp = x * y; elseif (y <= -3e-31) tmp = y; elseif (y <= 1.0) tmp = -x; elseif ((y <= 7.6e+92) || ~((y <= 6.7e+162))) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -6e+14], N[(x * y), $MachinePrecision], If[LessEqual[y, -3e-31], y, If[LessEqual[y, 1.0], (-x), If[Or[LessEqual[y, 7.6e+92], N[Not[LessEqual[y, 6.7e+162]], $MachinePrecision]], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6 \cdot 10^{+14}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3 \cdot 10^{-31}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 7.6 \cdot 10^{+92} \lor \neg \left(y \leq 6.7 \cdot 10^{+162}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -6e14 or 1 < y < 7.6000000000000001e92 or 6.6999999999999999e162 < y Initial program 100.0%
Taylor expanded in x around inf 64.6%
*-commutative64.6%
Simplified64.6%
Taylor expanded in y around inf 63.0%
if -6e14 < y < -2.99999999999999981e-31 or 7.6000000000000001e92 < y < 6.6999999999999999e162Initial program 99.9%
Taylor expanded in x around 0 73.6%
if -2.99999999999999981e-31 < y < 1Initial program 100.0%
Taylor expanded in y around 0 82.1%
neg-mul-182.1%
Simplified82.1%
Final simplification72.5%
(FPCore (x y) :precision binary64 (if (or (<= x -4.4e-22) (not (<= x 2.9e-58))) (* x (+ y -1.0)) y))
double code(double x, double y) {
double tmp;
if ((x <= -4.4e-22) || !(x <= 2.9e-58)) {
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 <= (-4.4d-22)) .or. (.not. (x <= 2.9d-58))) 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 <= -4.4e-22) || !(x <= 2.9e-58)) {
tmp = x * (y + -1.0);
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.4e-22) or not (x <= 2.9e-58): tmp = x * (y + -1.0) else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.4e-22) || !(x <= 2.9e-58)) 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 <= -4.4e-22) || ~((x <= 2.9e-58))) tmp = x * (y + -1.0); else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.4e-22], N[Not[LessEqual[x, 2.9e-58]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.4 \cdot 10^{-22} \lor \neg \left(x \leq 2.9 \cdot 10^{-58}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -4.4000000000000001e-22 or 2.8999999999999999e-58 < x Initial program 100.0%
Taylor expanded in x around inf 95.7%
if -4.4000000000000001e-22 < x < 2.8999999999999999e-58Initial program 100.0%
Taylor expanded in x around 0 79.3%
Final simplification89.8%
(FPCore (x y) :precision binary64 (if (or (<= y -9e-30) (not (<= y 6700000000.0))) (* y (+ x 1.0)) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -9e-30) || !(y <= 6700000000.0)) {
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 <= (-9d-30)) .or. (.not. (y <= 6700000000.0d0))) 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 <= -9e-30) || !(y <= 6700000000.0)) {
tmp = y * (x + 1.0);
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -9e-30) or not (y <= 6700000000.0): tmp = y * (x + 1.0) else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -9e-30) || !(y <= 6700000000.0)) 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 <= -9e-30) || ~((y <= 6700000000.0))) tmp = y * (x + 1.0); else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -9e-30], N[Not[LessEqual[y, 6700000000.0]], $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 -9 \cdot 10^{-30} \lor \neg \left(y \leq 6700000000\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -8.99999999999999935e-30 or 6.7e9 < y Initial program 100.0%
Taylor expanded in y around inf 97.7%
if -8.99999999999999935e-30 < y < 6.7e9Initial program 100.0%
Taylor expanded in x around inf 82.5%
Final simplification90.6%
(FPCore (x y) :precision binary64 (if (<= y -1e-29) y (if (<= y 2.2e-40) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1e-29) {
tmp = y;
} else if (y <= 2.2e-40) {
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 <= (-1d-29)) then
tmp = y
else if (y <= 2.2d-40) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1e-29) {
tmp = y;
} else if (y <= 2.2e-40) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1e-29: tmp = y elif y <= 2.2e-40: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1e-29) tmp = y; elseif (y <= 2.2e-40) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1e-29) tmp = y; elseif (y <= 2.2e-40) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1e-29], y, If[LessEqual[y, 2.2e-40], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \cdot 10^{-29}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{-40}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -9.99999999999999943e-30 or 2.20000000000000009e-40 < y Initial program 100.0%
Taylor expanded in x around 0 42.3%
if -9.99999999999999943e-30 < y < 2.20000000000000009e-40Initial program 100.0%
Taylor expanded in y around 0 84.5%
neg-mul-184.5%
Simplified84.5%
Final simplification60.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%
Taylor expanded in x around 0 31.9%
Final simplification31.9%
herbie shell --seed 2024079
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))