
(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 (fma x (+ y -1.0) y))
double code(double x, double y) {
return fma(x, (y + -1.0), y);
}
function code(x, y) return fma(x, Float64(y + -1.0), y) end
code[x_, y_] := N[(x * N[(y + -1.0), $MachinePrecision] + y), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y + -1, y\right)
\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%
(FPCore (x y) :precision binary64 (if (or (<= x -34000000.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -34000000.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 <= (-34000000.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 <= -34000000.0) || !(x <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -34000000.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 <= -34000000.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 <= -34000000.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, -34000000.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 -34000000 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -3.4e7 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.1%
if -3.4e7 < x < 1Initial program 100.0%
Taylor expanded in x around 0 99.5%
Final simplification99.3%
(FPCore (x y) :precision binary64 (if (or (<= y -1.0) (not (<= y 2.2))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 2.2)) {
tmp = x * y;
} 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 <= (-1.0d0)) .or. (.not. (y <= 2.2d0))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.0) || !(y <= 2.2)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.0) or not (y <= 2.2): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.0) || !(y <= 2.2)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.0) || ~((y <= 2.2))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.0], N[Not[LessEqual[y, 2.2]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1 \lor \neg \left(y \leq 2.2\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1 or 2.2000000000000002 < y Initial program 100.0%
Taylor expanded in x around inf 48.7%
Taylor expanded in y around inf 47.7%
if -1 < y < 2.2000000000000002Initial program 100.0%
Taylor expanded in y around 0 74.0%
neg-mul-174.0%
Simplified74.0%
Final simplification60.7%
(FPCore (x y) :precision binary64 (if (<= x -5.2e+207) (- x) (if (<= x -1.6e+24) (* x y) (- y x))))
double code(double x, double y) {
double tmp;
if (x <= -5.2e+207) {
tmp = -x;
} else if (x <= -1.6e+24) {
tmp = x * 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 (x <= (-5.2d+207)) then
tmp = -x
else if (x <= (-1.6d+24)) then
tmp = x * y
else
tmp = y - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= -5.2e+207) {
tmp = -x;
} else if (x <= -1.6e+24) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= -5.2e+207: tmp = -x elif x <= -1.6e+24: tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (x <= -5.2e+207) tmp = Float64(-x); elseif (x <= -1.6e+24) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= -5.2e+207) tmp = -x; elseif (x <= -1.6e+24) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, -5.2e+207], (-x), If[LessEqual[x, -1.6e+24], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.2 \cdot 10^{+207}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq -1.6 \cdot 10^{+24}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -5.1999999999999996e207Initial program 100.0%
Taylor expanded in y around 0 85.1%
neg-mul-185.1%
Simplified85.1%
if -5.1999999999999996e207 < x < -1.5999999999999999e24Initial program 100.0%
Taylor expanded in x around inf 100.0%
Taylor expanded in y around inf 68.0%
if -1.5999999999999999e24 < x Initial program 100.0%
Taylor expanded in x around 0 83.6%
(FPCore (x y) :precision binary64 (- (+ y (* x y)) x))
double code(double x, double y) {
return (y + (x * y)) - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + (x * y)) - x
end function
public static double code(double x, double y) {
return (y + (x * y)) - x;
}
def code(x, y): return (y + (x * y)) - x
function code(x, y) return Float64(Float64(y + Float64(x * y)) - x) end
function tmp = code(x, y) tmp = (y + (x * y)) - x; end
code[x_, y_] := N[(N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision] - x), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x \cdot y\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 (- (* 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%
Taylor expanded in y around 0 37.9%
neg-mul-137.9%
Simplified37.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 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 y around 0 37.9%
neg-mul-137.9%
Simplified37.9%
neg-sub037.9%
sub-neg37.9%
add-sqr-sqrt15.5%
sqrt-unprod13.8%
sqr-neg13.8%
sqrt-unprod1.3%
add-sqr-sqrt2.6%
Applied egg-rr2.6%
+-lft-identity2.6%
Simplified2.6%
herbie shell --seed 2024135
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))