
(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 (- (fma x y y) x))
double code(double x, double y) {
return fma(x, y, y) - x;
}
function code(x, y) return Float64(fma(x, y, y) - x) end
code[x_, y_] := N[(N[(x * y + y), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, y\right) - x
\end{array}
Initial program 100.0%
*-commutative100.0%
distribute-rgt-in100.0%
fma-def100.0%
*-lft-identity100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -4.9e+272)
y
(if (<= y -0.027)
(* x y)
(if (<= y 1.0) (- x) (if (<= y 8.8e+117) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -4.9e+272) {
tmp = y;
} else if (y <= -0.027) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else if (y <= 8.8e+117) {
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 <= (-4.9d+272)) then
tmp = y
else if (y <= (-0.027d0)) then
tmp = x * y
else if (y <= 1.0d0) then
tmp = -x
else if (y <= 8.8d+117) 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 <= -4.9e+272) {
tmp = y;
} else if (y <= -0.027) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else if (y <= 8.8e+117) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.9e+272: tmp = y elif y <= -0.027: tmp = x * y elif y <= 1.0: tmp = -x elif y <= 8.8e+117: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.9e+272) tmp = y; elseif (y <= -0.027) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(-x); elseif (y <= 8.8e+117) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.9e+272) tmp = y; elseif (y <= -0.027) tmp = x * y; elseif (y <= 1.0) tmp = -x; elseif (y <= 8.8e+117) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.9e+272], y, If[LessEqual[y, -0.027], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], (-x), If[LessEqual[y, 8.8e+117], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.9 \cdot 10^{+272}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -0.027:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 8.8 \cdot 10^{+117}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.9000000000000002e272 or 8.80000000000000056e117 < y Initial program 100.0%
Taylor expanded in x around 0 64.4%
if -4.9000000000000002e272 < y < -0.0269999999999999997 or 1 < y < 8.80000000000000056e117Initial program 99.9%
Taylor expanded in y around inf 96.7%
Taylor expanded in x around 0 96.7%
Taylor expanded in x around inf 60.5%
if -0.0269999999999999997 < y < 1Initial program 100.0%
Taylor expanded in y around 0 77.1%
neg-mul-177.1%
Simplified77.1%
Final simplification69.2%
(FPCore (x y) :precision binary64 (if (or (<= y -7.2e-45) (not (<= y 3.4e-11))) (* y (+ x 1.0)) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -7.2e-45) || !(y <= 3.4e-11)) {
tmp = y * (x + 1.0);
} 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 <= (-7.2d-45)) .or. (.not. (y <= 3.4d-11))) then
tmp = y * (x + 1.0d0)
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.2e-45) || !(y <= 3.4e-11)) {
tmp = y * (x + 1.0);
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.2e-45) or not (y <= 3.4e-11): tmp = y * (x + 1.0) else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.2e-45) || !(y <= 3.4e-11)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.2e-45) || ~((y <= 3.4e-11))) tmp = y * (x + 1.0); else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.2e-45], N[Not[LessEqual[y, 3.4e-11]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-45} \lor \neg \left(y \leq 3.4 \cdot 10^{-11}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -7.20000000000000001e-45 or 3.3999999999999999e-11 < y Initial program 99.9%
Taylor expanded in y around inf 96.6%
if -7.20000000000000001e-45 < y < 3.3999999999999999e-11Initial program 100.0%
Taylor expanded in y around 0 80.1%
neg-mul-180.1%
Simplified80.1%
Final simplification89.1%
(FPCore (x y) :precision binary64 (if (or (<= x -4.1e+15) (not (<= x 135.0))) (* x (+ y -1.0)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -4.1e+15) || !(x <= 135.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y * (x + 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 <= (-4.1d+15)) .or. (.not. (x <= 135.0d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4.1e+15) || !(x <= 135.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.1e+15) or not (x <= 135.0): tmp = x * (y + -1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.1e+15) || !(x <= 135.0)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.1e+15) || ~((x <= 135.0))) tmp = x * (y + -1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.1e+15], N[Not[LessEqual[x, 135.0]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+15} \lor \neg \left(x \leq 135\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -4.1e15 or 135 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
if -4.1e15 < x < 135Initial program 100.0%
Taylor expanded in y around inf 79.0%
Final simplification90.5%
(FPCore (x y) :precision binary64 (if (or (<= x -4.1e+15) (not (<= x 0.0115))) (* x (+ y -1.0)) (+ y (* x y))))
double code(double x, double y) {
double tmp;
if ((x <= -4.1e+15) || !(x <= 0.0115)) {
tmp = x * (y + -1.0);
} else {
tmp = y + (x * y);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((x <= (-4.1d+15)) .or. (.not. (x <= 0.0115d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = y + (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -4.1e+15) || !(x <= 0.0115)) {
tmp = x * (y + -1.0);
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -4.1e+15) or not (x <= 0.0115): tmp = x * (y + -1.0) else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if ((x <= -4.1e+15) || !(x <= 0.0115)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -4.1e+15) || ~((x <= 0.0115))) tmp = x * (y + -1.0); else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -4.1e+15], N[Not[LessEqual[x, 0.0115]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.1 \cdot 10^{+15} \lor \neg \left(x \leq 0.0115\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if x < -4.1e15 or 0.0115 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
if -4.1e15 < x < 0.0115Initial program 100.0%
Taylor expanded in y around inf 79.0%
Taylor expanded in x around 0 79.0%
Final simplification90.5%
(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 (* x y)) x))
double code(double x, double y) {
return (y + (x * y)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (x * y)) - x
end function
public static double code(double x, double y) {
return (y + (x * y)) - x;
}
def code(x, y): return (y + (x * y)) - x
function code(x, y) return Float64(Float64(y + Float64(x * y)) - x) end
function tmp = code(x, y) tmp = (y + (x * y)) - x; end
code[x_, y_] := N[(N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x \cdot y\right) - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= x -9.5e-34) (- x) (if (<= x 0.0042) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -9.5e-34) {
tmp = -x;
} else if (x <= 0.0042) {
tmp = 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 (x <= (-9.5d-34)) then
tmp = -x
else if (x <= 0.0042d0) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -9.5e-34) {
tmp = -x;
} else if (x <= 0.0042) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -9.5e-34: tmp = -x elif x <= 0.0042: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -9.5e-34) tmp = Float64(-x); elseif (x <= 0.0042) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -9.5e-34) tmp = -x; elseif (x <= 0.0042) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -9.5e-34], (-x), If[LessEqual[x, 0.0042], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -9.5 \cdot 10^{-34}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 0.0042:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -9.49999999999999985e-34 or 0.00419999999999999974 < x Initial program 99.9%
Taylor expanded in y around 0 51.5%
neg-mul-151.5%
Simplified51.5%
if -9.49999999999999985e-34 < x < 0.00419999999999999974Initial program 100.0%
Taylor expanded in x around 0 80.7%
Final simplification63.5%
(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 36.4%
Final simplification36.4%
herbie shell --seed 2023208
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))