
(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 8 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 (- (fma x y y) x))
double code(double x, double y) {
return fma(x, y, y) - x;
}
function code(x, y) return Float64(fma(x, y, y) - x) end
code[x_, y_] := N[(N[(x * y + y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, y\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
fma-def100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -1.95e-22) (- x) (if (<= x 1.0) y (if (<= x 4.3e+266) (* x y) (- x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.95e-22) {
tmp = -x;
} else if (x <= 1.0) {
tmp = y;
} else if (x <= 4.3e+266) {
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 <= (-1.95d-22)) then
tmp = -x
else if (x <= 1.0d0) then
tmp = y
else if (x <= 4.3d+266) 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 <= -1.95e-22) {
tmp = -x;
} else if (x <= 1.0) {
tmp = y;
} else if (x <= 4.3e+266) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.95e-22: tmp = -x elif x <= 1.0: tmp = y elif x <= 4.3e+266: tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.95e-22) tmp = Float64(-x); elseif (x <= 1.0) tmp = y; elseif (x <= 4.3e+266) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.95e-22) tmp = -x; elseif (x <= 1.0) tmp = y; elseif (x <= 4.3e+266) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.95e-22], (-x), If[LessEqual[x, 1.0], y, If[LessEqual[x, 4.3e+266], N[(x * y), $MachinePrecision], (-x)]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-22}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 4.3 \cdot 10^{+266}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -1.94999999999999999e-22 or 4.3000000000000002e266 < x Initial program 100.0%
Taylor expanded in y around 0 58.9%
neg-mul-158.9%
Simplified58.9%
if -1.94999999999999999e-22 < x < 1Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 78.4%
if 1 < x < 4.3000000000000002e266Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 70.4%
Final simplification70.9%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.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 <= (-1.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 <= -1.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.1%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.7%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (or (<= x -1700000000.0) (not (<= x 1.0))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1700000000.0) || !(x <= 1.0)) {
tmp = (x * 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 ((x <= (-1700000000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (x * y) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1700000000.0) || !(x <= 1.0)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1700000000.0) or not (x <= 1.0): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1700000000.0) || !(x <= 1.0)) tmp = Float64(Float64(x * y) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1700000000.0) || ~((x <= 1.0))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1700000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1700000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.7e9 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.7%
if -1.7e9 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.8%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (<= x 2.1e+36) (- y x) (if (<= x 2.9e+265) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (x <= 2.1e+36) {
tmp = y - x;
} else if (x <= 2.9e+265) {
tmp = x * 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 (x <= 2.1d+36) then
tmp = y - x
else if (x <= 2.9d+265) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 2.1e+36) {
tmp = y - x;
} else if (x <= 2.9e+265) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 2.1e+36: tmp = y - x elif x <= 2.9e+265: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= 2.1e+36) tmp = Float64(y - x); elseif (x <= 2.9e+265) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 2.1e+36) tmp = y - x; elseif (x <= 2.9e+265) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 2.1e+36], N[(y - x), $MachinePrecision], If[LessEqual[x, 2.9e+265], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.1 \cdot 10^{+36}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;x \leq 2.9 \cdot 10^{+265}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < 2.10000000000000004e36 or 2.89999999999999996e265 < x Initial program 100.0%
Taylor expanded in x around 0 84.4%
if 2.10000000000000004e36 < x < 2.89999999999999996e265Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 71.9%
Final simplification82.0%
(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 (<= x -4.9e-23) (- x) (if (<= x 2.5e-25) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -4.9e-23) {
tmp = -x;
} else if (x <= 2.5e-25) {
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 <= (-4.9d-23)) then
tmp = -x
else if (x <= 2.5d-25) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -4.9e-23) {
tmp = -x;
} else if (x <= 2.5e-25) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -4.9e-23: tmp = -x elif x <= 2.5e-25: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -4.9e-23) tmp = Float64(-x); elseif (x <= 2.5e-25) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -4.9e-23) tmp = -x; elseif (x <= 2.5e-25) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -4.9e-23], (-x), If[LessEqual[x, 2.5e-25], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.9 \cdot 10^{-23}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-25}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -4.8999999999999998e-23 or 2.49999999999999981e-25 < x Initial program 100.0%
Taylor expanded in y around 0 48.1%
neg-mul-148.1%
Simplified48.1%
if -4.8999999999999998e-23 < x < 2.49999999999999981e-25Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 79.5%
Final simplification63.2%
(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 100.0%
Taylor expanded in x around 0 41.0%
Final simplification41.0%
herbie shell --seed 2023200
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))