1Package $BringIn
2
3export BringIn;
4
5
6----------------------------------------------------------------------
7Define About()
8  PrintLn  "    Version  : CoCoA 4.1";
9  PrintLn  "    Date     : 11 March 2007";
10  PrintLn  "    Author   : Anna Bigatti";
11EndDefine;
12----------------------------------------------------------------------
13
14Define BringIn(...)
15  TopLevel CurrentRing;
16  If   len(ARGV) = 1 Then R := CurrentRing; F := ARGV[1];
17  Elif len(ARGV) = 2 Then R := ARGV[1];     F := ARGV[2];
18  Else
19    BringInErr := "Wrong number of arguments; found: "+sprint(len(ARGV))+
20    ", expecting: 1 or 2";
21    error(BringInErr);
22  EndIf;
23  If type(F) = INT Then Return RingElem(R, F); EndIf;
24  If type(F) = RAT Then Return RingElem(R, F); EndIf;
25  If type(F) = LIST Then Return [$.BringIn(R, X) | X In F]; EndIf;
26  If type(F) = MAT Then
27    Return mat([[$.BringIn(R, X) | X In ROW] | ROW in GetRows(F)]);
28  EndIf;
29  If type(F) = IDEAL Then
30    error("To map an ideal type: ideal(BringIn(gens(I)))");
31  EndIf;
32  If type(F) = RINGELEM Then
33    if IsZero(F) then return zero(R); endif;
34    Ch_F := characteristic(RingOf(F));
35    Ch_R := characteristic(R);
36    If Ch_F = Ch_R Then
37      If IsPolyRing(RingOf(F)) Then
38	Return apply(PolyAlgebraHom(RingOf(F), R, MapList(R,F)), F);
39      Else
40	Return apply(CanonicalHom(RingOf(F), R), F);
41      EndIf;
42    elif Ch_F = 0 Then
43      If IsPolyRing(RingOf(F)) Then
44	Return apply(PolyRingHom(RingOf(F), R, CanonicalHom(CoeffRing(RingOf(F)), R), MapList(R,F)), F);
45      Else
46	Return apply(CanonicalHom(RingOf(F), R), F);
47      EndIf;
48    else
49      error("BringIn: cannot convert into different finite characteristic");
50    EndIf;
51  EndIf;
52    error("BringIn: cannot apply to "+sprint(type(F)));
53EndDefine;
54
55
56Define MapList(R, f)  // RingOf(f) --> R
57  P := RingOf(f);
58  ML := NewList(NumIndets(P));
59  IndetsInF := IndetsProd(f);
60  for i := 1 to NumIndets(P) do
61    if IsDivisible(IndetsInF, indet(P,i)) then
62      ML[i] := RingElem(R, sprint(indet(P,i))); // indet in R with same name
63    endif;
64  endfor;
65  Return ML;
66EndDefine; -- MapList
67
68
69Define Man()
70  PrintLn " A package exporting the function BringIn which intelligently";
71  PrintLn "maps a polynomial into the current ring preserving variable names.";
72  PrintLn "";
73  PrintLn "-- >EXAMPLES< --";
74  PrintLn "";
75  PrintLn "RR ::= QQ[x[1..4],z,y];";
76  PrintLn "SS ::= ZZ/(101)[z,y,x[1..2]];";
77  PrintLn "Use RR;";
78  PrintLn "F := (x[1]-y-z)^5;";
79  PrintLn "len(F);";
80  PrintLn "F;";
81  PrintLn "Use SS;";
82  PrintLn "Time B := BringIn(F);";
83  PrintLn "B;";
84  PrintLn "";
85  PrintLn "-- >EXAMPLES< --";
86  PrintLn "";
87  PrintLn "Use R ::= QQ[x,y,z];";
88  PrintLn "F := 1/2*x^3+34/567*x*y*z-890;   -- a poly with rational coefficients";
89  PrintLn "Use S ::= ZZ/(101)[x,y,z];";
90  PrintLn "QZP(F);";
91  PrintLn "BringIn(F);";
92EndDefine;
93
94EndPackage;
95