
(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 (- (* (+ 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%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
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 <= 1.0d0))) 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 <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) 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 <= 1.0))) 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, 1.0]], $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 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.9%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (<= x -1.0) (- (* x y) x) (if (<= x 1.0) (- y x) (* x (+ y -1.0)))))
double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (x * y) - x;
} else if (x <= 1.0) {
tmp = y - x;
} 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 (x <= (-1.0d0)) then
tmp = (x * y) - x
else if (x <= 1.0d0) then
tmp = y - x
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.0) {
tmp = (x * y) - x;
} else if (x <= 1.0) {
tmp = y - x;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.0: tmp = (x * y) - x elif x <= 1.0: tmp = y - x else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if (x <= -1.0) tmp = Float64(Float64(x * y) - x); elseif (x <= 1.0) tmp = Float64(y - x); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.0) tmp = (x * y) - x; elseif (x <= 1.0) tmp = y - x; else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.0], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], If[LessEqual[x, 1.0], N[(y - x), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1:\\
\;\;\;\;x \cdot y - x\\
\mathbf{elif}\;x \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if x < -1Initial program 100.0%
Taylor expanded in x around inf 98.6%
*-commutative98.6%
Simplified98.6%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
if 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.3%
Final simplification99.2%
(FPCore (x y) :precision binary64 (if (or (<= y -3800.0) (not (<= y 3.5e+18))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -3800.0) || !(y <= 3.5e+18)) {
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 ((y <= (-3800.0d0)) .or. (.not. (y <= 3.5d+18))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3800.0) || !(y <= 3.5e+18)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3800.0) or not (y <= 3.5e+18): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3800.0) || !(y <= 3.5e+18)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3800.0) || ~((y <= 3.5e+18))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3800.0], N[Not[LessEqual[y, 3.5e+18]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3800 \lor \neg \left(y \leq 3.5 \cdot 10^{+18}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -3800 or 3.5e18 < y Initial program 100.0%
Taylor expanded in x around inf 49.6%
Taylor expanded in y around inf 49.3%
if -3800 < y < 3.5e18Initial program 100.0%
Taylor expanded in y around 0 71.0%
neg-mul-171.0%
Simplified71.0%
Final simplification60.7%
(FPCore (x y) :precision binary64 (if (<= x -1.32e+144) (- x) (if (<= x -5.9e+21) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (x <= -1.32e+144) {
tmp = -x;
} else if (x <= -5.9e+21) {
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 <= (-1.32d+144)) then
tmp = -x
else if (x <= (-5.9d+21)) 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 <= -1.32e+144) {
tmp = -x;
} else if (x <= -5.9e+21) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.32e+144: tmp = -x elif x <= -5.9e+21: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.32e+144) tmp = Float64(-x); elseif (x <= -5.9e+21) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.32e+144) tmp = -x; elseif (x <= -5.9e+21) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.32e+144], (-x), If[LessEqual[x, -5.9e+21], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.32 \cdot 10^{+144}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -5.9 \cdot 10^{+21}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.32e144Initial program 100.0%
Taylor expanded in y around 0 57.3%
neg-mul-157.3%
Simplified57.3%
if -1.32e144 < x < -5.9e21Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 76.4%
if -5.9e21 < x Initial program 100.0%
Taylor expanded in x around 0 87.4%
(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 39.0%
neg-mul-139.0%
Simplified39.0%
(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 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 39.0%
neg-mul-139.0%
Simplified39.0%
neg-sub039.0%
sub-neg39.0%
add-sqr-sqrt20.2%
sqrt-unprod18.1%
sqr-neg18.1%
sqrt-unprod1.1%
add-sqr-sqrt2.5%
Applied egg-rr2.5%
+-lft-identity2.5%
Simplified2.5%
herbie shell --seed 2024118
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))