
(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 (- (+ 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-rgt-in100.0%
*-lft-identity100.0%
Applied egg-rr100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (<= y -1.3e+229)
(- y x)
(if (or (<= y -3e+125) (and (not (<= y -1.04e+111)) (<= y -2.7e+15)))
(* x y)
(- y x))))
double code(double x, double y) {
double tmp;
if (y <= -1.3e+229) {
tmp = y - x;
} else if ((y <= -3e+125) || (!(y <= -1.04e+111) && (y <= -2.7e+15))) {
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.3d+229)) then
tmp = y - x
else if ((y <= (-3d+125)) .or. (.not. (y <= (-1.04d+111))) .and. (y <= (-2.7d+15))) 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.3e+229) {
tmp = y - x;
} else if ((y <= -3e+125) || (!(y <= -1.04e+111) && (y <= -2.7e+15))) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.3e+229: tmp = y - x elif (y <= -3e+125) or (not (y <= -1.04e+111) and (y <= -2.7e+15)): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if (y <= -1.3e+229) tmp = Float64(y - x); elseif ((y <= -3e+125) || (!(y <= -1.04e+111) && (y <= -2.7e+15))) 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.3e+229) tmp = y - x; elseif ((y <= -3e+125) || (~((y <= -1.04e+111)) && (y <= -2.7e+15))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.3e+229], N[(y - x), $MachinePrecision], If[Or[LessEqual[y, -3e+125], And[N[Not[LessEqual[y, -1.04e+111]], $MachinePrecision], LessEqual[y, -2.7e+15]]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.3 \cdot 10^{+229}:\\
\;\;\;\;y - x\\
\mathbf{elif}\;y \leq -3 \cdot 10^{+125} \lor \neg \left(y \leq -1.04 \cdot 10^{+111}\right) \land y \leq -2.7 \cdot 10^{+15}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -1.3e229 or -3.00000000000000015e125 < y < -1.04e111 or -2.7e15 < y Initial program 100.0%
Taylor expanded in x around 0 87.8%
if -1.3e229 < y < -3.00000000000000015e125 or -1.04e111 < y < -2.7e15Initial program 100.0%
Taylor expanded in x around inf 71.7%
*-commutative71.7%
Simplified71.7%
Taylor expanded in y around inf 71.7%
Final simplification85.2%
(FPCore (x y) :precision binary64 (if (or (<= x -1.0) (not (<= x 0.043))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.0) || !(x <= 0.043)) {
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 <= (-1.0d0)) .or. (.not. (x <= 0.043d0))) 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 <= -1.0) || !(x <= 0.043)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.0) or not (x <= 0.043): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.0) || !(x <= 0.043)) 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 <= -1.0) || ~((x <= 0.043))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.0], N[Not[LessEqual[x, 0.043]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1 \lor \neg \left(x \leq 0.043\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1 or 0.042999999999999997 < x Initial program 100.0%
Taylor expanded in x around inf 98.7%
*-commutative98.7%
Simplified98.7%
if -1 < x < 0.042999999999999997Initial program 100.0%
Taylor expanded in x around 0 98.6%
Final simplification98.7%
(FPCore (x y) :precision binary64 (if (<= y -1.0) (* x y) (if (<= y 1.0) (- x) (* x y))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 1.0) {
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 <= 1.0d0) 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 <= 1.0) {
tmp = -x;
} else {
tmp = x * y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 1.0: 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 <= 1.0) 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 <= 1.0) 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, 1.0], (-x), N[(x * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 1:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;x \cdot y\\
\end{array}
\end{array}
if y < -1 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 42.0%
*-commutative42.0%
Simplified42.0%
Taylor expanded in y around inf 42.0%
if -1 < y < 1Initial program 100.0%
Taylor expanded in x around inf 76.0%
*-commutative76.0%
Simplified76.0%
Taylor expanded in y around 0 75.1%
mul-1-neg75.1%
Simplified75.1%
Final simplification58.6%
(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 59.0%
*-commutative59.0%
Simplified59.0%
Taylor expanded in y around 0 39.1%
mul-1-neg39.1%
Simplified39.1%
Final simplification39.1%
herbie shell --seed 2023297
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))