How to calculate Upper/Low sums of an arbitrary partition?

If I'm given a function $f$ that is continuous on $[a,b]$ and asked to find the Upper sum $U(f,P)$ and Lower sum $L(f,P)$ where $P$ is an arbitrary partition of of a given interval $I$; $P$ = $\{x_i\}_{i=0}^n$.

$$U(f,P) = \sum_{i=1}^n M_i (x_i - x_{i-1}) \; \text{where} \; M_i = \sup\{f(x):p_0 ,..., p_{i-1}\}$$ $$L(f,P) = \sum_{i=1}^n m_i (x_i - x_{i-1}) \; \text{where} \; m_i = \inf\{f(x):p_0 ,..., p_{i-1}\}$$

How would I calculate the upper/lower sums of arbitrary partition $P$ = $\{x_i\}_{i=0}^n$ since I do not know my $n$ value?

If the function is is either increasing or decreasing over $I$, would I just choose the right or left endpoint of $I$ as my $M_i$ or $m_i$ value and simplify $(x_i - x_{i-1})$ to $(b-a)$?

If my function isn't either increasing or decreasing over $I$, how would I calculate my sums with no given partition?

• What is the context of this question? Usually you do not want to compute the sums directly. You are correct that for monotonous function you pick left of right endpoint. – Korf May 27 '18 at 15:02
• I'm being asked to calculate the upper and lower sums of a couple of given functions, over a given interval and for some, the partitions have been given and for others, it just says P is an arbitrary partition. However, the functions in which P is not defined, the functions are monotone over I, so I was just wondering what I was to do if the function was not monotone and I was told to calculate the Upper/Lower sums and P was not specified. – miweo May 27 '18 at 15:07
• That seems a bit strange to me. It might be possible that the sums actually do not depend on the partitioning, like for example for Dirichlet function. – Korf May 27 '18 at 15:17