0

I'd like to write pseudo code with mathematical notation, I will write the code phrases in Python. I need to know if

first question:

aList = []
aList.empty() is not True

equals

$aList \neq \emptyset $

second question

a = 5
aList.append(a)

equals

$a \gets 5$

$aList \cup a$

third question

how to write to get the first element and remove it from the list i.e.:

curElement = aList[0]
aList.remove(0)

Thanks for any advice the Internet couldn't help me out.

Kind Regards

  • 1
    I don't understand your first question and your second. – 3x89g2 Aug 31 '16 at 20:12
  • Pardon me. 1) A list is often referred as a vector or a dynamic array i.e.: a container for multiple values. 2) I updated the question, the goal is to insert/append a new value to this list/array - I know $\cup$ usually stand for uniting two sets, however I'm not sure if that counts for a set and a sole value to as shown in the question – user3085931 Aug 31 '16 at 20:16
  • 1
    I see. For second question, it should be $aList \cup {a}$. For the third one, it should be $aList - {curlElement}$. – 3x89g2 Aug 31 '16 at 20:19
  • I guess $aList -{ curElement }$ stands for removing the element from the list, but how do I define which element from the set was chosen to assigne $curElement$ beforehand (i.e. how to retrieve an element from an arbitrary position in the set)? – user3085931 Aug 31 '16 at 20:23
  • 1
    We don't have "list" in math. We only have set. – 3x89g2 Aug 31 '16 at 20:25
  • I understand. That came unexpected though – user3085931 Aug 31 '16 at 20:28
  • @Misakov: We have tuples and functions :D – user251257 Aug 31 '16 at 20:39

1 Answers1

1

Notice that mathematicians and computer scientists of that field (type system and so on) do have their own shorter notation for these operations. However, they are not that common among the general public.

What are lists?

There are many list like constructs in math. For mathematician they are all functions. Basically, a list/tuple is a function $f$ from $\{1,\dotsc,n\}$ into a set, say $X$. So typically you define the set of lists with values in $X$ as its Kleene star: $$ X^* = \{ f:\{1,\dotsc, n\} \to X \mid n \in\mathbb N \} = \bigcup_{n\in\mathbb N} X^n, $$ where $\mathbb N$ includes $0$.

Most computer scientists and mathematicians in that field use to work with partial functions. So you could also write $$ X^* = \{ f:\mathbb N\to X \mid \operatorname{dom} f = \{1, \dotsc, |\operatorname{dom} f| \} \}. $$ They also identify $f$ with its graph, that is $$ f = \{ (i,f(i)) \mid i\in\operatorname{dom} f \}. $$

Answer to your question:

Using partial functions you can express

  1. "$f\in X^*$ is a empty list" by $f = \emptyset$,
  2. "$g\in X^*$ is $f\in X^*$ appended with $a\in X$" by $$ g = f \cup \{ (|\operatorname{dom} f| + 1, a) \}, $$
  3. "$g\in X^*$ is $f\in X^*$ removed the first element" by $$ g = \{ (i-1, f(i)) \mid i\in \operatorname{dom} f\setminus\{1\} \}. $$
user251257
  • 9,229
  • First of all thanks for your answer, it brought some light in here. However I guess it looks more complicated as it would make sense in this case. Since the goal of this pseudo code structure is to facilitate the understanding of rather complex text phrase - at this point of the paper for people barely dealing with mathematical expressions. – user3085931 Aug 31 '16 at 21:10
  • 1
    @user3085931: Concerning pseudo code, some common concepts can be explained in text more easily :) There is no need to use formula with uncommon notations or concepts. – user251257 Aug 31 '16 at 21:12
  • Not when considering that programmers tend to be lazy guys, skipping text and rather used to read code ;) I'm thinking about a way inbetween atm – user3085931 Aug 31 '16 at 21:16