diff --git a/books/bookvol10.3.pamphlet b/books/bookvol10.3.pamphlet index 8f77e34..23ee487 100644 --- a/books/bookvol10.3.pamphlet +++ b/books/bookvol10.3.pamphlet @@ -1595,6 +1595,150 @@ Any(): SetCategory with @ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{domain ASTACK ArrayStack} +<>= +)sys rm -f ArrayStack.output +)spool ArrayStack.output +)set message test on +)set message auto off +)clear all + +--S 1 of 44 +a:Stack INT:= stack [1,2,3,4,5] +--R +--R +--R (1) [1,2,3,4,5] +--R Type: Stack Integer +--E 1 + +--S 2 of 44 +pop! a +--R +--R +--R (2) 1 +--R Type: PositiveInteger +--E 2 + +--S 3 of 44 +a +--R +--R +--R (3) [2,3,4,5] +--R Type: Stack Integer +--E 3 + +--S 4 of 44 +push!(9,a) +--R +--R +--R (4) 9 +--R Type: PositiveInteger +--E 4 + +--S 5 of 44 +a +--R +--R +--R (5) [9,2,3,4,5] +--R Type: Stack Integer +--E 5 + +--S 6 of 44 +empty? a +--R +--R +--R (6) false +--R Type: Boolean +--E 6 + +--S 7 of 44 +b:=empty()$(Stack INT) +--R +--R +--R (7) [] +--R Type: Stack Integer +--E 7 + +--S 8 of 44 +empty? b +--R +--R +--R (8) true +--R Type: Boolean +--E 8 + +)spool +)lisp (bye) + +@ +<>= +==================================================================== +Stack examples +==================================================================== + +A Stack object is represented as a list ordered by last-in, first-out. +It operates like a pile of books, where the "next" book is the one +on the top of the pile. + +Here we create a stack of integers from a list. Notice that the +order in the list is the order in the stack. + + a:Stack INT:= stack [1,2,3,4,5] + + (1) [1,2,3,4,5] + +We can remove the top of the stack using pop!: + + pop! a + + (2) 1 + +Notice that the use of pop! is destructive (destructive operations +in Axiom usually end with ! to indicate that the underylying data +structure is changed). + + a + + (3) [2,3,4,5] + +Next we push a new element on top of the stack: + + push!(9,a) + + (4) 9 + +Again, the push! operation is destructive so the stack is changed: + + a + + (5) [9,2,3,4,5] + +We can ask if the stack is empty (boolean predicates in Axiom +generally end in a question mark): + + empty? a + + (6) false + +We can create a new, empty stack: + + b:=empty()$(Stack INT) + + (7) [] + +And we can ask if b is empty: + + empty? b + + (8) true + +See Also: +o )show Stack +o )show ArrayStack +o )show Queue +o )show Dequeue +o )show Heap + +@ \pagehead{ArrayStack}{ASTACK} \pagepic{ps/v103arraystack.ps}{ASTACK}{1.00} {\bf See}\\ @@ -89375,6 +89519,566 @@ SquareMatrix(ndim,R): Exports == Implementation where @ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{domain STACK Stack} +<>= +-- stack.spad.pamphlet Stack.input +)sys rm -f Stack.output +)spool Stack.output +)set message test on +)set message auto off +)clear all + +--S 1 of 41 +a:Stack INT:= stack [1,2,3,4,5] +--R +--R (1) [1,2,3,4,5] +--R Type: Stack Integer +--E 1 + +--S 2 of 41 +pop! a +--R +--R (2) 1 +--R Type: PositiveInteger +--E 2 + +--S 3 of 41 +a +--R +--R (3) [2,3,4,5] +--R Type: Stack Integer +--E 3 + +--S 4 of 41 +extract! a +--R +--R (4) 2 +--R Type: PositiveInteger +--E 4 + +--S 5 of 41 +a +--R +--R (5) [3,4,5] +--R Type: Stack Integer +--E 5 + +--S 6 of 41 +push!(9,a) +--R +--R (6) 9 +--R Type: PositiveInteger +--E 6 + +--S 7 of 41 +a +--R +--R (7) [9,3,4,5] +--R Type: Stack Integer +--E 7 + +--S 8 of 41 +insert!(8,a) +--R +--R (8) [8,9,3,4,5] +--R Type: Stack Integer +--E 8 + +--S 9 of 41 +a +--R +--R (9) [8,9,3,4,5] +--R Type: Stack Integer +--E 9 + +--S 10 of 41 +inspect a +--R +--R (10) 8 +--R Type: PositiveInteger +--E 10 + +--S 11 of 41 +empty? a +--R +--R (11) false +--R Type: Boolean +--E 11 + +--S 12 of 41 +top a +--R +--R (12) 8 +--R Type: PositiveInteger +--E 12 + +--S 13 of 41 +depth a +--R +--R (13) 5 +--R Type: PositiveInteger +--E 13 + +--S 14 of 41 +#a +--R +--R (14) 5 +--R Type: PositiveInteger +--E 14 + +--S 15 of 41 +less?(a,9) +--R +--R (15) true +--R Type: Boolean +--E 15 + +--S 16 of 41 +more?(a,9) +--R +--R (16) false +--R Type: Boolean +--E 16 + +--S 17 of 41 +size?(a,#a) +--R +--R (17) true +--R Type: Boolean +--E 17 + +--S 18 of 41 +size?(a,9) +--R +--R (18) false +--R Type: Boolean +--E 18 + +--S 19 of 41 +parts a +--R +--R (19) [8,9,3,4,5] +--R Type: List Integer +--E 19 + +--S 20 of 41 +bag([1,2,3,4,5])$Stack(INT) +--R +--R (20) [5,4,3,2,1] +--R Type: Stack Integer +--E 20 + +--S 21 of 41 +b:=empty()$(Stack INT) +--R +--R (21) [] +--R Type: Stack Integer +--E 21 + +--S 22 of 41 +empty? b +--R +--R (22) true +--R Type: Boolean +--E 22 + +--S 23 of 41 +sample()$Stack(INT) +--R +--R (23) [] +--R Type: Stack Integer +--E 23 + +--S 24 of 41 +c:=copy a +--R +--R (24) [8,9,3,4,5] +--R Type: Stack Integer +--E 24 + +--S 25 of 41 +eq?(a,c) +--R +--R (25) false +--R Type: Boolean +--E 25 + +--S 26 of 41 +eq?(a,a) +--R +--R (26) true +--R Type: Boolean +--E 26 + +--S 27 of 41 +(a=c)@Boolean +--R +--R (27) true +--R Type: Boolean +--E 27 + +--S 28 of 41 +(a=a)@Boolean +--R +--R (28) true +--R Type: Boolean +--E 28 + +--S 29 of 41 +a~=c +--R +--R (29) false +--R Type: Boolean +--E 29 + +--S 30 of 41 +any?(x+->(x=4),a) +--R +--R (30) true +--R Type: Boolean +--E 30 + +--S 31 of 41 +any?(x+->(x=11),a) +--R +--R (31) false +--R Type: Boolean +--E 31 + +--S 32 of 41 +every?(x+->(x=11),a) +--R +--R (32) false +--R Type: Boolean +--E 32 + +--S 33 of 41 +count(4,a) +--R +--R (33) 1 +--R Type: PositiveInteger +--E 33 + +--S 34 of 41 +count(x+->(x>2),a) +--R +--R (34) 5 +--R Type: PositiveInteger +--E 34 + +--S 35 of 41 +map(x+->x+10,a) +--R +--R (35) [18,19,13,14,15] +--R Type: Stack Integer +--E 35 + +--S 36 of 41 +a +--R +--R (36) [8,9,3,4,5] +--R Type: Stack Integer +--E 36 + +--S 37 of 41 +map!(x+->x+10,a) +--R +--R (37) [18,19,13,14,15] +--R Type: Stack Integer +--E 37 + +--S 38 of 41 +a +--R +--R (38) [18,19,13,14,15] +--R Type: Stack Integer +--E 38 + +--S 39 of 41 +members a +--R +--R (39) [18,19,13,14,15] +--R Type: List Integer +--E 39 + +--S 40 of 41 +member?(14,a) +--R +--R (40) true +--R Type: Boolean +--E 40 + +--S 41 of 41 +)show Stack +--R Stack S: SetCategory is a domain constructor +--R Abbreviation for Stack is STACK +--R This constructor is exposed in this frame. +--R Issue )edit bookvol10.3.spad.pamphlet to see algebra source code for STACK +--R +--R------------------------------- Operations -------------------------------- +--R bag : List S -> % copy : % -> % +--R depth : % -> NonNegativeInteger empty : () -> % +--R empty? : % -> Boolean eq? : (%,%) -> Boolean +--R extract! : % -> S insert! : (S,%) -> % +--R inspect : % -> S map : ((S -> S),%) -> % +--R pop! : % -> S push! : (S,%) -> S +--R sample : () -> % stack : List S -> % +--R top : % -> S +--R #? : % -> NonNegativeInteger if $ has finiteAggregate +--R ?=? : (%,%) -> Boolean if S has SETCAT +--R any? : ((S -> Boolean),%) -> Boolean if $ has finiteAggregate +--R coerce : % -> OutputForm if S has SETCAT +--R count : (S,%) -> NonNegativeInteger if $ has finiteAggregate and S has SETCAT +--R count : ((S -> Boolean),%) -> NonNegativeInteger if $ has finiteAggregate +--R eval : (%,List S,List S) -> % if S has EVALAB S and S has SETCAT +--R eval : (%,S,S) -> % if S has EVALAB S and S has SETCAT +--R eval : (%,Equation S) -> % if S has EVALAB S and S has SETCAT +--R eval : (%,List Equation S) -> % if S has EVALAB S and S has SETCAT +--R every? : ((S -> Boolean),%) -> Boolean if $ has finiteAggregate +--R hash : % -> SingleInteger if S has SETCAT +--R latex : % -> String if S has SETCAT +--R less? : (%,NonNegativeInteger) -> Boolean +--R map! : ((S -> S),%) -> % if $ has shallowlyMutable +--R member? : (S,%) -> Boolean if $ has finiteAggregate and S has SETCAT +--R members : % -> List S if $ has finiteAggregate +--R more? : (%,NonNegativeInteger) -> Boolean +--R parts : % -> List S if $ has finiteAggregate +--R size? : (%,NonNegativeInteger) -> Boolean +--R ?~=? : (%,%) -> Boolean if S has SETCAT +--R +--E 41 +)spool +)lisp (bye) + +@ +<>= +==================================================================== +Stack examples +==================================================================== + +A Stack object is represented as a list ordered by last-in, first-out. +It operates like a pile of books, where the "next" book is the one +on the top of the pile. + +Here we create a stack of integers from a list. Notice that the +order in the list is the order in the stack. + + a:Stack INT:= stack [1,2,3,4,5] + [1,2,3,4,5] + +We can remove the top of the stack using pop!: + + pop! a + 1 + +Notice that the use of pop! is destructive (destructive operations +in Axiom usually end with ! to indicate that the underylying data +structure is changed). + + a + [2,3,4,5] + +The extract! operation is another name for the pop! operation and +has the same effect. This operation treats the stack as a BagAggregate: + +o extract! a + 2 + +and you can see that it also has destructively modified the stack: + + a + [3,4,5] + +Next we push a new element on top of the stack: + + push!(9,a) + 9 + +Again, the push! operation is destructive so the stack is changed: + + a + [9,2,3,4,5] + +Another name for push! is insert!, which treats the stack as a BagAggregate: + + insert!(8,a) + [8,9,3,4,5] + +and it modifies the stack: + + a + [8,9,3,4,5] + +The inspect function returns the top of the stack without modification, +viewed as a BagAggregate: + + inspect a + 8 + +The empty? operation returns true only if there are no element on the +stack, otherwise it returns false: + + empty? a + false + +The top operation returns the top of stack without modification, viewed +as a Stack: + + top a + 8 + +The depth operation returns the number of elements on the stack: + + depth a + 5 + +which is the same as the # (length) operation: + + #a + 5 + +The less? predicate will compare the stack length to an integer: + + less?(a,9) + true + +The more? predicate will compare the stack length to an integer: + + more?(a,9) + false + +The size? operation will compare the stack length to an integer: + + size?(a,#a) + true + +and since the last computation must alwasy be true we try: + + size?(a,9) + false + +The parts function will return the stack as a list of its elements: + + parts a + [8,9,3,4,5] + +If we have a BagAggregate of elements we can use it to construct a stack. +Notice that the elements are pushed in reverse order: + + bag([1,2,3,4,5])$Stack(INT) + [5,4,3,2,1] + +The empty function will construct an empty stack of a given type: + + b:=empty()$(Stack INT) + [] + +and the empty? predicate allows us to find out if a stack is empty: + + empty? b + true + +The sample function returns a sample, empty stack: + + sample()$Stack(INT) + [] + +We can copy a stack and it does not share storage so subsequent +modifications of the original stack will not affect the copy: + + c:=copy a + [8,9,3,4,5] + +The eq? function is only true if the lists are the same reference, +so even though c is a copy of a, they are not the same: + + eq?(a,c) + false + +However, a clearly shares a reference with itself: + + eq?(a,a) + true + +But we can compare a and c for equality: + + (a=c)@Boolean + true + +and clearly a is equal to itself: + + (a=a)@Boolean + true + +and since a and c are equal, they are clearly NOT not-equal: + + a~=c + false + +We can use the any? function to see if a predicate is true for any element: + + any?(x+->(x=4),a) + true + +or false for every element: + + any?(x+->(x=11),a) + false + +We can use the every? function to check every element satisfies a predicate: + + every?(x+->(x=11),a) + false + +We can count the elements that are equal to an argument of this type: + + count(4,a) + 1 + +or we can count against a boolean function: + + count(x+->(x>2),a) + 5 + +You can also map a function over every element, returning a new stack: + + map(x+->x+10,a) + [18,19,13,14,15] + +Notice that the orignal stack is unchanged: + + a + [8,9,3,4,5] + +You can use map! to map a function over every element and change +the original stack since map! is destructive: + + map!(x+->x+10,a) + [18,19,13,14,15] + +Notice that the orignal stack has been changed: + + a + [18,19,13,14,15] + +The member function can also get the element of the stack as a list: + + members a + [18,19,13,14,15] + +and using member? we can test if the stack holds a given element: + + member?(14,a) + true + +See Also: +o )show Stack +o )show ArrayStack +o )show Queue +o )show Dequeue +o )show Heap +o )show BagAggregate + +@ \pagehead{Stack}{STACK} \pagepic{ps/v103stack.ps}{STACK}{1.00} {\bf See}\\ @@ -89421,9 +90125,9 @@ SquareMatrix(ndim,R): Exports == Implementation where <>= )abbrev domain STACK Stack -++ Author: Michael Monagan and Stephen Watt +++ Author: Michael Monagan, Stephen Watt, Timothy Daly ++ Date Created:June 86 and July 87 -++ Date Last Updated:Feb 92 +++ Date Last Updated:Feb 09 ++ Basic Operations: ++ Related Domains: ++ Also See: @@ -89441,7 +90145,132 @@ Stack(S:SetCategory): StackAggregate S with ++ stack([x,y,...,z]) creates a stack with first (top) ++ element x, second element y,...,and last element z. ++ - ++E a:Stack INT:= stack [1,2,3,4,5] + ++X a:Stack INT:= stack [1,2,3,4,5] + + -- Inherited Signatures repeated for examples documentation + + pop_! : % -> S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X pop! a + ++X a + extract_! : % -> S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X extract! a + ++X a + push_! : (S,%) -> S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X push! a + ++X a + insert_! : (S,%) -> % + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X insert! a + ++X a + inspect : % -> S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X inspect a + top : % -> S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X top a + depth : % -> NonNegativeInteger + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X depth a + less? : (%,NonNegativeInteger) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X less?(a,9) + more? : (%,NonNegativeInteger) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X more?(a,9) + size? : (%,NonNegativeInteger) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X size?(a,5) + bag : List S -> % + ++ + ++X bag([1,2,3,4,5])$Stack(INT) + empty? : % -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X empty? a + empty : () -> % + ++ + ++X b:=empty()$(Stack INT) + sample : () -> % + ++ + ++X sample()$Stack(INT) + copy : % -> % + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X copy a + eq? : (%,%) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X b:=copy a + ++X eq?(a,b) + map : ((S -> S),%) -> % + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X map(x+->x+10,a) + ++X a + if $ has shallowlyMutable then + map! : ((S -> S),%) -> % + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X map!(x+->x+10,a) + ++X a + if S has SetCategory then + "=": (%,%) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X b:Stack INT:= stack [1,2,3,4,5] + ++X (a=b)@Boolean + "~=" : (%,%) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X b:=copy a + ++X (a~=b) + if % has finiteAggregate then + every? : ((S -> Boolean),%) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X every?(x+->(x=4),a) + any? : ((S -> Boolean),%) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X any?(x+->(x=4),a) + count : ((S -> Boolean),%) -> NonNegativeInteger + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X count(x+->(x>2),a) + _# : % -> NonNegativeInteger + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X #a + parts : % -> List S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X parts a + members : % -> List S + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X members a + if % has finiteAggregate and S has SetCategory then + member? : (S,%) -> Boolean + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X member?(3,a) + count : (S,%) -> NonNegativeInteger + ++ + ++X a:Stack INT:= stack [1,2,3,4,5] + ++X count(4,a) == add Rep := Reference List S @@ -89465,6 +90294,9 @@ Stack(S:SetCategory): StackAggregate S with empty() == ref nil()$List(S) empty? s == null deref s stack s == ref copy s + parts s == copy deref s + map(f,s) == ref map(f,deref s) + map!(f,s) == ref map!(f,deref s) @ <>= diff --git a/changelog b/changelog index a73b55d..0cf904a 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +20090222 tpd src/axiom-website/patches.html 20090222.02.tpd.patch +20090222 tpd src/interp/Makefile add regression, help for Stack +20090222 tpd books/bookvol10.3 add regression, help, examples for Stack 20090222 tpd src/axiom-website/patches.html 20090222.01.tpd.patch 20090222 tpd src/interp/setq.lisp Stephen Buchwald to credits 20090222 tpd readme add Stephen Buchwald to credits diff --git a/src/algebra/Makefile.pamphlet b/src/algebra/Makefile.pamphlet index 952fd83..841a1c1 100644 --- a/src/algebra/Makefile.pamphlet +++ b/src/algebra/Makefile.pamphlet @@ -16459,7 +16459,7 @@ SPADHELP=\ ${HELP}/SegmentBinding.help \ ${HELP}/Set.help ${HELP}/SingleInteger.help \ ${HELP}/SparseTable.help ${HELP}/SquareMatrix.help \ - ${HELP}/SquareFreeRegularTriangularSet.help \ + ${HELP}/SquareFreeRegularTriangularSet.help ${HELP}/Stack.help \ ${HELP}/Stream.help ${HELP}/String.help \ ${HELP}/StringTable.help ${HELP}/Symbol.help \ ${HELP}/Table.help ${HELP}/TextFile.help \ @@ -16525,7 +16525,7 @@ REGRESS=\ RomanNumeral.regress Segment.regress \ Set.regress SingleInteger.regress \ SparseTable.regress SquareMatrix.regress \ - SquareFreeRegularTriangularSet.regress \ + SquareFreeRegularTriangularSet.regress Stack.regress \ Stream.regress String.regress \ StringTable.regress Symbol.regress \ Table.regress TextFile.regress \ @@ -17408,6 +17408,15 @@ ${HELP}/SquareFreeRegularTriangularSet.help: ${BOOKS}/bookvol10.3.pamphlet >${INPUT}/SquareFreeRegularTriangularSet.input @echo "SquareFreeRegularTriangularSet (SREGSET)" >>${HELPFILE} +${HELP}/Stack.help: ${BOOKS}/bookvol10.3.pamphlet + @echo 7078 create Stack.help from ${BOOKS}/bookvol10.3.pamphlet + @${TANGLE} -R"Stack.help" ${BOOKS}/bookvol10.3.pamphlet \ + >${HELP}/Stack.help + @-cp ${HELP}/Stack.help ${HELP}/STREAM.help + @${TANGLE} -R"Stack.input" ${BOOKS}/bookvol10.3.pamphlet \ + >${INPUT}/Stack.input + @echo "Stack (STACK)" >>${HELPFILE} + ${HELP}/Stream.help: ${BOOKS}/bookvol10.3.pamphlet @echo 7078 create Stream.help from ${BOOKS}/bookvol10.3.pamphlet @${TANGLE} -R"Stream.help" ${BOOKS}/bookvol10.3.pamphlet \ diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index a861a06..a8c96df 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -955,5 +955,7 @@ remove bookvol5 dvi creation
add Scott Morrison's original hypertex plan
20090222.01.tpd.patch add Stephen Buchwald to credits
+20090222.02.tpd.patch +bookvol10.3 add regression, help, examples for Stack