
(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 (fma x y (- y x)))
double code(double x, double y) {
return fma(x, y, (y - x));
}
function code(x, y) return fma(x, y, Float64(y - x)) end
code[x_, y_] := N[(x * y + N[(y - x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x, y, y - x\right)
\end{array}
Initial program 100.0%
*-commutative100.0%
*-commutative100.0%
distribute-lft1-in100.0%
associate--l+100.0%
fma-def100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y) :precision binary64 (if (or (<= x -23.0) (not (<= x 5.5e-8))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -23.0) || !(x <= 5.5e-8)) {
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 <= (-23.0d0)) .or. (.not. (x <= 5.5d-8))) 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 <= -23.0) || !(x <= 5.5e-8)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -23.0) or not (x <= 5.5e-8): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -23.0) || !(x <= 5.5e-8)) 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 <= -23.0) || ~((x <= 5.5e-8))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -23.0], N[Not[LessEqual[x, 5.5e-8]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -23 \lor \neg \left(x \leq 5.5 \cdot 10^{-8}\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -23 or 5.5000000000000003e-8 < x Initial program 100.0%
Taylor expanded in x around inf 97.1%
*-commutative97.1%
Simplified97.1%
if -23 < x < 5.5000000000000003e-8Initial program 100.0%
Taylor expanded in x around 0 99.0%
Final simplification98.1%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 3.3e-6) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 3.3e-6) {
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 <= 3.3d-6) 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 <= 3.3e-6) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 3.3e-6: 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 <= 3.3e-6) 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 <= 3.3e-6) 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, 3.3e-6], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 3.3 \cdot 10^{-6}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 3.30000000000000017e-6 < y Initial program 100.0%
Taylor expanded in x around inf 43.6%
*-commutative43.6%
Simplified43.6%
Taylor expanded in y around inf 42.2%
if -1 < y < 3.30000000000000017e-6Initial program 100.0%
Taylor expanded in x around inf 72.5%
*-commutative72.5%
Simplified72.5%
Taylor expanded in y around 0 71.3%
neg-mul-171.3%
Simplified71.3%
Final simplification56.1%
(FPCore (x y) :precision binary64 (if (<= x 7.2e+127) (- y x) (if (<= x 2.3e+263) (* x y) (- x))))
double code(double x, double y) {
double tmp;
if (x <= 7.2e+127) {
tmp = y - x;
} else if (x <= 2.3e+263) {
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 (x <= 7.2d+127) then
tmp = y - x
else if (x <= 2.3d+263) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (x <= 7.2e+127) {
tmp = y - x;
} else if (x <= 2.3e+263) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if x <= 7.2e+127: tmp = y - x elif x <= 2.3e+263: tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if (x <= 7.2e+127) tmp = Float64(y - x); elseif (x <= 2.3e+263) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (x <= 7.2e+127) tmp = y - x; elseif (x <= 2.3e+263) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[x, 7.2e+127], N[(y - x), $MachinePrecision], If[LessEqual[x, 2.3e+263], N[(x * y), $MachinePrecision], (-x)]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 7.2 \cdot 10^{+127}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;x \leq 2.3 \cdot 10^{+263}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if x < 7.19999999999999958e127Initial program 100.0%
Taylor expanded in x around 0 82.7%
if 7.19999999999999958e127 < x < 2.29999999999999997e263Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around inf 75.7%
if 2.29999999999999997e263 < x Initial program 100.0%
Taylor expanded in x around inf 100.0%
*-commutative100.0%
Simplified100.0%
Taylor expanded in y around 0 100.0%
neg-mul-1100.0%
Simplified100.0%
Final simplification82.2%
(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 x around inf 57.4%
*-commutative57.4%
Simplified57.4%
Taylor expanded in y around 0 35.4%
neg-mul-135.4%
Simplified35.4%
Final simplification35.4%
herbie shell --seed 2023293
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))