Lists and arrays, part by part In this challenge, you'll get four different but somewhat related tasks that must be solved in a specific manner. First, I'll explain the tasks, then follows an explanation of how you must solve it.

Your code should for all four tasks take two positive integers as input: n,m, where n&lt;m. All tasks must be solved in the same language. The orientation of matrices are optional (n-by-m may be interpreted as "n rows, m columns", or "n columns, m rows").

Task 1:

Create (and output/print) a vector / list consisting of the elements: n, n+1 ... m-1, m. So, for n=4, m=9, you should output: 4,5,6,7,8,9.

Task 2:

Create (and output/print) a matrix / array / list of lists (or equivalent) looking like this:

n,   n+1, ... m-1, m
n+1, n+2, ... m-1, m+1
...
n+m, n+m+1, ... 2*m-1, 2*m


For n=4, m=9 you should output:

4, 5, 6, 7, 8, 9
5, 6, 7, 8, 9, 10
...
13, 14, 15, 16, 17, 18


Task 3:

Create (and output/print) an n-by-m multiplication table (on any suitable format). Example for n=4, m=9:

1   2   3  4
2   4   6  8
3   6   9  12
4   8  12  16
5  10  15  20
6  12  18  24
7  14  21  28
8  16  24  32
9  18  27  36


Task 4:

Output / print a vector / list consisting of the elements in the multiplication table from task 3, sorted in ascending order, keeping duplicate values. For n=4, m=9, you should output: 1, 2, 2, 3, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, 9, 9, 10, 12, 12, 12, 14, 15, 16, 16, 18, 18, 20, 21, 24, 24, 27, 28, 32, 36.

The challenge:

Now, all the tasks above are quite trivial. The real challenge here is that the code for task 2 must start with the code for task 1, the code for task 3 must start with the code for task 2 and the code for task 4 must start with the code for task 3.

To make it more clear:

Suppose the code for Task 1 is (works in Octave):

@(n,m)(n:m)


Then your code for Task 2 could be (works in Octave):

@(n,m)(n:m)+(0:m)'


The code for task Task 3 must be (doesn't work in Octave):

@(n,m)(n:m)+(0:m)'"Code_for_task_3"


And finally, the code for Task 4 must be (doesn't work in Octave):

@(n,m)(n:m)+(0:m)'"Code_for_task_3""Code_for_task_4"




This is code-golf, so the submission with the shortest code for task 4 in each language wins. As always: Explanations are highly encouraged.
Jelly, 12 bytes

Task 1

r


Try it online!

Task 2

r+þ0r$}


Try it online!

Task 3

r+þ0r$}
×þ


Try it online!

Task 4

r+þ0r$}
×þFṢ


Try it online!

How it works

Task 1

r is the dyadic range atom and does exactly what the task asks for.

Task 2

A dyadic chain that begins with three dyadic links is a fork; the outmost links get evaluated first, then the middle link is called with the results to both sides as arguments.


r behaves as before, yielding [n, …, m].
0r$} is a quicklink (or quickquicklink, if you will).

The quick $ (monadich chain) consumes the links 0 (yield 0) and r (dyadic range) and turns them into a monadic chain. When called with argument k, this will yield [0, …, k].

The quick } (right argument) takes the quicklink created by $ and turns it into a dyadic link that calls 0r$ with 0r$}'s right argument.

0r$} will be called with left argument n and right argument m, so 0r$ is alled with argument m and yields [0, …, m].
+þ is another quicklink. þ (table) will call + (addition) for every element in its left argument and any element in its right argument, grouping the results for each right argument into a single row.

+þ will be called with left argument [n, …, m] and right argument [0, …, m], yielding the desired table.


Task 3

Every line in a Jelly program defines a different link. The last one is the main link and, like C's main function, is the only link that is executed by default. The remaining links can be called from the main link, but we won't do this here.

As before, þ (table) will call × (addition) for every element in its left argument and any element in its right argument, grouping the results for each right argument into a single row.

Since both arguments to ×þ are integers, þ casts them to ranges, transforming the arguments n and m into [1, …, n] and [1, …, m].

Task 4

×þ works as before. The following links are monadic, making them atops, i.e., they are applied on top of the previous ones.

After executing ×þ, F flattens the resulting 2D array, and Ṣ sorts the resulting 1D array.