CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

| Download

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

Views: 418346
1
<?xml version="1.0" encoding="UTF-8"?>
2
3
<Chapter Label="functions">
4
<Heading>
5
The <Package>IntPic</Package> package main function
6
</Heading>
7
<!-- <Index>&IntPic; - functions</Index> -->
8
This chapter consists of two sections, the first of which decribes the main function of the package. The second one can be thought just as an example to produce a table where the integers appear ordered in a non standard way.
9
<Section>
10
<Heading>The main function</Heading>
11
The function <Ref Func="IP_TikzArrayOfIntegers"/> is the main function of the &IntPic; package. It aims to produce <C>tikz</C> code for displaying arrays of integers.
12
<ManSection>
13
<Heading>Tikz code for arrays of integers</Heading>
14
<Func Name="IP_TikzArrayOfIntegers" Arg="arg"/>
15
<Description>
16
The arguments (at most 3) are: <Enum>
17
<Item>(optional)<List>
18
<Item> a table of integers. In this case, the length of the rows is the maximum of the lengths of the sublists in the table, <Emph>or</Emph> </Item>
19
<Item> a list of integers and, optionally, an integer which indicates the length of the rows; when the length of the rows is not indicated, a compromise between the width and the height is tried.</Item>
20
</List></Item>
21
<Item>
22
a record of options. One of the fields of this record, named <C>highlights</C>, is an array whose entries are the numbers to be highlighted: one color per sublist. See details and other options in Chapter&nbsp;<Ref Sect="options"/>.
23
</Item>
24
</Enum>
25
When no list nor table is present, the smallest range containing all the integers to be highlighted is taken.
26
</Description>
27
</ManSection>
28
<Example><![CDATA[
29
gap> rg := [81..89];;
30
gap> len := 10;;
31
gap> arr := [Filtered(rg,IsPrime),Filtered(rg,u->(u mod 2)=0),
32
> Filtered(rg,u->(u mod 3)=0)];;
33
gap> tkz := IP_TikzArrayOfIntegers(rg,len,rec(highlights:=arr));;
34
]]></Example>
35
The aspect of the string <A>tkz</A> produced is not very appealing. We show it once, by asking it exlicitly in the next example. In the forthcomming examples we keep using two semicolons to avoid showing this kind of strings.
36
<P/>
37
<Listing Type="The tkz string"><![CDATA[
38
gap> tkz;
39
"%tikz\n\\begin{tikzpicture}[every node/.style={draw,scale=1pt,\nminimum width\
40
=20pt,inner sep=3pt,\nline width=1pt,draw=black}]\n\\matrix[row sep=2pt,column\
41
sep=2pt]\n{\\node[fill=-red]{86};&\n\\node[fill=green]{87};&\n\\node[fill=-re\
42
d]{88};&\n\\node[fill=red]{89};\\\\\n\\node[fill=green]{81};&\n\\node[fill=-re\
43
d]{82};&\n\\node[fill=red]{83};&\n\\node[left color=-red,right color=green]{84\
44
};&\n\\node[]{85};\\\\\n};\n\\end{tikzpicture}\n"
45
]]></Listing>
46
This string can be used at the users wish. In particular, it can be sent to the standard output using the command <Ref Func="Print" BookName="ref"/>.
47
<Listing Type="The tikz code"><![CDATA[
48
gap> Print(tkz);
49
%tikz
50
\begin{tikzpicture}[every node/.style={draw,scale=1pt,
51
minimum width=20pt,inner sep=3pt,
52
line width=1pt,draw=black}]
53
\matrix[row sep=2pt,column sep=2pt]
54
{\node[fill=-red]{86};&
55
\node[fill=green]{87};&
56
\node[fill=-red]{88};&
57
\node[fill=red]{89};\\
58
\node[fill=green]{81};&
59
\node[fill=-red]{82};&
60
\node[fill=red]{83};&
61
\node[left color=-red,right color=green]{84};&
62
\node[]{85};\\
63
};
64
\end{tikzpicture}
65
]]></Listing>
66
It can now be copied and pasted in a &LaTeX; document (having the appropriate packages in the preamble). See Chapter <Ref Chap="visualisation"/> for details and alternatives.
67
<P />
68
<!-- ###################################################### -->
69
The next function uses the previous one, but is called with a simpler argument. It will hopefully be useful for simple drawings. The length of each row and the umber of columns varies. A compromise based on some experiments has been established in order to obtain not too large nor too high images.
70
<ManSection>
71
<Heading>Tikz code for arrays, in a simplified way</Heading>
72
<Description>
73
</Description>
74
<Func Name="IP_SimpleTikzArrayOfIntegers" Arg="arg"/>
75
<Description>
76
The argument is either a list of integers or a matrix of integers. The integers involved are embeded in a range <A>rg</A> of minimum length and highlighted by using the list of default colors.
77
</Description>
78
</ManSection>
79
<Example><![CDATA[
80
gap> d := DivisorsInt(30);
81
[ 1, 2, 3, 5, 6, 10, 15, 30 ]
82
gap> IP_SimpleTikzArrayOfIntegers(d);;
83
]]></Example>
84
<Alt Only="LaTeX">
85
\begin{center}
86
\includegraphics[width=0.95\textwidth]{../images/divs30}
87
\end{center}
88
</Alt>
89
<Alt Only="HTML">
90
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/divs30.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
91
</Alt>
92
<Example><![CDATA[
93
gap> d30 := DivisorsInt(30);
94
[ 1, 2, 3, 5, 6, 10, 15, 30 ]
95
gap> d40 := DivisorsInt(40);
96
[ 1, 2, 4, 5, 8, 10, 20, 40 ]
97
gap> tkz := IP_SimpleTikzArrayOfIntegers([d30,d40]);;
98
]]></Example>
99
<Alt Only="LaTeX">
100
\begin{center}
101
\includegraphics[width=0.95\textwidth]{../images/divs3040}
102
\end{center}
103
</Alt>
104
<Alt Only="HTML">
105
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/divs3040.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
106
</Alt>
107
<P />
108
</Section>
109
<!-- ###################################################### -->
110
<Section>
111
<Heading>Producing tables</Heading>
112
When the user is interested in tables of a certain kind, it may be a good idea to write some code to produce these tables. The following function (whose code is part of the file <Emph>ip_tables.gi</Emph> in the <Emph>gap</Emph> folder of this package) is convenient to deal with numerical semigroups with two generators and has been used to produce the images contained in
113
<Cite Key="fengraoab"></Cite>.
114
<ManSection>
115
<Func Name="IP_TableWithModularOrder" Arg="o,a,b,depth,height,rep,pos"/>
116
<Description>
117
The arguments <A>rep</A> and <A>pos</A> are booleans (<C>true</C> or <C>false</C>). When <A>rep</A> is <C>true</C> there is some repetition: the last column is equal to the first, but pushed down some rows. When <A>pos</A> is <C>true</C>, no rows below 0 are considered, (contradicting <A>depth</A>, if needed).
118
<P/>
119
The first five arguments arguments <A>o, a, b,depth</A> and <A>height</A> are integers. What they represent is described in what follows.
120
There is assigned some kind of a referential on the constructed table and the fist argument, <A>o</A>, stands for the origin.
121
A table with <A>b</A> columns (<M><A>b</A>+1</M> columns when <A>rep</A> is <C>true</C>) is constructed as follows. The row containing the origin is
122
<List>
123
<Item><M><A>o</A>+ [0..<A>b</A>-1]*<A>a</A></M>, if <A>rep</A> is <C>false</C>, <Emph>or</Emph></Item>
124
<Item><M><A>o</A>+ [0..<A>b</A>]*<A>a</A></M>, if <A>rep</A> is <C>true</C></Item>
125
</List>
126
<P />
127
The remaining rows are obtained by adding <A>b</A> (the upper ones) or subtracting <A>b</A> (the others) to these rows. <P />
128
Note: when <M><A>a</A> &#60; <A>b</A></M> are co-prime, this construction provides a representation of the integers as an array. <P />
129
130
</Description>
131
</ManSection>
132
<Example><![CDATA[
133
gap> a := 8;; b := 19;;
134
gap> ns := NumericalSemigroup(a,b);;
135
gap> c := ConductorOfNumericalSemigroup(ns);;
136
gap> origin := 2*c-1;
137
251
138
gap> ground := [origin..origin+b-1];;
139
gap>
140
gap> height:=2;;
141
gap> depth:=8;;
142
gap> xaxis := [origin];;
143
gap> for n in [1..b-1] do
144
> Add(xaxis, origin+n*a);
145
> od;
146
gap> yaxis := [];;
147
gap> for n in [-depth..height] do
148
> Add(yaxis, origin+n*b);
149
> od;
150
gap>
151
gap> table := IP_TableWithModularOrder(origin,a,b,depth,height,false,false);;
152
gap> arr := [xaxis,yaxis,ground];
153
[ [ 251, 259, 267, 275, 283, 291, 299, 307, 315, 323, 331, 339, 347, 355,
154
363, 371, 379, 387, 395 ],
155
[ 99, 118, 137, 156, 175, 194, 213, 232, 251, 270, 289 ], [ 251 .. 269 ] ]
156
gap> tkz:=IP_TikzArrayOfIntegers(table,rec(highlights:=arr));;
157
]]></Example>
158
<Alt Only="LaTeX">
159
\begin{center}
160
\includegraphics[width=0.95\textwidth]{../images/table_axis_ground_8_19}
161
\end{center}
162
</Alt>
163
<Alt Only="HTML">
164
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/table_axis_ground_8_19.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
165
</Alt>
166
The next picture is obtained in the same way. The information that only the shape has interest is given by including the option <C>shape_only:=" "</C>. The variable <C>tkz</C> should be defined in a similar manner to the following one.
167
<Example><![CDATA[
168
gap> tkz:=IP_TikzArrayOfIntegers(table,rec(highlights:=arr,shape_only:=" ",
169
> cell_width := "6",colsep:="1",rowsep:="1",inner_sep:="2",
170
> line_color:="black!20"));;
171
]]></Example>
172
<Alt Only="LaTeX">
173
\begin{center}
174
\includegraphics[width=0.80\textwidth]{../images/table_axis_ground_shape}
175
\end{center}
176
</Alt>
177
<Alt Only="HTML">
178
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/table_axis_ground_shape.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
179
</Alt>
180
Next, a minimum of changes, just to illustrate the effect of <A>rep</A> and <A>pos</A>.
181
<Example><![CDATA[
182
gap> table := IP_TableWithModularOrder(origin,a,b,depth,50,true,true);;
183
gap> tkz:=IP_TikzArrayOfIntegers(table,rec(highlights:=arr));;
184
]]></Example>
185
<Alt Only="LaTeX">
186
\begin{center}
187
\includegraphics[width=0.80\textwidth]{../images/table_axis_ground_8_19_rep_pos}
188
\end{center}
189
</Alt>
190
<Alt Only="HTML">
191
&#60;br&#62;&#60;center&#62;&#60;img src=&#34;../images/table_axis_ground_8_19_rep_pos.jpg&#34;&#62;&#60;/center&#62;&#60;br&#62;
192
</Alt>
193
</Section>
194
</Chapter>
195
196
197
198