
(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 (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 y around inf 99.4%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around 0 99.4%
Taylor expanded in y around 0 99.4%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 4.5e-5))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.5e-5)) {
tmp = x * (y + -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 ((x <= (-1.0d0)) .or. (.not. (x <= 4.5d-5))) then
tmp = x * (y + (-1.0d0))
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 4.5e-5)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 4.5e-5): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 4.5e-5)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 4.5e-5))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 4.5e-5]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 4.5 \cdot 10^{-5}\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 4.50000000000000028e-5 < x Initial program 100.0%
Taylor expanded in x around inf 97.7%
if -1 < x < 4.50000000000000028e-5Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in y around 0 99.0%
Final simplification98.4%
(FPCore (x y) :precision binary64 (if (<= x -2.05e+158) (- x) (if (<= x -1.3e+31) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (x <= -2.05e+158) {
tmp = -x;
} else if (x <= -1.3e+31) {
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.05d+158)) then
tmp = -x
else if (x <= (-1.3d+31)) 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.05e+158) {
tmp = -x;
} else if (x <= -1.3e+31) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.05e+158: tmp = -x elif x <= -1.3e+31: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.05e+158) tmp = Float64(-x); elseif (x <= -1.3e+31) 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.05e+158) tmp = -x; elseif (x <= -1.3e+31) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.05e+158], (-x), If[LessEqual[x, -1.3e+31], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{+158}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{+31}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2.05000000000000002e158Initial program 100.0%
Taylor expanded in y around 0 62.5%
neg-mul-162.5%
Simplified62.5%
if -2.05000000000000002e158 < x < -1.3e31Initial program 100.0%
Taylor expanded in y around inf 77.9%
Taylor expanded in x around inf 77.9%
if -1.3e31 < x Initial program 100.0%
Taylor expanded in x around 0 83.6%
Taylor expanded in y around 0 83.6%
Final simplification80.1%
(FPCore (x y) :precision binary64 (if (<= y -2.7e-14) y (if (<= y 1.25e-37) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -2.7e-14) {
tmp = y;
} else if (y <= 1.25e-37) {
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 <= (-2.7d-14)) then
tmp = y
else if (y <= 1.25d-37) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.7e-14) {
tmp = y;
} else if (y <= 1.25e-37) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.7e-14: tmp = y elif y <= 1.25e-37: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.7e-14) tmp = y; elseif (y <= 1.25e-37) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.7e-14) tmp = y; elseif (y <= 1.25e-37) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.7e-14], y, If[LessEqual[y, 1.25e-37], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{-14}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.25 \cdot 10^{-37}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.6999999999999999e-14 or 1.2499999999999999e-37 < y Initial program 100.0%
Taylor expanded in x around 0 54.1%
if -2.6999999999999999e-14 < y < 1.2499999999999999e-37Initial program 100.0%
Taylor expanded in y around 0 83.1%
neg-mul-183.1%
Simplified83.1%
(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.0%
herbie shell --seed 2024132
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))