
(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 (fma x (+ y -1.0) y))
double code(double x, double y) {
return fma(x, (y + -1.0), y);
}
function code(x, y) return fma(x, Float64(y + -1.0), y) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, y\right)
\end{array}
Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.7e+215)
y
(if (<= y -7.6e+135)
(* x y)
(if (<= y -1.8e+83)
y
(if (<= y -400000.0) (* x y) (if (<= y 5.3e-14) (- x) y))))))
double code(double x, double y) {
double tmp;
if (y <= -2.7e+215) {
tmp = y;
} else if (y <= -7.6e+135) {
tmp = x * y;
} else if (y <= -1.8e+83) {
tmp = y;
} else if (y <= -400000.0) {
tmp = x * y;
} else if (y <= 5.3e-14) {
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+215)) then
tmp = y
else if (y <= (-7.6d+135)) then
tmp = x * y
else if (y <= (-1.8d+83)) then
tmp = y
else if (y <= (-400000.0d0)) then
tmp = x * y
else if (y <= 5.3d-14) 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+215) {
tmp = y;
} else if (y <= -7.6e+135) {
tmp = x * y;
} else if (y <= -1.8e+83) {
tmp = y;
} else if (y <= -400000.0) {
tmp = x * y;
} else if (y <= 5.3e-14) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.7e+215: tmp = y elif y <= -7.6e+135: tmp = x * y elif y <= -1.8e+83: tmp = y elif y <= -400000.0: tmp = x * y elif y <= 5.3e-14: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.7e+215) tmp = y; elseif (y <= -7.6e+135) tmp = Float64(x * y); elseif (y <= -1.8e+83) tmp = y; elseif (y <= -400000.0) tmp = Float64(x * y); elseif (y <= 5.3e-14) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.7e+215) tmp = y; elseif (y <= -7.6e+135) tmp = x * y; elseif (y <= -1.8e+83) tmp = y; elseif (y <= -400000.0) tmp = x * y; elseif (y <= 5.3e-14) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.7e+215], y, If[LessEqual[y, -7.6e+135], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.8e+83], y, If[LessEqual[y, -400000.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 5.3e-14], (-x), y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.7 \cdot 10^{+215}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -7.6 \cdot 10^{+135}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.8 \cdot 10^{+83}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -400000:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 5.3 \cdot 10^{-14}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.7e215 or -7.6000000000000003e135 < y < -1.7999999999999999e83 or 5.3000000000000001e-14 < y Initial program 100.0%
Taylor expanded in x around 0 63.1%
if -2.7e215 < y < -7.6000000000000003e135 or -1.7999999999999999e83 < y < -4e5Initial program 99.9%
Taylor expanded in y around inf 95.6%
Taylor expanded in x around inf 77.8%
if -4e5 < y < 5.3000000000000001e-14Initial program 100.0%
Taylor expanded in y around 0 79.6%
neg-mul-179.6%
Simplified79.6%
Final simplification73.0%
(FPCore (x y) :precision binary64 (if (or (<= x -2300.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -2300.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 <= (-2300.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 <= -2300.0) || !(x <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2300.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 <= -2300.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 <= -2300.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, -2300.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 -2300 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -2300 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.5%
if -2300 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.2%
Taylor expanded in y around 0 99.2%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (<= y -1.65e+215) y (if (<= y -6.4e+133) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.65e+215) {
tmp = y;
} else if (y <= -6.4e+133) {
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 (y <= (-1.65d+215)) then
tmp = y
else if (y <= (-6.4d+133)) 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 (y <= -1.65e+215) {
tmp = y;
} else if (y <= -6.4e+133) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.65e+215: tmp = y elif y <= -6.4e+133: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.65e+215) tmp = y; elseif (y <= -6.4e+133) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.65e+215) tmp = y; elseif (y <= -6.4e+133) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.65e+215], y, If[LessEqual[y, -6.4e+133], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+215}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -6.4 \cdot 10^{+133}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.6499999999999999e215Initial program 99.9%
Taylor expanded in x around 0 70.5%
if -1.6499999999999999e215 < y < -6.39999999999999994e133Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 80.6%
if -6.39999999999999994e133 < y Initial program 100.0%
Taylor expanded in x around 0 81.3%
Taylor expanded in y around 0 81.3%
Final simplification80.5%
(FPCore (x y) :precision binary64 (if (<= y -1.6e-20) y (if (<= y 1.55e-13) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.6e-20) {
tmp = y;
} else if (y <= 1.55e-13) {
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 <= (-1.6d-20)) then
tmp = y
else if (y <= 1.55d-13) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.6e-20) {
tmp = y;
} else if (y <= 1.55e-13) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e-20: tmp = y elif y <= 1.55e-13: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.6e-20) tmp = y; elseif (y <= 1.55e-13) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.6e-20) tmp = y; elseif (y <= 1.55e-13) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e-20], y, If[LessEqual[y, 1.55e-13], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-20}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.55 \cdot 10^{-13}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.59999999999999985e-20 or 1.55e-13 < y Initial program 100.0%
Taylor expanded in x around 0 54.6%
if -1.59999999999999985e-20 < y < 1.55e-13Initial program 100.0%
Taylor expanded in y around 0 81.8%
neg-mul-181.8%
Simplified81.8%
(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 37.5%
herbie shell --seed 2024130
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))