##################################################################
# init_exmat()
# This procedure reads the libraries used in exmat
##################################################################
with(linalg):
init_exmat := proc()
  global `optimize/remove`;
  readlib(optimize):
  readlib(C):
  readlib(write):
# redefinition of `optimize/remove included since I found a bug in
# the original code, a 1 (one) was inserted instead of a l (small L)
`optimize/remove`:=proc(s,locs,user)
local a,c,k,n,l,r,x,U;
options
    `Copyright 1993 by Waterloo Maple Software`
    ;
    n := nops(s);
    if n < 2 then RETURN(s) fi;
    c := table(sparse);
    for x in user do  c[x] := 2 od;
    for k to n do
        a[k] := s[k];
        l := op(1,a[k]);
        r := op(2,a[k]);
        `optimize/count`(r,c);
        if type(l,indexed) then
            `optimize/count`(l,c)
        elif type(r,`^`) and op(2,r) <> -1 or
           type(r,`+`) and 10 < nops(r) or
           type(r,function) and op(0,r) = ARRAY
            then
#
# original code
#
#            c[l] := c[1]+1
#
            c[l] := c[l]+1
        fi
    od;
    for k to n do
        l := op(1,a[k]);
        r := op(2,a[k]);
        r := ";
        if c[l] = 1 and k < n then
            U[l] := true;
            assign(l,r);
            a[k] := NULL
        else a[k] := l = r
        fi
    od;
    if assigned(U) then
        for x in [indices(U)] do
            assign(op(x),op(x))
        od
    fi;
    [seq(a[k],k = 1 .. n)]
end:
end:
init_exmat():
