
(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%
*-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 (<= x -5.7e+172)
(- x)
(if (<= x -2.4e+101)
(* y x)
(if (<= x -1.2e-14)
(- x)
(if (<= x 0.00038) y (if (<= x 5e+164) (- x) (* y x)))))))
double code(double x, double y) {
double tmp;
if (x <= -5.7e+172) {
tmp = -x;
} else if (x <= -2.4e+101) {
tmp = y * x;
} else if (x <= -1.2e-14) {
tmp = -x;
} else if (x <= 0.00038) {
tmp = y;
} else if (x <= 5e+164) {
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 <= (-5.7d+172)) then
tmp = -x
else if (x <= (-2.4d+101)) then
tmp = y * x
else if (x <= (-1.2d-14)) then
tmp = -x
else if (x <= 0.00038d0) then
tmp = y
else if (x <= 5d+164) 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 <= -5.7e+172) {
tmp = -x;
} else if (x <= -2.4e+101) {
tmp = y * x;
} else if (x <= -1.2e-14) {
tmp = -x;
} else if (x <= 0.00038) {
tmp = y;
} else if (x <= 5e+164) {
tmp = -x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.7e+172: tmp = -x elif x <= -2.4e+101: tmp = y * x elif x <= -1.2e-14: tmp = -x elif x <= 0.00038: tmp = y elif x <= 5e+164: tmp = -x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -5.7e+172) tmp = Float64(-x); elseif (x <= -2.4e+101) tmp = Float64(y * x); elseif (x <= -1.2e-14) tmp = Float64(-x); elseif (x <= 0.00038) tmp = y; elseif (x <= 5e+164) tmp = Float64(-x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.7e+172) tmp = -x; elseif (x <= -2.4e+101) tmp = y * x; elseif (x <= -1.2e-14) tmp = -x; elseif (x <= 0.00038) tmp = y; elseif (x <= 5e+164) tmp = -x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.7e+172], (-x), If[LessEqual[x, -2.4e+101], N[(y * x), $MachinePrecision], If[LessEqual[x, -1.2e-14], (-x), If[LessEqual[x, 0.00038], y, If[LessEqual[x, 5e+164], (-x), N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.7 \cdot 10^{+172}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -2.4 \cdot 10^{+101}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq -1.2 \cdot 10^{-14}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 0.00038:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq 5 \cdot 10^{+164}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -5.7e172 or -2.39999999999999988e101 < x < -1.2e-14 or 3.8000000000000002e-4 < x < 4.9999999999999995e164Initial program 100.0%
Taylor expanded in y around 0 60.0%
neg-mul-160.0%
Simplified60.0%
if -5.7e172 < x < -2.39999999999999988e101 or 4.9999999999999995e164 < x Initial program 100.0%
Taylor expanded in y around inf 71.8%
Taylor expanded in x around inf 71.8%
if -1.2e-14 < x < 3.8000000000000002e-4Initial program 100.0%
Taylor expanded in x around 0 79.3%
(FPCore (x y) :precision binary64 (if (or (<= x -13000.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -13000.0) || !(x <= 1.0)) {
tmp = x * (y + -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 ((x <= (-13000.0d0)) .or. (.not. (x <= 1.0d0))) then
tmp = x * (y + (-1.0d0))
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -13000.0) || !(x <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -13000.0) or not (x <= 1.0): tmp = x * (y + -1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -13000.0) || !(x <= 1.0)) tmp = Float64(x * Float64(y + -1.0)); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -13000.0) || ~((x <= 1.0))) tmp = x * (y + -1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -13000.0], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -13000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -13000 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
if -13000 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.8%
Taylor expanded in y around 0 98.8%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= x -1.3e-12) (not (<= x 0.00038))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -1.3e-12) || !(x <= 0.00038)) {
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 ((x <= (-1.3d-12)) .or. (.not. (x <= 0.00038d0))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -1.3e-12) || !(x <= 0.00038)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.3e-12) or not (x <= 0.00038): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.3e-12) || !(x <= 0.00038)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -1.3e-12) || ~((x <= 0.00038))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.3e-12], N[Not[LessEqual[x, 0.00038]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{-12} \lor \neg \left(x \leq 0.00038\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -1.29999999999999991e-12 or 3.8000000000000002e-4 < x Initial program 100.0%
Taylor expanded in y around 0 50.1%
neg-mul-150.1%
Simplified50.1%
if -1.29999999999999991e-12 < x < 3.8000000000000002e-4Initial program 100.0%
Taylor expanded in x around 0 79.3%
Final simplification65.3%
(FPCore (x y) :precision binary64 (if (<= y -3e+131) (* y x) (- y x)))
double code(double x, double y) {
double tmp;
if (y <= -3e+131) {
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 <= (-3d+131)) 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 <= -3e+131) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -3e+131: tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -3e+131) tmp = Float64(y * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -3e+131) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -3e+131], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3 \cdot 10^{+131}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -3.0000000000000001e131Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 68.8%
if -3.0000000000000001e131 < y Initial program 100.0%
Taylor expanded in x around 0 81.4%
Taylor expanded in y around 0 81.4%
(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 42.7%
herbie shell --seed 2024181
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))