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

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/zope2/var/LatexWiki/1676669208528368195-25px001.as using 
      AXIOM-XL compiler and options 
-O -Fasy -Fao -Flsp -laxiom -Mno-AXL_W_WillObsolete -DAxiom -Y $AXIOM/algebra
      Use the system command )set compiler args to change these 
      options.
#1 (Warning) Deprecated message prefix: use `ALDOR_' instead of `_AXL'
   Compiling Lisp source code from file 
      ./1676669208528368195-25px001.lsp
   Issuing )library command for 1676669208528368195-25px001
   Reading /var/zope2/var/LatexWiki/1676669208528368195-25px001.asy
   FiniteGraph is now explicitly exposed in frame initial 
   FiniteGraph will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1676669208528368195-25px001
   GraphCategory is now explicitly exposed in frame initial 
   GraphCategory will be automatically loaded when needed from 
      /var/zope2/var/LatexWiki/1676669208528368195-25px001

axiom
)sh FiniteGraph
FiniteGraph nodes: BasicType is a domain constructor Abbreviation for FiniteGraph is FINITEG This constructor is exposed in this frame. Issue )edit 1676669208528368195-25px001.as to see algebra source code for FINITEG
------------------------------- Operations -------------------------------- addNode : (%,nodes) -> List nodes new : () -> % nodeList : % -> List nodes addEdge : (%,nodes,nodes) -> Record(source: nodes,target: nodes) addNode : (%,List nodes) -> List nodes edgeList : % -> List Record(source: nodes,target: nodes) source : Record(source: nodes,target: nodes) -> nodes target : Record(source: nodes,target: nodes) -> nodes

Example 1: create a simple finite graph:

axiom
g:FiniteGraph(INT)
Type: Void
axiom
g:=new()
LISP output: ()
Type: FiniteGraph? Integer
axiom
addNode(g,1)
LatexWiki Image(1)
Type: List Integer
axiom
addNode(g,2)
LatexWiki Image(2)
Type: List Integer
axiom
e:=addEdge(g,1,2)
LatexWiki Image(3)
Type: Record(source: Integer,target: Integer)
axiom
source(e)$FiniteGraph(INT)
LatexWiki Image(4)
Type: Integer
axiom
edgeList(g)
LatexWiki Image(5)
Type: List Record(source: Integer,target: Integer)
axiom
nodeList(g)
LatexWiki Image(6)
Type: List Integer




subject:
  ( 7 subscribers )  
Please rate this page: