login  home  contents  what's new  discussion  bug reports help  links  subscribe  changes  refresh  edit
 Topics FrontPage SandBox SandBox Category of Graphs SandBox Category of Graphs 2 <-- You are here. This seems to work if the category is defined in the same source file (i.e. same section in MathAction). The code is based on the Spad version SandBox Category of Graphs in Spad aldor#pile #include "axiom.as" -- -- First we define the general category of graphs. -- GraphCategory(nodes:Type, edges:Type): Category == with source:edges->nodes target:edges->nodes -- -- Now we define finite graphs as follows: -- edges ==> Record(source:nodes,target:nodes) FiniteGraph(nodes: BasicType):GraphCategory(nodes,edges) with new: % addNode: (%,List nodes) -> List nodes addNode: (%,nodes) -> List nodes addEdge: (%,nodes,nodes) -> edges edgeList: (%) -> List edges nodeList: (%) -> List nodes == add import from NonNegativeInteger Rep == Record(node: List nodes, edge: List edges) new:% == n:List(nodes):=[] e:List(edges):=[] per([n,e]$Rep) addNode(g:%,n:nodes):List nodes == addNode(g,[n]) addNode(g:%,n:List nodes):List nodes == G:Rep:=g pretend Rep; if #G.node=0 then G.node:=n else concat!(G.node,n) n addEdge(g:%,source:nodes,target:nodes):edges == G:Rep:=g pretend Rep; if #G.edge=0 then G.edge:=[[source,target]$edges] else concat!(G.edge,[[source,target]$edges]) [source,target]$edges edgeList(g:%):List edges == G:Rep:=g pretend Rep; G.edge nodeList(g:%):List nodes == G:Rep:=g pretend Rep; G.node source(ed:edges):nodes == ed.source target(ed:edges):nodes == ed.target aldor Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1676669208528368195-25px001.as using Aldor compiler and options -O -Fasy -Fao -Flsp -lfricas -Mno-ALDOR_W_WillObsolete -DFriCAS -Y $FRICAS/algebra -I$FRICAS/algebra Use the system command )set compiler args to change these options. The )library system command was not called after compilation. fricas)sh FiniteGraph FiniteGraph(S: SetCategory) is a category constructor Abbreviation for FiniteGraph is FGRPH This constructor is not exposed in this frame. ------------------------------- Operations -------------------------------- ?+? : (%, %) -> % ?=? : (%, %) -> Boolean addObject! : (%, S) -> % coerce : % -> OutputForm flatten : DirectedGraph(%) -> % hash : % -> SingleInteger initial : () -> % isAcyclic? : % -> Boolean isDirected? : () -> Boolean isFunctional? : % -> Boolean kgraph : (List(S), String) -> % latex : % -> String loopsArrows : % -> List(Loop) loopsNodes : % -> List(Loop) looseEquals : (%, %) -> Boolean max : % -> NonNegativeInteger merge : (%, %) -> % min : % -> NonNegativeInteger terminal : S -> % unit : (List(S), String) -> % ?~=? : (%, %) -> Boolean addArrow! : (%, String, S, S) -> % addArrow! : (%, String, NonNegativeInteger, NonNegativeInteger, List(NonNegativeInteger)) -> % addArrow! : (%, String, NonNegativeInteger, NonNegativeInteger) -> % addArrow! : (%, Record(name: String,arrType: NonNegativeInteger,fromOb: NonNegativeInteger,toOb: NonNegativeInteger,xOffset: Integer,yOffset: Integer,map: List(NonNegativeInteger))) -> % addObject! : (%, Record(value: S,posX: NonNegativeInteger,posY: NonNegativeInteger)) -> % adjacencyMatrix : % -> Matrix(NonNegativeInteger) arrowName : (%, NonNegativeInteger, NonNegativeInteger) -> String arrowsFromArrow : (%, NonNegativeInteger) -> List(NonNegativeInteger) arrowsFromNode : (%, NonNegativeInteger) -> List(NonNegativeInteger) arrowsToArrow : (%, NonNegativeInteger) -> List(NonNegativeInteger) arrowsToNode : (%, NonNegativeInteger) -> List(NonNegativeInteger) createWidth : NonNegativeInteger -> NonNegativeInteger createX : (NonNegativeInteger, NonNegativeInteger) -> NonNegativeInteger createY : (NonNegativeInteger, NonNegativeInteger) -> NonNegativeInteger cycleClosed : (List(S), String) -> % cycleOpen : (List(S), String) -> % deepDiagramSvg : (String, %, Boolean) -> Void diagramHeight : % -> NonNegativeInteger diagramSvg : (String, %, Boolean) -> Void diagramWidth : % -> NonNegativeInteger diagramsSvg : (String, List(%), Boolean) -> Void distance : (%, NonNegativeInteger, NonNegativeInteger) -> Integer distanceMatrix : % -> Matrix(Integer) getArrowIndex : (%, NonNegativeInteger, NonNegativeInteger) -> NonNegativeInteger getArrows : % -> List(Record(name: String,arrType: NonNegativeInteger,fromOb: NonNegativeInteger,toOb: NonNegativeInteger,xOffset: Integer,yOffset: Integer,map: List(NonNegativeInteger))) getVertexIndex : (%, S) -> NonNegativeInteger getVertices : % -> List(Record(value: S,posX: NonNegativeInteger,posY: NonNegativeInteger)) hashUpdate! : (HashState, %) -> HashState inDegree : (%, NonNegativeInteger) -> NonNegativeInteger incidenceMatrix : % -> Matrix(Integer) isDirectSuccessor? : (%, NonNegativeInteger, NonNegativeInteger) -> Boolean isFixPoint? : (%, NonNegativeInteger) -> Boolean isGreaterThan? : (%, NonNegativeInteger, NonNegativeInteger) -> Boolean laplacianMatrix : % -> Matrix(Integer) loopsAtNode : (%, NonNegativeInteger) -> List(Loop) map : (%, List(NonNegativeInteger), List(S), Integer, Integer) -> % mapContra : (%, List(NonNegativeInteger), List(S), Integer, Integer) -> % max : (%, List(NonNegativeInteger)) -> NonNegativeInteger min : (%, List(NonNegativeInteger)) -> NonNegativeInteger nodeFromArrow : (%, NonNegativeInteger) -> List(NonNegativeInteger) nodeFromNode : (%, NonNegativeInteger) -> List(NonNegativeInteger) nodeToArrow : (%, NonNegativeInteger) -> List(NonNegativeInteger) nodeToNode : (%, NonNegativeInteger) -> List(NonNegativeInteger) outDegree : (%, NonNegativeInteger) -> NonNegativeInteger routeArrows : (%, NonNegativeInteger, NonNegativeInteger) -> List(NonNegativeInteger) routeNodes : (%, NonNegativeInteger, NonNegativeInteger) -> List(NonNegativeInteger) spanningForestArrow : % -> List(Tree(Integer)) spanningForestNode : % -> List(Tree(Integer)) spanningTreeArrow : (%, NonNegativeInteger) -> Tree(Integer) spanningTreeNode : (%, NonNegativeInteger) -> Tree(Integer) subdiagramSvg : (Scene(SCartesian(2)), %, Boolean, Boolean) -> Void Example 1: create a simple finite graph: fricasg:FiniteGraph(INT) FiniteGraph(Integer) is a category, not a domain, and declarations require domains.

 Subject:   Be Bold !! ( 14 subscribers )