How to express this computer science problem mathematically?

80 Views Asked by At

I am writing my dissertation for a software degree and want to provide a mathematical formula for a function I have.

The code I want to describe consists of two parts. First to build a collection of values by doing a calulation:

The input to this code is three lists of factors labled High, Medium and Low. What the factors are arn't important but how many there are is. Say there may be 5 high factors 7 meduim and 4 low. The number of each catagory of factors is timesed by a weighting. Say 100 for high 50 for meduim and 10 for low.

This looks like: Total Weight $= $(weighting of a high factor $\times$ Count of high factors) $+$ (weighting of a medium factor $\times$ Count of medium factors ) $+$ (weighting of a low factor $\times$ Count of low factors )

Each time it does that sum it adds the outcome to the collection of values.

Secondly afterwards the code selects the top 5 values from this collection and returns them

How would I describe this in a mathematical formula?

1

There are 1 best solutions below

3
On BEST ANSWER

Let be $S = \{a_i \; | \; i \in [[0, n[[\}$ a collection (array) of $n$ elements. We define a map $f: S \to V$, which to each to each element of $S$ associates a value; with $V = \{1, 2, 3, 4, 5\}$.

We denote $argmax_5(S, f)$ the subset of $S$ (ie, $argmax_5(S, f) \in \mathcal{P}(S)$) containing the $5$ elements of $S$ which have the highest values for the function $f$.

You can then use $\#(E)$, the cardinal of a set $E$, for your "count". For example, if the high factors are the set $H$, then you can define the weight of the high factors as $w_H$ and multiply that by $\#(H)$. If you have another question, comment below.