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
edgeList: (%) -> List edges
nodeList: (%) -> List nodes
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 AXIOM-XL compiler and options
-O -Fasy -Fao -Flsp -laxiom -Mno-ALDOR_W_WillObsolete -DAxiom -Y $AXIOM/algebra -I$AXIOM/algebra
Use the system command )set compiler args to change these
options.
#1 (Warning) Could not use archive file libaxiom.al'.
#2 (Warning) Could not use archive file libaxiom.al'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 4:
import from AxiomLib;
............^
[L4 C13] #3 (Error) No meaning for identifier AxiomLib'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 15:
import { true: %, false: % } from Boolean;
..................................^
[L15 C35] #4 (Error) No meaning for identifier Boolean'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 17:
string:         Literal -> %;
........................^.......^
[L17 C25] #5 (Error) No meaning for identifier Literal'.
[L17 C33] #6 (Error) There are no suitable meanings for the operator ->'.
"/usr/local/aldor/linux/1.1.0/include/axiom.as", line 18:
} from String;
.......^
[L18 C8] #8 (Error) No meaning for identifier String'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1676669208528368195-25px001.as", line 6:
GraphCategory(nodes:Type, edges:Type): Category == with
..............^.....^
[L6 C15] #10 (Error) Have determined 1 possible types for the expression.
Meaning 1: ?, ?
The context requires an expression of type Tuple(Type).
[L6 C21] #9 (Error) No meaning for identifier Type'.
"/var/lib/zope2.10/instance/axiom-wiki/var/LatexWiki/1676669208528368195-25px001.as", line 7:
source:edges->nodes
.........^......^
[L7 C10] #11 (Error) There are 0 meanings for edges' in this context.
The possible types were:
edges: Type, a local
The context requires an expression of type Tuple(Type).
[L7 C17] #12 (Error) There are 0 meanings for nodes' in this context.
The possible types were:
nodes: Type, a local
The context requires an expression of type Tuple(Type).
[L7 C17] #13 (Fatal Error) Too many errors (use -M emax=n' or -M no-emax' to change the limit).
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
coerce : % -> OutputForm              coerce : % -> OutputForm
cycleOpen : (List(S),String) -> %     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
addObject! : (%,Record(value: S,posX: NonNegativeInteger,posY: 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) -> %
deepDiagramSvg : (String,%,Boolean) -> Void
diagramHeight : % -> NonNegativeInteger
diagramSvg : (String,%,Boolean) -> Void
diagramWidth : % -> NonNegativeInteger
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:

fricas
g:FiniteGraph(INT)
FiniteGraph(Integer) is a category, not a domain, and declarations
require domains.
g:=new() (1)
Type: ScriptFormulaFormat?
fricas
addNode(g,1)
There are no library operations named addNode
Use HyperDoc Browse or issue
to learn if there is any operation containing " addNode " in its
name.
Cannot find a definition or applicable library operation named
ScriptFormulaFormat
PositiveInteger
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need. addNode(g,2) There are no library operations named addNode Use HyperDoc Browse or issue )what op addNode to learn if there is any operation containing " addNode " in its name. Cannot find a definition or applicable library operation named addNode with argument type(s) ScriptFormulaFormat PositiveInteger Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.
There are no library operations named addEdge
Use HyperDoc Browse or issue
to learn if there is any operation containing " addEdge " in its
name.
Cannot find a definition or applicable library operation named
ScriptFormulaFormat
PositiveInteger
PositiveInteger
Perhaps you should use "@" to indicate the required return type,
or "$" to specify which version of the function you need. source(e)$FiniteGraph(INT)
The right-hand side of the $operator must be a package or domain name, but FiniteGraph(Integer) is a category. edgeList(g) There are no library operations named edgeList Use HyperDoc Browse or issue )what op edgeList to learn if there is any operation containing " edgeList " in its name. Cannot find a definition or applicable library operation named edgeList with argument type(s) ScriptFormulaFormat Perhaps you should use "@" to indicate the required return type, or "$" to specify which version of the function you need.
nodeList(g)
There are no library operations named nodeList
Use HyperDoc Browse or issue
)what op nodeList
to learn if there is any operation containing " nodeList " in its
name.
Cannot find a definition or applicable library operation named
nodeList with argument type(s)
ScriptFormulaFormat
Perhaps you should use "@" to indicate the required return type,
or "\$" to specify which version of the function you need.

 Subject:   Be Bold !! ( 15 subscribers )