# straight-line program

###### Definition 1.

Given a set $S$, a straight-line program (SLP) is a family of functions $\mathcal{F}=\{f_{i}:1\leq i\leq m\}$

 $f_{i}:S^{n+i}\rightarrow S$

for some fixed $n\in\mathbb{N}$. An SLP is evaluated on a tuple $(s_{1},\dots,s_{n})$ by recursion in the following way: $f_{1}$ is evaluated on $(s_{1},\dots,s_{n})$ as a function. The remaining evaluations are recursive. So $f_{2}(s_{1},\dots,s_{n})$ denotes

 $f_{2}(s_{1},\dots,s_{n}):=f_{2}(s_{1},\dots,s_{n},f_{1}(s_{1},\dots,s_{n})).$

and in general

 $f_{i+1}(s_{1},\dots,s_{n}):=f_{i+1}(s_{1},\dots,s_{n},f_{1}(s_{1},\dots,s_{n})% ,\dots,f_{i}(s_{1},\dots,s_{n})).$

The final output $f_{m}(s_{1},\dots,s_{n})$ is denoted $\mathcal{F}(s_{1},\dots,s_{n})$. In this way we treat $\mathcal{F}$ as function from $S^{n}\rightarrow S$.

SLPs arrise from the multiple meansings of expressions of the sort $a^{n}$ in a some algebraic structure  $S$. First of all, one can formally treat $a^{n}$ as the word $a\cdots a$ in $S$. Secondly this can be interpreted as the actual result of this mulitplication.

In the former meaning, actually storing a word of the form $a^{n}$ as $a\cdots a$ is difficult hence it is abreviated. Other examples include words such as $a^{10}(bc)^{6}$ where the values of $a,b,c$ are continually changing or even unknown. Here an SLP can encode this word in such a way that if we replace $a$ by $bc$, then the resulting new word would result simply by evaluation the SLP at the input $(bc,b,c)$ instead of $(a,b,c)$.

In the second treatment where we whish to actually evaluate $a^{n}$ and the like, we find the problem of understanding what $a^{n}$ means as a program. Certainly we may have $a^{4}=(aa)(aa)=a(a(aa))$ etc. However this equivalence neglects the problem of selecting a method of computing the result. Usually an efficient method is desired. An SLP developed from simple functions  such as $f(x)=x^{2}$ and $f(x,y)=x+y$ formally address this problem.

The term straight-line reflects the fact that evaluating an SLP can be achieved by a program which does not branch or loop so its execution is a straight-line. It is common for SLPs to be built entirely from simple functions such as $f(x,y)=x+y$ or $f(x)=x\times x$.

Because each element $f_{i}$ of an SLP is evaluated externally only on $s_{1},\dots,s_{n}$ and the remaining inputs come internally from previous $f_{j}$, $1\leq j\leq i$, it is convient to write definitions for $f_{i}$ as taking inputs only from $(s_{1},\dots,s_{n})$ and implicitly allowing for the use of the outputs of previous $f_{j}$’s.

It is possible for a function $f:S^{n}\rightarrow S$ to be defined equivalently by multiple SLPs and so a notion of equality of SLPs is stronger than equivalence of final outputs.

###### Definition 2.

Two SLPs $\mathcal{F}=\{f_{i}:1\leq i\leq m\}$ and $\mathcal{G}=\{g_{i}:1\leq i\leq k\}$ are equivalent     if $\mathcal{F}$ and $\mathcal{G}$ can be evaluated on the same inputs and for every input $(s_{1},\dots,s_{n})$, $\mathcal{F}(s_{1},\dots,s_{n})=\mathcal{G}(s_{1},\dots,s_{n})$. When and SLP $\mathcal{F}$ is equivalent to a trivial SLP $\{f:S^{n}\rightarrow S\}$ we say that $\mathcal{F}$ is an SLP representation of $f$.

Every function $f:S^{n}\rightarrow S$ can be expressed as an SLP trivially by $\mathcal{F}=\{f\}$. However, this SLP is typically the least optimal for the actual evaluation of the output for a given input. This leads to a hierarchy imposed on equivalent SLPs based on their associated computational length.

It is evident that the trivial SLP of an algebraic expression has length equal to the length of the word.

 Title straight-line program Canonical name StraightlineProgram Date of creation 2013-03-22 16:16:02 Last modified on 2013-03-22 16:16:02 Owner Algeboy (12884) Last modified by Algeboy (12884) Numerical id 10 Author Algeboy (12884) Entry type Definition Classification msc 08A99 Classification msc 20A05 Classification msc 20-00 Related topic word Related topic Word Defines straight-line program Defines SLP Defines SLP representation