
(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 8 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 1.0) y (- x)))
double code(double x, double y) {
return fma((x + 1.0), y, -x);
}
function code(x, y) return fma(Float64(x + 1.0), y, Float64(-x)) end
code[x_, y_] := N[(N[(x + 1.0), $MachinePrecision] * y + (-x)), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(x + 1, y, -x\right)
\end{array}
Initial program 100.0%
fma-neg100.0%
Simplified100.0%
Final simplification100.0%
(FPCore (x y)
:precision binary64
(let* ((t_0 (* x (+ y -1.0))))
(if (<= x -8e-18)
t_0
(if (<= x -2.9e-27)
y
(if (<= x -7.8e-120) (- x) (if (<= x 2.5e-57) y t_0))))))
double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -8e-18) {
tmp = t_0;
} else if (x <= -2.9e-27) {
tmp = y;
} else if (x <= -7.8e-120) {
tmp = -x;
} else if (x <= 2.5e-57) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: t_0
real(8) :: tmp
t_0 = x * (y + (-1.0d0))
if (x <= (-8d-18)) then
tmp = t_0
else if (x <= (-2.9d-27)) then
tmp = y
else if (x <= (-7.8d-120)) then
tmp = -x
else if (x <= 2.5d-57) then
tmp = y
else
tmp = t_0
end if
code = tmp
end function
public static double code(double x, double y) {
double t_0 = x * (y + -1.0);
double tmp;
if (x <= -8e-18) {
tmp = t_0;
} else if (x <= -2.9e-27) {
tmp = y;
} else if (x <= -7.8e-120) {
tmp = -x;
} else if (x <= 2.5e-57) {
tmp = y;
} else {
tmp = t_0;
}
return tmp;
}
def code(x, y): t_0 = x * (y + -1.0) tmp = 0 if x <= -8e-18: tmp = t_0 elif x <= -2.9e-27: tmp = y elif x <= -7.8e-120: tmp = -x elif x <= 2.5e-57: tmp = y else: tmp = t_0 return tmp
function code(x, y) t_0 = Float64(x * Float64(y + -1.0)) tmp = 0.0 if (x <= -8e-18) tmp = t_0; elseif (x <= -2.9e-27) tmp = y; elseif (x <= -7.8e-120) tmp = Float64(-x); elseif (x <= 2.5e-57) tmp = y; else tmp = t_0; end return tmp end
function tmp_2 = code(x, y) t_0 = x * (y + -1.0); tmp = 0.0; if (x <= -8e-18) tmp = t_0; elseif (x <= -2.9e-27) tmp = y; elseif (x <= -7.8e-120) tmp = -x; elseif (x <= 2.5e-57) tmp = y; else tmp = t_0; end tmp_2 = tmp; end
code[x_, y_] := Block[{t$95$0 = N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -8e-18], t$95$0, If[LessEqual[x, -2.9e-27], y, If[LessEqual[x, -7.8e-120], (-x), If[LessEqual[x, 2.5e-57], y, t$95$0]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_0 := x \cdot \left(y + -1\right)\\
\mathbf{if}\;x \leq -8 \cdot 10^{-18}:\\
\;\;\;\;t\_0\\
\mathbf{elif}\;x \leq -2.9 \cdot 10^{-27}:\\
\;\;\;\;y\\
\mathbf{elif}\;x \leq -7.8 \cdot 10^{-120}:\\
\;\;\;\;-x\\
\mathbf{elif}\;x \leq 2.5 \cdot 10^{-57}:\\
\;\;\;\;y\\
\mathbf{else}:\\
\;\;\;\;t\_0\\
\end{array}
\end{array}
if x < -8.0000000000000006e-18 or 2.5000000000000001e-57 < x Initial program 100.0%
Taylor expanded in x around inf 94.5%
if -8.0000000000000006e-18 < x < -2.90000000000000004e-27 or -7.8000000000000003e-120 < x < 2.5000000000000001e-57Initial program 100.0%
Taylor expanded in x around 0 85.7%
if -2.90000000000000004e-27 < x < -7.8000000000000003e-120Initial program 100.0%
Taylor expanded in y around 0 62.8%
mul-1-neg62.8%
Simplified62.8%
Final simplification87.9%
(FPCore (x y)
:precision binary64
(if (<= y -1.0)
(* x y)
(if (<= y 2.65e-92)
(- x)
(if (<= y 2.9e+63) y (if (<= y 2.2e+157) (* x y) y)))))
double code(double x, double y) {
double tmp;
if (y <= -1.0) {
tmp = x * y;
} else if (y <= 2.65e-92) {
tmp = -x;
} else if (y <= 2.9e+63) {
tmp = y;
} else if (y <= 2.2e+157) {
tmp = x * y;
} 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 <= (-1.0d0)) then
tmp = x * y
else if (y <= 2.65d-92) then
tmp = -x
else if (y <= 2.9d+63) then
tmp = y
else if (y <= 2.2d+157) then
tmp = x * y
else
tmp = 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 <= 2.65e-92) {
tmp = -x;
} else if (y <= 2.9e+63) {
tmp = y;
} else if (y <= 2.2e+157) {
tmp = x * y;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -1.0: tmp = x * y elif y <= 2.65e-92: tmp = -x elif y <= 2.9e+63: tmp = y elif y <= 2.2e+157: tmp = x * y else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -1.0) tmp = Float64(x * y); elseif (y <= 2.65e-92) tmp = Float64(-x); elseif (y <= 2.9e+63) tmp = y; elseif (y <= 2.2e+157) tmp = Float64(x * y); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -1.0) tmp = x * y; elseif (y <= 2.65e-92) tmp = -x; elseif (y <= 2.9e+63) tmp = y; elseif (y <= 2.2e+157) tmp = x * y; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -1.0], N[(x * y), $MachinePrecision], If[LessEqual[y, 2.65e-92], (-x), If[LessEqual[y, 2.9e+63], y, If[LessEqual[y, 2.2e+157], N[(x * y), $MachinePrecision], y]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -1:\\
\;\;\;\;x \cdot y\\
\mathbf{elif}\;y \leq 2.65 \cdot 10^{-92}:\\
\;\;\;\;-x\\
\mathbf{elif}\;y \leq 2.9 \cdot 10^{+63}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 2.2 \cdot 10^{+157}:\\
\;\;\;\;x \cdot y\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -1 or 2.8999999999999999e63 < y < 2.2000000000000001e157Initial program 100.0%
Taylor expanded in x around inf 58.1%
*-commutative58.1%
Simplified58.1%
Taylor expanded in y around inf 57.2%
if -1 < y < 2.65000000000000015e-92Initial program 100.0%
Taylor expanded in y around 0 81.2%
mul-1-neg81.2%
Simplified81.2%
if 2.65000000000000015e-92 < y < 2.8999999999999999e63 or 2.2000000000000001e157 < y Initial program 100.0%
Taylor expanded in x around 0 72.8%
Final simplification71.8%
(FPCore (x y) :precision binary64 (if (or (<= y -7.5e-7) (not (<= y 5.7e-92))) (* (+ x 1.0) y) (* x (+ y -1.0))))
double code(double x, double y) {
double tmp;
if ((y <= -7.5e-7) || !(y <= 5.7e-92)) {
tmp = (x + 1.0) * y;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
real(8) function code(x, y)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8) :: tmp
if ((y <= (-7.5d-7)) .or. (.not. (y <= 5.7d-92))) then
tmp = (x + 1.0d0) * y
else
tmp = x * (y + (-1.0d0))
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.5e-7) || !(y <= 5.7e-92)) {
tmp = (x + 1.0) * y;
} else {
tmp = x * (y + -1.0);
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.5e-7) or not (y <= 5.7e-92): tmp = (x + 1.0) * y else: tmp = x * (y + -1.0) return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.5e-7) || !(y <= 5.7e-92)) tmp = Float64(Float64(x + 1.0) * y); else tmp = Float64(x * Float64(y + -1.0)); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.5e-7) || ~((y <= 5.7e-92))) tmp = (x + 1.0) * y; else tmp = x * (y + -1.0); end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.5e-7], N[Not[LessEqual[y, 5.7e-92]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision], N[(x * N[(y + -1.0), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.5 \cdot 10^{-7} \lor \neg \left(y \leq 5.7 \cdot 10^{-92}\right):\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(y + -1\right)\\
\end{array}
\end{array}
if y < -7.5000000000000002e-7 or 5.70000000000000009e-92 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
if -7.5000000000000002e-7 < y < 5.70000000000000009e-92Initial program 100.0%
Taylor expanded in x around inf 83.0%
Final simplification89.7%
(FPCore (x y) :precision binary64 (if (or (<= y -7.6e-7) (not (<= y 5.7e-92))) (* (+ x 1.0) y) (- (* x y) x)))
double code(double x, double y) {
double tmp;
if ((y <= -7.6e-7) || !(y <= 5.7e-92)) {
tmp = (x + 1.0) * y;
} else {
tmp = (x * 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 <= (-7.6d-7)) .or. (.not. (y <= 5.7d-92))) then
tmp = (x + 1.0d0) * y
else
tmp = (x * y) - x
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if ((y <= -7.6e-7) || !(y <= 5.7e-92)) {
tmp = (x + 1.0) * y;
} else {
tmp = (x * y) - x;
}
return tmp;
}
def code(x, y): tmp = 0 if (y <= -7.6e-7) or not (y <= 5.7e-92): tmp = (x + 1.0) * y else: tmp = (x * y) - x return tmp
function code(x, y) tmp = 0.0 if ((y <= -7.6e-7) || !(y <= 5.7e-92)) tmp = Float64(Float64(x + 1.0) * y); else tmp = Float64(Float64(x * y) - x); end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if ((y <= -7.6e-7) || ~((y <= 5.7e-92))) tmp = (x + 1.0) * y; else tmp = (x * y) - x; end tmp_2 = tmp; end
code[x_, y_] := If[Or[LessEqual[y, -7.6e-7], N[Not[LessEqual[y, 5.7e-92]], $MachinePrecision]], N[(N[(x + 1.0), $MachinePrecision] * y), $MachinePrecision], N[(N[(x * y), $MachinePrecision] - x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -7.6 \cdot 10^{-7} \lor \neg \left(y \leq 5.7 \cdot 10^{-92}\right):\\
\;\;\;\;\left(x + 1\right) \cdot y\\
\mathbf{else}:\\
\;\;\;\;x \cdot y - x\\
\end{array}
\end{array}
if y < -7.60000000000000029e-7 or 5.70000000000000009e-92 < y Initial program 100.0%
Taylor expanded in y around inf 95.9%
if -7.60000000000000029e-7 < y < 5.70000000000000009e-92Initial program 100.0%
Taylor expanded in x around inf 83.0%
*-commutative83.0%
Simplified83.0%
Final simplification89.7%
(FPCore (x y) :precision binary64 (if (<= y -5.4e-7) y (if (<= y 5.7e-92) (- x) y)))
double code(double x, double y) {
double tmp;
if (y <= -5.4e-7) {
tmp = y;
} else if (y <= 5.7e-92) {
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 <= (-5.4d-7)) then
tmp = y
else if (y <= 5.7d-92) then
tmp = -x
else
tmp = y
end if
code = tmp
end function
public static double code(double x, double y) {
double tmp;
if (y <= -5.4e-7) {
tmp = y;
} else if (y <= 5.7e-92) {
tmp = -x;
} else {
tmp = y;
}
return tmp;
}
def code(x, y): tmp = 0 if y <= -5.4e-7: tmp = y elif y <= 5.7e-92: tmp = -x else: tmp = y return tmp
function code(x, y) tmp = 0.0 if (y <= -5.4e-7) tmp = y; elseif (y <= 5.7e-92) tmp = Float64(-x); else tmp = y; end return tmp end
function tmp_2 = code(x, y) tmp = 0.0; if (y <= -5.4e-7) tmp = y; elseif (y <= 5.7e-92) tmp = -x; else tmp = y; end tmp_2 = tmp; end
code[x_, y_] := If[LessEqual[y, -5.4e-7], y, If[LessEqual[y, 5.7e-92], (-x), y]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.4 \cdot 10^{-7}:\\
\;\;\;\;y\\
\mathbf{elif}\;y \leq 5.7 \cdot 10^{-92}:\\
\;\;\;\;-x\\
\mathbf{else}:\\
\;\;\;\;y\\
\end{array}
\end{array}
if y < -5.40000000000000018e-7 or 5.70000000000000009e-92 < y Initial program 100.0%
Taylor expanded in x around 0 54.4%
if -5.40000000000000018e-7 < y < 5.70000000000000009e-92Initial program 100.0%
Taylor expanded in y around 0 82.4%
mul-1-neg82.4%
Simplified82.4%
Final simplification67.8%
(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 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 36.8%
Final simplification36.8%
herbie shell --seed 2024066
(FPCore (x y)
:name "Data.Colour.SRGB:transferFunction from colour-2.3.3"
:precision binary64
(- (* (+ x 1.0) y) x))