#
# modular(L) returns true or false according to whether the lattice L is
#  modular; i.e., L is ranked, and the rank function satisfies r[x]+r[y]=
#  r[meet(x,y)] + r[join(x,y)] for all vertices x and y.
# modular(L,'upper') and (respectively)  modular(L,'lower') returns true or
#  false according to whether the lattice L is upper (resp., lower) semi-
#  modular; i.e., L is ranked and the rank function satisfies r[x]+r[y] >=
#  (resp., <=) r[meet(x,y)] + r[join(x,y)] for all vertices x and y.
# The procedure does *not* check whether L is a lattice.
#
`posets/modular`:=proc(L) local X,down,A,x,i,j,Y;
  if args[nargs]='upper' then
    procname(posets['dual'](L),'lower')
  elif args[nargs]<>'lower' then
    procname(posets['dual'](L),'lower') and procname(L,'lower')
  else
    X:=map(op,L); down:=`posets/coversets`(L,X);
    for x in X do Y:=down[x];
      for i to nops(Y) do for j to i-1 do
        A:=down[Y[i]] intersect down[Y[j]];
        if nops(A)<>1 then RETURN(false) fi;
      od od
    od; true
  fi
end:
#
save `posets/modular`, cat(HomeLib,`/posets/modular.m`);
read cat(HomeLib,`/help/posets/modular`);
quit;
 
