First we define the general category of graphs.
fricas
(1) -> <spad>
fricas
)abbrev category GRAPHS GraphCategory
GraphCategory(nodes:Type, edges:Type): Category == with
source:edges->nodes
target:edges->nodes</spad>
fricas
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 01 NOV 2024 12:11:00 AM):
; wrote /var/aw/var/LatexWiki/GRAPHS.NRLIB/GRAPHS.fasl
; compilation finished in 0:00:00.008
------------------------------------------------------------------------
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 %
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
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)
(|Record| (|:| |node| (|List| |nodes|))
(|:| |edge|
(|List|
(|Record| (|:| |source| |nodes|) (|:| |target| |nodes|)))))))
****** level 1 ******
$x:= (DEF (Rep) (NIL) (Record (: node (List nodes)) (: edge (List (Record (: source nodes) (: target nodes))))))
$m:= $EmptyMode
$f:=
((((~= #) (= #) (|$DomainsInScope| # # #) (|target| #) ...)))
>> Apparent user error:
unspecified error
Example 1: create a simple finite graph:
fricas
g:FiniteGraph(INT)
Type: Void
fricas
g:=new()
There are 1 exposed and 8 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
.