2.2.18 Rings Inside User-Defined Functions |
Example |
Use R ::= QQ[x,y,z]; S ::= QQ[a,b]; Define Test() PrintLn (x+y)^2; PrintLn S :: (a+b)^3; T ::= ZZ/(5)[t]; I := T :: Ideal(t^2); Print I; EndDefine; Test(); x^2 + 2xy + y^2 S :: a^3 + 3a^2b + 3ab^2 + b^3 T :: Ideal(t^2) ------------------------------- I; -- the variable I was local to the function ERROR: Undefined variable I CONTEXT: I ------------------------------- T; -- The function created the ring T. (Note: T is not a variable.) ZZ/(5)[t] ------------------------------- |
Example |
Define Poincare2(I) Return Poincare(CurrentRing()/I); EndDefine; Use R ::= QQ[x,y]; Poincare2(Ideal(x^2,y^2)); (1 + 2x + x^2) ------------------------------- |
Example |
Define Create(Var(R)); Var(R) ::= QQ[a,b]; EndDefine; Create("K"); K; QQ[a,b] ------------------------------- Create("myring"); Var("myring"); QQ[a,b] ------------------------------- Use Var("myring"); -- make myring current |
Example |
Define CreateRing(I) NewRingName := NewId(); Var(NewRingName) ::= QQ[x[1..I]], Lex; Return NewRingName; EndDefine; Use R ::= QQ[x,y], DegRevLex; Use S ::= QQ[x,y,z], Lex; N := 5; For I := 1 To N Do RingName := CreateRing(I); -- RingName is a string Using Var(RingName) Do PrintLn Indets(); EndUsing; -- Destroy Var(RingName); -- uncomment if you want to destroy the tmp ring EndFor; [x[1]] [x[1], x[2]] [x[1], x[2], x[3]] [x[1], x[2], x[3], x[4]] [x[1], x[2], x[3], x[4], x[5]] ------------------------------- RingEnvs(); ["QQ", "QQt", "R", "S", "V#1", "V#3", "V#5", "V#7", "V#9", "ZZ"] ------------------------------- |