
(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 (* 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%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= x -5e+218)
(- x)
(if (<= x -6.6e+172)
(* y x)
(if (<= x -3.7e-17)
(- x)
(if (<= x 4.8e-22)
y
(if (<= x 1.1e+108) (- x) (if (<= x 4.2e+245) (* y x) (- x))))))))
double code(double x, double y) {
double tmp;
if (x <= -5e+218) {
tmp = -x;
} else if (x <= -6.6e+172) {
tmp = y * x;
} else if (x <= -3.7e-17) {
tmp = -x;
} else if (x <= 4.8e-22) {
tmp = y;
} else if (x <= 1.1e+108) {
tmp = -x;
} else if (x <= 4.2e+245) {
tmp = y * x;
} 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 <= (-5d+218)) then
tmp = -x
else if (x <= (-6.6d+172)) then
tmp = y * x
else if (x <= (-3.7d-17)) then
tmp = -x
else if (x <= 4.8d-22) then
tmp = y
else if (x <= 1.1d+108) then
tmp = -x
else if (x <= 4.2d+245) then
tmp = y * x
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5e+218) {
tmp = -x;
} else if (x <= -6.6e+172) {
tmp = y * x;
} else if (x <= -3.7e-17) {
tmp = -x;
} else if (x <= 4.8e-22) {
tmp = y;
} else if (x <= 1.1e+108) {
tmp = -x;
} else if (x <= 4.2e+245) {
tmp = y * x;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5e+218: tmp = -x elif x <= -6.6e+172: tmp = y * x elif x <= -3.7e-17: tmp = -x elif x <= 4.8e-22: tmp = y elif x <= 1.1e+108: tmp = -x elif x <= 4.2e+245: tmp = y * x else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -5e+218) tmp = Float64(-x); elseif (x <= -6.6e+172) tmp = Float64(y * x); elseif (x <= -3.7e-17) tmp = Float64(-x); elseif (x <= 4.8e-22) tmp = y; elseif (x <= 1.1e+108) tmp = Float64(-x); elseif (x <= 4.2e+245) tmp = Float64(y * x); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5e+218) tmp = -x; elseif (x <= -6.6e+172) tmp = y * x; elseif (x <= -3.7e-17) tmp = -x; elseif (x <= 4.8e-22) tmp = y; elseif (x <= 1.1e+108) tmp = -x; elseif (x <= 4.2e+245) tmp = y * x; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5e+218], (-x), If[LessEqual[x, -6.6e+172], N[(y * x), $MachinePrecision], If[LessEqual[x, -3.7e-17], (-x), If[LessEqual[x, 4.8e-22], y, If[LessEqual[x, 1.1e+108], (-x), If[LessEqual[x, 4.2e+245], N[(y * x), $MachinePrecision], (-x)]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5 \cdot 10^{+218}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -6.6 \cdot 10^{+172}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -3.7 \cdot 10^{-17}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 4.8 \cdot 10^{-22}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.1 \cdot 10^{+108}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+245}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -4.99999999999999983e218 or -6.59999999999999965e172 < x < -3.6999999999999997e-17 or 4.80000000000000005e-22 < x < 1.1000000000000001e108 or 4.19999999999999992e245 < x Initial program 100.0%
Taylor expanded in y around 0 60.2%
neg-mul-160.2%
Simplified60.2%
if -4.99999999999999983e218 < x < -6.59999999999999965e172 or 1.1000000000000001e108 < x < 4.19999999999999992e245Initial program 100.0%
Taylor expanded in y around inf 66.1%
Taylor expanded in x around 0 66.1%
Taylor expanded in x around inf 66.1%
if -3.6999999999999997e-17 < x < 4.80000000000000005e-22Initial program 100.0%
Taylor expanded in x around 0 84.8%
Final simplification72.9%
(FPCore (x y) :precision binary64 (if (or (<= y -4.5e-14) (not (<= y 0.000114))) (* y (+ x 1.0)) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -4.5e-14) || !(y <= 0.000114)) {
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 <= (-4.5d-14)) .or. (.not. (y <= 0.000114d0))) 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 <= -4.5e-14) || !(y <= 0.000114)) {
tmp = y * (x + 1.0);
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -4.5e-14) or not (y <= 0.000114): tmp = y * (x + 1.0) else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -4.5e-14) || !(y <= 0.000114)) 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 <= -4.5e-14) || ~((y <= 0.000114))) tmp = y * (x + 1.0); else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -4.5e-14], N[Not[LessEqual[y, 0.000114]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-14} \lor \neg \left(y \leq 0.000114\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -4.4999999999999998e-14 or 1.1400000000000001e-4 < y Initial program 100.0%
Taylor expanded in y around inf 99.4%
if -4.4999999999999998e-14 < y < 1.1400000000000001e-4Initial program 100.0%
Taylor expanded in y around 0 74.6%
neg-mul-174.6%
Simplified74.6%
Final simplification87.8%
(FPCore (x y) :precision binary64 (if (or (<= x -11.5) (not (<= x 1.55e-28))) (* x (- y 1.0)) (* y (+ x 1.0))))
double code(double x, double y) {
double tmp;
if ((x <= -11.5) || !(x <= 1.55e-28)) {
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 <= (-11.5d0)) .or. (.not. (x <= 1.55d-28))) 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 <= -11.5) || !(x <= 1.55e-28)) {
tmp = x * (y - 1.0);
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -11.5) or not (x <= 1.55e-28): tmp = x * (y - 1.0) else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if ((x <= -11.5) || !(x <= 1.55e-28)) 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 <= -11.5) || ~((x <= 1.55e-28))) tmp = x * (y - 1.0); else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -11.5], N[Not[LessEqual[x, 1.55e-28]], $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 -11.5 \lor \neg \left(x \leq 1.55 \cdot 10^{-28}\right):\\
\;\;\;\;x \cdot \left(y - 1\right)\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if x < -11.5 or 1.54999999999999996e-28 < x Initial program 100.0%
Taylor expanded in x around inf 96.9%
if -11.5 < x < 1.54999999999999996e-28Initial program 100.0%
Taylor expanded in y around inf 84.8%
Final simplification91.1%
(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 (<= x -2.5e-15) (- x) (if (<= x 2.05e-26) y (- x))))
double code(double x, double y) {
double tmp;
if (x <= -2.5e-15) {
tmp = -x;
} else if (x <= 2.05e-26) {
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 <= (-2.5d-15)) then
tmp = -x
else if (x <= 2.05d-26) then
tmp = y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.5e-15) {
tmp = -x;
} else if (x <= 2.05e-26) {
tmp = y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.5e-15: tmp = -x elif x <= 2.05e-26: tmp = y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= -2.5e-15) tmp = Float64(-x); elseif (x <= 2.05e-26) tmp = y; else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.5e-15) tmp = -x; elseif (x <= 2.05e-26) tmp = y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.5e-15], (-x), If[LessEqual[x, 2.05e-26], y, (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.5 \cdot 10^{-15}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 2.05 \cdot 10^{-26}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < -2.5e-15 or 2.0499999999999999e-26 < x Initial program 100.0%
Taylor expanded in y around 0 53.6%
neg-mul-153.6%
Simplified53.6%
if -2.5e-15 < x < 2.0499999999999999e-26Initial program 100.0%
Taylor expanded in x around 0 84.8%
Final simplification68.6%
(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 43.2%
Final simplification43.2%
herbie shell --seed 2023240
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))