14.3.5 Changing which GAP is used

Use this code to change which GAP interpreter is run. E.g.,
   import sage.interfaces.gap
   sage.interfaces.gap.gap_cmd = "/usr/local/bin/gap"

Author Log:

Module-level Functions

gap_command( [use_workspace_cache=True], [local=True])

gap_console( [use_workspace_cache=True])

Spawn a new GAP command-line session.

sage: gap.console() #not tested
GAP4, Version: 4.4.10 of 02-Oct-2007, x86_64-unknown-linux-gnu-gcc
gap>

gap_reset_workspace( [max_workspace_size=None], [verbose=False])

Call this to completely reset the GAP workspace, which is used by default when SAGE first starts GAP.

The first time you start GAP from SAGE, it saves the startup state of GAP in the file

        $HOME/.sage/gap-workspace
This is useful, since then subsequent startup of GAP is at least 10 times as fast. Unfortunately, if you install any new code for GAP, it won't be noticed unless you explicitly load it, e.g., with gap.load_package("my_package")

The packages sonata, guava, factint, gapdoc, grape, design, toric, and laguna are loaded in all cases before the workspace is saved, if they are available.

gap_version( )

Returns the version of GAP being used.

sage: gap_version()
'4.4.10'

gfq_gap_to_sage( x, F)

Input:

x
- gap finite field element
F
- SAGE finite field
Output: element of F

sage: x = gap('Z(13)')
sage: F = GF(13, 'a')
sage: F(x)
2
sage: F(gap('0*Z(13)'))
0
sage: F = GF(13^2, 'a')
sage: x = gap('Z(13)')
sage: F(x)
2
sage: x = gap('Z(13^2)^3')
sage: F(x)
12*a + 11
sage: F.multiplicative_generator()^3
12*a + 11

Author: David Joyner and William Stein

is_GapElement( x)

Returns True if x is a GapElement.

sage: is_GapElement(gap(2))
True
sage: is_GapElement(2)
False

reduce_load( )

Returns an invalid GAP element. Note that this is the object returned when a GAP element is unpickled.

sage: from sage.interfaces.gap import reduce_load
sage: reduce_load()
(invalid object -- defined in terms of closed session)
sage: loads(dumps(gap(2)))
(invalid object -- defined in terms of closed session)

reduce_load_GAP( )

Returns the GAP interface object definedin sage.interfaces.gap.

sage: from sage.interfaces.gap import reduce_load_GAP
sage: reduce_load_GAP()
Gap

Class: Gap

class Gap
Interface to the GAP interpreter.

Author: William Stein and David Joyner

Gap( self, [max_workspace_size=None], [maxread=100000], [script_subdirectory=None], [use_workspace_cache=True], [server=None], [server_tmpdir=None], [logfile=None])

sage: gap == loads(dumps(gap))
True

Functions: console,$ \,$ cputime,$ \,$ eval,$ \,$ get,$ \,$ help,$ \,$ load_package,$ \,$ save_workspace,$ \,$ set,$ \,$ trait_names,$ \,$ unbind,$ \,$ version

console( self)

Spawn a new GAP command-line session.

sage: gap.console() #not tested
GAP4, Version: 4.4.10 of 02-Oct-2007, x86_64-unknown-linux-gnu-gcc
gap>

cputime( self, [t=None])

Returns the amount of CPU time that the GAP session has used. If t is not None, then it returns the difference between the current CPU time and t.

sage: t = gap.cputime()
sage: t  #random                
0.13600000000000001
sage: gap.Order(gap.SymmetricGroup(5)) 
120
sage: gap.cputime(t)  #random
0.059999999999999998

eval( self, x, [newlines=False], [strip=True])

Send the code in the string s to the GAP interpreter and return the output as a string.

Input:

s
- string containing GAP code.
newlines
- bool (default: True); if False, remove all backslash-newlines inserted by the GAP output formatter.
strip
- ignored

sage: gap.eval('2+2')
'4'

get( self, var, [use_file=False])

Get the string representation of the variable var.

sage: gap.set('x', '2')
sage: gap.get('x')
'2'

help( self, s, [pager=True])

Print help on a given topic.

sage: print gap.help('SymmetricGroup', pager=False)
Basic Groups _____________________________________________ Group Libraries
...

load_package( self, pkg, [verbose=False])

Load the Gap package with the given name.

If loading fails, raise a RuntimeError exception.

set( self, var, value)

Set the variable var to the given value.

sage: gap.set('x', '2')
sage: gap.get('x')
'2'

trait_names( self)

sage: c = gap.trait_names()
sage: len(c) > 100
True
sage: 'Order' in c
True

unbind( self, var)

Clear the variable named var.

sage: gap.set('x', '2') 
sage: gap.get('x')      
'2'
sage: gap.unbind('x')    
sage: gap.get('x')     
Traceback (most recent call last):
...
RuntimeError: Gap produced error output
Variable: 'x' must have a value
...

version( self)

Returns the version of GAP being used.

sage: gap.version()
'4.4.10'

Special Functions: __init__,$ \,$ __reduce__,$ \,$ _contains,$ \,$ _continuation_prompt,$ \,$ _equality_symbol,$ \,$ _eval_line,$ \,$ _eval_line_using_file,$ \,$ _execute_line,$ \,$ _false_symbol,$ \,$ _function_class,$ \,$ _function_element_class,$ \,$ _keyboard_interrupt,$ \,$ _next_var_name,$ \,$ _object_class,$ \,$ _post_interact,$ \,$ _pre_interact,$ \,$ _quit_string,$ \,$ _read_in_file_command,$ \,$ _start,$ \,$ _true_symbol

__reduce__( self)

sage: gap.__reduce__()
(<function reduce_load_GAP at 0x...>, ())
sage: f, args = _
sage: f(*args)
Gap

_contains( self, v1, v2)

sage: Integers = gap('Integers')
sage: two = gap(2)
sage: gap._contains(two.name(), Integers.name())
True

sage: 2 in gap('Integers')
True

_continuation_prompt( self)

Returns the continuation prompt in GAP.

sage: gap._continuation_prompt()
'> '

_equality_symbol( self)

Returns the symbol for equality in GAP.

sage: gap._equality_symbol()
'='
sage: gap(2) == gap(2)
True

_eval_line( self, line, [allow_use_file=True], [wait_for_prompt=True])

sage: gap._eval_line('2+2;')
'4'

_false_symbol( self)

Returns the symbol for falsity in GAP.

sage: gap._false_symbol()
'false'
sage: gap(2) == gap(3)
False

_function_class( self)

Returns the GapFunction class.

sage: gap._function_class()
<class 'sage.interfaces.gap.GapFunction'>

sage: type(gap.Order)
<class 'sage.interfaces.gap.GapFunction'>

_function_element_class( self)

Returns the GapFunctionElement class.

sage: gap._function_element_class()
<class 'sage.interfaces.gap.GapFunctionElement'>
sage: type(gap.SymmetricGroup(4).Order)
<class 'sage.interfaces.gap.GapFunctionElement'>

_next_var_name( self)

Returns the next unused variable name.

sage: g = Gap()
sage: g._next_var_name()
'$sage1'
sage: g(2)^2
4
sage: g._next_var_name()
'$sage5'

_object_class( self)

Returns the GapElement class.

sage: gap._object_class()
<class 'sage.interfaces.gap.GapElement'>
sage: type(gap(2))
<class 'sage.interfaces.gap.GapElement'>

_post_interact( self)

sage: gap._pre_interact()
sage: gap._post_interact()

_pre_interact( self)

sage: gap._pre_interact()
sage: gap._post_interact()

_quit_string( self)

Returns the string used to quit GAP.

sage: gap._quit_string()
'quit'

sage: g = Gap()
sage: a = g(2); g.is_running()
True
sage: g.quit()
sage: g.is_running()
False

_read_in_file_command( self, filename)

Returns the command use to read in a file in GAP.

sage: gap._read_in_file_command('test')
'Read("test");'

            sage: filename = tmp_filename()
            sage: f = open(filename, 'w')
            sage: f.write('xx := 22;
')
            sage: f.close()
            sage: gap.read(filename)   
            sage: gap.get('xx').strip() 
            '22'

_start( self)

sage: g = Gap()
sage: g.is_running()
False
sage: g._start()
sage: g.is_running()
True
sage: g.quit()

_true_symbol( self)

Returns the symbol for truth in GAP.

sage: gap._true_symbol()
'true'
sage: gap(2) == gap(2)
True

Class: GapElement

class GapElement

Functions: bool,$ \,$ str,$ \,$ trait_names

bool( self)

sage: bool(gap(2))
True
sage: gap(0).bool()
False
sage: gap('false').bool()
False

str( self, [use_file=False])

sage: print gap(2)
2

trait_names( self)

sage: s5 = gap.SymmetricGroup(5)
sage: 'Centralizer' in s5.trait_names()
True

Special Functions: __getitem__,$ \,$ __len__,$ \,$ __reduce__,$ \,$ __repr__,$ \,$ _latex_,$ \,$ _matrix_

__getitem__( self, n)

sage: a = gap([1,2,3])
sage: a[1]
1

__len__( self)

sage: v = gap('[1,2,3]'); v
[ 1, 2, 3 ]
sage: len(v)
3

len is also called implicitly by if:

sage: if gap('1+1 = 2'):
...    print "1 plus 1 does equal 2"
1 plus 1 does equal 2

sage: if gap('1+1 = 3'): 
...    print "it is true"
... else:
...    print "it is false"
it is false

__reduce__( self)

Note that GAP elements cannot be pickled.

sage: gap(2).__reduce__()
(<function reduce_load at 0x...>, ())
sage: f, args = _
sage: f(*args)
(invalid object -- defined in terms of closed session)

__repr__( self)

sage: gap(2)
2

_latex_( self)

sage: s = gap("[[1,2], [3/4, 5/6]]")
sage: latex(s)
\left(\begin{array}{rr} 1\&2\\ 3/4\&\frac{5}{6}\\ \end{array}\right)

_matrix_( self, R)

Return matrix over the (Sage) ring R determined by self, where self should be a Gap matrix.

sage: s = gap("(Z(7)^0)*[[1,2,3],[4,5,6]]"); s
[ [ Z(7)^0, Z(7)^2, Z(7) ], [ Z(7)^4, Z(7)^5, Z(7)^3 ] ]
sage: s._matrix_(GF(7))
[1 2 3]
[4 5 6]

sage: s = gap("[[1,2], [3/4, 5/6]]"); s
[ [ 1, 2 ], [ 3/4, 5/6 ] ]
sage: m = s._matrix_(QQ); m
[  1   2]
[3/4 5/6]            
sage: parent(m)
Full MatrixSpace of 2 by 2 dense matrices over Rational Field

sage: s = gap('[[Z(16),Z(16)^2],[Z(16)^3,Z(16)]]')
sage: s._matrix_(GF(16,'a'))
[  a a^2]
[a^3   a]

Class: GapFunction

class GapFunction

Special Functions: _sage_doc_

_sage_doc_( self)

sage: print gap.SymmetricGroup._sage_doc_()
Basic Groups _____________________________________________ Group Libraries
...

Class: GapFunctionElement

class GapFunctionElement

Special Functions: _sage_doc_

_sage_doc_( self)

sage: print gap(4).SymmetricGroup._sage_doc_()
Basic Groups _____________________________________________ Group Libraries
...

See About this document... for information on suggesting changes.