
(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 9 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%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.75e+215)
y
(if (<= y -2.5e+151)
(* y x)
(if (<= y -2.9e-16)
y
(if (<= y 3.8e-53) (- x) (if (<= y 4.7e+61) y (* y x)))))))
double code(double x, double y) {
double tmp;
if (y <= -1.75e+215) {
tmp = y;
} else if (y <= -2.5e+151) {
tmp = y * x;
} else if (y <= -2.9e-16) {
tmp = y;
} else if (y <= 3.8e-53) {
tmp = -x;
} else if (y <= 4.7e+61) {
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 <= (-1.75d+215)) then
tmp = y
else if (y <= (-2.5d+151)) then
tmp = y * x
else if (y <= (-2.9d-16)) then
tmp = y
else if (y <= 3.8d-53) then
tmp = -x
else if (y <= 4.7d+61) 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 <= -1.75e+215) {
tmp = y;
} else if (y <= -2.5e+151) {
tmp = y * x;
} else if (y <= -2.9e-16) {
tmp = y;
} else if (y <= 3.8e-53) {
tmp = -x;
} else if (y <= 4.7e+61) {
tmp = y;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.75e+215: tmp = y elif y <= -2.5e+151: tmp = y * x elif y <= -2.9e-16: tmp = y elif y <= 3.8e-53: tmp = -x elif y <= 4.7e+61: tmp = y else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.75e+215) tmp = y; elseif (y <= -2.5e+151) tmp = Float64(y * x); elseif (y <= -2.9e-16) tmp = y; elseif (y <= 3.8e-53) tmp = Float64(-x); elseif (y <= 4.7e+61) tmp = y; else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.75e+215) tmp = y; elseif (y <= -2.5e+151) tmp = y * x; elseif (y <= -2.9e-16) tmp = y; elseif (y <= 3.8e-53) tmp = -x; elseif (y <= 4.7e+61) tmp = y; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.75e+215], y, If[LessEqual[y, -2.5e+151], N[(y * x), $MachinePrecision], If[LessEqual[y, -2.9e-16], y, If[LessEqual[y, 3.8e-53], (-x), If[LessEqual[y, 4.7e+61], y, N[(y * x), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \cdot 10^{+215}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -2.5 \cdot 10^{+151}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -2.9 \cdot 10^{-16}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.8 \cdot 10^{-53}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 4.7 \cdot 10^{+61}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -1.74999999999999988e215 or -2.5000000000000001e151 < y < -2.8999999999999998e-16 or 3.7999999999999998e-53 < y < 4.6999999999999998e61Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 64.1%
if -1.74999999999999988e215 < y < -2.5000000000000001e151 or 4.6999999999999998e61 < y Initial program 100.0%
Taylor expanded in x around inf 66.2%
Taylor expanded in y around inf 66.2%
if -2.8999999999999998e-16 < y < 3.7999999999999998e-53Initial program 100.0%
Taylor expanded in y around 0 80.8%
neg-mul-180.8%
Simplified80.8%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (or (<= y -6.4e+211) (and (not (<= y -5.05e+151)) (<= y 2.4e+62))) (- y x) (* y x)))
double code(double x, double y) {
double tmp;
if ((y <= -6.4e+211) || (!(y <= -5.05e+151) && (y <= 2.4e+62))) {
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 <= (-6.4d+211)) .or. (.not. (y <= (-5.05d+151))) .and. (y <= 2.4d+62)) 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 <= -6.4e+211) || (!(y <= -5.05e+151) && (y <= 2.4e+62))) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -6.4e+211) or (not (y <= -5.05e+151) and (y <= 2.4e+62)): tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if ((y <= -6.4e+211) || (!(y <= -5.05e+151) && (y <= 2.4e+62))) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -6.4e+211) || (~((y <= -5.05e+151)) && (y <= 2.4e+62))) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -6.4e+211], And[N[Not[LessEqual[y, -5.05e+151]], $MachinePrecision], LessEqual[y, 2.4e+62]]], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -6.4 \cdot 10^{+211} \lor \neg \left(y \leq -5.05 \cdot 10^{+151}\right) \land y \leq 2.4 \cdot 10^{+62}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if y < -6.39999999999999953e211 or -5.0499999999999998e151 < y < 2.4e62Initial program 100.0%
Taylor expanded in x around 0 87.6%
if -6.39999999999999953e211 < y < -5.0499999999999998e151 or 2.4e62 < y Initial program 100.0%
Taylor expanded in x around inf 66.2%
Taylor expanded in y around inf 66.2%
Final simplification81.6%
(FPCore (x y) :precision binary64 (if (or (<= y -8500000.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -8500000.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 <= (-8500000.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 <= -8500000.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -8500000.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 <= -8500000.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 <= -8500000.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, -8500000.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 -8500000 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -8.5e6 or 1 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.3%
if -8.5e6 < y < 1Initial program 100.0%
Taylor expanded in x around 0 97.7%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (or (<= x -19000.0) (not (<= x 1.0))) (* x (- y 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -19000.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 <= (-19000.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 <= -19000.0) || !(x <= 1.0)) {
tmp = x * (y - 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -19000.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 <= -19000.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 <= -19000.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, -19000.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 -19000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y - 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -19000 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.4%
if -19000 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.5%
Final simplification99.0%
(FPCore (x y) :precision binary64 (if (or (<= x -19000.0) (not (<= x 1.0))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -19000.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 <= (-19000.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 <= -19000.0) || !(x <= 1.0)) {
tmp = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -19000.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 <= -19000.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 <= -19000.0) || ~((x <= 1.0))) tmp = (y * x) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -19000.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 -19000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -19000 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.5%
if -19000 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.5%
Final simplification99.0%
(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 (<= y -1.6e-15) y (if (<= y 5.4e-52) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.6e-15) {
tmp = y;
} else if (y <= 5.4e-52) {
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.6d-15)) then
tmp = y
else if (y <= 5.4d-52) 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.6e-15) {
tmp = y;
} else if (y <= 5.4e-52) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.6e-15: tmp = y elif y <= 5.4e-52: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.6e-15) tmp = y; elseif (y <= 5.4e-52) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.6e-15) tmp = y; elseif (y <= 5.4e-52) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.6e-15], y, If[LessEqual[y, 5.4e-52], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.6 \cdot 10^{-15}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{-52}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.6e-15 or 5.40000000000000019e-52 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 50.2%
if -1.6e-15 < y < 5.40000000000000019e-52Initial program 100.0%
Taylor expanded in y around 0 80.8%
neg-mul-180.8%
Simplified80.8%
Final simplification63.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 100.0%
Taylor expanded in x around 0 37.6%
Final simplification37.6%
herbie shell --seed 2023274
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))