
(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 7 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 -7.8e+25)
(* x y)
(if (<= y -3.1e-9)
y
(if (<= y 6.2e-92) (- x) (if (<= y 2.65e+14) y (* x y))))))
double code(double x, double y) {
double tmp;
if (y <= -7.8e+25) {
tmp = x * y;
} else if (y <= -3.1e-9) {
tmp = y;
} else if (y <= 6.2e-92) {
tmp = -x;
} else if (y <= 2.65e+14) {
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 <= (-7.8d+25)) then
tmp = x * y
else if (y <= (-3.1d-9)) then
tmp = y
else if (y <= 6.2d-92) then
tmp = -x
else if (y <= 2.65d+14) 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 <= -7.8e+25) {
tmp = x * y;
} else if (y <= -3.1e-9) {
tmp = y;
} else if (y <= 6.2e-92) {
tmp = -x;
} else if (y <= 2.65e+14) {
tmp = y;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -7.8e+25: tmp = x * y elif y <= -3.1e-9: tmp = y elif y <= 6.2e-92: tmp = -x elif y <= 2.65e+14: tmp = y else: tmp = x * y return tmp
function code(x, y) tmp = 0.0 if (y <= -7.8e+25) tmp = Float64(x * y); elseif (y <= -3.1e-9) tmp = y; elseif (y <= 6.2e-92) tmp = Float64(-x); elseif (y <= 2.65e+14) tmp = y; else tmp = Float64(x * y); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -7.8e+25) tmp = x * y; elseif (y <= -3.1e-9) tmp = y; elseif (y <= 6.2e-92) tmp = -x; elseif (y <= 2.65e+14) tmp = y; else tmp = x * y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -7.8e+25], N[(x * y), $MachinePrecision], If[LessEqual[y, -3.1e-9], y, If[LessEqual[y, 6.2e-92], (-x), If[LessEqual[y, 2.65e+14], y, N[(x * y), $MachinePrecision]]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.8 \cdot 10^{+25}:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq -3.1 \cdot 10^{-9}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 6.2 \cdot 10^{-92}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{+14}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -7.8000000000000004e25 or 2.65e14 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 63.9%
if -7.8000000000000004e25 < y < -3.10000000000000005e-9 or 6.2000000000000002e-92 < y < 2.65e14Initial program 100.0%
Taylor expanded in x around 0 70.0%
if -3.10000000000000005e-9 < y < 6.2000000000000002e-92Initial program 100.0%
Taylor expanded in y around 0 81.3%
neg-mul-181.3%
Simplified81.3%
Final simplification72.5%
(FPCore (x y) :precision binary64 (if (or (<= y -205.0) (not (<= y 1.0))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -205.0) || !(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 <= (-205.0d0)) .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 <= -205.0) || !(y <= 1.0)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -205.0) 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 <= -205.0) || !(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 <= -205.0) || ~((y <= 1.0))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -205.0], 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 -205 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -205 or 1 < y Initial program 100.0%
Taylor expanded in y around inf 98.9%
if -205 < y < 1Initial program 100.0%
Taylor expanded in x around 0 99.3%
Taylor expanded in y around 0 99.3%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.65e+22) (not (<= y 69000000000.0))) (* x y) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.65e+22) || !(y <= 69000000000.0)) {
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 <= (-1.65d+22)) .or. (.not. (y <= 69000000000.0d0))) 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 <= -1.65e+22) || !(y <= 69000000000.0)) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.65e+22) or not (y <= 69000000000.0): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.65e+22) || !(y <= 69000000000.0)) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.65e+22) || ~((y <= 69000000000.0))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.65e+22], N[Not[LessEqual[y, 69000000000.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.65 \cdot 10^{+22} \lor \neg \left(y \leq 69000000000\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.6499999999999999e22 or 6.9e10 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
Taylor expanded in x around inf 63.9%
if -1.6499999999999999e22 < y < 6.9e10Initial program 100.0%
Taylor expanded in x around 0 98.1%
Taylor expanded in y around 0 98.1%
Final simplification83.8%
(FPCore (x y) :precision binary64 (if (<= y -4.5e-12) y (if (<= y 1.1e-91) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -4.5e-12) {
tmp = y;
} else if (y <= 1.1e-91) {
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 <= (-4.5d-12)) then
tmp = y
else if (y <= 1.1d-91) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -4.5e-12) {
tmp = y;
} else if (y <= 1.1e-91) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -4.5e-12: tmp = y elif y <= 1.1e-91: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -4.5e-12) tmp = y; elseif (y <= 1.1e-91) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -4.5e-12) tmp = y; elseif (y <= 1.1e-91) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -4.5e-12], y, If[LessEqual[y, 1.1e-91], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.5 \cdot 10^{-12}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 1.1 \cdot 10^{-91}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -4.49999999999999981e-12 or 1.1e-91 < y Initial program 100.0%
Taylor expanded in x around 0 45.3%
if -4.49999999999999981e-12 < y < 1.1e-91Initial program 100.0%
Taylor expanded in y around 0 81.3%
neg-mul-181.3%
Simplified81.3%
(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 33.8%
herbie shell --seed 2024145
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))