
(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%
Taylor expanded in x around 0 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.65e+98)
(* y x)
(if (<= y -1.6e+51)
y
(if (<= y -420000000.0)
(* y x)
(if (<= y 1.45e-29)
(- x)
(if (<= y 8.5e+178) y (if (<= y 3.3e+220) (* y x) y)))))))
double code(double x, double y) {
double tmp;
if (y <= -2.65e+98) {
tmp = y * x;
} else if (y <= -1.6e+51) {
tmp = y;
} else if (y <= -420000000.0) {
tmp = y * x;
} else if (y <= 1.45e-29) {
tmp = -x;
} else if (y <= 8.5e+178) {
tmp = y;
} else if (y <= 3.3e+220) {
tmp = y * 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 <= (-2.65d+98)) then
tmp = y * x
else if (y <= (-1.6d+51)) then
tmp = y
else if (y <= (-420000000.0d0)) then
tmp = y * x
else if (y <= 1.45d-29) then
tmp = -x
else if (y <= 8.5d+178) then
tmp = y
else if (y <= 3.3d+220) then
tmp = y * x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.65e+98) {
tmp = y * x;
} else if (y <= -1.6e+51) {
tmp = y;
} else if (y <= -420000000.0) {
tmp = y * x;
} else if (y <= 1.45e-29) {
tmp = -x;
} else if (y <= 8.5e+178) {
tmp = y;
} else if (y <= 3.3e+220) {
tmp = y * x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.65e+98: tmp = y * x elif y <= -1.6e+51: tmp = y elif y <= -420000000.0: tmp = y * x elif y <= 1.45e-29: tmp = -x elif y <= 8.5e+178: tmp = y elif y <= 3.3e+220: tmp = y * x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.65e+98) tmp = Float64(y * x); elseif (y <= -1.6e+51) tmp = y; elseif (y <= -420000000.0) tmp = Float64(y * x); elseif (y <= 1.45e-29) tmp = Float64(-x); elseif (y <= 8.5e+178) tmp = y; elseif (y <= 3.3e+220) tmp = Float64(y * x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.65e+98) tmp = y * x; elseif (y <= -1.6e+51) tmp = y; elseif (y <= -420000000.0) tmp = y * x; elseif (y <= 1.45e-29) tmp = -x; elseif (y <= 8.5e+178) tmp = y; elseif (y <= 3.3e+220) tmp = y * x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.65e+98], N[(y * x), $MachinePrecision], If[LessEqual[y, -1.6e+51], y, If[LessEqual[y, -420000000.0], N[(y * x), $MachinePrecision], If[LessEqual[y, 1.45e-29], (-x), If[LessEqual[y, 8.5e+178], y, If[LessEqual[y, 3.3e+220], N[(y * x), $MachinePrecision], y]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.65 \cdot 10^{+98}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq -1.6 \cdot 10^{+51}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq -420000000:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-29}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 8.5 \cdot 10^{+178}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{+220}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -2.64999999999999999e98 or -1.6000000000000001e51 < y < -4.2e8 or 8.49999999999999991e178 < y < 3.30000000000000021e220Initial program 100.0%
Taylor expanded in x around inf 66.9%
Taylor expanded in y around inf 66.9%
if -2.64999999999999999e98 < y < -1.6000000000000001e51 or 1.45000000000000012e-29 < y < 8.49999999999999991e178 or 3.30000000000000021e220 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 64.8%
if -4.2e8 < y < 1.45000000000000012e-29Initial program 100.0%
Taylor expanded in y around 0 85.0%
neg-mul-185.0%
Simplified85.0%
Final simplification74.1%
(FPCore (x y) :precision binary64 (if (or (<= y -420000000.0) (not (<= y 1.45e-29))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -420000000.0) || !(y <= 1.45e-29)) {
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 <= (-420000000.0d0)) .or. (.not. (y <= 1.45d-29))) 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 <= -420000000.0) || !(y <= 1.45e-29)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -420000000.0) or not (y <= 1.45e-29): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -420000000.0) || !(y <= 1.45e-29)) 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 <= -420000000.0) || ~((y <= 1.45e-29))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -420000000.0], N[Not[LessEqual[y, 1.45e-29]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -420000000 \lor \neg \left(y \leq 1.45 \cdot 10^{-29}\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -4.2e8 or 1.45000000000000012e-29 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.8%
if -4.2e8 < y < 1.45000000000000012e-29Initial program 100.0%
Taylor expanded in x around 0 99.4%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (<= y -420000000.0) (+ y (* y x)) (if (<= y 1.45e-29) (- y x) (* y (+ x 1.0)))))
double code(double x, double y) {
double tmp;
if (y <= -420000000.0) {
tmp = y + (y * x);
} else if (y <= 1.45e-29) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if (y <= (-420000000.0d0)) then
tmp = y + (y * x)
else if (y <= 1.45d-29) then
tmp = y - x
else
tmp = y * (x + 1.0d0)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -420000000.0) {
tmp = y + (y * x);
} else if (y <= 1.45e-29) {
tmp = y - x;
} else {
tmp = y * (x + 1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -420000000.0: tmp = y + (y * x) elif y <= 1.45e-29: tmp = y - x else: tmp = y * (x + 1.0) return tmp
function code(x, y) tmp = 0.0 if (y <= -420000000.0) tmp = Float64(y + Float64(y * x)); elseif (y <= 1.45e-29) tmp = Float64(y - x); else tmp = Float64(y * Float64(x + 1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -420000000.0) tmp = y + (y * x); elseif (y <= 1.45e-29) tmp = y - x; else tmp = y * (x + 1.0); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -420000000.0], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.45e-29], N[(y - x), $MachinePrecision], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -420000000:\\
\;\;\;\;y + y \cdot x\\
\mathbf{elif}\;y \leq 1.45 \cdot 10^{-29}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\end{array}
\end{array}
if y < -4.2e8Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around 0 100.0%
if -4.2e8 < y < 1.45000000000000012e-29Initial program 100.0%
Taylor expanded in x around 0 99.4%
if 1.45000000000000012e-29 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in y around inf 99.7%
Final simplification99.7%
(FPCore (x y) :precision binary64 (if (<= x -6.6e+130) (* y x) (if (<= x 1.35e+105) (- y x) (* y x))))
double code(double x, double y) {
double tmp;
if (x <= -6.6e+130) {
tmp = y * x;
} else if (x <= 1.35e+105) {
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 (x <= (-6.6d+130)) then
tmp = y * x
else if (x <= 1.35d+105) 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 (x <= -6.6e+130) {
tmp = y * x;
} else if (x <= 1.35e+105) {
tmp = y - x;
} else {
tmp = y * x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -6.6e+130: tmp = y * x elif x <= 1.35e+105: tmp = y - x else: tmp = y * x return tmp
function code(x, y) tmp = 0.0 if (x <= -6.6e+130) tmp = Float64(y * x); elseif (x <= 1.35e+105) tmp = Float64(y - x); else tmp = Float64(y * x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -6.6e+130) tmp = y * x; elseif (x <= 1.35e+105) tmp = y - x; else tmp = y * x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -6.6e+130], N[(y * x), $MachinePrecision], If[LessEqual[x, 1.35e+105], N[(y - x), $MachinePrecision], N[(y * x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -6.6 \cdot 10^{+130}:\\
\;\;\;\;y \cdot x\\
\mathbf{elif}\;x \leq 1.35 \cdot 10^{+105}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y \cdot x\\
\end{array}
\end{array}
if x < -6.6e130 or 1.35000000000000008e105 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 62.2%
if -6.6e130 < x < 1.35000000000000008e105Initial program 100.0%
Taylor expanded in x around 0 86.6%
Final simplification79.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 -0.00046) y (if (<= y 1.35e-29) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -0.00046) {
tmp = y;
} else if (y <= 1.35e-29) {
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 <= (-0.00046d0)) then
tmp = y
else if (y <= 1.35d-29) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -0.00046) {
tmp = y;
} else if (y <= 1.35e-29) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -0.00046: tmp = y elif y <= 1.35e-29: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -0.00046) tmp = y; elseif (y <= 1.35e-29) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -0.00046) tmp = y; elseif (y <= 1.35e-29) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -0.00046], y, If[LessEqual[y, 1.35e-29], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -0.00046:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-29}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.6000000000000001e-4 or 1.35000000000000011e-29 < y Initial program 100.0%
Taylor expanded in x around 0 100.0%
Taylor expanded in x around 0 51.5%
if -4.6000000000000001e-4 < y < 1.35000000000000011e-29Initial program 100.0%
Taylor expanded in y around 0 85.7%
neg-mul-185.7%
Simplified85.7%
Final simplification66.3%
(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 36.1%
Final simplification36.1%
herbie shell --seed 2023196
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))