Skip to content

Commit

Permalink
Add GAP syntax highlight
Browse files Browse the repository at this point in the history
Closes #2
  • Loading branch information
olexandr-konovalov committed Aug 28, 2024
1 parent 6e834c9 commit 2eae9d0
Show file tree
Hide file tree
Showing 7 changed files with 134 additions and 134 deletions.
76 changes: 38 additions & 38 deletions episodes/01-command-line.md
Original file line number Diff line number Diff line change
Expand Up @@ -47,13 +47,13 @@ including this one, must be finished with a semicolon! Practice entering
may wish to enter the following command to display GAP prompts and user inputs
in different colours:

```source
```gap
ColorPrompt(true);
```

The easiest way to start trying GAP out is as a calculator:

```source
```gap
( 1 + 2^32 ) / (1 - 2*3*107 );
```

Expand All @@ -64,7 +64,7 @@ The easiest way to start trying GAP out is as a calculator:
If you want to record what you did in a GAP session, so you can look over it
later, you can enable logging with the `LogTo` function, like this.

```source
```gap
LogTo("gap-intro.log");
```

Expand All @@ -79,7 +79,7 @@ return to it in the future. A comment in GAP starts with the symbol `#` and
continues to the end of the line. You can enter the following after the
GAP prompt:

```source
```gap
# GAP Software Carpentry Lesson
```

Expand All @@ -93,7 +93,7 @@ arrow keys to scroll the *command line history*. Repeat this until you see
the formula again, then press Return (the location of the cursor in the command
line does not matter):

```source
```gap
( 1 + 2^32 ) / (1 - 2*3*107 );
```

Expand All @@ -108,7 +108,7 @@ Ctrl-A and Ctrl-E to move the cursor to the beginning and end of the
line, respectively). Now press the Return key (at any position of the
cursor in the command line):

```source
```gap
( 1 + 2^64 ) / (1 - 2*3*107 );
```

Expand All @@ -124,7 +124,7 @@ the same string.
If you want to store a value for later use, you can assign it to a name
using `:=`

```source
```gap
universe := 6*7;
```

Expand All @@ -140,15 +140,15 @@ universe := 6*7;

- Finally, GAP uses `<>` to check if two things are not equal (rather than the `!=`
you might have seen before).


::::::::::::::::::::::::::::::::::::::::::::::::::

Whitespace characters (i.e. Spaces, Tabs and Returns) are insignificant in GAP,
except if they occur inside a string. For example, the previous input
could be typed without spaces:

```source
```gap
(1+2^64)/(1-2*3*107);
```

Expand All @@ -159,7 +159,7 @@ could be typed without spaces:
Whitespace symbols are often used to format more complicated commands for
better readability. For example, the following input which creates a 3×3 matrix:

```source
```gap
m:=[[1,2,3],[4,5,6],[7,8,9]];
```

Expand All @@ -171,7 +171,7 @@ We can instead write our matrix over 3 lines. In this case, instead of the full
`gap>`, a partial prompt `>` will be displayed until the user finishes
the input with a semicolon:

```source
```gap
gap> m:=[[ 1, 2, 3 ],
> [ 4, 5, 6 ],
> [ 7, 8, 9 ]];
Expand All @@ -183,7 +183,7 @@ gap> m:=[[ 1, 2, 3 ],

You can use `Display` to pretty-print variables, including this matrix:

```source
```gap
Display(m);
```

Expand All @@ -209,7 +209,7 @@ We will explain the differences in these outputs later.

Here are some examples of calling other GAP functions:

```source
```gap
Factorial(100);
```

Expand All @@ -221,7 +221,7 @@ Factorial(100);

(the exact width of output will depend on your terminal settings),

```source
```gap
Determinant(m);
```

Expand All @@ -231,7 +231,7 @@ Determinant(m);

and

```source
```gap
Factors(2^64-1);
```

Expand All @@ -245,7 +245,7 @@ used as arguments of other functions, for example, the
all elements of the list which satisfy the function.
`IsEvenInt`, unsurprisingly, checks if an integer is even!

```source
```gap
Filtered( [2,9,6,3,4,5], IsEvenInt);
```

Expand All @@ -257,7 +257,7 @@ A useful time-saving feature of the GAP command-line interfaces is completion
of identifiers when the Tab key is pressed. For example, type `Fib` and then
press the Tab key to complete the input to `Fibonacci`:

```source
```gap
Fibonacci(100);
```

Expand All @@ -281,7 +281,7 @@ for general use. Use them with extreme care!
It is important to remember that GAP is case-sensitive. For example, the following
input causes an error:

```source
```gap
factorial(100);
```

Expand Down Expand Up @@ -340,7 +340,7 @@ own computer, you can set the help viewer to the default browser. If you are
running GAP on a remote machine, this (probably) will not work. (see
`?WriteGapIniFile` on how to make this setting permanent):

```source
```gap
SetHelpViewer("browser");
```

Expand All @@ -358,13 +358,13 @@ This guide shows how permutations in GAP are written in cycle notation, and also
shows common functions which are used with groups. Also, in some places two semi-colons
are used at the end of a line. This stops GAP from showing the result of a computation.

```source
```gap
a:=(1,2,3);;b:=(2,3,4);;
```

Next, let `G` be a group generated by `a` and `b`:

```source
```gap
G:=Group(a,b);
```

Expand All @@ -374,7 +374,7 @@ Group([ (1,2,3), (2,3,4) ])

We may explore some properties of `G` and its generators:

```source
```gap
Size(G); IsAbelian(G); StructureDescription(G); Order(a);
```

Expand All @@ -391,7 +391,7 @@ the entry from the Tutorial does not seem relevant, but the entry from the
Reference manual is. It also explains the difference between using `AsSSortedList`
and `AsList`. So, this is the list of elements of `G`:

```source
```gap
AsList(G);
```

Expand All @@ -406,7 +406,7 @@ course, we may use the command line history to restore the last command, edit
it and call again. But instead, we will use `last` which is a special variable
holding the last result returned by GAP:

```source
```gap
elts:=last;
```

Expand All @@ -418,7 +418,7 @@ elts:=last;
This is a list. Lists in GAP are indexed from 1.
The following commands are (hopefully!) self-explanatory:

```source
```gap
gap> elts[1]; elts[3]; Length(elts);
```

Expand All @@ -439,14 +439,14 @@ gap> elts[1]; elts[3]; Length(elts);
- Not required to contain objects of the same type

- See more in [GAP Tutorial: Lists and Records](https://www.gap-system.org/Manuals/doc/tut/chap3.html)


::::::::::::::::::::::::::::::::::::::::::::::::::

Many functions in GAP refer to `Set`s. A set in GAP is just a list that happens to have
no repetitions, no holes, and elements in increasing order. Here are some examples:

```source
```gap
gap> IsSet([1,3,5]); IsSet([1,5,3]); IsSet([1,3,3]);
```

Expand All @@ -463,15 +463,15 @@ here.
A `for` loop in GAP allows you to do something for every member of a collection.
The general form of a `for` loop is:

```source
```gap
for val in collection do
<something with val>
od;
```

For example, to find the average order of our group `G` we can do.

```source
```gap
s:=0;;
for g in elts do
s := s + Order(g);
Expand All @@ -487,7 +487,7 @@ Actually, we can just directly loop over the elements of `G` (in general GAP
will let you loop over most types of object). We have to switch to using `Size`
instead of `Length`, as groups don't have a length!

```source
```gap
s:=0;;
for g in G do
s := s + Order(g);
Expand All @@ -502,7 +502,7 @@ s/Size(G);
There are other ways of looping. For example, we can instead loop over a range of integers,
and accept `elts` like an array:

```source
```gap
s:=0;;
for i in [ 1 .. Length(elts) ] do
s := s + Order( elts[i] );
Expand All @@ -517,7 +517,7 @@ s/Length(elts);
However, often there are more compact ways of doing things. Here is a very
short way:

```source
```gap
Sum( List( elts, Order ) ) / Length( elts );
```

Expand Down Expand Up @@ -551,7 +551,7 @@ and returns the value of the expression `e`. Here are some examples:

- finding all elements of `G` with no fixed points:

```source
```gap
Filtered( elts, g -> NrMovedPoints(g) = 4 );
```

Expand All @@ -561,7 +561,7 @@ Filtered( elts, g -> NrMovedPoints(g) = 4 );

- finding a permutation in `G` that conjugates (1,2) to (2,3)

```source
```gap
First( elts, g -> (1,2)^g = (2,3) );
```

Expand All @@ -571,7 +571,7 @@ First( elts, g -> (1,2)^g = (2,3) );

Let's check this (remember that in GAP permutations are multiplied from left to right!):

```source
```gap
(1,2,3)^-1*(1,2)*(1,2,3)=(2,3);
```

Expand All @@ -581,7 +581,7 @@ true

- checking whether all elements of `G` move the point 1 to 2:

```source
```gap
ForAll( elts, g -> 1^g <> 2 );
```

Expand All @@ -591,7 +591,7 @@ false

- checking whether there is an element in `G` which moves exactly two points:

```source
```gap
ForAny( elts, g -> NrMovedPoints(g) = 2 );
```

Expand All @@ -606,7 +606,7 @@ false
- `Filtered( elts, g -> 2^g = 2 );`

- `Filtered( elts, g -> (1,2)^g = (1,2) );`


::::::::::::::::::::::::::::::::::::::::::::::::::

Expand Down
Loading

0 comments on commit 2eae9d0

Please sign in to comment.