InstallDocumentation(
rec( 
kind:= "KEYWORD",
name:= "Constants",
short := 
"For convenience some constants are predefined in KASH.  "+
"These constants cannot be overwritten.  Some constants, namely 'E' and 'PI'.  "+
"change their value with the global precision 'Precision'.  By convention constants are "+
"written in capitals.\n\n"+
"Enter '?*.|CONSTANT' to see a list of all constants.",
see:= [DocHash("InstallConstants()"),
       DocHash("Precision()"), 
       DocHash("Precision(elt-ord^rat)")]
)
);
###################################################################
C := VOID;
E := VOID;
I := VOID;
INFTY := VOID;
PI := VOID;
Q := VOID;
R := VOID;
X := VOID;
Z := VOID;
ZX := VOID;

_InstallConstants := function()
  C := ComplexField();
  R := RealField();
  Q := RationalField();
  PI := Pi(R);
  E := Exp(1);
  I := C.1;
  AssignNames_(C,["I"]);
  INFTY := Infinity();
  Z := IntegerRing();
  ZX := PolynomialAlgebra(Z);
  X  := ZX.1;
  AssignNames_(ZX,["X"]);
end;

InstallMethod(
rec(
kind:= "FUNCTION",
name:= "InstallConstants",
sin := [ ],
sou := [ ],
short := 
"Reinitialize the constants\n"+
"C := ComplexField();\n"+
"E := Exp(1);\n"+
"I := C.1;\n"+
"PI:= Pi(R);\n"+
"Q := RationalField();\n"+
"R := RealField();\n"+
"X := ZX.1;\n"+
"Z := Integers();\n"+
"ZX:= PolynomialRing(Z);",
see:= [DocHash("Constants"),
       DocHash("Precision(elt-ord^rat)")]
),
_InstallConstants
);
InstallConstants();
#################### install docu for constants initialized above
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "Q",
sou := [[Type(Q)]],
short := 
"The field of rational numbers."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "Z",
sou := [[Type(Z)]],
short := 
"The ring of rational integers."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "ZX",
sou := [[Type(ZX)]],
short := 
"The ring of polynomials in X over the ring of rational integers Z."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "X",
sou := [[Type(X)]],
short := 
"The variable of the ring of polynomials ZX over the ring of rational integers Z."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "R",
sou := [[fld^rea]],
short := 
"The global real field."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "C",
sou := [[Type(C)]],
short := 
"The global complex field."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "I",
sou := [[Type(I)]],
short := 
"A complex number I with I^2=-1."
)
);
InstallDocumentation(
rec( 
kind:= "CONSTANT",
name:= "E",
sou := [[Type(E)]],
short := 
"Eulers constant to the global precision 'Precision()'."
)
);

##################################################################

InstallMethod(
rec( 
kind:= "FUNCTION",
name:= "Precision",
sin := [ ],
sou := [[elt-ord^rat,"prec"]],
short := 
"Returns the global precision for real and complex computations in the shell.",
see := [DocHash("Precision(elt-ord^rat)")]
),
function()
  return Precision(RealField());
end
);

InstallMethod(
rec( 
kind:= "FUNCTION",
name:= "Precision",
sin := [[elt-ord^rat,"n"]],
sou := [[elt-ord^rat,"prec"]],
short := 
"Sets the global precision for real and complex computations in the shell to 'n' and\
 returns the  new global precision.  The default precision is 20.  This function\
 also reinstalls the constants C, E, PI, Q, R, X, Z, ZX.",
see := [DocHash("InstallConstants()"),
        DocHash("SetDefaultRealFieldPrecision(elt-ord^rat)")]
),
function(n)
  SetDefaultRealFieldPrecision(n);
  InstallConstants();
  return Precision(RealField());
end
);
