
(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 (- (+ 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 (<= y -1.9e+33) (not (<= y 0.021))) (* y (+ x 1.0)) (- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.9e+33) || !(y <= 0.021)) {
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 <= (-1.9d+33)) .or. (.not. (y <= 0.021d0))) 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 <= -1.9e+33) || !(y <= 0.021)) {
tmp = y * (x + 1.0);
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.9e+33) or not (y <= 0.021): tmp = y * (x + 1.0) else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.9e+33) || !(y <= 0.021)) 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 <= -1.9e+33) || ~((y <= 0.021))) tmp = y * (x + 1.0); else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.9e+33], N[Not[LessEqual[y, 0.021]], $MachinePrecision]], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+33} \lor \neg \left(y \leq 0.021\right):\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.90000000000000001e33 or 0.0210000000000000013 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
if -1.90000000000000001e33 < y < 0.0210000000000000013Initial program 100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in y around 0 98.0%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (<= y -1.9e+33) (* y (+ x 1.0)) (if (<= y 0.021) (- y x) (+ y (* y x)))))
double code(double x, double y) {
double tmp;
if (y <= -1.9e+33) {
tmp = y * (x + 1.0);
} else if (y <= 0.021) {
tmp = y - x;
} else {
tmp = y + (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.9d+33)) then
tmp = y * (x + 1.0d0)
else if (y <= 0.021d0) then
tmp = y - x
else
tmp = y + (y * x)
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -1.9e+33) {
tmp = y * (x + 1.0);
} else if (y <= 0.021) {
tmp = y - x;
} else {
tmp = y + (y * x);
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.9e+33: tmp = y * (x + 1.0) elif y <= 0.021: tmp = y - x else: tmp = y + (y * x) return tmp
function code(x, y) tmp = 0.0 if (y <= -1.9e+33) tmp = Float64(y * Float64(x + 1.0)); elseif (y <= 0.021) tmp = Float64(y - x); else tmp = Float64(y + Float64(y * x)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.9e+33) tmp = y * (x + 1.0); elseif (y <= 0.021) tmp = y - x; else tmp = y + (y * x); end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.9e+33], N[(y * N[(x + 1.0), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 0.021], N[(y - x), $MachinePrecision], N[(y + N[(y * x), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.9 \cdot 10^{+33}:\\
\;\;\;\;y \cdot \left(x + 1\right)\\
\mathbf{elif}\;y \leq 0.021:\\
\;\;\;\;y - x\\
\mathbf{else}:\\
\;\;\;\;y + y \cdot x\\
\end{array}
\end{array}
if y < -1.90000000000000001e33Initial program 100.0%
Taylor expanded in y around inf 100.0%
if -1.90000000000000001e33 < y < 0.0210000000000000013Initial program 100.0%
Taylor expanded in x around 0 98.0%
Taylor expanded in y around 0 98.0%
if 0.0210000000000000013 < y Initial program 100.0%
Taylor expanded in y around inf 100.0%
distribute-rgt-in100.0%
*-un-lft-identity100.0%
*-commutative100.0%
+-commutative100.0%
Applied egg-rr100.0%
Final simplification98.9%
(FPCore (x y) :precision binary64 (if (or (<= x -2.65e-73) (not (<= x 6.8e-55))) (- x) y))
double code(double x, double y) {
double tmp;
if ((x <= -2.65e-73) || !(x <= 6.8e-55)) {
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 ((x <= (-2.65d-73)) .or. (.not. (x <= 6.8d-55))) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((x <= -2.65e-73) || !(x <= 6.8e-55)) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -2.65e-73) or not (x <= 6.8e-55): tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if ((x <= -2.65e-73) || !(x <= 6.8e-55)) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((x <= -2.65e-73) || ~((x <= 6.8e-55))) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -2.65e-73], N[Not[LessEqual[x, 6.8e-55]], $MachinePrecision]], (-x), y]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.65 \cdot 10^{-73} \lor \neg \left(x \leq 6.8 \cdot 10^{-55}\right):\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if x < -2.64999999999999986e-73 or 6.79999999999999946e-55 < x Initial program 100.0%
Taylor expanded in y around 0 61.5%
neg-mul-161.5%
Simplified61.5%
if -2.64999999999999986e-73 < x < 6.79999999999999946e-55Initial program 100.0%
Taylor expanded in x around 0 86.7%
Final simplification72.8%
(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 x))
double code(double x, double y) {
return y - x;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
code = y - x
end function
public static double code(double x, double y) {
return y - x;
}
def code(x, y): return y - x
function code(x, y) return Float64(y - x) end
function tmp = code(x, y) tmp = y - x; end
code[x_, y_] := N[(y - x), $MachinePrecision]
\begin{array}{l}
\\
y - x
\end{array}
Initial program 100.0%
Taylor expanded in x around 0 81.6%
Taylor expanded in y around 0 81.6%
(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 43.0%
herbie shell --seed 2024180
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))