Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place. Commercial Alternative to JupyterHub.
| Download
GAP 4.8.9 installation with standard packages -- copy to your CoCalc project to get it
Project: cocalc-sagemath-dev-slelievre
Views: 510758########################################################## #DeclareCategory("IsPseudoList",IsObject); #DeclareRepresentation( "IsPseudoListRep", # IsComponentObjectRep, # ["elts", # "pos" ]); PseudoListFamily:=NewFamily( "PseudoListFamily", IsPseudoList, IsPseudoList); PseudoList:=NewType(PseudoListFamily,IsPseudoListRep); InstallMethod( ViewObj, "for PseudoList", [IsPseudoList], function(R) Print( R!.lst); end); InstallMethod( PrintObj, "for PseudoList", [IsPseudoList], function(R) Print(R!.lst); end); ############################################################# ############################################################# InstallGlobalFunction(ListToPseudoList, function(L) local Lst,Sslst,Pos; if IsPseudoList(L) then return L; fi; #New line ( Nov 2007) Sslst:=SSortedList(L); Lst:=L; Pos:=List(Sslst,x->Position(Lst,x)); return Objectify(PseudoList, rec( lst:=Lst, pos:=Pos, sslst:=Sslst)); end); ############################################################# ############################################################# InstallOtherMethod(ELM_LIST, "for PseudoLists", [IsPseudoList,IsInt], function(PL,i) return PL!.lst[i]; end); ############################################################# ############################################################# InstallOtherMethod(ELM_LIST, "for PseudoLists with functions", [IsPseudoListWithFunction,IsInt], function(PL,i) return PL!.eltfun(i); end); ############################################################# ############################################################# InstallOtherMethod(Position, "for PseudoLists", [IsPseudoList,IsObject,IsInt], function(PL,g,i) local p; p:=Position(PL!.sslst,g,i); if IsInt(p) then return PL!.pos[p]; else return p; fi; end); ############################################################# ############################################################# InstallOtherMethod(Position, "for PseudoLists", [IsPseudoListWithFunction and IsPseudoList,IsObject,IsInt], function(PL,g,i) #local p,A; #A:=List([1..Length(PL)],j->PL!.eltfun(j)); #return Position(A,g,i); local j; for j in [i+1..Length(PL)] do if PL!.eltfun(j)=g then return j; fi; od; return fail; #local p; #p:=PositionProperty([i+1..Length(PL)],j->PL!.eltfun(j)=g); #if p=fail then return p; #else return i+p; fi; end); ############################################################# ############################################################# InstallOtherMethod(Position, "for PseudoLists", [IsPseudoListWithFunction and IsPseudoList,IsObject], function(PL,g) local p; return PL!.posfun(g); end); ############################################################# ############################################################# InstallOtherMethod(Length, "for PseudoLists", [IsPseudoList], function(PL) return Length(PL!.lst); end); ############################################################# ############################################################# InstallOtherMethod(Length, "for PseudoLists", [IsPseudoListWithFunction], function(PL) return PL!.lnthfun(); end); ############################################################# ############################################################# InstallOtherMethod(IN, "for PseudoLists", [IsObject,IsPseudoList], function(x,PL) return x in PL!.sslst; end); ############################################################# ############################################################# InstallOtherMethod(IN, "for PseudoLists", [IsObject,IsPseudoListWithFunction], function(x,PL) return not fail = PL!.posfun(x); end); ############################################################# ############################################################# InstallOtherMethod(Add, "for PseudoLists", [IsPseudoList,IsObject], function(L,x) local p,shft; if not x in L then Add(L!.lst,x); AddSet(L!.sslst,x); p:=Position(L!.sslst,x); shft:=L!.pos{[p..Length(L!.pos)]}; L!.pos:=L!.pos{[1..p-1]}; Add(L!.pos,Length(L!.lst)); Append(L!.pos,shft); fi; end); ############################################################# ############################################################# InstallOtherMethod(Add, "for PseudoLists", [IsPseudoListWithFunction,IsObject], function(L,x) L!.addfun(x); end); ############################################################# ############################################################# InstallOtherMethod(Append, "for PseudoLists", [IsPseudoList,IsObject], function(L,K) local x; for x in K do Add(L,x); od; end); ############################################################# ############################################################# InstallOtherMethod(Iterator, "for PseudoLists", [IsPseudoList], function(L) return Iterator(L!.lst); end); ############################################################# ############################################################# InstallOtherMethod(ListOp, "for PseudoLists", [IsPseudoList,IsObject], function(L,f) return ListOp(L!.lst,f); end); ############################################################# ############################################################# InstallOtherMethod(ListOp, "for PseudoLists", [IsPseudoListWithFunction,IsObject], function(L,f) return List(List([1..Length(L)],i->L!.eltfun(i)) , f); end); #############################################################