From d3637bef2bad7bf8fa9e4f8d0d8f9aa603e9b68c Mon Sep 17 00:00:00 2001 From: Max Horn Date: Thu, 18 Aug 2022 03:09:31 +0200 Subject: [PATCH] Add GAP console session mode This is also appropriate for GAP .tst files --- pygments/lexers/_mapping.py | 1 + pygments/lexers/algebra.py | 58 +- tests/examplefiles/gap-repl/euclidean.tst | 60 ++ .../gap-repl/euclidean.tst.output | 838 ++++++++++++++++++ tests/examplefiles/gap-repl/magma.tst | 58 ++ tests/examplefiles/gap-repl/magma.tst.output | 694 +++++++++++++++ 6 files changed, 1706 insertions(+), 3 deletions(-) create mode 100644 tests/examplefiles/gap-repl/euclidean.tst create mode 100644 tests/examplefiles/gap-repl/euclidean.tst.output create mode 100644 tests/examplefiles/gap-repl/magma.tst create mode 100644 tests/examplefiles/gap-repl/magma.tst.output diff --git a/pygments/lexers/_mapping.py b/pygments/lexers/_mapping.py index 577d6645c9..27fe33f3c3 100644 --- a/pygments/lexers/_mapping.py +++ b/pygments/lexers/_mapping.py @@ -168,6 +168,7 @@ 'FoxProLexer': ('pygments.lexers.foxpro', 'FoxPro', ('foxpro', 'vfp', 'clipper', 'xbase'), ('*.PRG', '*.prg'), ()), 'FreeFemLexer': ('pygments.lexers.freefem', 'Freefem', ('freefem',), ('*.edp',), ('text/x-freefem',)), 'FutharkLexer': ('pygments.lexers.futhark', 'Futhark', ('futhark',), ('*.fut',), ('text/x-futhark',)), + 'GAPConsoleLexer': ('pygments.lexers.algebra', 'GAP session', ('gap-repl',), ('*.tst',), ()), 'GAPLexer': ('pygments.lexers.algebra', 'GAP', ('gap',), ('*.g', '*.gd', '*.gi', '*.gap'), ()), 'GDScriptLexer': ('pygments.lexers.gdscript', 'GDScript', ('gdscript', 'gd'), ('*.gd',), ('text/x-gdscript', 'application/x-gdscript')), 'GLShaderLexer': ('pygments.lexers.graphics', 'GLSL', ('glsl',), ('*.vert', '*.frag', '*.geo'), ('text/x-glslsrc',)), diff --git a/pygments/lexers/algebra.py b/pygments/lexers/algebra.py index 59072708dd..535d8ec4d9 100644 --- a/pygments/lexers/algebra.py +++ b/pygments/lexers/algebra.py @@ -10,11 +10,11 @@ import re -from pygments.lexer import RegexLexer, bygroups, words +from pygments.lexer import Lexer, RegexLexer, bygroups, do_insertions, words from pygments.token import Text, Comment, Operator, Keyword, Name, String, \ - Number, Punctuation, Whitespace + Number, Punctuation, Generic, Whitespace -__all__ = ['GAPLexer', 'MathematicaLexer', 'MuPADLexer', 'BCLexer'] +__all__ = ['GAPLexer', 'GAPConsoleLexer', 'MathematicaLexer', 'MuPADLexer', 'BCLexer'] class GAPLexer(RegexLexer): @@ -88,6 +88,58 @@ def analyse_text(text): return min(score, 1.0) +class GAPConsoleLexer(Lexer): + """ + For GAP console sessions. Modeled after JuliaConsoleLexer. + + .. versionadded:: 2.14 + """ + name = 'GAP session' + aliases = ['gap-repl'] + filenames = ['*.tst'] + + def get_tokens_unprocessed(self, text): + gaplexer = GAPLexer(**self.options) + start = 0 + curcode = '' + insertions = [] + output = False + error = False + + for line in text.splitlines(True): + if line.startswith('gap> ') or line.startswith('brk> '): + insertions.append((len(curcode), [(0, Generic.Prompt, line[:5])])) + curcode += line[5:] + output = False + error = False + elif not output and line.startswith('> '): + insertions.append((len(curcode), [(0, Generic.Prompt, line[:2])])) + curcode += line[2:] + else: + if curcode: + yield from do_insertions( + insertions, gaplexer.get_tokens_unprocessed(curcode)) + curcode = '' + insertions = [] + if line.startswith('Error, ') or error: + yield start, Generic.Error, line + error = True + else: + yield start, Generic.Output, line + output = True + start += len(line) + + if curcode: + yield from do_insertions( + insertions, gaplexer.get_tokens_unprocessed(curcode)) + + def analyse_text(text): + if re.search(r"(^gap> )", text): + return 0.9 + else: + return 0.0 + + class MathematicaLexer(RegexLexer): """ Lexer for Mathematica source code. diff --git a/tests/examplefiles/gap-repl/euclidean.tst b/tests/examplefiles/gap-repl/euclidean.tst new file mode 100644 index 0000000000..ca3b3285db --- /dev/null +++ b/tests/examplefiles/gap-repl/euclidean.tst @@ -0,0 +1,60 @@ +#@local checkEuclideanRing +gap> START_TEST("euclidean.tst"); + +# test consistency of EuclideanDegree, EuclideanQuotient, EuclideanRemainder, +# and QuotientRemainder for some ring and elements of it +gap> checkEuclideanRing := +> function(R, colls...) +> local coll1, coll2, a, b, deg_b, deg_r, q, r, qr; +> if Length(colls) >= 1 then coll1:=colls[1]; +> elif Size(R) <= 100 then coll1 := R; +> else coll1 := List([1..100],i->Random(R)); +> fi; +> if Length(colls) >= 2 then coll2:=colls[2]; +> elif Size(R) <= 100 then coll2 := R; +> else coll2 := List([1..100],i->Random(R)); +> fi; +> for b in coll1 do +> if IsZero(b) then continue; fi; +> deg_b := EuclideanDegree(R, b); +> for a in coll2 do +> q := EuclideanQuotient(R, a, b); Assert(0, q in R); +> r := EuclideanRemainder(R, a, b); Assert(0, r in R); +> if a <> q*b + r then Error("a <> q*b + r for ", [R,a,b]); fi; +> deg_r := EuclideanDegree(R, r); +> if not IsZero(r) and deg_r >= deg_b then Error("Euclidean degree did not decrease for ",[R,a,b]); fi; +> qr := QuotientRemainder(R, a, b); +> if qr <> [q, r] then Error("QuotientRemainder inconsistent for ", [R,a,b]); fi; +> od; +> od; +> return true; +> end;; + +# rings in characteristic 0 +gap> checkEuclideanRing(Integers,[-100..100],[-100..100]); +true +gap> checkEuclideanRing(Rationals); +true +gap> checkEuclideanRing(GaussianIntegers); +true +gap> checkEuclideanRing(GaussianRationals); +true + +# finite fields +gap> ForAll(Filtered([2..50], IsPrimePowerInt), q->checkEuclideanRing(GF(q))); +true + +# ZmodnZ +gap> ForAll([1..50], m -> checkEuclideanRing(Integers mod m)); +true +gap> checkEuclideanRing(Integers mod ((2*3*5)^2)); +true +gap> checkEuclideanRing(Integers mod ((2*3*5)^3)); +true +gap> checkEuclideanRing(Integers mod ((2*3*5*7)^2)); +true +gap> checkEuclideanRing(Integers mod ((2*3*5*7)^3)); +true + +# +gap> STOP_TEST( "euclidean.tst", 1); diff --git a/tests/examplefiles/gap-repl/euclidean.tst.output b/tests/examplefiles/gap-repl/euclidean.tst.output new file mode 100644 index 0000000000..17eafe60d3 --- /dev/null +++ b/tests/examplefiles/gap-repl/euclidean.tst.output @@ -0,0 +1,838 @@ +'#@local checkEuclideanRing\n' Generic.Output + +'gap> ' Generic.Prompt +'START_TEST' Name.Variable +'(' Punctuation +'"euclidean.tst"' Literal.String +')' Punctuation +';' Operator +'\n' Text + +'\n' Generic.Output + +'# test consistency of EuclideanDegree, EuclideanQuotient, EuclideanRemainder,\n' Generic.Output + +'# and QuotientRemainder for some ring and elements of it\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +' ' Text +':=' Operator +'\n' Text + +'> ' Generic.Prompt +'function' Keyword +'(' Punctuation +'R' Name.Variable +',' Operator +' ' Text +'colls' Name.Variable +'.' Operator +'.' Operator +'.' Operator +')' Punctuation +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'local' Keyword +' ' Text +'coll1' Name.Variable +',' Operator +' ' Text +'coll2' Name.Variable +',' Operator +' ' Text +'a' Name.Variable +',' Operator +' ' Text +'b' Name.Variable +',' Operator +' ' Text +'deg_b' Name.Variable +',' Operator +' ' Text +'deg_r' Name.Variable +',' Operator +' ' Text +'q' Name.Variable +',' Operator +' ' Text +'r' Name.Variable +',' Operator +' ' Text +'qr' Name.Variable +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'if' Keyword +' ' Text +'Length' Name.Variable +'(' Punctuation +'colls' Name.Variable +')' Punctuation +' ' Text +'>' Operator +'=' Operator +' ' Text +'1' Name.Variable +' ' Text +'then' Keyword +' ' Text +'coll1' Name.Variable +':=' Operator +'colls' Name.Variable +'[' Punctuation +'1' Name.Variable +']' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'elif' Keyword +' ' Text +'Size' Name.Variable +'(' Punctuation +'R' Name.Variable +')' Punctuation +' ' Text +'<' Operator +'=' Operator +' ' Text +'100' Name.Variable +' ' Text +'then' Keyword +' ' Text +'coll1' Name.Variable +' ' Text +':=' Operator +' ' Text +'R' Name.Variable +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'else' Keyword +' ' Text +'coll1' Name.Variable +' ' Text +':=' Operator +' ' Text +'List' Name.Variable +'(' Punctuation +'[' Punctuation +'1' Name.Variable +'.' Operator +'.' Operator +'100' Name.Variable +']' Punctuation +',' Operator +'i' Name.Variable +'-' Operator +'>' Operator +'Random' Name.Variable +'(' Punctuation +'R' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'fi' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'if' Keyword +' ' Text +'Length' Name.Variable +'(' Punctuation +'colls' Name.Variable +')' Punctuation +' ' Text +'>' Operator +'=' Operator +' ' Text +'2' Name.Variable +' ' Text +'then' Keyword +' ' Text +'coll2' Name.Variable +':=' Operator +'colls' Name.Variable +'[' Punctuation +'2' Name.Variable +']' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'elif' Keyword +' ' Text +'Size' Name.Variable +'(' Punctuation +'R' Name.Variable +')' Punctuation +' ' Text +'<' Operator +'=' Operator +' ' Text +'100' Name.Variable +' ' Text +'then' Keyword +' ' Text +'coll2' Name.Variable +' ' Text +':=' Operator +' ' Text +'R' Name.Variable +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'else' Keyword +' ' Text +'coll2' Name.Variable +' ' Text +':=' Operator +' ' Text +'List' Name.Variable +'(' Punctuation +'[' Punctuation +'1' Name.Variable +'.' Operator +'.' Operator +'100' Name.Variable +']' Punctuation +',' Operator +'i' Name.Variable +'-' Operator +'>' Operator +'Random' Name.Variable +'(' Punctuation +'R' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'fi' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'for' Keyword +' ' Text +'b' Name.Variable +' ' Text +'in' Operator.Word +' ' Text +'coll1' Name.Variable +' ' Text +'do' Keyword +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +'if' Keyword +' ' Text +'IsZero' Name.Variable +'(' Punctuation +'b' Name.Variable +')' Punctuation +' ' Text +'then' Keyword +' ' Text +'continue' Keyword +';' Operator +' ' Text +'fi' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +'deg_b' Name.Variable +' ' Text +':=' Operator +' ' Text +'EuclideanDegree' Name.Variable +'(' Punctuation +'R' Name.Variable +',' Operator +' ' Text +'b' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +'for' Keyword +' ' Text +'a' Name.Variable +' ' Text +'in' Operator.Word +' ' Text +'coll2' Name.Variable +' ' Text +'do' Keyword +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'q' Name.Variable +' ' Text +':=' Operator +' ' Text +'EuclideanQuotient' Name.Variable +'(' Punctuation +'R' Name.Variable +',' Operator +' ' Text +'a' Name.Variable +',' Operator +' ' Text +'b' Name.Variable +')' Punctuation +';' Operator +' ' Text +'Assert' Keyword +'(' Punctuation +'0' Name.Variable +',' Operator +' ' Text +'q' Name.Variable +' ' Text +'in' Operator.Word +' ' Text +'R' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'r' Name.Variable +' ' Text +':=' Operator +' ' Text +'EuclideanRemainder' Name.Variable +'(' Punctuation +'R' Name.Variable +',' Operator +' ' Text +'a' Name.Variable +',' Operator +' ' Text +'b' Name.Variable +')' Punctuation +';' Operator +' ' Text +'Assert' Keyword +'(' Punctuation +'0' Name.Variable +',' Operator +' ' Text +'r' Name.Variable +' ' Text +'in' Operator.Word +' ' Text +'R' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'if' Keyword +' ' Text +'a' Name.Variable +' ' Text +'<' Operator +'>' Operator +' ' Text +'q' Name.Variable +'*' Operator +'b' Name.Variable +' ' Text +'+' Operator +' ' Text +'r' Name.Variable +' ' Text +'then' Keyword +' ' Text +'Error' Name.Variable +'(' Punctuation +'"a <> q*b + r for "' Literal.String +',' Operator +' ' Text +'[' Punctuation +'R' Name.Variable +',' Operator +'a' Name.Variable +',' Operator +'b' Name.Variable +']' Punctuation +')' Punctuation +';' Operator +' ' Text +'fi' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'deg_r' Name.Variable +' ' Text +':=' Operator +' ' Text +'EuclideanDegree' Name.Variable +'(' Punctuation +'R' Name.Variable +',' Operator +' ' Text +'r' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'if' Keyword +' ' Text +'not' Operator.Word +' ' Text +'IsZero' Name.Variable +'(' Punctuation +'r' Name.Variable +')' Punctuation +' ' Text +'and' Operator.Word +' ' Text +'deg_r' Name.Variable +' ' Text +'>' Operator +'=' Operator +' ' Text +'deg_b' Name.Variable +' ' Text +'then' Keyword +' ' Text +'Error' Name.Variable +'(' Punctuation +'"Euclidean degree did not decrease for "' Literal.String +',' Operator +'[' Punctuation +'R' Name.Variable +',' Operator +'a' Name.Variable +',' Operator +'b' Name.Variable +']' Punctuation +')' Punctuation +';' Operator +' ' Text +'fi' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'qr' Name.Variable +' ' Text +':=' Operator +' ' Text +'QuotientRemainder' Name.Variable +'(' Punctuation +'R' Name.Variable +',' Operator +' ' Text +'a' Name.Variable +',' Operator +' ' Text +'b' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +' ' Text +'if' Keyword +' ' Text +'qr' Name.Variable +' ' Text +'<' Operator +'>' Operator +' ' Text +'[' Punctuation +'q' Name.Variable +',' Operator +' ' Text +'r' Name.Variable +']' Punctuation +' ' Text +'then' Keyword +' ' Text +'Error' Name.Variable +'(' Punctuation +'"QuotientRemainder inconsistent for "' Literal.String +',' Operator +' ' Text +'[' Punctuation +'R' Name.Variable +',' Operator +'a' Name.Variable +',' Operator +'b' Name.Variable +']' Punctuation +')' Punctuation +';' Operator +' ' Text +'fi' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +' ' Text +' ' Text +'od' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'od' Keyword +';' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'return' Keyword +' ' Text +'true' Name.Constant +';' Operator +'\n' Text + +'> ' Generic.Prompt +'end' Keyword +';' Operator +';' Operator +'\n' Text + +'\n' Generic.Output + +'# rings in characteristic 0\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Integers' Name.Variable +',' Operator +'[' Punctuation +'-' Operator +'100' Name.Variable +'.' Operator +'.' Operator +'100' Name.Variable +']' Punctuation +',' Operator +'[' Punctuation +'-' Operator +'100' Name.Variable +'.' Operator +'.' Operator +'100' Name.Variable +']' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Rationals' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'GaussianIntegers' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'GaussianRationals' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'\n' Generic.Output + +'# finite fields\n' Generic.Output + +'gap> ' Generic.Prompt +'ForAll' Name.Variable +'(' Punctuation +'Filtered' Name.Variable +'(' Punctuation +'[' Punctuation +'2' Name.Variable +'.' Operator +'.' Operator +'50' Name.Variable +']' Punctuation +',' Operator +' ' Text +'IsPrimePowerInt' Name.Variable +')' Punctuation +',' Operator +' ' Text +'q' Name.Variable +'-' Operator +'>' Operator +'checkEuclideanRing' Name.Variable +'(' Punctuation +'GF' Name.Variable +'(' Punctuation +'q' Name.Variable +')' Punctuation +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'\n' Generic.Output + +'# ZmodnZ\n' Generic.Output + +'gap> ' Generic.Prompt +'ForAll' Name.Variable +'(' Punctuation +'[' Punctuation +'1' Name.Variable +'.' Operator +'.' Operator +'50' Name.Variable +']' Punctuation +',' Operator +' ' Text +'m' Name.Variable +' ' Text +'-' Operator +'>' Operator +' ' Text +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Integers' Name.Variable +' ' Text +'mod' Operator.Word +' ' Text +'m' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Integers' Name.Variable +' ' Text +'mod' Operator.Word +' ' Text +'(' Punctuation +'(' Punctuation +'2' Name.Variable +'*' Operator +'3' Name.Variable +'*' Operator +'5' Name.Variable +')' Punctuation +'^' Operator +'2' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Integers' Name.Variable +' ' Text +'mod' Operator.Word +' ' Text +'(' Punctuation +'(' Punctuation +'2' Name.Variable +'*' Operator +'3' Name.Variable +'*' Operator +'5' Name.Variable +')' Punctuation +'^' Operator +'3' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Integers' Name.Variable +' ' Text +'mod' Operator.Word +' ' Text +'(' Punctuation +'(' Punctuation +'2' Name.Variable +'*' Operator +'3' Name.Variable +'*' Operator +'5' Name.Variable +'*' Operator +'7' Name.Variable +')' Punctuation +'^' Operator +'2' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'checkEuclideanRing' Name.Variable +'(' Punctuation +'Integers' Name.Variable +' ' Text +'mod' Operator.Word +' ' Text +'(' Punctuation +'(' Punctuation +'2' Name.Variable +'*' Operator +'3' Name.Variable +'*' Operator +'5' Name.Variable +'*' Operator +'7' Name.Variable +')' Punctuation +'^' Operator +'3' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'\n' Generic.Output + +'#\n' Generic.Output + +'gap> ' Generic.Prompt +'STOP_TEST' Name.Variable +'(' Punctuation +' ' Text +'"euclidean.tst"' Literal.String +',' Operator +' ' Text +'1' Name.Variable +')' Punctuation +';' Operator +'\n' Text diff --git a/tests/examplefiles/gap-repl/magma.tst b/tests/examplefiles/gap-repl/magma.tst new file mode 100644 index 0000000000..fac994f8c2 --- /dev/null +++ b/tests/examplefiles/gap-repl/magma.tst @@ -0,0 +1,58 @@ +#@local F,M,T +gap> START_TEST( "magma.tst" ); + +# +gap> M:= MagmaByMultiplicationTable( [ [ 1, 1 ], [ 1, 1 ] ] );; +gap> IsGeneratorsOfMagmaWithInverses( Elements( M ) ); +false + +# IsAssociative and IsCommutative +gap> T := [ +> [ 2, 4, 3, 4, 5 ], +> [ 3, 3, 2, 3, 3 ], +> [ 5, 5, 5, 4, 4 ], +> [ 5, 1, 4, 1, 1 ], +> [ 5, 3, 3, 4, 5 ] +> ];; +gap> M := MagmaByMultiplicationTable(T); + +gap> IsAssociative(M) or IsCommutative(M); +false +gap> Filtered(Combinations(Elements(M)), x -> Size(x) > 0 and IsAssociative(x)); +[ [ m5 ] ] +gap> Filtered(Combinations(Elements(M)), x -> Size(x) > 0 and IsCommutative(x)); +[ [ m1 ], [ m1, m5 ], [ m2 ], [ m2, m5 ], [ m3 ], [ m3, m4 ], [ m4 ], [ m5 ] ] +gap> T := [ +> [ 1, 4, 3, 3, 2 ], +> [ 4, 2, 4, 4, 2 ], +> [ 3, 4, 3, 4, 1 ], +> [ 1, 4, 5, 4, 3 ], +> [ 2, 2, 3, 5, 3 ] +> ];; +gap> M := MagmaByMultiplicationTable(T); + +gap> IsAssociative(M) or IsCommutative(M); +false +gap> Filtered(Combinations(Elements(M)), x -> Size(x) > 0 and IsAssociative(x)); +[ [ m1 ], [ m1, m3 ], [ m2 ], [ m2, m4 ], [ m3 ], [ m4 ] ] +gap> AsSemigroup([Elements(M)[1], Elements(M)[2]]); +fail +gap> AsSemigroup([Elements(M)[1], Elements(M)[3]]); + +gap> Filtered(Combinations(Elements(M)), x -> Size(x) > 0 and IsCommutative(x)); +[ [ m1 ], [ m1, m2 ], [ m1, m2, m3 ], [ m1, m2, m5 ], [ m1, m3 ], [ m1, m5 ], + [ m2 ], [ m2, m3 ], [ m2, m4 ], [ m2, m5 ], [ m3 ], [ m4 ], [ m5 ] ] + +# +gap> F := Elements( GL(2,2) );; +gap> IsAssociative( F ); +true +gap> IsCommutative( F ); +false +gap> Number( Combinations( F, 3 ), IsCommutative ); +1 +gap> AsSemigroup( F ); + + +# +gap> STOP_TEST( "magma.tst" ); diff --git a/tests/examplefiles/gap-repl/magma.tst.output b/tests/examplefiles/gap-repl/magma.tst.output new file mode 100644 index 0000000000..b4de844d07 --- /dev/null +++ b/tests/examplefiles/gap-repl/magma.tst.output @@ -0,0 +1,694 @@ +'#@local F,M,T\n' Generic.Output + +'gap> ' Generic.Prompt +'START_TEST' Name.Variable +'(' Punctuation +' ' Text +'"magma.tst"' Literal.String +' ' Text +')' Punctuation +';' Operator +'\n' Text + +'\n' Generic.Output + +'#\n' Generic.Output + +'gap> ' Generic.Prompt +'M' Name.Variable +':=' Operator +' ' Text +'MagmaByMultiplicationTable' Name.Variable +'(' Punctuation +' ' Text +'[' Punctuation +' ' Text +'[' Punctuation +' ' Text +'1' Name.Variable +',' Operator +' ' Text +'1' Name.Variable +' ' Text +']' Punctuation +',' Operator +' ' Text +'[' Punctuation +' ' Text +'1' Name.Variable +',' Operator +' ' Text +'1' Name.Variable +' ' Text +']' Punctuation +' ' Text +']' Punctuation +' ' Text +')' Punctuation +';' Operator +';' Operator +'\n' Text + +'gap> ' Generic.Prompt +'IsGeneratorsOfMagmaWithInverses' Name.Variable +'(' Punctuation +' ' Text +'Elements' Name.Variable +'(' Punctuation +' ' Text +'M' Name.Variable +' ' Text +')' Punctuation +' ' Text +')' Punctuation +';' Operator +'\n' Text + +'false\n' Generic.Output + +'\n' Generic.Output + +'# IsAssociative and IsCommutative\n' Generic.Output + +'gap> ' Generic.Prompt +'T' Name.Variable +' ' Text +':=' Operator +' ' Text +'[' Punctuation +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'2' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'5' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'2' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'1' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'1' Name.Variable +',' Operator +' ' Text +'1' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'5' Name.Variable +' ' Text +']' Punctuation +'\n' Text + +'> ' Generic.Prompt +']' Punctuation +';' Operator +';' Operator +'\n' Text + +'gap> ' Generic.Prompt +'M' Name.Variable +' ' Text +':=' Operator +' ' Text +'MagmaByMultiplicationTable' Name.Variable +'(' Punctuation +'T' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'\n' Generic.Output + +'gap> ' Generic.Prompt +'IsAssociative' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +' ' Text +'or' Operator.Word +' ' Text +'IsCommutative' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'false\n' Generic.Output + +'gap> ' Generic.Prompt +'Filtered' Name.Variable +'(' Punctuation +'Combinations' Name.Variable +'(' Punctuation +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +')' Punctuation +',' Operator +' ' Text +'x' Name.Variable +' ' Text +'-' Operator +'>' Operator +' ' Text +'Size' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +' ' Text +'>' Operator +' ' Text +'0' Name.Variable +' ' Text +'and' Operator.Word +' ' Text +'IsAssociative' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'[ [ m5 ] ]\n' Generic.Output + +'gap> ' Generic.Prompt +'Filtered' Name.Variable +'(' Punctuation +'Combinations' Name.Variable +'(' Punctuation +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +')' Punctuation +',' Operator +' ' Text +'x' Name.Variable +' ' Text +'-' Operator +'>' Operator +' ' Text +'Size' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +' ' Text +'>' Operator +' ' Text +'0' Name.Variable +' ' Text +'and' Operator.Word +' ' Text +'IsCommutative' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'[ [ m1 ], [ m1, m5 ], [ m2 ], [ m2, m5 ], [ m3 ], [ m3, m4 ], [ m4 ], [ m5 ] ]\n' Generic.Output + +'gap> ' Generic.Prompt +'T' Name.Variable +' ' Text +':=' Operator +' ' Text +'[' Punctuation +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'1' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'2' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'2' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'2' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'1' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'1' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'4' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +' ' Text +']' Punctuation +',' Operator +'\n' Text + +'> ' Generic.Prompt +' ' Text +' ' Text +'[' Punctuation +' ' Text +'2' Name.Variable +',' Operator +' ' Text +'2' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +',' Operator +' ' Text +'5' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +' ' Text +']' Punctuation +'\n' Text + +'> ' Generic.Prompt +']' Punctuation +';' Operator +';' Operator +'\n' Text + +'gap> ' Generic.Prompt +'M' Name.Variable +' ' Text +':=' Operator +' ' Text +'MagmaByMultiplicationTable' Name.Variable +'(' Punctuation +'T' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'\n' Generic.Output + +'gap> ' Generic.Prompt +'IsAssociative' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +' ' Text +'or' Operator.Word +' ' Text +'IsCommutative' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +';' Operator +'\n' Text + +'false\n' Generic.Output + +'gap> ' Generic.Prompt +'Filtered' Name.Variable +'(' Punctuation +'Combinations' Name.Variable +'(' Punctuation +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +')' Punctuation +',' Operator +' ' Text +'x' Name.Variable +' ' Text +'-' Operator +'>' Operator +' ' Text +'Size' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +' ' Text +'>' Operator +' ' Text +'0' Name.Variable +' ' Text +'and' Operator.Word +' ' Text +'IsAssociative' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'[ [ m1 ], [ m1, m3 ], [ m2 ], [ m2, m4 ], [ m3 ], [ m4 ] ]\n' Generic.Output + +'gap> ' Generic.Prompt +'AsSemigroup' Name.Variable +'(' Punctuation +'[' Punctuation +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +'[' Punctuation +'1' Name.Variable +']' Punctuation +',' Operator +' ' Text +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +'[' Punctuation +'2' Name.Variable +']' Punctuation +']' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'fail\n' Generic.Output + +'gap> ' Generic.Prompt +'AsSemigroup' Name.Variable +'(' Punctuation +'[' Punctuation +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +'[' Punctuation +'1' Name.Variable +']' Punctuation +',' Operator +' ' Text +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +'[' Punctuation +'3' Name.Variable +']' Punctuation +']' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'\n' Generic.Output + +'gap> ' Generic.Prompt +'Filtered' Name.Variable +'(' Punctuation +'Combinations' Name.Variable +'(' Punctuation +'Elements' Name.Variable +'(' Punctuation +'M' Name.Variable +')' Punctuation +')' Punctuation +',' Operator +' ' Text +'x' Name.Variable +' ' Text +'-' Operator +'>' Operator +' ' Text +'Size' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +' ' Text +'>' Operator +' ' Text +'0' Name.Variable +' ' Text +'and' Operator.Word +' ' Text +'IsCommutative' Name.Variable +'(' Punctuation +'x' Name.Variable +')' Punctuation +')' Punctuation +';' Operator +'\n' Text + +'[ [ m1 ], [ m1, m2 ], [ m1, m2, m3 ], [ m1, m2, m5 ], [ m1, m3 ], [ m1, m5 ], \n' Generic.Output + +' [ m2 ], [ m2, m3 ], [ m2, m4 ], [ m2, m5 ], [ m3 ], [ m4 ], [ m5 ] ]\n' Generic.Output + +'\n' Generic.Output + +'#\n' Generic.Output + +'gap> ' Generic.Prompt +'F' Name.Variable +' ' Text +':=' Operator +' ' Text +'Elements' Name.Variable +'(' Punctuation +' ' Text +'GL' Name.Variable +'(' Punctuation +'2' Name.Variable +',' Operator +'2' Name.Variable +')' Punctuation +' ' Text +')' Punctuation +';' Operator +';' Operator +'\n' Text + +'gap> ' Generic.Prompt +'IsAssociative' Name.Variable +'(' Punctuation +' ' Text +'F' Name.Variable +' ' Text +')' Punctuation +';' Operator +'\n' Text + +'true\n' Generic.Output + +'gap> ' Generic.Prompt +'IsCommutative' Name.Variable +'(' Punctuation +' ' Text +'F' Name.Variable +' ' Text +')' Punctuation +';' Operator +'\n' Text + +'false\n' Generic.Output + +'gap> ' Generic.Prompt +'Number' Name.Variable +'(' Punctuation +' ' Text +'Combinations' Name.Variable +'(' Punctuation +' ' Text +'F' Name.Variable +',' Operator +' ' Text +'3' Name.Variable +' ' Text +')' Punctuation +',' Operator +' ' Text +'IsCommutative' Name.Variable +' ' Text +')' Punctuation +';' Operator +'\n' Text + +'1\n' Generic.Output + +'gap> ' Generic.Prompt +'AsSemigroup' Name.Variable +'(' Punctuation +' ' Text +'F' Name.Variable +' ' Text +')' Punctuation +';' Operator +'\n' Text + +'\n' Generic.Output + +'\n' Generic.Output + +'#\n' Generic.Output + +'gap> ' Generic.Prompt +'STOP_TEST' Name.Variable +'(' Punctuation +' ' Text +'"magma.tst"' Literal.String +' ' Text +')' Punctuation +';' Operator +'\n' Text