
#--------------------------------------------------------------------#
# MuPAD - Systeminitialisierungsdatei		     (16.09.94)	     #
#--------------------------------------------------------------------#


proc()
    local x, path, ttype, newElem, lightFun, ownlocals, pathSep,
          filedescr, lib_path;
begin	# Wird als Prozedur geschrieben, um Eintragungen in  #
 	# in die History zu vermeiden.			     #

#  the local variables of this procedure should not be protected #
ownlocals := { hold(x), hold(path), hold(ttype),
               hold(newElem), hold(lightFun), hold(ownlocals),
               hold(filedescr) }:

#--------------------------------------------------------------------#
# if tar-lib exists, use it                                          #
# since the library is not yet loaded, we have no pathname()         #
# therefore we must construct the correct path by hand.              #
#--------------------------------------------------------------------#
  if sysname() = "MACOS" then
    pathSep := ":":
  else
    pathSep := "":
  end_if:
				  
  lib_path:= LIB_PATH;
  filedescr := fopen(LIB_PATH.pathSep."lib.tar");
  if filedescr <> FAIL then
    fclose(filedescr):
    filedescr := NIL:
    LIB_PATH := LIB_PATH.pathSep."lib.tar#lib":
  end_if:

#--------------------------------------------------------------------#
# initialize domains for buit-in types 				     #
#--------------------------------------------------------------------#

lightFun:= proc() # fun's are not yet declared #
    option hold;
begin
    newpurefunc("fun(...)", NIL, args(1), FALSE);
end_proc:

ttype:= lightFun((
    if domtype(args(1)) = args(2) then
	TRUE
    else
	FAIL
    end_if
)):

newElem:= lightFun((args(1))::new(args(2..args(0))));

protected(hold(_assign), None); 
                              # do all assignments, even if protected #
block( _assign, (
sysassign( _assign, sysassign );

DOM_ARRAY:= domtype(array(1..1));
DOM_ARRAY::testtype:= ttype;
DOM_ARRAY::func_call:= lightFun(
    map(context(args(1)),
	fun(args(1)(args(2..args(0)))),
	context(args(2..args(0))))
):
DOM_ARRAY::new:= array:
DOM_ARRAY::new_extelement:= newElem:

DOM_BOOL:= domtype(TRUE);
DOM_BOOL::testtype:= ttype;
DOM_BOOL::new:= lightFun( args()):
DOM_BOOL::new_extelement:= newElem:

DOM_COMPLEX:= domtype(I);
DOM_COMPLEX::testtype:= ttype;
DOM_COMPLEX::D := 0 ;
DOM_COMPLEX::new:= lightFun( args(1)+I*args(2)):
DOM_COMPLEX::new_extelement:= newElem:
 
DOM_DOMAIN:= domtype(domain("DOM_DOMAIN"));
DOM_DOMAIN::testtype:= ttype;
DOM_DOMAIN::func_call:= domainfunccall ;
DOM_DOMAIN::new:= domain:
DOM_DOMAIN::new_extelement:= newElem:

DOM_EXEC:= domtype(op(_assign, 1));
DOM_EXEC::testtype:= ttype;
DOM_EXEC::new:= built_in:
DOM_EXEC::new_extelement:= newElem:

DOM_EXPR:= domtype(x+1);
DOM_EXPR::testtype:= lightFun((
    if domtype(args(2)) = DOM_EXPR then
	if domtype(args(1)) <> DOM_EXPR then
	    FALSE
	elif op(args(1), 0) <> op(args(2), 0) then
	    FALSE
	elif nops(args(1)) <> nops(args(2)) then
	    FALSE
	elif nops(args(1)) = 0 then
	    TRUE
	elif nops(args(1)) = 1 then
	    testtype(op(args(1), 1), op(args(2), 1))
	else
	    testtype(op(args(1)), Type::Product(op(args(2))))
	end_if
    elif domtype(args(1)) = args(2) then
	TRUE
    else
	FAIL
    end_if
));
DOM_EXPR::new:= lightFun( args(1)(args(2..args(0)))):
DOM_EXPR::new_extelement:= newElem:

DOM_FAIL:= domtype(FAIL);
DOM_FAIL::testtype:= ttype;
DOM_FAIL::D := lightFun( FAIL);
DOM_FAIL::new:= lightFun(FAIL ):
DOM_FAIL::new_extelement:= newElem:

DOM_FLOAT:= domtype(1.0);
DOM_FLOAT::testtype:= ttype;
DOM_FLOAT::D := 0 ;
DOM_FLOAT::new:= lightFun( args() ):
DOM_FLOAT::new_extelement:= newElem:
 
DOM_FUNC_ENV:= domtype(_assign);
DOM_FUNC_ENV::testtype:= ttype;
DOM_FUNC_ENV::new:= func_env:
DOM_FUNC_ENV::new_extelement:= newElem:
 
DOM_IDENT:= domtype(x);
DOM_IDENT::testtype:= ttype;
DOM_IDENT::new:= lightFun( args() ):
DOM_IDENT::new_extelement:= newElem:
 
DOM_INT:= domtype(1);
DOM_INT::testtype:= ttype;
DOM_INT::D := 0 ;
DOM_INT::new:= lightFun( args() ):
DOM_INT::new_extelement:= newElem:

DOM_NIL:= domtype(NIL);
DOM_NIL::testtype:= ttype;
DOM_NIL::new:= lightFun(NIL ):
DOM_NIL::new_extelement:= newElem:

DOM_NULL:= domtype(null());
DOM_NULL::testtype:= ttype;
DOM_NULL::new:= lightFun(null() ):
DOM_NULL::new_extelement:= newElem:

DOM_POLY:= domtype(poly(0, [x]));
DOM_POLY::testtype:= ttype;
DOM_POLY::new:= poly:
DOM_POLY::new_extelement:= newElem:

DOM_PROC:= domtype(proc() begin end_proc);
DOM_PROC::testtype:= ttype;
DOM_PROC::new:= _procdef: 

DOM_RAT:= domtype(1/2);
DOM_RAT::testtype:= ttype;
DOM_RAT::D := 0 ;
DOM_RAT::new:= lightFun(args(1)/args(2)):
DOM_RAT::new_extelement:= newElem:

DOM_SET:= domtype({});
DOM_SET::testtype:= ttype;
DOM_SET::func_call:= DOM_ARRAY::func_call:
DOM_SET::new:= lightFun({args()}):
DOM_SET::new_extelement:= newElem:
 
DOM_LIST:= domtype([]);
DOM_LIST::testtype:= ttype;
DOM_LIST::func_call:= DOM_ARRAY::func_call:
DOM_LIST::new:= lightFun([args()]):
DOM_LIST::new_extelement:= newElem:

DOM_STRING:= domtype("");
DOM_STRING::testtype:= lightFun((
    if domtype(args(2)) = DOM_STRING then
	bool(type(args(1)) = args(2))
    elif domtype(args(1)) = args(2) then
	TRUE
    else
	FAIL
    end_if
));
DOM_STRING::_less := lightFun(
  bool(sort([args(1),args(2)])=[args(1),args(2)] and args(1) <> args(2))) ;
DOM_STRING::_leequal := lightFun(
  bool(sort([args(1),args(2)])=[args(1),args(2)])) ;
DOM_STRING::new:= lightFun(args()):
DOM_STRING::new_extelement:= newElem:

DOM_TABLE:= domtype(table());
DOM_TABLE::testtype:= ttype;
DOM_TABLE::func_call:= DOM_ARRAY::func_call:
DOM_TABLE::new:= table:
DOM_TABLE::new_extelement:= newElem:

NUMERIC:= domain("NUMERIC");
NUMERIC::testtype:= lightFun((
    if contains({ DOM_INT, DOM_RAT, DOM_FLOAT, DOM_COMPLEX },
	        domtype(args(1))) then
        TRUE
    else
	FAIL
    end_if
));
NUMERIC::new:= lightFun(args()):
NUMERIC::new_extelement:= newElem:


DOM_POINT:= domtype(point(1,2,3));
DOM_POINT::testtype := ttype;
DOM_POINT::new:= point:
DOM_POINT::new_extelement:= newElem:

DOM_POLYGON:= domtype(polygon(point(1,2,3)));
DOM_POLYGON::testtype := ttype;
DOM_POLYGON::new:= polygon:
DOM_POLYGON::new_extelement:= newElem:

#--------------------------------------------------------------------#
# remember values for special functions                              #
#--------------------------------------------------------------------#

abs(I):= 1: abs(PI):=PI: abs(E):=E: abs(EULER):=EULER:

#--------------------------------------------------------------------#
# Operatorregeln f"ur +, *, ^ und @                                  #
#--------------------------------------------------------------------#

#(f+g)(x) --> f(x)+g(x)#
_plus := funcattr(_plus, "operator", op_plusmult) :

#(f*g)(x) --> f(x)*g(x)#
_mult := funcattr(_mult, "operator", op_plusmult) :

# ((f=g))(x) --> f(x)=g(x) #
_equal := funcattr(_equal, "operator", op_plusmult) :

# (f<g)(x) --> f(x)<g(x) #
_less := funcattr(_less, "operator", op_plusmult) :

# (f<=g)(x) --> f(x)<=g(x) #
_leequal := funcattr(_leequal, "operator", op_plusmult) :

# (f<>g)(x) --> f(x)<>g(x) #
_unequal := funcattr(_unequal, "operator", op_plusmult) :

# (f and g)(x) --> f(x) and g(x) #
_and := funcattr(_and, "operator", op_plusmult) :

# (f or g)(x) --> f(x) or g(x) #
_or := funcattr(_or, "operator", op_plusmult) :

# NSB version need this definition #
#(not f)(x) --> not f(x)#
_not := funcattr(_not, "operator", op_plusmult) :

#(f^n)(x) --> f(x)^n#
_power := funcattr(_power, "operator", op_power) :

#(f@g)(x) --> f(g(x))#
_fconcat := funcattr(_fconcat, "operator", op_fconcat) :

#--------------------------------------------------------------------#
# define "float" attributes for basic arithmetic operators           #
#--------------------------------------------------------------------#

_plus:=  funcattr(_plus, "float",
		  subsop(float_gen, 5=op(_plus,1), 3="_plus"));

_mult:=  funcattr(_mult, "float",
		  subsop(float_gen, 5=op(_mult,1), 3="_mult"));

_power:= funcattr(_power, "float",
		  subsop(float_gen, 5=op(_power,1), 3="_power"));


#--------------------------------------------------------------------#
# define standard prefix for 'genident'                                                  #
#--------------------------------------------------------------------#

genident := func_env(built_in(1056, NIL, "genident", NIL, "X" ),
		    built_in(1101, 0, NIL, "genident" ),
		    NIL );

#--------------------------------------------------------------------#
# Polynome als Operatoren                                            #
#--------------------------------------------------------------------#

DOM_POLY::func_call:= proc()		# func_call ueberladen #
begin
    if args(0) <> nops(op(args(1),2))+1 then
	error("wrong no of args")
    end_if;
    evalp(args(1), op(zip(op(args(1),2), context([args(2..args(0))]), _equal)))
end_proc;

#--------------------------------------------------------------------#
# Erzeugung des stdlib-Domains (wird von loadproc benoetigt)	     #
#--------------------------------------------------------------------#

# the 'stdlib' library domain serves only as name space for utilies #

stdlib:= domain("stdlib"):
stdlib::info:= "Library 'stdlib': \
Utilities for the standard library":
stdlib::interface:= {}:

#--------------------------------------------------------------------#
# Soem attributes for kernel functions                               #
#--------------------------------------------------------------------#

phi:= funcattr( phi,"conjugate",newpurefunc("fun(...)", NIL, hold(hold(phi)(args()))) ):
phi:= funcattr( phi,"info","the Euler phi function [try ?phi for help]" ):

#--------------------------------------------------------------------#
# Kern-Funktionen sichern (werden in specfunc/stdlib umdefiniert)    #
#--------------------------------------------------------------------#

stdlib::sin:= sin:
stdlib::cos:= cos:
stdlib::tan:= tan:
stdlib::asin:= asin:
stdlib::acos:= acos:
stdlib::atan:= atan:
stdlib::sinh:= sinh:
stdlib::cosh:= cosh:
stdlib::tanh:= tanh:
stdlib::asinh:= asinh:
stdlib::acosh:= acosh:
stdlib::atanh:= atanh:
stdlib::exp:= exp:
stdlib::ln:= ln:
stdlib::sqrt:= sqrt:
stdlib::gamma:= gamma:
stdlib::igamma:= igamma:
stdlib::zeta:= zeta:
stdlib::erfc:= erfc:
stdlib::eint:= eint:
stdlib::psi:= psi:
stdlib::sign:= sign: 
stdlib::abs:= abs: 
stdlib::fact:= fact: 
stdlib::psi:=psi:
stdlib::powermod:= powermod:
stdlib::ithprime:= ithprime:
stdlib::floor:= floor:
stdlib::max:= max:
stdlib::min:= min:

powermod:=NIL:
ithprime:=NIL:

#--------------------------------------------------------------------#
# Initialisierung der vordefinierten Standardprozeduren, die bei     #
# Bedarf automatisch nachgeladen werden sollen.                      #
#--------------------------------------------------------------------#

# read loading utils #

case sysname()
of "UNIX" do
    stdlib::PathSep:= "/";
    path:= LIB_PATH;
    break;
of "MACOS" do
    stdlib::PathSep:= ":";
    path:= LIB_PATH.":";
    break;
of "MSDOS" do
    stdlib::PathSep:= "\\";
    path:= LIB_PATH;
    break;
end_case:

stdlib::BinPath:= "BIN".stdlib::PathSep:
stdlib::LoadlibState:= table():

fread(path."STDLIB".stdlib::PathSep."fun.mu"):
fread(path."STDLIB".stdlib::PathSep."read.mu"):

# use library patch archive first if one exists #

  filedescr := fopen(lib_path.pathSep."plib.tar");
  if filedescr <> FAIL then
    fclose(filedescr):
    filedescr := NIL:
    LIB_PATH := lib_path.pathSep."plib.tar#plib", LIB_PATH:
  else
    patchlevel:= fun(1):
  end_if:

read("STDLIB".stdlib::PathSep."pathname.mu"):
read("STDLIB".stdlib::PathSep."loadproc.mu"):
read("STDLIB".stdlib::PathSep."PREF".stdlib::PathSep."Pref.mu"):
read("STDLIB".stdlib::PathSep."PREF".stdlib::PathSep."verbread.mu"):

read("LIBFILES".stdlib::PathSep."stdlib.mu"):
read("LIBFILES".stdlib::PathSep."misc.mu"):
read("LIBFILES".stdlib::PathSep."specfunc.mu"):

#--------------------------------------------------------------------#
# load packages                                                      #
#--------------------------------------------------------------------#

path:= pathname("LIBFILES"):

Semaphore       := loadproc(Semaphore,       path, "sema");
Lock            := loadproc(Lock,            path, "sema");
GlobalSemaphore := loadproc(GlobalSemaphore, path, "sema");

Ax       := loadproc(Ax,       path, "Ax"):
Cat      := loadproc(Cat,      path, "Cat"):
Dom      := loadproc(Dom,      path, "Dom"):
ERROR    := loadproc(ERROR,    path, "ERROR"):
Lsys     := loadproc(Lsys,     path, "Lsys"):
Network  := loadproc(Network,  path, "Network"):
RGB      := loadproc(RGB,      path, "RGB"):
Series   := loadproc(Series,   path, "Series"):
property := loadproc(property, path, "property"):
Type     := loadproc(Type,     path, "Type"):
combinat := loadproc(combinat, path, "combinat"):
domains  := loadproc(domains,  path, "domains"):
faclib   := loadproc(faclib,   path, "faclib"):
fp       := loadproc(fp,       path, "fp"):
gcdlib   := loadproc(gcdlib,   path, "gcdlib"):
generate := loadproc(generate, path, "generate"):
groebner := loadproc(groebner, path, "groebner"):
intlib   := loadproc(intlib,   path, "intlib"):
io       := loadproc(io,       path, "io"):
linalg   := loadproc(linalg,   path, "linalg"):
listtools:= loadproc(listtools,path, "list"):
linopt   := loadproc(linopt,   path, "linopt"):
module   := loadproc(module,   path, "module"):
numeric  := loadproc(numeric,  path, "numeric"):
numlib   := loadproc(numlib,   path, "numlib"):
ode      := loadproc(ode,      path, "ode"):
orthpoly := loadproc(orthpoly, path, "orthpoly"):
plotlib  := loadproc(plotlib,  path, "plotlib"):
rec      := loadproc(rec,      path, "rec"):
sharelib := loadproc(sharelib, path, "sharelib"):
stats    := loadproc(stats,    path, "stats"):
string   := loadproc(string,   path, "string"):
student  := loadproc(student,  path, "student"):
transform:= loadproc(transform, path, "Trans"):

# wurden bisher mit 'domains' geladen: #
path:= pathname("DOMAINS", "CONSTR");
DomainConstructor:=   loadproc(DomainConstructor,   path, "DomCons"):
Category:=            loadproc(Category,            path, "Category"):
CategoryConstructor:= loadproc(CategoryConstructor, path, "CatCons"):
Axiom:=               loadproc(Axiom,               path, "Axiom"):
AxiomConstructor:=    loadproc(AxiomConstructor,    path, "AxCons"):

#--------------------------------------------------------------------#
# Funktionsattribute fuer ``diff'' (Hier???)                         #
#--------------------------------------------------------------------#

id:= funcattr(id, "diff", 
	fun(diff(op(args(1), 1), args(2..args(0))))):

_negate:= funcattr(_negate, "diff",
	fun(diff(-op(args(1),1), args(2..args(0))))):

_subtract:= funcattr(_subtract, "diff",
	fun(diff(op(args(1),1) - op(args(1),2), args(2..args(0))))):

_invert:= funcattr(_invert, "diff",
	fun(diff(1/op(args(1),1), args(2..args(0))))):

_divide:= funcattr(_divide, "diff",
	fun(diff(op(args(1),1) / op(args(1),2), args(2..args(0))))):

_equal:= funcattr(_equal, "diff",
	fun(_equal( diff(op(args(1),1),args(2..args(0))) , diff(op(args(1),2),args(2..args(0)))  ))):

stdlib::PROTECTED := 
    (anames(3)                # all variables with a value assigned  #
      minus stdlib::ENVIRONMENT_VARIABLES      # must be changeable  #
      minus stdlib::SYSTEM_CONSTANTS      # protected by the system  #
      minus ownlocals)               # the locals of this procedure  #
      union stdlib::LIBRARY_CONSTANTS         # just to go for sure  #
      union stdlib::OPTIONS:        # don't overwrite MuPAD options  #

map((anames(3)                # all variables with a value assigned  #
      minus stdlib::ENVIRONMENT_VARIABLES      # must be changeable  #
      minus stdlib::SYSTEM_CONSTANTS      # protected by the system  #
      minus ownlocals)               # the locals of this procedure  #
      union stdlib::LIBRARY_CONSTANTS,        # just to go for sure  #
    protected, Error):
                                    # don't overwrite MuPAD options  #
map(stdlib::OPTIONS, protected, Warning);

));                         # end of block with _assign = sysassign  #

#--------------------------------------------------------------------#
# Diese Variablen sollen nicht schreibgeschuetzt sein, ihre Werte    #
# bereits vor dem Laden der Datei stdlib/plotfunc.mu zugewiesen sein #
#--------------------------------------------------------------------#

plotfunc_2DSceneOptions := {Scaling=UnConstrained, Axes=Origin, Labeling=TRUE}:
plotfunc_3DSceneOptions := {Scaling=UnConstrained, Labeling=TRUE}:

#--------------------------------------------------------------------#
# Versionsnummern von Kern und Library vergleichen.                  #
#--------------------------------------------------------------------#

if( _pref(hold(Kernel)) <> version() ) then
    print( Unquoted, 
           "Warning: Kernel and library release number differ!\n".
           "Kernel : ".expr2text(_pref(hold(Kernel)))."\n".
           "Library: ".expr2text(version())."\n"
    ):
end_if:

#--------------------------------------------------------------------#
# Fuer deutschsprachige MuPAD Versionen (z.B. MuPAD Pro) kann der    #
# Malpunkt zwischen Faktoren von Produkten gesetzt werden. Die       #
# Kommentarzeichen muessen aber explizit entfernt werden, sonst      #
# wird diese Einstellung nicht aktiv!                                #
#--------------------------------------------------------------------#
# LANGUAGE=ger #
#Pref::printTimesDot(TRUE):#

null();
end_proc():

#- the end ----------------------------------------------------------#
