On Wed, Mar 4, 2009 at 5:44 AM, David Kohel <drko...@gmail.com> wrote:
>
> Hi,
>
> 1. Here is a bug in evaluation of Magma code
>
> sage: m = Magma()
> sage: s = "for i in [1..7] do print i^2+i+1; end for;"
> sage: m(s)
> ...
> TypeError: Error evaluating Magma code.
> IN:_sage_[5]:=for i in [1..7] do print i^2+i+1; end for;
> OUT:
>>> _sage_[5]:=for i in [1..7] do print i^2+i+1; end for;
>              ^
> User error: bad syntax

That is not a bug.  Use

   m(foo)

(for foo a Sage object or string) to create a new Magma object.  This
is like coercion or m!foo in Magma.  Above you should use m.eval(s).

>
> 2. And here is a bug in the pre-parser:
>
> sage: s = """
> for i in [1..7] do
>    print i^2+i+1;
> end for;
> """
> sage: s
> '\nfor i in (ellipsis_range(1,Ellipsis,7)) do\n        print i^2+i
> +1;\nend for;\n'

This works fine in sage-3.4.alpha0, so I think Robert Bradshaw's
recent rewrite of the preparser must have fixed it.

> Similarly:
>
> sage: s = "\
> for i in [1..7] do\
>    print i^2+i+1;\
> end for;"
> sage: s
> 'for i in (ellipsis_range(1,Ellipsis,7)) do        print i^2+i+1;end
> for;'
>

Similarly this works fine:

sage: s = "\
....: for i in [1..7] do\
....:    print i^2+i+1;\
....: end for;"
sage:
sage: s
'for i in [1..7] do   print i^2+i+1;end for;'


> 3. Although this is not the sage-support list, I'll ask some
> questions:
>   a. Is it possible to pass user_config=True to the %magma shell
>       as for Magma()?
>   b. Where do I find the source code for %magma?

If you define *any* variable in Sage called "magma" and arrange that
it has an eval method (with the right signature), then it will get
used by %magma.  In fact, more generally anybody can trivially make
their own %foo modes.
Anyway, type magma.eval?? to see the source for %magma.  You could
overwrite that function with your own.

>   c.  In the notebook, I don't have the same preprocessing of the
>        input.  In both, the sage shell and notebook I would like to
>        be able to preprocess  ("=","==") -> (":=","=") and keep the

This does happen in the shell.   This was a hack I did specifically
for you, and shouldn't have done.  I think it should be off by
default, *but* it should be very easy for you to turn it on in either
the notebook or command line by adding something to init.sage.

> 4. In the notebook, is it desirable to require a %magma at the top
>   of every cell in order to interpret a sequence of Magma code as
>   such?
>
> Ex.
> %magma
> x := 1;
> for i in [1..7] do
>    x +:= i^2+i+1;
> end for;
>
> Next cell:
>
> %magma
> print x
>
> I expected to remain in %magma mode until executing "quit;"
> as in the Sage command-line shell.

It might be too confusing having what you suggest, given the highly
nonlinear mode in which cells often get evaluated by users.  However,
you can switch a whole worksheet over to Magma mode by selecting magma
in the dropdown list box at the top of the screen.

When we add sectioning to the notebook it would make a lot of sense to
have each section of a worksheet have a default mode for all cells in
a section.

>
> 5. Instead
>
> %magma
> quit
>
> then
>
> %magma
> 1 + 1;
>
> Gives an error; I think it fails to restart a Magma session.

In the command line the above works fine:

magma: quit;

  --> Exiting back to SAGE <--

sage: %magma

  --> Switching to Magma <--

''
magma: 2+2
4

In the notebook I get:

----------
Error evaluating
ChangeDirectory("/Users/wstein/.sage/sage_notebook/worksheets/admin/51/c\
ells/4"); in Magma
--------

That's a valid bug... please report to trac.  This will likely be very
very easy to fix.

> If any Magma users want to suggest or comment on good ways
> to merge Sage and Magma code and port code this would be
> helpful.  I have some 10 years worth of integrated code:
>
> http://echidna.maths.usyd.edu.au/~kohel/alg/index.html
>
> and directories of worked examples.   It is not a simple matter
> of porting a handful of functions.  Instead I need an means of
> working with Magma within Sage, and verifying results in the
> two systems as individual functions do get ported or rewritten
> in Sage.

It's also useful to write some little scripts to replace ":=" by "=", delete
semicolons, etc.  I used to have some when I was porting code.

Is all the code you have above GPL-licensed now?

There are a lot of people porting code from Magma to Sage, and of
course your approach of testing as you go is very good.  You should
also post lists of any low-level functions you need that are in Magma
but are not in Sage, or are too *slow* in Sage.

 -- William

--~--~---------~--~----~------------~-------~--~----~
To post to this group, send email to sage-devel@googlegroups.com
To unsubscribe from this group, send email to 
sage-devel-unsubscr...@googlegroups.com
For more options, visit this group at http://groups.google.com/group/sage-devel
URLs: http://www.sagemath.org
-~----------~----~----~----~------~----~------~--~---

Reply via email to