Ticket #2171: extcode-trac2171.patch

File extcode-trac2171.patch, 2.5 KB (added by was, 15 years ago)
  • magma/sage/basic.m

    # 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 
     1function PreparseElts(R)
     2    if Type(R) eq RngInt then
     3       return false;
     4    end if;
     5    return true;
     6end function;
     7
    18intrinsic Sage(X::.) -> MonStgElt
    29{}
    3     return Sprintf("%o", X);
     10    return Sprintf("%o", X), true;
    411end intrinsic;
    512
    613intrinsic Sage(X::SetEnum) -> MonStgElt
    714{}
    815    Y := [Sage(z) : z in X];
    9     return Sprintf("Set(%o)", Y);
     16    return Sprintf("Set(%o)", Y), true;
    1017end intrinsic;
    1118
    1219intrinsic Sage(X::SetIndx) -> MonStgElt
    1320{WARNING: Sage does not have an analogue of indexed sets.}
    1421    Y := [z : z in X];
    15     return Sprintf("%o", Y);
     22    return Sprintf("%o", Y), true;
    1623end intrinsic;
    1724
    18 intrinsic Sage(X::SetMulti) -> MonStgElt
     25intrinsic Sage(X::SetMulti) -> MonStgElt, BoolElt
    1926{WARNING: Sage does not have an analogue of multisets.}
    2027    Y := [z : z in X];
    21     return Sprintf("%o", Y);
     28    return Sprintf("%o", Y), true;
    2229end intrinsic;
    2330
    24 intrinsic Sage(X::RngInt) -> MonStgElt
     31intrinsic Sage(X::RngInt) -> MonStgElt, BoolElt
    2532{}
    26     return "ZZ";
     33    return "ZZ", false;
    2734end intrinsic;
    2835
    29 function convert_matrix(X)
    30     return Sprintf("matrix(%o, %o, %o, %o)", Sage(BaseRing(X)),
     36intrinsic Sage(X::RngIntElt) -> MonStgElt, BoolElt
     37{}
     38    return Sprintf("Integer('%h')", X), false;
     39end intrinsic;
     40
     41/* Matrices */
     42
     43function convert_matrix(X, preparse_entries)
     44    if preparse_entries then
     45        return Sprintf("matrix(%o, %o, %o, %o)", Sage(BaseRing(X)),
    3146                    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;
    3251end function;
    3352
    34 intrinsic Sage(X::AlgMatElt) -> MonStgElt
     53intrinsic Sage(X::AlgMatElt) -> MonStgElt, BoolElt
    3554{}
    36     return convert_matrix(X);
     55    pp := PreparseElts(BaseRing(X));
     56    return convert_matrix(X, pp), pp;
    3757end intrinsic;
    3858
    39 intrinsic Sage(X::ModMatRngElt) -> MonStgElt
     59intrinsic Sage(X::ModMatRngElt) -> MonStgElt, BoolElt
    4060{}
    41     return convert_matrix(X);
     61    pp := PreparseElts(BaseRing(X));
     62    return convert_matrix(X, pp), pp;
    4263end intrinsic;