Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it

563690 views
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<Chapter Label="visualisation">
4
<Heading>Visualization of the pictures created</Heading>
5
This chapter describes two easy ways to visualize the images created by using the &IntPic; package. Both require &LaTeX; and some &LaTeX; packages, such as <Package>Tikz</Package> and <Package>pgf</Package>, to be installed and working. One of the ways we will describe is almost completely automatic. It makes use of the function <C>Splash</C>, borrowed from the <Package>Viz</Package> package. The other is not so automatic but has the advantage of not requiring other packages, besides the &LaTeX; ones, and should work in any operation system.
6
7
<P />
8
<!-- <Section>
9
<Heading>Visualization</Heading>-->
10
<Section>
11
<Heading>Viewing using <Package>Viz</Package></Heading>
12
Producing and displaying a picture from a <C>tikz</C> string <A>tkz</A> may me achieved in a simple way. (Warning: extenvive tests have only been done with Linux.) One just have to type the following:
13
<P />
14
<P />
15
<Listing Type="IP\_Splash"><![CDATA[
16
IP_Splash(tkz);
17
]]></Listing>
18
A picture is popped up after this use of the function <C>IP_Splash</C>.<!--<Ref Func="Splash" BookName="viz"/>-->. To see the name of the temporary directory created to perform the computations, and thus being able to copy the files involved to any other place, one should set the info level <C>InfoViz</C> to <M>1</M> or more. The following example illustrates this and the use of some options of the function <C>IP_Splash</C>.<!--<Ref Func="Splash" BookName="viz"/> function of the <Package>Viz</Package> package. -->
19
<!--
20
Setting the option <C>papersize</C> to "a0paper" may be convenient for the visualization of large images.
21
-->
22
For instance, the <C>pdf</C> viewer can be changed.
23
24
<Listing Type="infoviz: temporary directory"><![CDATA[
25
gap> SetInfoLevel(InfoViz,1);
26
gap> IP_Splash(tkz,rec(viewer:="okular"));
27
#I The temporary directory used is: /tmp/tmJcpphI/
28
]]></Listing>
29
30
The temporary directory /tmp/tmJcpphI/ contains the file and vizpicture.tex. The file vizpicture.tex is the &LaTeX; document to be processed. Other files, namely the <C>vizpicture.pdf</C> are created by the <C>pdflatex</C> command that is called by the <C>IP_Splash</C><!--<Ref Func="Splash" BookName="viz"/>--> function.
31
<P/>
32
<C>Warning:</C> In the case of large pictures, it may happen the &LaTeX; memory being exceeded. In this case, no image is produced and the user is not warned.
33
</Section>
34
<Section>
35
<Heading>Viewing without using <Package>Viz</Package></Heading>
36
This section describes a way to visualize images without sing <Package>Viz</Package>. Besides being useful in the case of not having a working copy of <Package>Viz</Package>, it is rather convenient when the decision of where to save the pictures is made. In this case, you may start your gap session in the desired place, the working directory. Furthermore, if your intention is, for instance, to include the images in a document, you may just decide the name for the file containing the <C>tikz</C> code and let your document input it.
37
38
The glogal variables <C>IP_Preamble</C> and <C>Closing</C> can be used to pruduce a complete &LaTeX; document rather than only the <C>tizk</C> code for the picture. The document may then be processed by using <C>pdflatex</C> and the picture viewed by using some <C>pdf</C> viewer. The <C>pdf</C> produced can be included in a &LaTeX; document instead of the <C>tizk</C> code. In the later case, the code is processed each time the document is processed, which should perhaps be avoided in the case of large images.
39
<P/>
40
Note the use of the <C>preview</C> package, which is used to produce the complete picture without having to pay attention to the paper size nor to crop the image. It is useful for viewing purposes and also to include the <C>pdf</C> file produced in a &LaTeX; document to be processed with <C>pdflatex</C>.
41
<Listing Type="Preamble"><![CDATA[
42
gap> Print(IP_Preamble);
43
\documentclass{minimal}
44
\usepackage{amsmath}
45
\usepackage[active,tightpage]{preview}
46
\setlength\PreviewBorder{1pt}
47
\usepackage{pgf}
48
\usepackage{tikz}
49
\usepgfmodule{plot}
50
\usepgflibrary{plothandlers}
51
\usetikzlibrary{shapes.geometric}
52
\usetikzlibrary{shadings}
53
\begin{document}
54
\begin{preview}
55
]]></Listing>
56
<Listing Type="Closing"><![CDATA[
57
gap> Print(IP_Closing);
58
\end{preview}
59
\end{document}
60
]]></Listing>
61
<Subsection>
62
<Heading>A complete example</Heading>
63
Admit you want to produce a document which contains the picture corresponding to the <C>tikz</C> code obtained through the instructions
64
<Listing Type="instructions to obtain some tikz code"><![CDATA[
65
arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;
66
tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;
67
]]></Listing>
68
The picture is:
69
<Alt Only="LaTeX">
70
\begin{center}
71
\includegraphics[width=0.95\textwidth]{../images/pic_for_complete_document.pdf}
72
\end{center}
73
</Alt>
74
<Alt Only="HTML">
75
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/pic_for_complete_document.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
76
</Alt>
77
The elements of the set
78
<M>[1,2,3,4,5,6]</M> are highlighted using the first color (red); those of the set
79
<M>[1,2,3,4,5]</M> are highlighted using the second color (green); those of the set
80
<M>[1,2,3,4]</M> are highlighted using the third color (blue); those of the set
81
<M>[1,2,3]</M> are highlighted using the fourth color (cyan); those of the set
82
<M>[1,2]</M> are highlighted using the fifth color (magenta); those of the set
83
<M>[1]</M> is highlighted using the sixth color (yellow).
84
<P/>
85
Let us explain how the six colors used for the cell containing <M>1</M> are distributed:
86
upper left corner -- red;
87
upper right corner -- green;
88
lower left corner -- blue;
89
lower right corner -- cyan;
90
the number -- magenta;
91
the border -- yellow.
92
<P/>
93
The colors of the cell containing <M>2</M> and <M>3</M> are distributed in a similar way.
94
<P/>
95
The colors of the cell containing <M>4</M>:
96
left -- red;
97
middle -- blue;
98
right -- green.
99
<P/>
100
After the session listed below, the files <C>tikz_pic_for_complete_document.tex</C> and <C>pic_for_complete_document.tex</C> have been created in the current directory (that is, the one where the &GAP; session has started). For other directories, complete paths may have to be given.
101
<Listing Type="the GAP session"><![CDATA[
102
gap> tikzfile := "tikz_pic_for_complete_document.tex";;
103
gap> file := "pic_for_complete_document.tex";;
104
gap>
105
gap> arr := [[1,2,3,4,5,6],[1,2,3,4,5],[1,2,3,4],[1,2,3],[1,2],[1]];;
106
gap> tkz := IP_TikzArrayOfIntegers([1..10],5,rec(highlights:=arr));;
107
gap>
108
gap> FileString(tikzfile,tkz);
109
642
110
gap> FileString(file,Concatenation(IP_Preamble,tkz,IP_Closing));
111
961
112
]]></Listing>
113
Executing something like
114
<Listing Type="the pdf and the jpg of the picture"><![CDATA[
115
pdflatex pic_for_complete_document.tex
116
convert pic_for_complete_document.pdf pic_for_complete_document.jpg
117
]]></Listing>
118
the <C>pdf</C> and the <C>jpg</C> formats of the image have been created. The <C>jpg</C> format is usefull to be included into an html document, for instance.
119
<P/>
120
Note that the tikz code has been saved into the file <C>tikz_pic_for_complete_document.tex</C>. A complete example of a &LaTeX; document follows.
121
<Listing Type="a LaTeX document"><![CDATA[
122
\documentclass{article}
123
\usepackage{amsmath}
124
%\usepackage[active,tightpage]{preview}
125
%\setlength\PreviewBorder{1pt}
126
\usepackage{pgf}
127
\usepackage{tikz}
128
\usepgfmodule{plot}
129
\usepgflibrary{plothandlers}
130
\usetikzlibrary{shapes.geometric}
131
\usetikzlibrary{shadings}
132
\usepackage{graphicx}
133
\author{Author}
134
\title{How to include images in a \LaTeX\ document}
135
\date{June, 2013}
136
\begin{document}
137
%\begin{preview}
138
\maketitle
139
Using the pdf file:
140
141
\begin{center}
142
\includegraphics[width=0.80\textwidth]{../images/pic_for_complete_document.pdf}
143
\end{center}
144
145
Using the PGF/TikZ code:
146
147
\begin{center}
148
\input{../images/tikz_pic_for_complete_document.tex}
149
\end{center}
150
If you want to scale this immage, please chang the ``scale'' in the file
151
\textt{tikz_pic_for_complete_document.tex}
152
%\end{preview}
153
\end{document}
154
]]></Listing>
155
The output, after processing with <C>pdflatex</C> is as follows:
156
<Alt Only="LaTeX">
157
\begin{center}
158
\includegraphics[width=0.95\textwidth]{../images/complete_latex_document.pdf}
159
\end{center}
160
</Alt>
161
<Alt Only="HTML">
162
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/complete_latex_document.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
163
</Alt>
164
165
166
</Subsection>
167
</Section>
168
<Section>
169
<Heading>Other examples of use of the <Package>IntPic</Package> package</Heading>
170
171
<Subsection>
172
<Heading>Varia</Heading>
173
174
The following example shows how to produce <C>tikz</C> code for a picture containing the odd integers from <M>801</M> to <M>999</M>. Each line (except the highest) contains <M>15</M> cells.
175
<Example><![CDATA[
176
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
177
gap> flen := 15;;
178
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
179
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
180
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(highlights:=arr));;
181
]]></Example>
182
The picture obtained highlights the primes, the twin primes and the multiples of <M>3</M>. As the twins are also primes, a gradient is used to highlight them. In this example the default list of colors is used.
183
<Alt Only="LaTeX">
184
\begin{center}
185
\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd}
186
\end{center}
187
</Alt>
188
<Alt Only="HTML">
189
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/primesandtwinsamongodd.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
190
</Alt>
191
The same computations, but defining other color lists.
192
<Example><![CDATA[
193
gap> cls := IP_ColorsCompRedTones;;
194
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
195
gap> flen := 15;;
196
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
197
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
198
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;
199
]]></Example>
200
<Alt Only="LaTeX">
201
\begin{center}
202
\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd_comp_red}
203
\end{center}
204
</Alt>
205
<Alt Only="HTML">
206
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/primesandtwinsamongodd_comp_red.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
207
</Alt>
208
<Example><![CDATA[
209
gap> cls := IP_ColorsDGrayTones;;
210
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
211
gap> flen := 15;;
212
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
213
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
214
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec(colors := cls,highlights:=arr));;
215
]]></Example>
216
<Alt Only="LaTeX">
217
\begin{center}
218
\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd_dark_gray}
219
\end{center}
220
</Alt>
221
<Alt Only="HTML">
222
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/primesandtwinsamongodd_dark_gray.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
223
</Alt>
224
<Example><![CDATA[
225
gap> cls := ["blue","-blue","black"];;
226
gap> rg := Filtered([801..889],u->(u mod 2)<>0);;
227
gap> flen := 15;;
228
gap> twins := Filtered(Primes, p -> p + 2 in Primes);;
229
gap> arr := [Primes,Union(twins,twins+2),Filtered(rg,u->(u mod 3)=0)];;
230
gap> tkz := IP_TikzArrayOfIntegers(rg,flen,rec( colors := cls,highlights:=arr));;
231
]]></Example>
232
<Alt Only="LaTeX">
233
\begin{center}
234
\includegraphics[width=0.95\textwidth]{../images/primesandtwinsamongodd_other}
235
\end{center}
236
</Alt>
237
<Alt Only="HTML">
238
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/primesandtwinsamongodd_other.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
239
</Alt>
240
The following example uses the
241
<Alt Not='Text'>
242
<URL
243
Text='NumericalSgps'>http://www.fc.up.pt/cmup/mdelgado/numericalsgps</URL>
244
</Alt>
245
<Alt Only='Text'>
246
<Package>NumericalSgps</Package>
247
</Alt>
248
package.
249
<Example><![CDATA[
250
gap> #LoadPackage("numericalsgps");
251
gap>
252
gap> ns := NumericalSemigroup(11,19,30,42,59);;
253
gap> cls := ShuffleIP_Colors([IP_ColorsGreenTones,IP_ColorsCompBlueTones]);;
254
gap> flen := 20;;
255
gap> #some notable elements
256
gap> arr := [SmallElementsOfNumericalSemigroup(ns),
257
> GapsOfNumericalSemigroup(ns),
258
> MinimalGeneratingSystemOfNumericalSemigroup(ns),
259
> FundamentalGapsOfNumericalSemigroup(ns),
260
> [ConductorOfNumericalSemigroup(ns)],
261
> PseudoFrobeniusOfNumericalSemigroup(ns)];;
262
gap>
263
gap> tkz := IP_TikzArrayOfIntegers(flen,rec(colors := cls,highlights:=arr));;
264
]]></Example>
265
<Alt Only="LaTeX">
266
\begin{center}
267
\includegraphics[width=0.95\textwidth]{../images/numericalsgp_notable}
268
\end{center}
269
</Alt>
270
<Alt Only="HTML">
271
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/numericalsgp_notable.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
272
</Alt>
273
Using the default colors
274
<Alt Only="LaTeX">
275
\begin{center}
276
\includegraphics[width=0.95\textwidth]{../images/numericalsgp_notable_df_colors}
277
\end{center}
278
</Alt>
279
<Alt Only="HTML">
280
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/numericalsgp_notable_df_colors.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
281
</Alt>
282
</Subsection>
283
<Subsection>
284
<Heading>The banner</Heading>
285
The code in the following example has been used to produce one possible banner for the homepage of the &IntPic; package. It is a nice picture that gives an idea about the primes less than <M>10000</M>. Of course, other ranges could have been chosen. I warn the user that pictures involving a large amount of data may face the problem of exceeding &TeX; capacity...
286
<Example><![CDATA[
287
gap> row_length := 200;; # the legth of each row
288
gap> columns := 50;; # the number of colums
289
gap> n := row_length*columns;
290
10000
291
gap>
292
gap> ##compute the primes less than n
293
gap> # Primes is a GAP variable representing the list of primes less than 1000
294
gap> mp := Maximum(Primes);
295
997
296
gap> newprimes := [];;
297
gap> while mp < n do
298
> mp := NextPrimeInt(mp);
299
> Add(newprimes, mp);
300
> od;
301
gap> small_primes := Union(Primes, newprimes);;
302
gap> ##compute the first element of each pair of twin primes less than n
303
gap> twins := Filtered(small_primes, p -> IsPrime(p+2));;
304
gap>
305
gap> rg := [1..n];;
306
gap>
307
gap> arr := [Intersection(small_primes,rg),[],[],
308
> Intersection(Union(twins,twins+2),rg),[],[],[],[],[],[],[],
309
> [],[],[],[],[],[],Difference(rg,small_primes)];;
310
gap>
311
gap> tkz:=IP_TikzArrayOfIntegers([1..n],row_length,rec(highlights:=arr,
312
> cell_width := "6",colsep:="0",rowsep:="0",inner_sep:="2",
313
> shape_only:=" ",line_width:="0",line_color:="black!20" ));;
314
]]></Example>
315
<Alt Only="LaTeX">
316
\begin{center}
317
\includegraphics[width=0.99\textwidth]{../images/intpic_banner.pdf}
318
\end{center}
319
</Alt>
320
<Alt Only="HTML">
321
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/intpic_banner.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
322
</Alt>
323
324
</Subsection>
325
</Section>
326
</Chapter>
327
328