
(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 6 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 (or (<= x -950000.0) (not (<= x 2.8e-7))) (- (* y x) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -950000.0) || !(x <= 2.8e-7)) {
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 <= (-950000.0d0)) .or. (.not. (x <= 2.8d-7))) 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 <= -950000.0) || !(x <= 2.8e-7)) {
tmp = (y * x) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -950000.0) or not (x <= 2.8e-7): tmp = (y * x) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -950000.0) || !(x <= 2.8e-7)) 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 <= -950000.0) || ~((x <= 2.8e-7))) tmp = (y * x) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -950000.0], N[Not[LessEqual[x, 2.8e-7]], $MachinePrecision]], N[(N[(y * x), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -950000 \lor \neg \left(x \leq 2.8 \cdot 10^{-7}\right):\\
\;\;\;\;y \cdot x - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -9.5e5 or 2.80000000000000019e-7 < x Initial program 100.0%
Taylor expanded in x around inf 99.3%
*-commutative99.3%
Simplified99.3%
if -9.5e5 < x < 2.80000000000000019e-7Initial program 100.0%
Taylor expanded in x around 0 98.4%
Final simplification98.8%
(FPCore (x y) :precision binary64 (if (or (<= y -3300000000.0) (not (<= y 55000.0))) (* y x) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -3300000000.0) || !(y <= 55000.0)) {
tmp = y * x;
} else {
tmp = -x;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-3300000000.0d0)) .or. (.not. (y <= 55000.0d0))) then
tmp = y * x
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -3300000000.0) || !(y <= 55000.0)) {
tmp = y * x;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -3300000000.0) or not (y <= 55000.0): tmp = y * x else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -3300000000.0) || !(y <= 55000.0)) tmp = Float64(y * x); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -3300000000.0) || ~((y <= 55000.0))) tmp = y * x; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -3300000000.0], N[Not[LessEqual[y, 55000.0]], $MachinePrecision]], N[(y * x), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3300000000 \lor \neg \left(y \leq 55000\right):\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -3.3e9 or 55000 < y Initial program 100.0%
Taylor expanded in x around inf 46.3%
*-commutative46.3%
Simplified46.3%
Taylor expanded in y around inf 46.1%
if -3.3e9 < y < 55000Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 77.0%
mul-1-neg77.0%
Simplified77.0%
Final simplification60.7%
(FPCore (x y) :precision binary64 (if (<= x -1.3e+249) (- x) (if (<= x -9.6e+191) (* y x) (- y x))))
double code(double x, double y) {
double tmp;
if (x <= -1.3e+249) {
tmp = -x;
} else if (x <= -9.6e+191) {
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 <= (-1.3d+249)) then
tmp = -x
else if (x <= (-9.6d+191)) 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 <= -1.3e+249) {
tmp = -x;
} else if (x <= -9.6e+191) {
tmp = y * x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -1.3e+249: tmp = -x elif x <= -9.6e+191: tmp = y * x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -1.3e+249) tmp = Float64(-x); elseif (x <= -9.6e+191) tmp = Float64(y * x); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -1.3e+249) tmp = -x; elseif (x <= -9.6e+191) tmp = y * x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -1.3e+249], (-x), If[LessEqual[x, -9.6e+191], N[(y * x), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.3 \cdot 10^{+249}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -9.6 \cdot 10^{+191}:\\
\;\;\;\;y \cdot x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.3000000000000001e249Initial program 100.0%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 75.3%
mul-1-neg75.3%
Simplified75.3%
if -1.3000000000000001e249 < x < -9.59999999999999943e191Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 83.7%
if -9.59999999999999943e191 < x Initial program 100.0%
Taylor expanded in x around 0 78.5%
Final simplification78.6%
(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 (- 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%
sub-neg100.0%
*-commutative100.0%
+-commutative100.0%
distribute-lft-in100.0%
*-rgt-identity100.0%
associate-+l+100.0%
*-commutative100.0%
+-commutative100.0%
*-commutative100.0%
neg-mul-1100.0%
distribute-rgt-out100.0%
fma-define100.0%
Simplified100.0%
Taylor expanded in y around 0 38.0%
mul-1-neg38.0%
Simplified38.0%
herbie shell --seed 2024087
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))