
(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 11 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 (<= y -1.7e+15)
(* x y)
(if (<= y -1.25e-64)
y
(if (<= y 6.8e-22) (- x) (if (<= y 7e+32) (+ x y) (* x y))))))
double code(double x, double y) {
double tmp;
if (y <= -1.7e+15) {
tmp = x * y;
} else if (y <= -1.25e-64) {
tmp = y;
} else if (y <= 6.8e-22) {
tmp = -x;
} else if (y <= 7e+32) {
tmp = x + y;
} 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.7d+15)) then
tmp = x * y
else if (y <= (-1.25d-64)) then
tmp = y
else if (y <= 6.8d-22) then
tmp = -x
else if (y <= 7d+32) then
tmp = x + y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.7e+15) {
tmp = x * y;
} else if (y <= -1.25e-64) {
tmp = y;
} else if (y <= 6.8e-22) {
tmp = -x;
} else if (y <= 7e+32) {
tmp = x + y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.7e+15: tmp = x * y elif y <= -1.25e-64: tmp = y elif y <= 6.8e-22: tmp = -x elif y <= 7e+32: tmp = x + y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.7e+15) tmp = Float64(x * y); elseif (y <= -1.25e-64) tmp = y; elseif (y <= 6.8e-22) tmp = Float64(-x); elseif (y <= 7e+32) tmp = Float64(x + y); else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.7e+15) tmp = x * y; elseif (y <= -1.25e-64) tmp = y; elseif (y <= 6.8e-22) tmp = -x; elseif (y <= 7e+32) tmp = x + y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.7e+15], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.25e-64], y, If[LessEqual[y, 6.8e-22], (-x), If[LessEqual[y, 7e+32], N[(x + y), $MachinePrecision], N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.7 \cdot 10^{+15}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-64}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.8 \cdot 10^{-22}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 7 \cdot 10^{+32}:\\
\;\;\;\;x + y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1.7e15 or 7.0000000000000002e32 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 58.3%
if -1.7e15 < y < -1.25000000000000008e-64Initial program 99.8%
Taylor expanded in x around 0 67.5%
if -1.25000000000000008e-64 < y < 6.7999999999999997e-22Initial program 100.0%
Taylor expanded in y around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
if 6.7999999999999997e-22 < y < 7.0000000000000002e32Initial program 100.0%
Taylor expanded in x around 0 68.0%
*-un-lft-identity68.0%
sub-neg68.0%
add-sqr-sqrt38.7%
sqrt-unprod57.6%
sqr-neg57.6%
sqrt-unprod24.2%
add-sqr-sqrt58.3%
Applied egg-rr58.3%
Final simplification69.0%
(FPCore (x y)
:precision binary64
(if (<= y -2.4e+16)
(* x y)
(if (<= y -1.25e-64)
y
(if (<= y 7.8e-22) (- x) (if (<= y 5.4e+34) y (* x y))))))
double code(double x, double y) {
double tmp;
if (y <= -2.4e+16) {
tmp = x * y;
} else if (y <= -1.25e-64) {
tmp = y;
} else if (y <= 7.8e-22) {
tmp = -x;
} else if (y <= 5.4e+34) {
tmp = y;
} 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 <= (-2.4d+16)) then
tmp = x * y
else if (y <= (-1.25d-64)) then
tmp = y
else if (y <= 7.8d-22) then
tmp = -x
else if (y <= 5.4d+34) then
tmp = y
else
tmp = x * y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -2.4e+16) {
tmp = x * y;
} else if (y <= -1.25e-64) {
tmp = y;
} else if (y <= 7.8e-22) {
tmp = -x;
} else if (y <= 5.4e+34) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -2.4e+16: tmp = x * y elif y <= -1.25e-64: tmp = y elif y <= 7.8e-22: tmp = -x elif y <= 5.4e+34: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -2.4e+16) tmp = Float64(x * y); elseif (y <= -1.25e-64) tmp = y; elseif (y <= 7.8e-22) tmp = Float64(-x); elseif (y <= 5.4e+34) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -2.4e+16) tmp = x * y; elseif (y <= -1.25e-64) tmp = y; elseif (y <= 7.8e-22) tmp = -x; elseif (y <= 5.4e+34) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -2.4e+16], N[(x * y), $MachinePrecision], If[LessEqual[y, -1.25e-64], y, If[LessEqual[y, 7.8e-22], (-x), If[LessEqual[y, 5.4e+34], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2.4 \cdot 10^{+16}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -1.25 \cdot 10^{-64}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 7.8 \cdot 10^{-22}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 5.4 \cdot 10^{+34}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -2.4e16 or 5.4000000000000001e34 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 58.3%
if -2.4e16 < y < -1.25000000000000008e-64 or 7.79999999999999996e-22 < y < 5.4000000000000001e34Initial program 99.9%
Taylor expanded in x around 0 63.5%
if -1.25000000000000008e-64 < y < 7.79999999999999996e-22Initial program 100.0%
Taylor expanded in y around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
(FPCore (x y) :precision binary64 (if (or (<= y -12.2) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -12.2) || !(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 <= (-12.2d0)) .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 <= -12.2) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -12.2) 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 <= -12.2) || !(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 <= -12.2) || ~((y <= 1.0))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -12.2], 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 -12.2 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -12.199999999999999 or 1 < y Initial program 99.9%
Taylor expanded in y around inf 98.0%
if -12.199999999999999 < y < 1Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in y around 0 99.0%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 1.0))) (* x (+ y -1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.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 <= (-1.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 <= -1.0) || !(x <= 1.0)) {
tmp = x * (y + -1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.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 <= -1.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 <= -1.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, -1.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 -1 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 98.9%
if -1 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in y around 0 98.0%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (<= y -12.2) (* y (+ x 1.0)) (if (<= y 1.0) (- y x) (+ y (* x y)))))
double code(double x, double y) {
double tmp;
if (y <= -12.2) {
tmp = y * (x + 1.0);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y + (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 <= (-12.2d0)) then
tmp = y * (x + 1.0d0)
else if (y <= 1.0d0) then
tmp = y - x
else
tmp = y + (x * y)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -12.2) {
tmp = y * (x + 1.0);
} else if (y <= 1.0) {
tmp = y - x;
} else {
tmp = y + (x * y);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -12.2: tmp = y * (x + 1.0) elif y <= 1.0: tmp = y - x else: tmp = y + (x * y) return tmp
function code(x, y) tmp = 0.0 if (y <= -12.2) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 1.0) tmp = Float64(y - x); else tmp = Float64(y + Float64(x * y)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -12.2) tmp = y * (x + 1.0); elseif (y <= 1.0) tmp = y - x; else tmp = y + (x * y); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -12.2], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.0], N[(y - x), $MachinePrecision], N[(y + N[(x * y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -12.2:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y + x \cdot y\\
\end{array}
\end{array}
if y < -12.199999999999999Initial program 99.9%
Taylor expanded in y around inf 97.4%
if -12.199999999999999 < y < 1Initial program 100.0%
Taylor expanded in x around 0 99.0%
Taylor expanded in y around 0 99.0%
if 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.6%
+-commutative98.6%
distribute-lft-in98.6%
*-rgt-identity98.6%
Applied egg-rr98.6%
Final simplification98.5%
(FPCore (x y) :precision binary64 (if (or (<= y -5.2e+15) (not (<= y 4.2e+33))) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -5.2e+15) || !(y <= 4.2e+33)) {
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 ((y <= (-5.2d+15)) .or. (.not. (y <= 4.2d+33))) 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 ((y <= -5.2e+15) || !(y <= 4.2e+33)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5.2e+15) or not (y <= 4.2e+33): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5.2e+15) || !(y <= 4.2e+33)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5.2e+15) || ~((y <= 4.2e+33))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5.2e+15], N[Not[LessEqual[y, 4.2e+33]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.2 \cdot 10^{+15} \lor \neg \left(y \leq 4.2 \cdot 10^{+33}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -5.2e15 or 4.2000000000000001e33 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 58.3%
if -5.2e15 < y < 4.2000000000000001e33Initial program 100.0%
Taylor expanded in x around 0 94.8%
Taylor expanded in y around 0 94.8%
Final simplification78.9%
(FPCore (x y) :precision binary64 (if (<= y -1.18e-64) y (if (<= y 3.9e-22) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -1.18e-64) {
tmp = y;
} else if (y <= 3.9e-22) {
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.18d-64)) then
tmp = y
else if (y <= 3.9d-22) 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.18e-64) {
tmp = y;
} else if (y <= 3.9e-22) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.18e-64: tmp = y elif y <= 3.9e-22: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.18e-64) tmp = y; elseif (y <= 3.9e-22) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.18e-64) tmp = y; elseif (y <= 3.9e-22) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.18e-64], y, If[LessEqual[y, 3.9e-22], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.18 \cdot 10^{-64}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 3.9 \cdot 10^{-22}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1.17999999999999996e-64 or 3.89999999999999998e-22 < y Initial program 99.9%
Taylor expanded in x around 0 48.1%
if -1.17999999999999996e-64 < y < 3.89999999999999998e-22Initial program 100.0%
Taylor expanded in y around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
(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 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 35.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 x around 0 72.3%
*-un-lft-identity72.3%
sub-neg72.3%
add-sqr-sqrt30.9%
sqrt-unprod48.6%
sqr-neg48.6%
sqrt-unprod19.1%
add-sqr-sqrt35.4%
Applied egg-rr35.4%
Taylor expanded in y around 0 2.6%
herbie shell --seed 2024123
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))