/usr/share/axiom-20170501/src/algebra/SUBSPACE.spad is in axiom-source 20170501-3.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 | )abbrev domain SUBSPACE SubSpace
++ Author: Mark Botch
++ Description:
++ This domain is not documented
SubSpace(n,R) : SIG == CODE where
n : PositiveInteger
R : Ring
I ==> Integer
PI ==> PositiveInteger
NNI ==> NonNegativeInteger
L ==> List
B ==> Boolean
POINT ==> Point(R)
PROP ==> SubSpaceComponentProperty()
S ==> String
O ==> OutputForm
empty ==> nil -- macro to ease conversion to new aggcat.spad
SIG ==> SetCategory with
leaf? : % -> B
++ leaf?(x) is not documented
root? : % -> B
++ root?(x) is not documented
internal? : % -> B
++ internal?(x) is not documented
new : () -> %
++ new() is not documented
subspace : () -> %
++ subspace() is not documented
birth : % -> % -- returns a pointer to the baby
++ birth(x) is not documented
child : (%,NNI) -> %
++ child(x,n) is not documented
children : % -> List %
++ children(x) is not documented
numberOfChildren: % -> NNI
++ numberOfChildren(x) is not documented
shallowCopy : % -> %
++ shallowCopy(x) is not documented
deepCopy : % -> %
++ deepCopy(x) is not documented
merge : (%,%) -> %
++ merge(s1,s2) the subspaces s1 and s2 into a single subspace.
merge : List % -> %
++ merge(ls) a list of subspaces, ls, into one subspace.
separate : % -> List %
++ separate(s) makes each of the components of the \spadtype{SubSpace},
++ s, into a list of separate and distinct subspaces and returns
++ the list.
addPoint : (%,List NNI,POINT) -> %
++ addPoint(s,li,p) adds the 4 dimensional point, p, to the 3
++ dimensional subspace, s. The list of non negative integers, li,
++ dictates the path to follow, or, to look at it another way,
++ points to the component in which the point is to be added. It's
++ length should range from 0 to \spad{n - 1} where n is the dimension
++ of the subspace. If the length is \spad{n - 1}, then a specific
++ lowest level component is being referenced. If it is less than
++ \spad{n - 1}, then some higher level component (0 indicates top
++ level component) is being referenced and a component of that level
++ with the desired point is created. The subspace s is returned
++ with the additional point.
addPoint2 : (%,POINT) -> %
++ addPoint2(s,p) adds the 4 dimensional point, p, to the 3
++ dimensional subspace, s.
++ The subspace s is returned with the additional point.
addPointLast : (%,%,POINT, NNI) -> %
++ addPointLast(s,s2,li,p) adds the 4 dimensional point, p, to the 3
++ dimensional subspace, s. s2 point to the end of the subspace
++ s. n is the path in the s2 component.
++ The subspace s is returned with the additional point.
modifyPoint : (%,List NNI,POINT) -> %
++ modifyPoint(s,li,p) replaces an existing point in the 3 dimensional
++ subspace, s, with the 4 dimensional point, p. The list of non
++ negative integers, li, dictates the path to follow, or, to look at
++ it another way, points to the component in which the existing point
++ is to be modified. An error message occurs if s is empty, otherwise
++ the subspace s is returned with the point modification.
addPoint : (%,List NNI,NNI) -> %
++ addPoint(s,li,i) adds the 4 dimensional point indicated by the
++ index location, i, to the 3 dimensional subspace, s. The list of
++ non negative integers, li, dictates the path to follow, or, to
++ look at it another way, points to the component in which the point
++ is to be added. It's length should range from 0 to \spad{n - 1}
++ where n is the dimension of the subspace. If the length is
++ \spad{n - 1}, then a specific lowest level component is being
++ referenced. If it is less than \spad{n - 1}, then some higher
++ level component (0 indicates top level component) is being
++ referenced and a component of that level with the desired point
++ is created. The subspace s is returned with the additional point.
modifyPoint : (%,List NNI,NNI) -> %
++ modifyPoint(s,li,i) replaces an existing point in the 3 dimensional
++ subspace, s, with the 4 dimensional point indicated by the index
++ location, i. The list of non negative integers, li, dictates
++ the path to follow, or, to look at it another way, points to the
++ component in which the existing point is to be modified. An error
++ message occurs if s is empty, otherwise the subspace s is returned
++ with the point modification.
addPoint : (%,POINT) -> NNI
++ addPoint(s,p) adds the point, p, to the 3 dimensional subspace, s,
++ and returns the new total number of points in s.
modifyPoint : (%,NNI,POINT) -> %
++ modifyPoint(s,ind,p) modifies the point referenced by the index
++ location, ind, by replacing it with the point, p in the 3 dimensional
++ subspace, s. An error message occurs if s is empty, otherwise the
++ subspace s is returned with the point modification.
closeComponent : (%,List NNI,B) -> %
++ closeComponent(s,li,b) sets the property of the component in the
++ 3 dimensional subspace, s, to be closed if b is true, or open if
++ b is false. The list of non negative integers, li, dictates the
++ path to follow, or, to look at it another way, points to the
++ component whose closed property is to be set. The subspace, s,
++ is returned with the component property modification.
defineProperty : (%,List NNI,PROP) -> %
++ defineProperty(s,li,p) defines the component property in the
++ 3 dimensional subspace, s, to be that of p, where p is of the
++ domain \spadtype{SubSpaceComponentProperty}. The list of non
++ negative integers, li, dictates the path to follow, or, to look
++ at it another way, points to the component whose property is
++ being defined. The subspace, s, is returned with the component
++ property definition.
traverse : (%,List NNI) -> %
++ traverse(s,li) follows the branch list of the 3 dimensional
++ subspace, s, along the path dictated by the list of non negative
++ integers, li, which points to the component which has been
++ traversed to. The subspace, s, is returned, where s is now
++ the subspace pointed to by li.
extractPoint : % -> POINT
++ extractPoint(s) returns the point which is given by the current
++ index location into the point data field of the 3 dimensional
++ subspace s.
extractIndex : % -> NNI
++ extractIndex(s) returns a non negative integer which is the current
++ index of the 3 dimensional subspace s.
extractClosed : % -> B
++ extractClosed(s) returns the \spadtype{Boolean} value of the closed
++ property for the indicated 3 dimensional subspace s. If the
++ property is closed, \spad{True} is returned, otherwise \spad{False}
++ is returned.
extractProperty : % -> PROP
++ extractProperty(s) returns the property of domain
++ \spadtype{SubSpaceComponentProperty} of the indicated 3 dimensional
++ subspace s.
level : % -> NNI
++ level(s) returns a non negative integer which is the current
++ level field of the indicated 3 dimensional subspace s.
parent : % -> %
++ parent(s) returns the subspace which is the parent of the indicated
++ 3 dimensional subspace s. If s is the top level subspace an error
++ message is returned.
pointData : % -> L POINT
++ pointData(s) returns the list of points from the point data field
++ of the 3 dimensional subspace s.
CODE ==> add
import String()
Rep := Record(pt:POINT, index:NNI, property:PROP, _
childrenField:List %, _
lastChild: List %, _
levelField:NNI, _
pointDataField:L POINT, _
lastPoint: L POINT, _
noPoints: NNI, _
noChildren: NNI, _
parentField:List %) -- needn't be list but...base case?
TELLWATT : String := "Non-null list: Please inform Tim Daly"
leaf? space == empty? children space
root? space == (space.levelField = 0$NNI)
internal? space == ^(root? space and leaf? space)
new() ==
[point(empty())$POINT,0,new()$PROP,empty(),empty(),0,_
empty(),empty(),0,0,empty()]
subspace() == new()
birth momma ==
baby := new()
baby.levelField := momma.levelField+1
baby.parentField := [momma]
if not empty?(lastKid := momma.lastChild) then
not empty? rest lastKid => error TELLWATT
if empty? lastKid
then
momma.childrenField := [baby]
momma.lastChild := momma.childrenField
momma.noChildren := 1
else
setrest_!(lastKid,[baby])
momma.lastChild := rest lastKid
momma.noChildren := momma.noChildren + 1
baby
child(space,num) ==
space.childrenField.num
children space == space.childrenField
numberOfChildren space == space.noChildren
shallowCopy space ==
node := new()
node.pt := space.pt
node.index := space.index
node.property := copy(space.property)
node.levelField := space.levelField
node.parentField := nil()
if root? space then
node.pointDataField := copy(space.pointDataField)
node.lastPoint := tail(node.pointDataField)
node.noPoints := space.noPoints
node
deepCopy space ==
node := shallowCopy(space)
leaf? space => node
for c in children space repeat
cc := deepCopy c
cc.parentField := [node]
node.childrenField := cons(cc,node.childrenField)
node.childrenField := reverse_!(node.childrenField)
node.lastChild := tail node.childrenField
node
merge(s1,s2) ==
------------------ need to worry about reindexing s2 & parentField
n1 : Rep := deepCopy s1
n2 : Rep := deepCopy s2
n1.childrenField := append(children n1,children n2)
n1
merge listOfSpaces ==
------------------ need to worry about reindexing & parentField
empty? listOfSpaces => error "empty list passed as argument to merge"
-- notice that the properties of the first subspace on the
-- list are the ones that are inherited...hmmmm...
space := deepCopy first listOfSpaces
for s in rest listOfSpaces repeat
-- because of the initial deepCopy, above, everything is
-- deepCopied to be consistent...more hmmm...
space.childrenField := _
append(space.childrenField,[deepCopy c for c in s.childrenField])
space
separate space ==
------------------ need to worry about reindexing & parentField
spaceList := empty()
for s in space.childrenField repeat
spc:=shallowCopy space
spc.childrenField:=[deepCopy s]
spaceList := cons(spc,spaceList)
spaceList
addPoint(space:%,path:List NNI,point:POINT) ==
if not empty?(lastPt := space.lastPoint) then
not empty? rest lastPt => error TELLWATT
if empty? lastPt
then
space.pointDataField := [point]
space.lastPoint := space.pointDataField
else
setrest_!(lastPt,[point])
space.lastPoint := rest lastPt
space.noPoints := space.noPoints + 1
which := space.noPoints
node := space
depth : NNI := 0
for i in path repeat
node := child(node,i)
depth := depth + 1
for more in depth..(n-1) repeat
node := birth node
node.pt := point -- will be obsolete field
node.index := which
space
addPoint2(space:%,point:POINT) ==
if not empty?(lastPt := space.lastPoint) then
not empty? rest lastPt => error TELLWATT
if empty? lastPt
then
space.pointDataField := [point]
space.lastPoint := space.pointDataField
else
setrest_!(lastPt,[point])
space.lastPoint := rest lastPt
space.noPoints := space.noPoints + 1
which := space.noPoints
node := space
depth : NNI := 0
node := birth node
first := node
for more in 1..n-1 repeat
node := birth node
node.pt := point -- will be obsolete field
node.index := which
first
addPointLast(space:%,node:%, point:POINT, depth:NNI) ==
if not empty?(lastPt := space.lastPoint) then
not empty? rest lastPt => error TELLWATT
if empty? lastPt
then
space.pointDataField := [point]
space.lastPoint := space.pointDataField
else
setrest_!(lastPt,[point])
space.lastPoint := rest lastPt
space.noPoints := space.noPoints + 1
which := space.noPoints
if depth = 2 then node := child(node, 2)
for more in depth..(n-1) repeat
node := birth node
node.pt := point -- will be obsolete field
node.index := which
node -- space
addPoint(space:%,path:List NNI,which:NNI) ==
node := space
depth : NNI := 0
for i in path repeat
node := child(node,i)
depth := depth + 1
for more in depth..(n-1) repeat
node := birth node
node.pt := space.pointDataField.which -- will be obsolete field
node.index := which
space
addPoint(space:%,point:POINT) ==
root? space =>
if not empty?(lastPt := space.lastPoint) then
not empty? rest lastPt => error TELLWATT
if empty? lastPt
then
space.pointDataField := [point]
space.lastPoint := space.pointDataField
else
setrest_!(lastPt,[point])
space.lastPoint := rest lastPt
space.noPoints := space.noPoints + 1
error "You need to pass a top level SubSpace (level should be zero)"
modifyPoint(space:%,path:List NNI,point:POINT) ==
if not empty?(lastPt := space.lastPoint) then
not empty? rest lastPt => error TELLWATT
if empty? lastPt
then
space.pointDataField := [point]
space.lastPoint := space.pointDataField
else
setrest_!(lastPt,[point])
space.lastPoint := rest lastPt
space.noPoints := space.noPoints + 1
which := space.noPoints
node := space
for i in path repeat
node := child(node,i)
node.pt := point ---------- will be obsolete field
node.index := which
space
modifyPoint(space:%,path:List NNI,which:NNI) ==
node := space
for i in path repeat
node := child(node,i)
node.pt := space.pointDataField.which ---------- will be obsolete field
node.index := which
space
modifyPoint(space:%,which:NNI,point:POINT) ==
root? space =>
space.pointDataField.which := point
space
error "You need to pass a top level SubSpace (level should be zero)"
closeComponent(space,path,val) ==
node := space
for i in path repeat
node := child(node,i)
close(node.property,val)
space
defineProperty(space,path,prop) ==
node := space
for i in path repeat
node := child(node,i)
node.property := prop
space
traverse(space,path) ==
for i in path repeat space := child(space,i)
space
extractPoint space ==
node := space
while ^root? node repeat node := parent node
(node.pointDataField).(space.index)
extractIndex space == space.index
extractClosed space == closed? space.property
extractProperty space == space.property
parent space ==
empty? space.parentField => _
error "This is a top level SubSpace - it does not have a parent"
first space.parentField
pointData space == space.pointDataField
level space == space.levelField
s1 = s2 ==
------------ extra checks for list of point data
(leaf? s1 and leaf? s2) =>
(s1.pt = s2.pt) and (s1.property = s2.property) _
and (s1.levelField = s2.levelField)
-- note that the ordering of children is important
#s1.childrenField ^= #s2.childrenField => false
and/[c1 = c2 for c1 in s1.childrenField for c2 in s2.childrenField]
and (s1.property = s2.property) and (s1.levelField = s2.levelField)
coerce(space:%):O ==
hconcat([n::O,"-Space with depth of "::O, _
(n - space.levelField)::O," and "::O,(s:=(#space.childrenField))::O, _
(s=1 => " component"::O;" components"::O)])
|