
(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 -7.5e+115)
(* x y)
(if (<= y -1.25e-21)
y
(if (<= y 5.5e-9)
(- x)
(if (<= y 6.2e+25) y (if (<= y 6e+181) (* x y) y))))))
double code(double x, double y) {
double tmp;
if (y <= -7.5e+115) {
tmp = x * y;
} else if (y <= -1.25e-21) {
tmp = y;
} else if (y <= 5.5e-9) {
tmp = -x;
} else if (y <= 6.2e+25) {
tmp = y;
} else if (y <= 6e+181) {
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 <= (-7.5d+115)) then
tmp = x * y
else if (y <= (-1.25d-21)) then
tmp = y
else if (y <= 5.5d-9) then
tmp = -x
else if (y <= 6.2d+25) then
tmp = y
else if (y <= 6d+181) 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 <= -7.5e+115) {
tmp = x * y;
} else if (y <= -1.25e-21) {
tmp = y;
} else if (y <= 5.5e-9) {
tmp = -x;
} else if (y <= 6.2e+25) {
tmp = y;
} else if (y <= 6e+181) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.5e+115: tmp = x * y elif y <= -1.25e-21: tmp = y elif y <= 5.5e-9: tmp = -x elif y <= 6.2e+25: tmp = y elif y <= 6e+181: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.5e+115) tmp = Float64(x * y); elseif (y <= -1.25e-21) tmp = y; elseif (y <= 5.5e-9) tmp = Float64(-x); elseif (y <= 6.2e+25) tmp = y; elseif (y <= 6e+181) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.5e+115) tmp = x * y; elseif (y <= -1.25e-21) tmp = y; elseif (y <= 5.5e-9) tmp = -x; elseif (y <= 6.2e+25) tmp = y; elseif (y <= 6e+181) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.5e+115], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.25e-21], y, If[LessEqual[y, 5.5e-9], (-x), If[LessEqual[y, 6.2e+25], y, If[LessEqual[y, 6e+181], N[(x * y), $MachinePrecision], y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{+115}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-21}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.5 \cdot 10^{-9}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{+25}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6 \cdot 10^{+181}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -7.4999999999999997e115 or 6.1999999999999996e25 < y < 6.00000000000000024e181Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 66.4%
if -7.4999999999999997e115 < y < -1.24999999999999993e-21 or 5.4999999999999996e-9 < y < 6.1999999999999996e25 or 6.00000000000000024e181 < y Initial program 100.0%
Taylor expanded in x around 0 64.1%
if -1.24999999999999993e-21 < y < 5.4999999999999996e-9Initial program 100.0%
Taylor expanded in y around 0 87.2%
neg-mul-187.2%
Simplified87.2%
Final simplification76.2%
(FPCore (x y) :precision binary64 (if (<= y -8e+119) (* x y) (if (<= y 1.8e+25) (- y x) (if (<= y 8e+181) (* x y) y))))
double code(double x, double y) {
double tmp;
if (y <= -8e+119) {
tmp = x * y;
} else if (y <= 1.8e+25) {
tmp = y - x;
} else if (y <= 8e+181) {
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 <= (-8d+119)) then
tmp = x * y
else if (y <= 1.8d+25) then
tmp = y - x
else if (y <= 8d+181) 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 <= -8e+119) {
tmp = x * y;
} else if (y <= 1.8e+25) {
tmp = y - x;
} else if (y <= 8e+181) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8e+119: tmp = x * y elif y <= 1.8e+25: tmp = y - x elif y <= 8e+181: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -8e+119) tmp = Float64(x * y); elseif (y <= 1.8e+25) tmp = Float64(y - x); elseif (y <= 8e+181) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8e+119) tmp = x * y; elseif (y <= 1.8e+25) tmp = y - x; elseif (y <= 8e+181) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8e+119], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.8e+25], N[(y - x), $MachinePrecision], If[LessEqual[y, 8e+181], N[(x * y), $MachinePrecision], y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8 \cdot 10^{+119}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+25}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq 8 \cdot 10^{+181}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -7.99999999999999955e119 or 1.80000000000000008e25 < y < 7.9999999999999993e181Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 66.4%
if -7.99999999999999955e119 < y < 1.80000000000000008e25Initial program 100.0%
Taylor expanded in x around 0 93.5%
Taylor expanded in y around 0 93.5%
if 7.9999999999999993e181 < y Initial program 100.0%
Taylor expanded in x around 0 62.1%
Final simplification83.3%
(FPCore (x y) :precision binary64 (if (or (<= x -62000000000.0) (not (<= x 1.0))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -62000000000.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 <= (-62000000000.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 <= -62000000000.0) || !(x <= 1.0)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -62000000000.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 <= -62000000000.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 <= -62000000000.0) || ~((x <= 1.0))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -62000000000.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 -62000000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -6.2e10 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.8%
if -6.2e10 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.3%
Taylor expanded in y around 0 99.3%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (or (<= y -16.0) (not (<= y 0.0018))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -16.0) || !(y <= 0.0018)) {
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 <= (-16.0d0)) .or. (.not. (y <= 0.0018d0))) 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 <= -16.0) || !(y <= 0.0018)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -16.0) or not (y <= 0.0018): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -16.0) || !(y <= 0.0018)) 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 <= -16.0) || ~((y <= 0.0018))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -16.0], N[Not[LessEqual[y, 0.0018]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -16 \lor \neg \left(y \leq 0.0018\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -16 or 0.0018 < y Initial program 100.0%
Taylor expanded in y around inf 98.2%
if -16 < y < 0.0018Initial program 100.0%
Taylor expanded in x around 0 99.6%
Taylor expanded in y around 0 99.6%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (<= y -8.2e-22) y (if (<= y 1.3e-9) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -8.2e-22) {
tmp = y;
} else if (y <= 1.3e-9) {
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 <= (-8.2d-22)) then
tmp = y
else if (y <= 1.3d-9) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -8.2e-22) {
tmp = y;
} else if (y <= 1.3e-9) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -8.2e-22: tmp = y elif y <= 1.3e-9: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -8.2e-22) tmp = y; elseif (y <= 1.3e-9) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -8.2e-22) tmp = y; elseif (y <= 1.3e-9) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -8.2e-22], y, If[LessEqual[y, 1.3e-9], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -8.2 \cdot 10^{-22}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.3 \cdot 10^{-9}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -8.1999999999999999e-22 or 1.3000000000000001e-9 < y Initial program 100.0%
Taylor expanded in x around 0 49.5%
if -8.1999999999999999e-22 < y < 1.3000000000000001e-9Initial program 100.0%
Taylor expanded in y around 0 87.2%
neg-mul-187.2%
Simplified87.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 32.7%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))