-
Notifications
You must be signed in to change notification settings - Fork 5
/
20A05-ExampleOfStraightlineProgram.tex
176 lines (106 loc) · 4.06 KB
/
20A05-ExampleOfStraightlineProgram.tex
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
\documentclass[12pt]{article}
\usepackage{pmmeta}
\pmcanonicalname{ExampleOfStraightlineProgram}
\pmcreated{2013-03-22 16:16:18}
\pmmodified{2013-03-22 16:16:18}
\pmowner{Algeboy}{12884}
\pmmodifier{Algeboy}{12884}
\pmtitle{example of straight-line program}
\pmrecord{7}{38382}
\pmprivacy{1}
\pmauthor{Algeboy}{12884}
\pmtype{Example}
\pmcomment{trigger rebuild}
\pmclassification{msc}{20A05}
\pmclassification{msc}{20-00}
\pmclassification{msc}{08A99}
\endmetadata
\usepackage{latexsym}
\usepackage{amssymb}
\usepackage{amsmath}
\usepackage{amsfonts}
\usepackage{amsthm}
%%\usepackage{xypic}
%-----------------------------------------------------
% Standard theoremlike environments.
% Stolen directly from AMSLaTeX sample
%-----------------------------------------------------
%% \theoremstyle{plain} %% This is the default
\newtheorem{thm}{Theorem}
\newtheorem{coro}[thm]{Corollary}
\newtheorem{lem}[thm]{Lemma}
\newtheorem{lemma}[thm]{Lemma}
\newtheorem{prop}[thm]{Proposition}
\newtheorem{conjecture}[thm]{Conjecture}
\newtheorem{conj}[thm]{Conjecture}
\newtheorem{defn}[thm]{Definition}
\newtheorem{remark}[thm]{Remark}
\newtheorem{ex}[thm]{Example}
%\countstyle[equation]{thm}
%--------------------------------------------------
% Item references.
%--------------------------------------------------
\newcommand{\exref}[1]{Example-\ref{#1}}
\newcommand{\thmref}[1]{Theorem-\ref{#1}}
\newcommand{\defref}[1]{Definition-\ref{#1}}
\newcommand{\eqnref}[1]{(\ref{#1})}
\newcommand{\secref}[1]{Section-\ref{#1}}
\newcommand{\lemref}[1]{Lemma-\ref{#1}}
\newcommand{\propref}[1]{Prop\-o\-si\-tion-\ref{#1}}
\newcommand{\corref}[1]{Cor\-ol\-lary-\ref{#1}}
\newcommand{\figref}[1]{Fig\-ure-\ref{#1}}
\newcommand{\conjref}[1]{Conjecture-\ref{#1}}
% Normal subgroup or equal.
\providecommand{\normaleq}{\unlhd}
% Normal subgroup.
\providecommand{\normal}{\lhd}
\providecommand{\rnormal}{\rhd}
% Divides, does not divide.
\providecommand{\divides}{\mid}
\providecommand{\ndivides}{\nmid}
\providecommand{\union}{\cup}
\providecommand{\bigunion}{\bigcup}
\providecommand{\intersect}{\cap}
\providecommand{\bigintersect}{\bigcap}
\begin{document}
SLPs can be used to shorten computations of algebraic expressions.
For example: The product $5^{19}$ may be evaluated in fewer than 19 multiplication.
Let $f_0(x)=x$ and $f_{i+1}(x)=f_{i}(x)\cdot f_{i}(x)$, for $i\in \mathbb{N}$.
Evidently
\[f_i(x) =x^{2^i},\qquad \forall i\in\mathbb{N}.\]
However, we do not evaluate $f_i(5)$ as $5^i$. For instance, to compute $f_3(5)=5^8$ we
follow the program. Expand the first the expression from the left first until we
reach an $f_0(x)$ term:
\begin{eqnarray*}
f_3(5) & = & f_2(5)\cdot f_2(5) \\
& = & ( f_1(5)\cdot f_1(5) )\cdot f_2(5)\\
& = & ( ( f_0(5)\cdot f_0(5) ) \cdot f_1(5) ) \cdot f_2(5).
\end{eqnarray*}
Now evaluate the terminal parts and store all the intermediate results:
\begin{eqnarray*}
f_0(5) & = & 5,\\
f_1(5) & = & f_0(5)\cdot f_0(5)=5\cdot 5=25,\\
f_2(5) & = & f_1(5)\cdot f_1(5) = 25\cdot 25 = 625,\textnormal{ and }\\
f_3(5) & = & 625\cdot 625=390625.
\end{eqnarray*}
The total number of multiplications here was 3, rather than 8.
Then $x^{19}$ can be encoded as an SLP using the binary number for 19.
First, write 19 in binary (base 2):
\[ 19=1\cdot 2^4+0\cdot 2^3+0\cdot 2^2+1\cdot 2^1+1\cdot 2^0,\]
or rather $10011$ in the usual binary notation.
\begin{equation*}
\begin{split}
\mathcal{F}(x) & = f_4(x)^1 \cdot f_3(x)^0 \cdot f_2(x)^0\cdot f_1(x)^1\cdot f_0(x)^1\\
& = f_4(x)\cdot f_1(x)\cdot f_0(x).
\end{split}
\end{equation*}
\emph{Remark.} To evaluate this SLP we had to store intermediate values that
were ultimately not part of the final answer. In this example the final answer
was much larger than the intermediate steps and so we are free to assume that
any memory used in the process was far less than what was required for the final
outcome. However, it is entirely possible that evaluating an SLP will at times
use far more memory than required by the final product and may therefore be
infeasible.
%%%%%
%%%%%
\end{document}