$SPAD/src/input finitegraph.input

Unknown December 3, 2016

Abstract

Contents

2

— fgraf.spad —

)abbrev category GRAPHS GraphCategory
GraphCategory(nodes:Type, edges:Type): Category == with
source:edges->nodes
target:edges->nodes
)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 %
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

———-

— * —

)set break resume
)spool finitegraph.output
)set message test on
)set message auto off
)clear all
)sys cp $AXIOM/../../src/input/finitegraph.input.pamphlet .
)lisp (tangle "finitegraph.input.pamphlet" "fgraf.spad" "fgraf.spad")
)co fgraf
--S 1 of 8
g:FiniteGraph(INT):=new();
--R
--R
--R                                                   Type: FiniteGraph(Integer)
--E 1
--S 2 of 8
addNode(g,1)
--R
--R
--R   (2)  [1]
--R                                                          Type: List(Integer)
--E 2
--S 3 of 8
addNode(g,2)
--R
--R
--R   (3)  [2]
--R                                                          Type: List(Integer)
--E 3
--S 4 of 8
e:=addEdge(g,1,2)
--R
--R
--R   (4)  [source= 1,target= 2]
--R                                Type: Record(source: Integer,target: Integer)
--E 4

--S 5 of 8
source(e)$FiniteGraph(INT)
--R
--R
--R   (5)  1
--R                                                                Type: Integer
--E 5
--S 6 of 8
target(e)$FiniteGraph(INT)
--R
--R
--R   (6)  2
--R                                                                Type: Integer
--E 6
--S 7 of 8
edgeList(g)
--R
--R
--R   (7)  [[source= 1,target= 2]]
--R                          Type: List(Record(source: Integer,target: Integer))
--E 7
--S 8 of 8
nodeList(g)
--R
--R
--R   (8)  [1,2]
--R                                                          Type: List(Integer)
--E 8
)spool
)lisp (bye)

———-

References

[1] http://axiom-wiki.newsynthesis.org/SandBoxCategoryOfGraphsInSPAD