### Assignment 1

Distributed: Nov 9 - Solutions Emailed in: Nov 12/13 - Resolved: Nov 16

#### Information Systems for Business Applications, Harold Boley, Winter 1998

General hints: Use the RelFun implementation where possible for
this and later assignments.
Here, you can paste `az`-*definitions* and *calls* into a file named `solve1.bat`, edit possible
`more`'s/`tupof`'s into this file, and issue `exec solve1`.
Also, you may paste or type `az`-less *definitions* into a file named `solve1.rfp`, issue `consult solve1`, and test your calls.
**a)** Compute/explain all results of the following calls after
the definitions made by
`exec opstup` :

tup(1, [2, 3]) % (how) can this be written without tup?
tup(1+(0), [2, 3]) % and that? builtin: 1+(N) = +(N,1)
tup(1 | [2, 3]) % (how) can this be written without tup?
tup(1+(0) | [2, 3]) % and that?
smultup(0.5, [1.12, 4.75, 0.81])
addtup([3.14, -2.48, 7.02], smultup(0.5, [1.12, 4.75, 0.81]))
combtup[max]([3.14, -2.48, 7.02], [1.12, 4.75, 0.81]) % maximum
combtup[max](maptup[sqrt]([1.12, 4.75, 0.81]),[1.12, 4.75, 0.81])
combtup[swap]([1, 2, 3], [a, b, c])
combtup[listswap]([X, Y], [a, b])
maptup[round](order(N,time[Y,11,D])) % rounding to an integer
tupof(maptup[1-](order(N,time[1998 | MD]))) % 1-(N) = -(N,1)

**b)** Given the definition of `cns` below,
what do its subsequent calls produce? Give equivalent `tup` calls.

az cns(A1, A2toN) !& [A1 | A2toN].
cns(1, [])
cns(1, [2, 3])
cns(X1, [X2, X3])
cns(X, Y)
cns(1-(2), cns(2, [3]))

Which definitions from
`exec opstup`
could be slightly simplified by using `cns`?

What does the definition `initup` below produce for its sample calls?

az initup(I,0) !& [].
az initup(I,N) !& cns(I,initup(I,1-(N))). % 1- as in a)
initup(1.0, 0)
initup(0.0, 5)
initup(abc, 2)
initup(X, 3)
initup(initup(X, 3), 3)

Give the equivalent mathematical equations for the `initup` definition.

Like any binary function, `initup` can be used as an
actual parameter to `combtup`; compute/explain result below. Define functions `initupi[I]`
and `initupn[N]` as unary versions of `initup` and briefly
explain the results of their below uses as `maptup` parameters.

combtup[initup]([0.0, abc, X], [5, 2, 3])
maptup[initupi[abc]]([5, 2, 3])
maptup[initupn[2]]([0.0, abc, X])

**c)** Recursively define the product of *two* N-tuples (of equal N) as a function `tmultup` satisfying these mathematical equations:

tmultup([],[]) = 0 for N=0
tmultup([a1, a2, ..., aN], [b1, b2, ..., bN]) =
a1*b1 + a2*b2 + ... + aN*bN for N>0

How does `tmultup` differ from `combtup[*]`?
Now try to parameter-abstract `tmultup`'s use of both "`*`" and
"`+`" into a higher-order reduction function `redtup[Z,E,F]`,
where `F` is an element-level function and `E` is a tuple-level function with neutral element `Z`,
such that we get `tmultup = redtup[0,+,*]` and `combtup[F] = redtup[[],cns,F]`, with `cns` from **b)**.
**d)** Define a further recursive function of your own choosing in
two mathematical equations and in the corresponding RelFun syntax.