# Is it possible to run GAP code in Sage?

This might be a very basic question, but I'm struggling to find a solution. I have created a function in GAP, and I want to use it in Sagemath. So my question is: is it possible to run GAP code in Sage? For example:

f = gap('f := function(n) .... my entire code in GAP ... end;')

If it's not possible to run an entire code block, can I at least create a function in Sage that calls GAP functions?

To illustrate a simple scenario: Suppose I define vector spaces V and U in Sage. I want to define a morphism f using the GAP function LeftModuleHomomorphismByImages(V, U, gens, imgs).

rather use libgap

Thanks, FrédéricC! This was very helpful, and my code is running now. One thing I couldn't fix was when we called a GAP function that contains some strings, but I managed to work around it in my code.

You could post your solution as an answer below, if you like.

You

shouldpost your solution as an answer below for the benefit of future`ask.sagemath.org`

(per-)users...