
(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 5 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 (- (* (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 2.32e-7))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 2.32e-7)) {
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 <= (-1.0d0)) .or. (.not. (x <= 2.32d-7))) 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 <= -1.0) || !(x <= 2.32e-7)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 2.32e-7): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 2.32e-7)) 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 <= -1.0) || ~((x <= 2.32e-7))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 2.32e-7]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 2.32 \cdot 10^{-7}\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 2.3200000000000001e-7 < x Initial program 100.0%
Taylor expanded in x around inf 98.1%
if -1 < x < 2.3200000000000001e-7Initial program 100.0%
Taylor expanded in x around 0 99.4%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
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 <= (-1.0d0)) then
tmp = x * y
else if (y <= 1.0d0) 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 <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.0: tmp = -x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 1.0) tmp = Float64(-x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 1.0) tmp = -x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 1.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 47.5%
Taylor expanded in y around inf 46.7%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around inf 69.6%
Taylor expanded in y around 0 67.9%
neg-mul-167.9%
Simplified67.9%
Final simplification58.0%
(FPCore (x y) :precision binary64 (if (<= x -2.05e+212) (* x y) (if (<= x 1.6e+139) (- y x) (* x y))))
double code(double x, double y) {
double tmp;
if (x <= -2.05e+212) {
tmp = x * y;
} else if (x <= 1.6e+139) {
tmp = y - 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 (x <= (-2.05d+212)) then
tmp = x * y
else if (x <= 1.6d+139) then
tmp = y - x
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -2.05e+212) {
tmp = x * y;
} else if (x <= 1.6e+139) {
tmp = y - x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -2.05e+212: tmp = x * y elif x <= 1.6e+139: tmp = y - x else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (x <= -2.05e+212) tmp = Float64(x * y); elseif (x <= 1.6e+139) tmp = Float64(y - x); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -2.05e+212) tmp = x * y; elseif (x <= 1.6e+139) tmp = y - x; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -2.05e+212], N[(x * y), $MachinePrecision], If[LessEqual[x, 1.6e+139], N[(y - x), $MachinePrecision], N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{+212}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;x \leq 1.6 \cdot 10^{+139}:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if x < -2.04999999999999995e212 or 1.6000000000000001e139 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 61.1%
if -2.04999999999999995e212 < x < 1.6000000000000001e139Initial program 100.0%
Taylor expanded in x around 0 87.0%
Final simplification81.9%
(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 Float64(-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 inf 59.3%
Taylor expanded in y around 0 37.4%
neg-mul-137.4%
Simplified37.4%
Final simplification37.4%
herbie shell --seed 2023221
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))