
(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 9 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 (* y x)) x))
double code(double x, double y) {
return (y + (y * x)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (y * x)) - x
end function
public static double code(double x, double y) {
return (y + (y * x)) - x;
}
def code(x, y): return (y + (y * x)) - x
function code(x, y) return Float64(Float64(y + Float64(y * x)) - x) end
function tmp = code(x, y) tmp = (y + (y * x)) - x; end
code[x_, y_] := N[(N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + y \cdot x\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -6e+203) (* y x) (if (or (<= x -1.3e-65) (not (<= x 3.2e-25))) (- x) y)))
double code(double x, double y) {
double tmp;
if (x <= -6e+203) {
tmp = y * x;
} else if ((x <= -1.3e-65) || !(x <= 3.2e-25)) {
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 (x <= (-6d+203)) then
tmp = y * x
else if ((x <= (-1.3d-65)) .or. (.not. (x <= 3.2d-25))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -6e+203) {
tmp = y * x;
} else if ((x <= -1.3e-65) || !(x <= 3.2e-25)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6e+203: tmp = y * x elif (x <= -1.3e-65) or not (x <= 3.2e-25): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (x <= -6e+203) tmp = Float64(y * x); elseif ((x <= -1.3e-65) || !(x <= 3.2e-25)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6e+203) tmp = y * x; elseif ((x <= -1.3e-65) || ~((x <= 3.2e-25))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6e+203], N[(y * x), $MachinePrecision], If[Or[LessEqual[x, -1.3e-65], N[Not[LessEqual[x, 3.2e-25]], $MachinePrecision]], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6 \cdot 10^{+203}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.3 \cdot 10^{-65} \lor \neg \left(x \leq 3.2 \cdot 10^{-25}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -5.9999999999999999e203Initial program 100.0%
Taylor expanded in y around inf 61.5%
Taylor expanded in x around inf 61.5%
if -5.9999999999999999e203 < x < -1.30000000000000005e-65 or 3.2000000000000001e-25 < x Initial program 100.0%
Taylor expanded in y around 0 60.6%
neg-mul-160.6%
Simplified60.6%
if -1.30000000000000005e-65 < x < 3.2000000000000001e-25Initial program 100.0%
Taylor expanded in x around 0 79.7%
Final simplification69.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 1.0)) {
tmp = (y * x) - 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 <= (-1.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (y * x) - x
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 = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 1.0): tmp = (y * x) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 1.0)) tmp = Float64(Float64(y * x) - x); 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 = (y * x) - x; 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[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x - x\\
\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.6%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
Taylor expanded in y around 0 99.5%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.42e+29) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.42e+29) || !(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.42d+29)) .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.42e+29) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.42e+29) 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.42e+29) || !(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.42e+29) || ~((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.42e+29], 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.42 \cdot 10^{+29} \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.42e29 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 99.3%
if -1.42e29 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.1%
Taylor expanded in y around 0 98.1%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (<= y -1.42e+29) (* y (+ x 1.0)) (if (<= y 1.0) (- y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.42e+29) {
tmp = y * (x + 1.0);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y + (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.42d+29)) then
tmp = y * (x + 1.0d0)
else if (y <= 1.0d0) then
tmp = y - x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.42e+29) {
tmp = y * (x + 1.0);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.42e+29: tmp = y * (x + 1.0) elif y <= 1.0: tmp = y - x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.42e+29) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 1.0) tmp = Float64(y - x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.42e+29) tmp = y * (x + 1.0); elseif (y <= 1.0) tmp = y - x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.42e+29], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(y - x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.42 \cdot 10^{+29}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -1.42e29Initial program 100.0%
Taylor expanded in y around inf 100.0%
if -1.42e29 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.1%
Taylor expanded in y around 0 98.1%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.6%
distribute-rgt-in98.7%
*-un-lft-identity98.7%
*-commutative98.7%
+-commutative98.7%
Applied egg-rr98.7%
Final simplification98.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.3e-63) (not (<= x 2.85e-25))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.3e-63) || !(x <= 2.85e-25)) {
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 ((x <= (-1.3d-63)) .or. (.not. (x <= 2.85d-25))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.3e-63) || !(x <= 2.85e-25)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.3e-63) or not (x <= 2.85e-25): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.3e-63) || !(x <= 2.85e-25)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.3e-63) || ~((x <= 2.85e-25))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.3e-63], N[Not[LessEqual[x, 2.85e-25]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-63} \lor \neg \left(x \leq 2.85 \cdot 10^{-25}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.3000000000000001e-63 or 2.8500000000000002e-25 < x Initial program 100.0%
Taylor expanded in y around 0 56.9%
neg-mul-156.9%
Simplified56.9%
if -1.3000000000000001e-63 < x < 2.8500000000000002e-25Initial program 100.0%
Taylor expanded in x around 0 79.7%
Final simplification67.5%
(FPCore (x y) :precision binary64 (if (<= y 2.6e+102) (- y x) (* y x)))
double code(double x, double y) {
double tmp;
if (y <= 2.6e+102) {
tmp = 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 (y <= 2.6d+102) then
tmp = y - x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= 2.6e+102) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2.6e+102: tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= 2.6e+102) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2.6e+102) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2.6e+102], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2.6 \cdot 10^{+102}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < 2.60000000000000006e102Initial program 100.0%
Taylor expanded in x around 0 85.2%
Taylor expanded in y around 0 85.2%
if 2.60000000000000006e102 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 56.3%
(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 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 39.8%
herbie shell --seed 2024156
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))