Question: *Now I'm a programmer who's recently discovered how bad he is when it comes to mathematics and decided to focus a bit on it from that point forward, so **I apologize if my question insults your intelligence**.*

In mathematics, is there the concept of strings that is used in programming? i.e. a permutation of characters.

As an example, say I wanted to translate the following into mathematical notation:

```
let s be a string of n number of characters.

```

Reason being I would want to use that representation in find other things about string `s`, such as its length: `len(s)`.

How do you formally represent such a thing in mathematics?

---

Talking more practically, so to speak, let's say I wanted to mathematically explain such a function:

```
fitness(s,n) = 1 / |n - len(s)|

```

Or written in more "programming-friendly" sort of way:

```
fitness(s,n) = 1 / abs(n - len(s))

```

*I used this function to explain how a fitness function for a given GA works; the question was about finding strings with 5 characters, and I needed the solutions to be sorted in ascending order according to their fitness score, given by the above function.*

So my question is, **how do you represent the above pseudo-code in mathematical notation?**

Answer: 
You can use the notation of language theory, which is used to discuss things like regular languages, context free grammars, compiler theory, etc. A quick overview:

* A set of characters is known as an **alphabet**. You could write: "Let *A* be the ASCII alphabet, a set containing the 128 ASCII characters."
* A **string** is a sequence of characters. ε is the empty string.
* A set of strings is formally known as a **language**. A common statement is, "Let *s* ∈ *L* be a string in language *L*."
* Concatenating alphabets produces sets of strings (languages). *A* represents all 1-character strings, *A**A*, also written *A*2, is the set of all two character strings. *A*0 is the set of all zero-length strings and is precisely *A*0 = {ε}. (It contains exactly one string, the empty string.)
* *A*\* is special notation and represents the set of all strings over the alphabet *A*, of any length. That is, *A*\* = *A*0 ∪ *A*1 ∪ *A*2 ∪ *A*3 ... . You may recognize this notation from regular expressions.
* For length use absolute value bars. The length of a string *s* is |*s*|.

So for your statement:

> 
> let s be a string of n number of characters.
> 
> 
> 

You could write:

> 
> Let *A* be a set of characters and *s* ∈ *A**n* be a string of *n* characters. The length of *s* is |*s*| = *n*.
> 
> 
>
Mathematically, you have explained `fitness(s, n)` just fine as long as `len(s)` is well-defined.

In CS texts, a string *s* over a set *S* is defined as a finite ordered list of elements of *S* and its length is often written as *|s|* - but this is only notation, and doesn't change the (mathematical) meaning behind your definition of `fitness`, which is pretty clear just how you've written it.