
(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 (- (* (+ 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}
Initial program 100.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.9e+121)
(* x y)
(if (<= y -1e-21)
y
(if (<= y 4.4e-6)
(- x)
(if (<= y 1.8e+25) y (if (<= y 1e+182) (* x y) y))))))
double code(double x, double y) {
double tmp;
if (y <= -2.9e+121) {
tmp = x * y;
} else if (y <= -1e-21) {
tmp = y;
} else if (y <= 4.4e-6) {
tmp = -x;
} else if (y <= 1.8e+25) {
tmp = y;
} else if (y <= 1e+182) {
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 <= (-2.9d+121)) then
tmp = x * y
else if (y <= (-1d-21)) then
tmp = y
else if (y <= 4.4d-6) then
tmp = -x
else if (y <= 1.8d+25) then
tmp = y
else if (y <= 1d+182) 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 <= -2.9e+121) {
tmp = x * y;
} else if (y <= -1e-21) {
tmp = y;
} else if (y <= 4.4e-6) {
tmp = -x;
} else if (y <= 1.8e+25) {
tmp = y;
} else if (y <= 1e+182) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.9e+121: tmp = x * y elif y <= -1e-21: tmp = y elif y <= 4.4e-6: tmp = -x elif y <= 1.8e+25: tmp = y elif y <= 1e+182: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.9e+121) tmp = Float64(x * y); elseif (y <= -1e-21) tmp = y; elseif (y <= 4.4e-6) tmp = Float64(-x); elseif (y <= 1.8e+25) tmp = y; elseif (y <= 1e+182) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.9e+121) tmp = x * y; elseif (y <= -1e-21) tmp = y; elseif (y <= 4.4e-6) tmp = -x; elseif (y <= 1.8e+25) tmp = y; elseif (y <= 1e+182) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.9e+121], N[(x * y), $MachinePrecision], If[LessEqual[y, -1e-21], y, If[LessEqual[y, 4.4e-6], (-x), If[LessEqual[y, 1.8e+25], y, If[LessEqual[y, 1e+182], N[(x * y), $MachinePrecision], y]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.9 \cdot 10^{+121}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1 \cdot 10^{-21}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 4.4 \cdot 10^{-6}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+25}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 10^{+182}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.8999999999999999e121 or 1.80000000000000008e25 < y < 1.0000000000000001e182Initial program 100.0%
Taylor expanded in x around inf 66.4%
*-commutative66.4%
Simplified66.4%
Taylor expanded in y around inf 66.4%
if -2.8999999999999999e121 < y < -9.99999999999999908e-22 or 4.4000000000000002e-6 < y < 1.80000000000000008e25 or 1.0000000000000001e182 < y Initial program 100.0%
Taylor expanded in x around 0 67.2%
Taylor expanded in y around inf 64.1%
if -9.99999999999999908e-22 < y < 4.4000000000000002e-6Initial program 100.0%
Taylor expanded in y around 0 87.2%
neg-mul-187.2%
Simplified87.2%
(FPCore (x y) :precision binary64 (if (<= y -2.1e+123) (* x y) (if (<= y 3.5e+25) (- y x) (if (<= y 6.4e+180) (* x y) y))))
double code(double x, double y) {
double tmp;
if (y <= -2.1e+123) {
tmp = x * y;
} else if (y <= 3.5e+25) {
tmp = y - x;
} else if (y <= 6.4e+180) {
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 <= (-2.1d+123)) then
tmp = x * y
else if (y <= 3.5d+25) then
tmp = y - x
else if (y <= 6.4d+180) 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 <= -2.1e+123) {
tmp = x * y;
} else if (y <= 3.5e+25) {
tmp = y - x;
} else if (y <= 6.4e+180) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.1e+123: tmp = x * y elif y <= 3.5e+25: tmp = y - x elif y <= 6.4e+180: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.1e+123) tmp = Float64(x * y); elseif (y <= 3.5e+25) tmp = Float64(y - x); elseif (y <= 6.4e+180) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.1e+123) tmp = x * y; elseif (y <= 3.5e+25) tmp = y - x; elseif (y <= 6.4e+180) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.1e+123], N[(x * y), $MachinePrecision], If[LessEqual[y, 3.5e+25], N[(y - x), $MachinePrecision], If[LessEqual[y, 6.4e+180], N[(x * y), $MachinePrecision], y]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.1 \cdot 10^{+123}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.5 \cdot 10^{+25}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq 6.4 \cdot 10^{+180}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.09999999999999994e123 or 3.49999999999999999e25 < y < 6.39999999999999987e180Initial program 100.0%
Taylor expanded in x around inf 66.4%
*-commutative66.4%
Simplified66.4%
Taylor expanded in y around inf 66.4%
if -2.09999999999999994e123 < y < 3.49999999999999999e25Initial program 100.0%
Taylor expanded in x around 0 93.5%
if 6.39999999999999987e180 < y Initial program 100.0%
Taylor expanded in x around 0 62.1%
Taylor expanded in y around inf 62.1%
(FPCore (x y) :precision binary64 (if (or (<= x -62000000000.0) (not (<= x 1.0))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -62000000000.0) || !(x <= 1.0)) {
tmp = (x * 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 <= (-62000000000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (x * y) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -62000000000.0) || !(x <= 1.0)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -62000000000.0) or not (x <= 1.0): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -62000000000.0) || !(x <= 1.0)) tmp = Float64(Float64(x * y) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -62000000000.0) || ~((x <= 1.0))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -62000000000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -62000000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -6.2e10 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.8%
*-commutative99.8%
Simplified99.8%
if -6.2e10 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.3%
Final simplification99.6%
(FPCore (x y) :precision binary64 (if (<= y -1.25e-21) y (if (<= y 3.3e-9) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.25e-21) {
tmp = y;
} else if (y <= 3.3e-9) {
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.25d-21)) then
tmp = y
else if (y <= 3.3d-9) 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.25e-21) {
tmp = y;
} else if (y <= 3.3e-9) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.25e-21: tmp = y elif y <= 3.3e-9: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.25e-21) tmp = y; elseif (y <= 3.3e-9) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.25e-21) tmp = y; elseif (y <= 3.3e-9) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.25e-21], y, If[LessEqual[y, 3.3e-9], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.25 \cdot 10^{-21}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-9}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.24999999999999993e-21 or 3.30000000000000018e-9 < y Initial program 100.0%
Taylor expanded in x around 0 51.1%
Taylor expanded in y around inf 49.5%
if -1.24999999999999993e-21 < y < 3.30000000000000018e-9Initial program 100.0%
Taylor expanded in y around 0 87.2%
neg-mul-187.2%
Simplified87.2%
(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 75.5%
Taylor expanded in y around inf 32.7%
(FPCore (x y) :precision binary64 x)
double code(double x, double y) {
return x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = x
end function
public static double code(double x, double y) {
return x;
}
def code(x, y): return x
function code(x, y) return x end
function tmp = code(x, y) tmp = x; end
code[x_, y_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in y around 0 45.7%
neg-mul-145.7%
Simplified45.7%
neg-sub045.7%
sub-neg45.7%
add-sqr-sqrt25.1%
sqrt-unprod17.8%
sqr-neg17.8%
sqrt-unprod1.2%
add-sqr-sqrt2.4%
Applied egg-rr2.4%
+-lft-identity2.4%
Simplified2.4%
herbie shell --seed 2024137
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))