How to describe a function that depends on the cardinality of a vector with mathematical notation

164 Views Asked by At

I have to describe a code I have written using formal mathematical notation, but I don't know how to define an operation that depends on the number of elements.

Here's an example pseudocode:

example_function(vector):
  relevant_values = 0
  positive_values = 0
  for each element of vector:
    if element > 0.7:
      relevant_values += 1
      positive_values += 1
    if element < 0.3:
      relevant_values += 1

  return positive_values/relevant_values

Given the example pseudocode above I need to describe it as a function something like:

\begin{equation} f(\mathbf{v}) = \text{something} \end{equation}

I want to know if this is even possible, and any directions on where I can possibly find the answer will be good as well.

2

There are 2 best solutions below

0
On

Guide:

There are a few ways.

  • we can use the cardinality of a set , $A$, using notation $|A|$. Hence you just have to describe the set.

  • Alternatively, we can also use indicator variable. $\mathbb{1}_p$ to take value $1$ if condition $p$ holds and $0$ otherwise and then sum it up. For example, if we want to check whether the first element is more than $0.7$, we can write $\mathbb{1}_{v_1>0.7}$. If we want to check how many elements in the vector satisfy that condition, just use an index and sum it up, $\sum_{i=1}^{n} \mathbb{1}_{v_i>0.7}$.

Do give it a try, edit your post, and discuss further if you need further help.

0
On

You can simply say

$f(v)$ is the ratio of the number of elements of $v$ that are greater than $0.7$ to the number that are either greater than $0.7$ or less than $0.3$.

That is perfectly respectable mathematics and will be much kinder to your readers than asking them to parse complicated notation.

If you must have more formality, you could say

Let $n$ be the number of elements of $v$ greater than $0.7$ and $m$ the number less than $0.3$. Then $f(v) = n/(m+n)$.

In general terms: "formal mathematics" does not mean "use symbols rather than words" unless you are studying mathematical logic.