# HG changeset patch
# User William Stein <wstein@gmail.com>
# Date 1203062905 28800
# Node ID ad5d8bd802bc4a04661f55bf699bb9f3fefd197d
# Parent 4f079c4bcca31e52f4dd9fa1b22221516148067e
followup to #2169 -- (magma/sage interface) some further optimizations and fixes
diff -r 4f079c4bcca3 -r ad5d8bd802bc magma/sage/basic.m
a
|
b
|
intrinsic Sage(X::.) -> MonStgElt |
| 1 | function PreparseElts(R) |
| 2 | if Type(R) eq RngInt then |
| 3 | return false; |
| 4 | end if; |
| 5 | return true; |
| 6 | end function; |
| 7 | |
1 | 8 | intrinsic Sage(X::.) -> MonStgElt |
2 | 9 | {} |
3 | | return Sprintf("%o", X); |
| 10 | return Sprintf("%o", X), true; |
4 | 11 | end intrinsic; |
5 | 12 | |
6 | 13 | intrinsic Sage(X::SetEnum) -> MonStgElt |
7 | 14 | {} |
8 | 15 | Y := [Sage(z) : z in X]; |
9 | | return Sprintf("Set(%o)", Y); |
| 16 | return Sprintf("Set(%o)", Y), true; |
10 | 17 | end intrinsic; |
11 | 18 | |
12 | 19 | intrinsic Sage(X::SetIndx) -> MonStgElt |
13 | 20 | {WARNING: Sage does not have an analogue of indexed sets.} |
14 | 21 | Y := [z : z in X]; |
15 | | return Sprintf("%o", Y); |
| 22 | return Sprintf("%o", Y), true; |
16 | 23 | end intrinsic; |
17 | 24 | |
18 | | intrinsic Sage(X::SetMulti) -> MonStgElt |
| 25 | intrinsic Sage(X::SetMulti) -> MonStgElt, BoolElt |
19 | 26 | {WARNING: Sage does not have an analogue of multisets.} |
20 | 27 | Y := [z : z in X]; |
21 | | return Sprintf("%o", Y); |
| 28 | return Sprintf("%o", Y), true; |
22 | 29 | end intrinsic; |
23 | 30 | |
24 | | intrinsic Sage(X::RngInt) -> MonStgElt |
| 31 | intrinsic Sage(X::RngInt) -> MonStgElt, BoolElt |
25 | 32 | {} |
26 | | return "ZZ"; |
| 33 | return "ZZ", false; |
27 | 34 | end intrinsic; |
28 | 35 | |
29 | | function convert_matrix(X) |
30 | | return Sprintf("matrix(%o, %o, %o, %o)", Sage(BaseRing(X)), |
| 36 | intrinsic Sage(X::RngIntElt) -> MonStgElt, BoolElt |
| 37 | {} |
| 38 | return Sprintf("Integer('%h')", X), false; |
| 39 | end intrinsic; |
| 40 | |
| 41 | /* Matrices */ |
| 42 | |
| 43 | function convert_matrix(X, preparse_entries) |
| 44 | if preparse_entries then |
| 45 | return Sprintf("matrix(%o, %o, %o, %o)", Sage(BaseRing(X)), |
31 | 46 | Nrows(X), Ncols(X), [Sage(y) : y in Eltseq(X)]); |
| 47 | else |
| 48 | return Sprintf("matrix(%o, %o, %o, %o)", Sage(BaseRing(X)), |
| 49 | Nrows(X), Ncols(X), Eltseq(X)); |
| 50 | end if; |
32 | 51 | end function; |
33 | 52 | |
34 | | intrinsic Sage(X::AlgMatElt) -> MonStgElt |
| 53 | intrinsic Sage(X::AlgMatElt) -> MonStgElt, BoolElt |
35 | 54 | {} |
36 | | return convert_matrix(X); |
| 55 | pp := PreparseElts(BaseRing(X)); |
| 56 | return convert_matrix(X, pp), pp; |
37 | 57 | end intrinsic; |
38 | 58 | |
39 | | intrinsic Sage(X::ModMatRngElt) -> MonStgElt |
| 59 | intrinsic Sage(X::ModMatRngElt) -> MonStgElt, BoolElt |
40 | 60 | {} |
41 | | return convert_matrix(X); |
| 61 | pp := PreparseElts(BaseRing(X)); |
| 62 | return convert_matrix(X, pp), pp; |
42 | 63 | end intrinsic; |