
(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 (or (<= y 9.5e+92) (and (not (<= y 3.9e+105)) (<= y 1.25e+171))) (- y x) (* x y)))
double code(double x, double y) {
double tmp;
if ((y <= 9.5e+92) || (!(y <= 3.9e+105) && (y <= 1.25e+171))) {
tmp = y - 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 ((y <= 9.5d+92) .or. (.not. (y <= 3.9d+105)) .and. (y <= 1.25d+171)) then
tmp = y - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= 9.5e+92) || (!(y <= 3.9e+105) && (y <= 1.25e+171))) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= 9.5e+92) or (not (y <= 3.9e+105) and (y <= 1.25e+171)): tmp = y - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if ((y <= 9.5e+92) || (!(y <= 3.9e+105) && (y <= 1.25e+171))) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= 9.5e+92) || (~((y <= 3.9e+105)) && (y <= 1.25e+171))) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, 9.5e+92], And[N[Not[LessEqual[y, 3.9e+105]], $MachinePrecision], LessEqual[y, 1.25e+171]]], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 9.5 \cdot 10^{+92} \lor \neg \left(y \leq 3.9 \cdot 10^{+105}\right) \land y \leq 1.25 \cdot 10^{+171}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < 9.4999999999999995e92 or 3.89999999999999978e105 < y < 1.2500000000000001e171Initial program 100.0%
Taylor expanded in x around 0 82.3%
if 9.4999999999999995e92 < y < 3.89999999999999978e105 or 1.2500000000000001e171 < y Initial program 100.0%
Taylor expanded in x around inf 67.1%
Taylor expanded in y around inf 67.1%
Final simplification80.4%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.0148))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.0148)) {
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 <= 0.0148d0))) 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 <= 0.0148)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.0148): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.0148)) 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 <= 0.0148))) 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, 0.0148]], $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 0.0148\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 0.014800000000000001 < x Initial program 100.0%
Taylor expanded in x around inf 98.9%
if -1 < x < 0.014800000000000001Initial program 100.0%
Taylor expanded in x around 0 99.7%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (* x (+ y -1.0)) (if (<= x 0.0148) (- y x) (- (* x y) x))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 0.0148) {
tmp = y - x;
} 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 (x <= (-1.0d0)) then
tmp = x * (y + (-1.0d0))
else if (x <= 0.0148d0) then
tmp = y - x
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = x * (y + -1.0);
} else if (x <= 0.0148) {
tmp = y - x;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = x * (y + -1.0) elif x <= 0.0148: tmp = y - x else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(x * Float64(y + -1.0)); elseif (x <= 0.0148) tmp = Float64(y - x); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = x * (y + -1.0); elseif (x <= 0.0148) tmp = y - x; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 0.0148], N[(y - x), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{elif}\;x \leq 0.0148:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 99.2%
if -1 < x < 0.014800000000000001Initial program 100.0%
Taylor expanded in x around 0 99.7%
if 0.014800000000000001 < x Initial program 100.0%
Taylor expanded in x around inf 98.6%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (<= y -7.0) (* x y) (if (<= y 1.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -7.0) {
tmp = x * y;
} else if (y <= 1.0) {
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 (y <= (-7.0d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = -x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.0: tmp = x * y elif y <= 1.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.0) tmp = x * y; elseif (y <= 1.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 49.3%
Taylor expanded in y around inf 48.4%
if -7 < y < 1Initial program 100.0%
Taylor expanded in y around 0 72.1%
neg-mul-172.1%
Simplified72.1%
Final simplification60.5%
(FPCore (x y) :precision binary64 (- x))
double code(double x, double y) {
return -x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = -x
end function
public static double code(double x, double y) {
return -x;
}
def code(x, y): return -x
function code(x, y) return Float64(-x) end
function tmp = code(x, y) tmp = -x; end
code[x_, y_] := (-x)
\begin{array}{l}
\\
-x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 38.2%
neg-mul-138.2%
Simplified38.2%
Final simplification38.2%
herbie shell --seed 2023224
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))