
(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 (* 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%
*-commutative100.0%
distribute-lft-in100.0%
*-commutative100.0%
*-un-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (<= y -9e-22) y (if (<= y 3e-143) (- x) (if (<= y 3.8e+49) y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -9e-22) {
tmp = y;
} else if (y <= 3e-143) {
tmp = -x;
} else if (y <= 3.8e+49) {
tmp = y;
} 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 <= (-9d-22)) then
tmp = y
else if (y <= 3d-143) then
tmp = -x
else if (y <= 3.8d+49) then
tmp = y
else
tmp = y * x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -9e-22) {
tmp = y;
} else if (y <= 3e-143) {
tmp = -x;
} else if (y <= 3.8e+49) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -9e-22: tmp = y elif y <= 3e-143: tmp = -x elif y <= 3.8e+49: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -9e-22) tmp = y; elseif (y <= 3e-143) tmp = Float64(-x); elseif (y <= 3.8e+49) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -9e-22) tmp = y; elseif (y <= 3e-143) tmp = -x; elseif (y <= 3.8e+49) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -9e-22], y, If[LessEqual[y, 3e-143], (-x), If[LessEqual[y, 3.8e+49], y, N[(y * x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -9 \cdot 10^{-22}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-143}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{+49}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -8.99999999999999973e-22 or 2.99999999999999985e-143 < y < 3.7999999999999999e49Initial program 100.0%
Taylor expanded in x around 0 75.8%
Taylor expanded in y around inf 61.8%
if -8.99999999999999973e-22 < y < 2.99999999999999985e-143Initial program 100.0%
Taylor expanded in y around 0 89.2%
neg-mul-189.2%
Simplified89.2%
if 3.7999999999999999e49 < y Initial program 100.0%
Taylor expanded in x around inf 65.0%
*-commutative65.0%
Simplified65.0%
Taylor expanded in y around inf 65.0%
Final simplification72.7%
(FPCore (x y) :precision binary64 (if (or (<= x -68.0) (not (<= x 1.0))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -68.0) || !(x <= 1.0)) {
tmp = (y * x) - 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 <= (-68.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = (y * x) - x
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -68.0) || !(x <= 1.0)) {
tmp = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -68.0) or not (x <= 1.0): tmp = (y * x) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -68.0) || !(x <= 1.0)) tmp = Float64(Float64(y * x) - x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -68.0) || ~((x <= 1.0))) tmp = (y * x) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -68.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -68 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -68 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.9%
*-commutative99.9%
Simplified99.9%
if -68 < x < 1Initial program 100.0%
Taylor expanded in x around 0 97.8%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (<= y -1.05e-21) y (if (<= y 3e-143) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.05e-21) {
tmp = y;
} else if (y <= 3e-143) {
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.05d-21)) then
tmp = y
else if (y <= 3d-143) 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.05e-21) {
tmp = y;
} else if (y <= 3e-143) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.05e-21: tmp = y elif y <= 3e-143: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.05e-21) tmp = y; elseif (y <= 3e-143) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.05e-21) tmp = y; elseif (y <= 3e-143) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.05e-21], y, If[LessEqual[y, 3e-143], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.05 \cdot 10^{-21}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3 \cdot 10^{-143}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.05000000000000006e-21 or 2.99999999999999985e-143 < y Initial program 100.0%
Taylor expanded in x around 0 63.3%
Taylor expanded in y around inf 53.9%
if -1.05000000000000006e-21 < y < 2.99999999999999985e-143Initial program 100.0%
Taylor expanded in y around 0 89.2%
neg-mul-189.2%
Simplified89.2%
(FPCore (x y) :precision binary64 (if (<= y 2e+47) (- y x) (* y x)))
double code(double x, double y) {
double tmp;
if (y <= 2e+47) {
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 (y <= 2d+47) 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 (y <= 2e+47) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= 2e+47: tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= 2e+47) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= 2e+47) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, 2e+47], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 2 \cdot 10^{+47}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < 2.0000000000000001e47Initial program 100.0%
Taylor expanded in x around 0 87.1%
if 2.0000000000000001e47 < y Initial program 100.0%
Taylor expanded in x around inf 65.0%
*-commutative65.0%
Simplified65.0%
Taylor expanded in y around inf 65.0%
Final simplification82.8%
(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)
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 77.1%
Taylor expanded in y around inf 38.5%
(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 41.1%
neg-mul-141.1%
Simplified41.1%
neg-sub041.1%
sub-neg41.1%
add-sqr-sqrt21.8%
sqrt-unprod21.2%
sqr-neg21.2%
sqrt-unprod1.4%
add-sqr-sqrt2.7%
Applied egg-rr2.7%
+-lft-identity2.7%
Simplified2.7%
herbie shell --seed 2024116
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))