
(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 5 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 (- (* (+ 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}
Initial program 100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(if (or (<= y -5e+70)
(not
(or (<= y 6.8e+142) (and (not (<= y 2.55e+215)) (<= y 5.6e+236)))))
(* x y)
(- y x)))
double code(double x, double y) {
double tmp;
if ((y <= -5e+70) || !((y <= 6.8e+142) || (!(y <= 2.55e+215) && (y <= 5.6e+236)))) {
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 <= (-5d+70)) .or. (.not. (y <= 6.8d+142) .or. (.not. (y <= 2.55d+215)) .and. (y <= 5.6d+236))) 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 <= -5e+70) || !((y <= 6.8e+142) || (!(y <= 2.55e+215) && (y <= 5.6e+236)))) {
tmp = x * y;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -5e+70) or not ((y <= 6.8e+142) or (not (y <= 2.55e+215) and (y <= 5.6e+236))): tmp = x * y else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -5e+70) || !((y <= 6.8e+142) || (!(y <= 2.55e+215) && (y <= 5.6e+236)))) tmp = Float64(x * y); else tmp = Float64(y - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -5e+70) || ~(((y <= 6.8e+142) || (~((y <= 2.55e+215)) && (y <= 5.6e+236))))) tmp = x * y; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -5e+70], N[Not[Or[LessEqual[y, 6.8e+142], And[N[Not[LessEqual[y, 2.55e+215]], $MachinePrecision], LessEqual[y, 5.6e+236]]]], $MachinePrecision]], N[(x * y), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+70} \lor \neg \left(y \leq 6.8 \cdot 10^{+142} \lor \neg \left(y \leq 2.55 \cdot 10^{+215}\right) \land y \leq 5.6 \cdot 10^{+236}\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if y < -5.0000000000000002e70 or 6.7999999999999996e142 < y < 2.55e215 or 5.59999999999999985e236 < y Initial program 100.0%
Taylor expanded in x around inf 64.8%
*-commutative64.8%
Simplified64.8%
Taylor expanded in y around inf 64.8%
if -5.0000000000000002e70 < y < 6.7999999999999996e142 or 2.55e215 < y < 5.59999999999999985e236Initial program 100.0%
Taylor expanded in x around 0 87.9%
Final simplification80.5%
(FPCore (x y) :precision binary64 (if (or (<= x -1.05) (not (<= x 1.0))) (- (* x y) x) (- y x)))
double code(double x, double y) {
double tmp;
if ((x <= -1.05) || !(x <= 1.0)) {
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.05d0)) .or. (.not. (x <= 1.0d0))) 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.05) || !(x <= 1.0)) {
tmp = (x * y) - x;
} else {
tmp = y - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (x <= -1.05) or not (x <= 1.0): tmp = (x * y) - x else: tmp = y - x return tmp
function code(x, y) tmp = 0.0 if ((x <= -1.05) || !(x <= 1.0)) 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.05) || ~((x <= 1.0))) tmp = (x * y) - x; else tmp = y - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[x, -1.05], N[Not[LessEqual[x, 1.0]], $MachinePrecision]], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision], N[(y - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.05 \lor \neg \left(x \leq 1\right):\\
\;\;\;\;x \cdot y - x\\
\mathbf{else}:\\
\;\;\;\;y - x\\
\end{array}
\end{array}
if x < -1.05000000000000004 or 1 < x Initial program 100.0%
Taylor expanded in x around inf 99.4%
*-commutative99.4%
Simplified99.4%
if -1.05000000000000004 < x < 1Initial program 100.0%
Taylor expanded in x around 0 98.9%
Final simplification99.1%
(FPCore (x y) :precision binary64 (if (or (<= y -1.75) (not (<= y 1.0))) (* x y) (- x)))
double code(double x, double y) {
double tmp;
if ((y <= -1.75) || !(y <= 1.0)) {
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 ((y <= (-1.75d0)) .or. (.not. (y <= 1.0d0))) then
tmp = x * y
else
tmp = -x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -1.75) || !(y <= 1.0)) {
tmp = x * y;
} else {
tmp = -x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -1.75) or not (y <= 1.0): tmp = x * y else: tmp = -x return tmp
function code(x, y) tmp = 0.0 if ((y <= -1.75) || !(y <= 1.0)) tmp = Float64(x * y); else tmp = Float64(-x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -1.75) || ~((y <= 1.0))) tmp = x * y; else tmp = -x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -1.75], N[Not[LessEqual[y, 1.0]], $MachinePrecision]], N[(x * y), $MachinePrecision], (-x)]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1.75 \lor \neg \left(y \leq 1\right):\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;-x\\
\end{array}
\end{array}
if y < -1.75 or 1 < y Initial program 100.0%
Taylor expanded in x around inf 56.8%
*-commutative56.8%
Simplified56.8%
Taylor expanded in y around inf 55.9%
if -1.75 < y < 1Initial program 100.0%
Taylor expanded in x around inf 74.4%
*-commutative74.4%
Simplified74.4%
Taylor expanded in y around 0 72.8%
neg-mul-172.8%
Simplified72.8%
Final simplification64.4%
(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 65.7%
*-commutative65.7%
Simplified65.7%
Taylor expanded in y around 0 38.0%
neg-mul-138.0%
Simplified38.0%
Final simplification38.0%
herbie shell --seed 2024031
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))