Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
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
Project: cocalc-sagemath-dev-slelievre
Views: 418346<?xml version="1.0" encoding="UTF-8"?>12<Chapter Label="functions">3<Heading>4The <Package>IntPic</Package> package main function5</Heading>6<!-- <Index>&IntPic; - functions</Index> -->7This 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.8<Section>9<Heading>The main function</Heading>10The 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.11<ManSection>12<Heading>Tikz code for arrays of integers</Heading>13<Func Name="IP_TikzArrayOfIntegers" Arg="arg"/>14<Description>15The arguments (at most 3) are: <Enum>16<Item>(optional)<List>17<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>18<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>19</List></Item>20<Item>21a 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 <Ref Sect="options"/>.22</Item>23</Enum>24When no list nor table is present, the smallest range containing all the integers to be highlighted is taken.25</Description>26</ManSection>27<Example><![CDATA[28gap> rg := [81..89];;29gap> len := 10;;30gap> arr := [Filtered(rg,IsPrime),Filtered(rg,u->(u mod 2)=0),31> Filtered(rg,u->(u mod 3)=0)];;32gap> tkz := IP_TikzArrayOfIntegers(rg,len,rec(highlights:=arr));;33]]></Example>34The 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.35<P/>36<Listing Type="The tkz string"><![CDATA[37gap> tkz;38"%tikz\n\\begin{tikzpicture}[every node/.style={draw,scale=1pt,\nminimum width\39=20pt,inner sep=3pt,\nline width=1pt,draw=black}]\n\\matrix[row sep=2pt,column\40sep=2pt]\n{\\node[fill=-red]{86};&\n\\node[fill=green]{87};&\n\\node[fill=-re\41d]{88};&\n\\node[fill=red]{89};\\\\\n\\node[fill=green]{81};&\n\\node[fill=-re\42d]{82};&\n\\node[fill=red]{83};&\n\\node[left color=-red,right color=green]{84\43};&\n\\node[]{85};\\\\\n};\n\\end{tikzpicture}\n"44]]></Listing>45This 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"/>.46<Listing Type="The tikz code"><![CDATA[47gap> Print(tkz);48%tikz49\begin{tikzpicture}[every node/.style={draw,scale=1pt,50minimum width=20pt,inner sep=3pt,51line width=1pt,draw=black}]52\matrix[row sep=2pt,column sep=2pt]53{\node[fill=-red]{86};&54\node[fill=green]{87};&55\node[fill=-red]{88};&56\node[fill=red]{89};\\57\node[fill=green]{81};&58\node[fill=-red]{82};&59\node[fill=red]{83};&60\node[left color=-red,right color=green]{84};&61\node[]{85};\\62};63\end{tikzpicture}64]]></Listing>65It 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.66<P />67<!-- ###################################################### -->68The 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.69<ManSection>70<Heading>Tikz code for arrays, in a simplified way</Heading>71<Description>72</Description>73<Func Name="IP_SimpleTikzArrayOfIntegers" Arg="arg"/>74<Description>75The 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.76</Description>77</ManSection>78<Example><![CDATA[79gap> d := DivisorsInt(30);80[ 1, 2, 3, 5, 6, 10, 15, 30 ]81gap> IP_SimpleTikzArrayOfIntegers(d);;82]]></Example>83<Alt Only="LaTeX">84\begin{center}85\includegraphics[width=0.95\textwidth]{../images/divs30}86\end{center}87</Alt>88<Alt Only="HTML">89<br><center><img src="../images/divs30.jpg"></center><br>90</Alt>91<Example><![CDATA[92gap> d30 := DivisorsInt(30);93[ 1, 2, 3, 5, 6, 10, 15, 30 ]94gap> d40 := DivisorsInt(40);95[ 1, 2, 4, 5, 8, 10, 20, 40 ]96gap> tkz := IP_SimpleTikzArrayOfIntegers([d30,d40]);;97]]></Example>98<Alt Only="LaTeX">99\begin{center}100\includegraphics[width=0.95\textwidth]{../images/divs3040}101\end{center}102</Alt>103<Alt Only="HTML">104<br><center><img src="../images/divs3040.jpg"></center><br>105</Alt>106<P />107</Section>108<!-- ###################################################### -->109<Section>110<Heading>Producing tables</Heading>111When 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 in112<Cite Key="fengraoab"></Cite>.113<ManSection>114<Func Name="IP_TableWithModularOrder" Arg="o,a,b,depth,height,rep,pos"/>115<Description>116The 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).117<P/>118The first five arguments arguments <A>o, a, b,depth</A> and <A>height</A> are integers. What they represent is described in what follows.119There is assigned some kind of a referential on the constructed table and the fist argument, <A>o</A>, stands for the origin.120A 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 is121<List>122<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>123<Item><M><A>o</A>+ [0..<A>b</A>]*<A>a</A></M>, if <A>rep</A> is <C>true</C></Item>124</List>125<P />126The remaining rows are obtained by adding <A>b</A> (the upper ones) or subtracting <A>b</A> (the others) to these rows. <P />127Note: when <M><A>a</A> < <A>b</A></M> are co-prime, this construction provides a representation of the integers as an array. <P />128129</Description>130</ManSection>131<Example><![CDATA[132gap> a := 8;; b := 19;;133gap> ns := NumericalSemigroup(a,b);;134gap> c := ConductorOfNumericalSemigroup(ns);;135gap> origin := 2*c-1;136251137gap> ground := [origin..origin+b-1];;138gap>139gap> height:=2;;140gap> depth:=8;;141gap> xaxis := [origin];;142gap> for n in [1..b-1] do143> Add(xaxis, origin+n*a);144> od;145gap> yaxis := [];;146gap> for n in [-depth..height] do147> Add(yaxis, origin+n*b);148> od;149gap>150gap> table := IP_TableWithModularOrder(origin,a,b,depth,height,false,false);;151gap> arr := [xaxis,yaxis,ground];152[ [ 251, 259, 267, 275, 283, 291, 299, 307, 315, 323, 331, 339, 347, 355,153363, 371, 379, 387, 395 ],154[ 99, 118, 137, 156, 175, 194, 213, 232, 251, 270, 289 ], [ 251 .. 269 ] ]155gap> tkz:=IP_TikzArrayOfIntegers(table,rec(highlights:=arr));;156]]></Example>157<Alt Only="LaTeX">158\begin{center}159\includegraphics[width=0.95\textwidth]{../images/table_axis_ground_8_19}160\end{center}161</Alt>162<Alt Only="HTML">163<br><center><img src="../images/table_axis_ground_8_19.jpg"></center><br>164</Alt>165The 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.166<Example><![CDATA[167gap> tkz:=IP_TikzArrayOfIntegers(table,rec(highlights:=arr,shape_only:=" ",168> cell_width := "6",colsep:="1",rowsep:="1",inner_sep:="2",169> line_color:="black!20"));;170]]></Example>171<Alt Only="LaTeX">172\begin{center}173\includegraphics[width=0.80\textwidth]{../images/table_axis_ground_shape}174\end{center}175</Alt>176<Alt Only="HTML">177<br><center><img src="../images/table_axis_ground_shape.jpg"></center><br>178</Alt>179Next, a minimum of changes, just to illustrate the effect of <A>rep</A> and <A>pos</A>.180<Example><![CDATA[181gap> table := IP_TableWithModularOrder(origin,a,b,depth,50,true,true);;182gap> tkz:=IP_TikzArrayOfIntegers(table,rec(highlights:=arr));;183]]></Example>184<Alt Only="LaTeX">185\begin{center}186\includegraphics[width=0.80\textwidth]{../images/table_axis_ground_8_19_rep_pos}187\end{center}188</Alt>189<Alt Only="HTML">190<br><center><img src="../images/table_axis_ground_8_19_rep_pos.jpg"></center><br>191</Alt>192</Section>193</Chapter>194195196197198