
(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 8 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 (+ 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 (or (<= x -290.0) (not (<= x 5.8e-21))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -290.0) || !(x <= 5.8e-21)) {
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 <= (-290.0d0)) .or. (.not. (x <= 5.8d-21))) 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 <= -290.0) || !(x <= 5.8e-21)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -290.0) or not (x <= 5.8e-21): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -290.0) || !(x <= 5.8e-21)) 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 <= -290.0) || ~((x <= 5.8e-21))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -290.0], N[Not[LessEqual[x, 5.8e-21]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -290 \lor \neg \left(x \leq 5.8 \cdot 10^{-21}\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -290 or 5.8e-21 < x Initial program 100.0%
Taylor expanded in x around inf 99.5%
if -290 < x < 5.8e-21Initial program 100.0%
Taylor expanded in x around 0 99.1%
Taylor expanded in y around 0 99.1%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= y -880000000000.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -880000000000.0) || !(y <= 1.0)) {
tmp = y * (x + 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 ((y <= (-880000000000.0d0)) .or. (.not. (y <= 1.0d0))) then
tmp = y * (x + 1.0d0)
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -880000000000.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -880000000000.0) or not (y <= 1.0): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -880000000000.0) || !(y <= 1.0)) tmp = Float64(y * Float64(x + 1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -880000000000.0) || ~((y <= 1.0))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -880000000000.0], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -880000000000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -8.8e11 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 97.1%
if -8.8e11 < y < 1Initial program 100.0%
Taylor expanded in x around 0 98.9%
Taylor expanded in y around 0 98.9%
Final simplification98.1%
(FPCore (x y) :precision binary64 (if (<= y -7.2e-72) y (if (<= y 3.6e-26) (- x) (+ x y))))
double code(double x, double y) {
double tmp;
if (y <= -7.2e-72) {
tmp = y;
} else if (y <= 3.6e-26) {
tmp = -x;
} else {
tmp = x + y;
}
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-72)) then
tmp = y
else if (y <= 3.6d-26) then
tmp = -x
else
tmp = x + y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -7.2e-72) {
tmp = y;
} else if (y <= 3.6e-26) {
tmp = -x;
} else {
tmp = x + y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.2e-72: tmp = y elif y <= 3.6e-26: tmp = -x else: tmp = x + y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.2e-72) tmp = y; elseif (y <= 3.6e-26) tmp = Float64(-x); else tmp = Float64(x + y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.2e-72) tmp = y; elseif (y <= 3.6e-26) tmp = -x; else tmp = x + y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.2e-72], y, If[LessEqual[y, 3.6e-26], (-x), N[(x + y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.2 \cdot 10^{-72}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.6 \cdot 10^{-26}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x + y\\
\end{array}
\end{array}
if y < -7.2e-72Initial program 100.0%
Taylor expanded in x around 0 64.0%
if -7.2e-72 < y < 3.6000000000000001e-26Initial program 100.0%
Taylor expanded in y around 0 81.8%
neg-mul-181.8%
Simplified81.8%
if 3.6000000000000001e-26 < y Initial program 100.0%
Taylor expanded in x around 0 55.1%
*-un-lft-identity55.1%
sub-neg55.1%
add-sqr-sqrt26.2%
sqrt-unprod59.5%
sqr-neg59.5%
sqrt-unprod28.9%
add-sqr-sqrt55.3%
Applied egg-rr55.3%
Final simplification69.3%
(FPCore (x y) :precision binary64 (if (<= y -1.45e-72) y (if (<= y 1.15e-24) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.45e-72) {
tmp = y;
} else if (y <= 1.15e-24) {
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.45d-72)) then
tmp = y
else if (y <= 1.15d-24) 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.45e-72) {
tmp = y;
} else if (y <= 1.15e-24) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.45e-72: tmp = y elif y <= 1.15e-24: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.45e-72) tmp = y; elseif (y <= 1.15e-24) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.45e-72) tmp = y; elseif (y <= 1.15e-24) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.45e-72], y, If[LessEqual[y, 1.15e-24], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.45 \cdot 10^{-72}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.15 \cdot 10^{-24}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.44999999999999999e-72 or 1.1500000000000001e-24 < y Initial program 100.0%
Taylor expanded in x around 0 59.0%
if -1.44999999999999999e-72 < y < 1.1500000000000001e-24Initial program 100.0%
Taylor expanded in y around 0 81.8%
neg-mul-181.8%
Simplified81.8%
(FPCore (x y) :precision binary64 (- y x))
double code(double x, double y) {
return y - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - x
end function
public static double code(double x, double y) {
return y - x;
}
def code(x, y): return y - x
function code(x, y) return Float64(y - x) end
function tmp = code(x, y) tmp = y - x; end
code[x_, y_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 79.9%
Taylor expanded in y around 0 79.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 42.4%
(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 x around 0 79.9%
*-un-lft-identity79.9%
sub-neg79.9%
add-sqr-sqrt41.2%
sqrt-unprod59.3%
sqr-neg59.3%
sqrt-unprod22.0%
add-sqr-sqrt42.1%
Applied egg-rr42.1%
Taylor expanded in y around 0 2.7%
herbie shell --seed 2024160
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))