login  home  contents  what's new  discussion  bug reports help  links  subscribe  changes  refresh  edit

# Edit detail for SandBox Category of Graphs in SPAD revision 1 of 1

 1 Editor: Time: 2007/11/18 17:57:48 GMT-8 Note:

changed:
-
First we define the general category of graphs.
)abbrev category GRAPHS GraphCategory
GraphCategory(nodes:Type, edges:Type): Category == with
source:edges->nodes
target:edges->nodes

Now we define finite graphs as follows:
)abbrev domain FGRAPHS FiniteGraph

FiniteGraph(nodes: BasicType): exports == implementation where
edges ==> Record(source:nodes,target:nodes)
exports == GraphCategory(nodes,edges) with
new: () -> %
addNode: (%,List nodes) -> List nodes
edgeList: (%) -> List edges
nodeList: (%) -> List nodes

Rep == Record(node: List nodes, edge: List edges)

new:% ==
n:List(nodes):=[]
e:List(edges):=[]
[n,e]$Rep pretend % 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 addNode(g:%,n:nodes):List nodes == addNode(g,[n]) addEdge(g:%,src:nodes,tar:nodes):edges == G:Rep:=g pretend Rep; if #G.edge=0 then G.edge:=[[src,tar]$edges]
else
concat!(G.edge,[[src,tar]$edges]) [src,tar]$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

Example 1: create a simple finite graph:
\begin{axiom}
g:FiniteGraph(INT)
g:=new()
source(e)$FiniteGraph(INT) edgeList(g) nodeList(g) \end{axiom}  First we define the general category of graphs. spad )abbrev category GRAPHS GraphCategory GraphCategory(nodes:Type, edges:Type): Category == with source:edges->nodes target:edges->nodes spad  Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/7569958594964485335-25px001.spad using old system compiler. GRAPHS abbreviates category GraphCategory ------------------------------------------------------------------------ initializing NRLIB GRAPHS for GraphCategory compiling into NRLIB GRAPHS ;;; *** |GraphCategory| REDEFINED Time: 0 SEC. finalizing NRLIB GRAPHS Processing GraphCategory for Browser database: --->-->GraphCategory(constructor): Not documented!!!! --->-->GraphCategory((source (nodes edges))): Not documented!!!! --->-->GraphCategory((target (nodes edges))): Not documented!!!! --->-->GraphCategory(): Missing Description ; compiling file "/var/aw/var/LatexWiki/GRAPHS.NRLIB/GRAPHS.lsp" (written 14 JUL 2013 10:46:24 AM): ; /var/aw/var/LatexWiki/GRAPHS.NRLIB/GRAPHS.fasl written ; compilation finished in 0:00:00.005 ------------------------------------------------------------------------ GraphCategory is now explicitly exposed in frame initial GraphCategory will be automatically loaded when needed from /var/aw/var/LatexWiki/GRAPHS.NRLIB/GRAPHS Now we define finite graphs as follows: spad )abbrev domain FGRAPHS FiniteGraph FiniteGraph(nodes: BasicType): exports == implementation where edges ==> Record(source:nodes,target:nodes) exports == GraphCategory(nodes,edges) with new: () -> % addNode: (%,List nodes) -> List nodes addNode: (%,nodes) -> List nodes addEdge: (%,nodes,nodes) -> edges edgeList: (%) -> List edges nodeList: (%) -> List nodes implementation == add Rep == Record(node: List nodes, edge: List edges) new:% == n:List(nodes):=[] e:List(edges):=[] [n,e]$Rep pretend %
G:Rep:=g pretend Rep;
if #G.node=0 then
G.node:=n
else
concat!(G.node,n)
n
G.edge:=[[src,tar]$edges] else concat!(G.edge,[[src,tar]$edges])
[src,tar]$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 spad  Compiling FriCAS source code from file /var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/3160513407949145091-25px002.spad using old system compiler. FGRAPHS abbreviates domain FiniteGraph ------------------------------------------------------------------------ initializing NRLIB FGRAPHS for FiniteGraph compiling into NRLIB FGRAPHS ************* USER ERROR ********** available signatures for Rep: NONE NEED Rep: () -> ? ****** comp fails at level 1 with expression: ****** ((DEF (|Rep|) (NIL) (NIL) (|Record| (|:| |node| (|List| |nodes|)) (|:| |edge| (|List| (|Record| (|:| |source| |nodes|) (|:| |target| |nodes|))))))) ****** level 1 ******$x:= (DEF (Rep) (NIL) (NIL) (Record (: node (List nodes)) (: edge (List (Record (: source nodes) (: target nodes))))))
$m:=$EmptyMode
$f:= ((((|$Information| #) (~= #) (= #) (|$DomainsInScope| # # #) ...))) >> Apparent user error: unspecified error Example 1: create a simple finite graph: fricas g:FiniteGraph(INT) Type: Void fricas g:=new() There are 3 exposed and 5 unexposed library operations named new having 0 argument(s) but none was determined to be applicable. Use HyperDoc Browse, or issue )display op new to learn more about the available operations. Perhaps package-calling the operation or using coercions on the arguments will allow you to apply the operation. Cannot find a no-argument definition or library operation named new . addNode(g,1) g is declared as being in FiniteGraph(Integer) but has not been given a value. addNode(g,2) g is declared as being in FiniteGraph(Integer) but has not been given a value. e:=addEdge(g,1,2) g is declared as being in FiniteGraph(Integer) but has not been given a value. source(e)$FiniteGraph(INT)
given a value.