
(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 1.0) x)))
double code(double x, double y) {
return y + ((y - 1.0) * x);
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y + ((y - 1.0d0) * x)
end function
public static double code(double x, double y) {
return y + ((y - 1.0) * x);
}
def code(x, y): return y + ((y - 1.0) * x)
function code(x, y) return Float64(y + Float64(Float64(y - 1.0) * x)) end
function tmp = code(x, y) tmp = y + ((y - 1.0) * x); end
code[x_, y_] := N[(y + N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
y + \left(y - 1\right) \cdot x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -23.0)
y
(if (<= y -6.3e-31)
(- x)
(if (<= y -2.1e-63) y (if (<= y 1.4e-137) (- x) y)))))
double code(double x, double y) {
double tmp;
if (y <= -23.0) {
tmp = y;
} else if (y <= -6.3e-31) {
tmp = -x;
} else if (y <= -2.1e-63) {
tmp = y;
} else if (y <= 1.4e-137) {
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 <= (-23.0d0)) then
tmp = y
else if (y <= (-6.3d-31)) then
tmp = -x
else if (y <= (-2.1d-63)) then
tmp = y
else if (y <= 1.4d-137) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -23.0) {
tmp = y;
} else if (y <= -6.3e-31) {
tmp = -x;
} else if (y <= -2.1e-63) {
tmp = y;
} else if (y <= 1.4e-137) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -23.0: tmp = y elif y <= -6.3e-31: tmp = -x elif y <= -2.1e-63: tmp = y elif y <= 1.4e-137: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -23.0) tmp = y; elseif (y <= -6.3e-31) tmp = Float64(-x); elseif (y <= -2.1e-63) tmp = y; elseif (y <= 1.4e-137) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -23.0) tmp = y; elseif (y <= -6.3e-31) tmp = -x; elseif (y <= -2.1e-63) tmp = y; elseif (y <= 1.4e-137) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -23.0], y, If[LessEqual[y, -6.3e-31], (-x), If[LessEqual[y, -2.1e-63], y, If[LessEqual[y, 1.4e-137], (-x), y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -23:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -6.3 \cdot 10^{-31}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq -2.1 \cdot 10^{-63}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.4 \cdot 10^{-137}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -23 or -6.3000000000000002e-31 < y < -2.1e-63 or 1.3999999999999999e-137 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 56.2%
if -23 < y < -6.3000000000000002e-31 or -2.1e-63 < y < 1.3999999999999999e-137Initial program 100.0%
Taylor expanded in y around 0 85.8%
neg-mul-185.8%
Simplified85.8%
Final simplification66.4%
(FPCore (x y) :precision binary64 (if (<= x -1.66e-7) (* y x) (if (<= x 5.2e-27) y (if (<= x 1.55e+27) (- x) (* y x)))))
double code(double x, double y) {
double tmp;
if (x <= -1.66e-7) {
tmp = y * x;
} else if (x <= 5.2e-27) {
tmp = y;
} else if (x <= 1.55e+27) {
tmp = -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.66d-7)) then
tmp = y * x
else if (x <= 5.2d-27) then
tmp = y
else if (x <= 1.55d+27) then
tmp = -x
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -1.66e-7) {
tmp = y * x;
} else if (x <= 5.2e-27) {
tmp = y;
} else if (x <= 1.55e+27) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.66e-7: tmp = y * x elif x <= 5.2e-27: tmp = y elif x <= 1.55e+27: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.66e-7) tmp = Float64(y * x); elseif (x <= 5.2e-27) tmp = y; elseif (x <= 1.55e+27) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.66e-7) tmp = y * x; elseif (x <= 5.2e-27) tmp = y; elseif (x <= 1.55e+27) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.66e-7], N[(y * x), $MachinePrecision], If[LessEqual[x, 5.2e-27], y, If[LessEqual[x, 1.55e+27], (-x), N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.66 \cdot 10^{-7}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 5.2 \cdot 10^{-27}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 1.55 \cdot 10^{+27}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -1.66000000000000004e-7 or 1.54999999999999998e27 < x Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 58.0%
+-commutative58.0%
distribute-rgt1-in58.0%
Simplified58.0%
Taylor expanded in x around inf 57.5%
if -1.66000000000000004e-7 < x < 5.20000000000000034e-27Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 75.0%
if 5.20000000000000034e-27 < x < 1.54999999999999998e27Initial program 100.0%
Taylor expanded in y around 0 74.0%
neg-mul-174.0%
Simplified74.0%
Final simplification67.6%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 8e-26))) (* (- y 1.0) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 8e-26)) {
tmp = (y - 1.0) * 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 <= 8d-26))) then
tmp = (y - 1.0d0) * 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 <= 8e-26)) {
tmp = (y - 1.0) * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 8e-26): tmp = (y - 1.0) * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 8e-26)) tmp = Float64(Float64(y - 1.0) * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.0) || ~((x <= 8e-26))) tmp = (y - 1.0) * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 8e-26]], $MachinePrecision]], N[(N[(y - 1.0), $MachinePrecision] * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 8 \cdot 10^{-26}\right):\\
\;\;\;\;\left(y - 1\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 8.0000000000000003e-26 < x Initial program 100.0%
Taylor expanded in x around inf 99.0%
if -1 < x < 8.0000000000000003e-26Initial program 100.0%
Taylor expanded in x around 0 99.8%
Final simplification99.4%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 0.00072))) (+ y (* y x)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.00072)) {
tmp = y + (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 <= (-1.0d0)) .or. (.not. (y <= 0.00072d0))) then
tmp = y + (y * x)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 0.00072)) {
tmp = y + (y * x);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 0.00072): tmp = y + (y * x) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 0.00072)) tmp = Float64(y + Float64(y * x)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 0.00072))) tmp = y + (y * x); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 0.00072]], $MachinePrecision]], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 0.00072\right):\\
\;\;\;\;y + y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1 or 7.20000000000000045e-4 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.3%
+-commutative99.3%
distribute-rgt1-in99.3%
Simplified99.3%
if -1 < y < 7.20000000000000045e-4Initial program 100.0%
Taylor expanded in x around 0 100.0%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (<= x -5.7e+15) (* y x) (if (<= x 2.7e+32) (- y x) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -5.7e+15) {
tmp = y * x;
} else if (x <= 2.7e+32) {
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 (x <= (-5.7d+15)) then
tmp = y * x
else if (x <= 2.7d+32) 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 (x <= -5.7e+15) {
tmp = y * x;
} else if (x <= 2.7e+32) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.7e+15: tmp = y * x elif x <= 2.7e+32: tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -5.7e+15) tmp = Float64(y * x); elseif (x <= 2.7e+32) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.7e+15) tmp = y * x; elseif (x <= 2.7e+32) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.7e+15], N[(y * x), $MachinePrecision], If[LessEqual[x, 2.7e+32], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.7 \cdot 10^{+15}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 2.7 \cdot 10^{+32}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.7e15 or 2.70000000000000013e32 < x Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 59.4%
+-commutative59.4%
distribute-rgt1-in59.4%
Simplified59.4%
Taylor expanded in x around inf 59.4%
if -5.7e15 < x < 2.70000000000000013e32Initial program 100.0%
Taylor expanded in x around 0 97.4%
Final simplification81.9%
(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 100.0%
Taylor expanded in x around 0 41.5%
Final simplification41.5%
herbie shell --seed 2023214
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))