Add regression tests, a help page, and )d op example documentation for Queue
===================================================================== diff --git a/books/bookvol10.3.pamphlet b/books/bookvol10.3.pamphlet index c232fc0..3a34055 100644 --- a/books/bookvol10.3.pamphlet +++ b/books/bookvol10.3.pamphlet @@ -2304,12 +2304,12 @@ ArrayStack(S:SetCategory): StackAggregate(S) with push_! : (S,%) -> S ++ ++X a:ArrayStack INT:= arrayStack [1,2,3,4,5] - ++X push! a + ++X push!(9,a) ++X a insert_! : (S,%) -> % ++ ++X a:ArrayStack INT:= arrayStack [1,2,3,4,5] - ++X insert! a + ++X insert!(8,a) ++X a inspect : % -> S ++ @@ -75215,6 +75215,660 @@ QueryEquation(): Exports == Implementation where @ %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% \section{domain QUEUE Queue} +<<Queue.input>>= +)sys rm -f Queue.output +)spool Queue.output +)set message test on +)set message auto off +)clear all + +--S 1 of 46 +a:Queue INT:= queue [1,2,3,4,5] +--R +--R +--R (1) [1,2,3,4,5] +--R Type: Queue Integer +--E 1 + +--S 2 of 46 +dequeue! a +--R +--R +--R (2) 1 +--R Type: PositiveInteger +--E 2 + +--S 3 of 46 +a +--R +--R +--R (3) [2,3,4,5] +--R Type: Queue Integer +--E 3 + +--S 4 of 46 +extract! a +--R +--R +--R (4) 2 +--R Type: PositiveInteger +--E 4 + +--S 5 of 46 +a +--R +--R +--R (5) [3,4,5] +--R Type: Queue Integer +--E 5 + +--S 6 of 46 +enqueue!(9,a) +--R +--R +--R (6) 9 +--R Type: PositiveInteger +--E 6 + +--S 7 of 46 +a +--R +--R +--R (7) [3,4,5,9] +--R Type: Queue Integer +--E 7 + +--S 8 of 46 +insert!(8,a) +--R +--R +--R (8) [3,4,5,9,8] +--R Type: Queue Integer +--E 8 + +--S 9 of 46 +a +--R +--R +--R (9) [3,4,5,9,8] +--R Type: Queue Integer +--E 9 + +--S 10 of 46 +inspect a +--R +--R +--R (10) 3 +--R Type: PositiveInteger +--E 10 + +--S 11 of 46 +empty? a +--R +--R +--R (11) false +--R Type: Boolean +--E 11 + +--S 12 of 46 +front a +--R +--R +--R (12) 3 +--R Type: PositiveInteger +--E 12 + +--S 13 of 46 +back a +--R +--R +--R (13) 8 +--R Type: PositiveInteger +--E 13 + +--S 14 of 46 +rotate! a +--R +--R +--R (14) [4,5,9,8,3] +--R Type: Queue Integer +--E 14 + +--S 15 of 46 +#a +--R +--R +--R (15) 5 +--R Type: PositiveInteger +--E 15 + +--S 16 of 46 +length a +--R +--R +--R (16) 5 +--R Type: PositiveInteger +--E 16 + +--S 17 of 46 +less?(a,9) +--R +--R +--R (17) true +--R Type: Boolean +--E 17 + +--S 18 of 46 +more?(a,9) +--R +--R +--R (18) false +--R Type: Boolean +--E 18 + +--S 19 of 46 +size?(a,#a) +--R +--R +--R (19) true +--R Type: Boolean +--E 19 + +--S 20 of 46 +size?(a,9) +--R +--R +--R (20) false +--R Type: Boolean +--E 20 + +--S 21 of 46 +parts a +--R +--R +--R (21) [4,5,9,8,3] +--R Type: List Integer +--E 21 + +--S 22 of 46 +bag([1,2,3,4,5])$Queue(INT) +--R +--R +--R (22) [1,2,3,4,5] +--R Type: Queue Integer +--E 22 + +--S 23 of 46 +b:=empty()$(Queue INT) +--R +--R +--R (23) [] +--R Type: Queue Integer +--E 23 + +--S 24 of 46 +empty? b +--R +--R +--R (24) true +--R Type: Boolean +--E 24 + +--S 25 of 46 +sample()$Queue(INT) +--R +--R +--R (25) [] +--R Type: Queue Integer +--E 25 + +--S 26 of 46 +c:=copy a +--R +--R +--R (26) [4,5,9,8,3] +--R Type: Queue Integer +--E 26 + +--S 27 of 46 +eq?(a,c) +--R +--R +--R (27) false +--R Type: Boolean +--E 27 + +--S 28 of 46 +eq?(a,a) +--R +--R +--R (28) true +--R Type: Boolean +--E 28 + +--S 29 of 46 +(a=c)@Boolean +--R +--R +--R (29) true +--R Type: Boolean +--E 29 + +--S 30 of 46 +(a=a)@Boolean +--R +--R +--R (30) true +--R Type: Boolean +--E 30 + +--S 31 of 46 +a~=c +--R +--R +--R (31) false +--R Type: Boolean +--E 31 + +--S 32 of 46 +any?(x+->(x=4),a) +--R +--R +--R (32) true +--R Type: Boolean +--E 32 + +--S 33 of 46 +any?(x+->(x=11),a) +--R +--R +--R (33) false +--R Type: Boolean +--E 33 + +--S 34 of 46 +every?(x+->(x=11),a) +--R +--R +--R (34) false +--R Type: Boolean +--E 34 + +--S 35 of 46 +count(4,a) +--R +--R +--R (35) 1 +--R Type: PositiveInteger +--E 35 + +--S 36 of 46 +count(x+->(x>2),a) +--R +--R +--R (36) 5 +--R Type: PositiveInteger +--E 36 + +--S 37 of 46 +map(x+->x+10,a) +--R +--R +--R (37) [14,15,19,18,13] +--R Type: Queue Integer +--E 37 + +--S 38 of 46 +a +--R +--R +--R (38) [4,5,9,8,3] +--R Type: Queue Integer +--E 38 + +--S 39 of 46 +map!(x+->x+10,a) +--R +--R +--R (39) [14,15,19,18,13] +--R Type: Queue Integer +--E 39 + +--S 40 of 46 +a +--R +--R +--R (40) [14,15,19,18,13] +--R Type: Queue Integer +--E 40 + +--S 41 of 46 +members a +--R +--R +--R (41) [14,15,19,18,13] +--R Type: List Integer +--E 41 + +--S 42 of 46 +member?(14,a) +--R +--R +--R (42) true +--R Type: Boolean +--E 42 + +--S 43 of 46 +coerce a +--R +--R +--R (43) [14,15,19,18,13] +--R Type: OutputForm +--E 43 + +--S 44 of 46 +hash a +--R +--R +--R (44) 0 +--R Type: SingleInteger +--E 44 + +--S 45 of 46 +latex a +--R +--R +--R (45) "\mbox{\bf Unimplemented}" +--R Type: String +--E 45 + +--S 46 of 46 +)show Queue +--R +--R Queue S: SetCategory is a domain constructor +--R Abbreviation for Queue is QUEUE +--R This constructor is exposed in this frame. +--R Issue )edit bookvol10.3.spad.pamphlet to see algebra source code for QUEUE +--R +--R------------------------------- Operations -------------------------------- +--R back : % -> S bag : List S -> % +--R copy : % -> % dequeue! : % -> S +--R empty : () -> % empty? : % -> Boolean +--R enqueue! : (S,%) -> S eq? : (%,%) -> Boolean +--R extract! : % -> S front : % -> S +--R insert! : (S,%) -> % inspect : % -> S +--R length : % -> NonNegativeInteger map : ((S -> S),%) -> % +--R queue : List S -> % rotate! : % -> % +--R sample : () -> % +--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 46 + + +)spool +)lisp (bye) + +@ +<<Queue.help>>= +==================================================================== +Queue examples +==================================================================== + +A Queue object is represented as a list ordered by first-in, first-out. +It operates like a line of people, where the "next" person is the one +at the front of the line. + +Here we create an queue of integers from a list. Notice that the +order in the list is the order in the queue. + + a:Queue INT:= queue [1,2,3,4,5] + [1,2,3,4,5] + +We can remove the top of the queue using dequeue!: + + dequeue! a + 1 + +Notice that the use of dequeue! 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 queue as a BagAggregate: + + extract! a + 2 + +and you can see that it also has destructively modified the queue: + + a + [3,4,5] + +Next we use enqueue! to add a new element to the end of the queue: + + push!(9,a) + 9 + +Again, the push! operation is destructive so the queue is changed: + + a + [3,4,5,9] + +Another name for enqueue! is insert!, which treats the queue as a +BagAggregate: + + insert!(8,a) + [3,4,5,9,8] + +and it modifies the queue: + + a + [3,4,5,9,8] + +The inspect function returns the top of the queue without modification, +viewed as a BagAggregate: + + inspect a + 8 + +The empty? operation returns true only if there are no element on the +queue, otherwise it returns false: + + empty? a + false + +The front operation returns the front of the queue without modification: + + front a + 3 + +The back operation returns the back of the queue without modification: + + back a + 8 + +The rotate! operation moves the item at the front of the queue to the +back of the queue: + + rotate! a + [4,5,9,8,3] + +The # (length) operation: + + #a + 5 + +The length operation does the same thing: + + length a + 5 + +The less? predicate will compare the queue length to an integer: + + less?(a,9) + true + +The more? predicate will compare the queue length to an integer: + + more?(a,9) + false + +The size? operation will compare the queue 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 queue 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 queue: + + bag([1,2,3,4,5])$Queue(INT) + [1,2,3,4,5] + +The empty function will construct an empty queue of a given type: + + b:=empty()$(Queue INT) + [] + +and the empty? predicate allows us to find out if a queue is empty: + + empty? b + true + +The sample function returns a sample, empty queue: + + sample()$Queue(INT) + [] + +We can copy a queue and it does not share storage so subsequent +modifications of the original queue will not affect the copy: + + c:=copy a + [4,5,9,8,3] + +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 queue: + + map(x+->x+10,a) + [14,15,19,18,13] + +Notice that the orignal queue is unchanged: + + a + [4,5,9,8,3] + +You can use map! to map a function over every element and change +the original queue since map! is destructive: + + map!(x+->x+10,a) + [14,15,19,18,13] +o +Notice that the orignal queue has been changed: + + a + [14,15,19,18,13] + +The member function can also get the element of the queue as a list: + + members a + [18,19,13,14,15] + +and using member? we can test if the queue 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{Queue}{QUEUE} \pagepic{ps/v103queue.ps}{QUEUE}{1.00} {\bf See}\\ @@ -75285,6 +75939,151 @@ Queue(S:SetCategory): QueueAggregate S with ++ ++E e:Queue INT:= queue [1,2,3,4,5] + -- Inherited Signatures repeated for examples documentation + + dequeue_! : % -> S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X dequeue! a + ++X a + extract_! : % -> S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X extract! a + ++X a + enqueue_! : (S,%) -> S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X enqueue! (9,a) + ++X a + insert_! : (S,%) -> % + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X insert! (8,a) + ++X a + inspect : % -> S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X inspect a + front : % -> S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X front a + back : % -> S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X back a + rotate_! : % -> % + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X rotate! a + length : % -> NonNegativeInteger + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X length a + less? : (%,NonNegativeInteger) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X less?(a,9) + more? : (%,NonNegativeInteger) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X more?(a,9) + size? : (%,NonNegativeInteger) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X size?(a,5) + bag : List S -> % + ++ + ++X bag([1,2,3,4,5])$Queue(INT) + empty? : % -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X empty? a + empty : () -> % + ++ + ++X b:=empty()$(Queue INT) + sample : () -> % + ++ + ++X sample()$Queue(INT) + copy : % -> % + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X copy a + eq? : (%,%) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X b:=copy a + ++X eq?(a,b) + map : ((S -> S),%) -> % + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X map(x+->x+10,a) + ++X a + if $ has shallowlyMutable then + map! : ((S -> S),%) -> % + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X map!(x+->x+10,a) + ++X a + if S has SetCategory then + latex : % -> String + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X latex a + hash : % -> SingleInteger + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X hash a + coerce : % -> OutputForm + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X coerce a + "=": (%,%) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X b:Queue INT:= queue [1,2,3,4,5] + ++X (a=b)@Boolean + "~=" : (%,%) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X b:=copy a + ++X (a~=b) + if % has finiteAggregate then + every? : ((S -> Boolean),%) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X every?(x+->(x=4),a) + any? : ((S -> Boolean),%) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X any?(x+->(x=4),a) + count : ((S -> Boolean),%) -> NonNegativeInteger + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X count(x+->(x>2),a) + _# : % -> NonNegativeInteger + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X #a + parts : % -> List S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X parts a + members : % -> List S + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X members a + if % has finiteAggregate and S has SetCategory then + member? : (S,%) -> Boolean + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X member?(3,a) + count : (S,%) -> NonNegativeInteger + ++ + ++X a:Queue INT:= queue [1,2,3,4,5] + ++X count(4,a) + == Stack S add Rep := Reference List S lastTail==> LAST$Lisp @@ -90810,12 +91609,12 @@ Stack(S:SetCategory): StackAggregate S with push_! : (S,%) -> S ++ ++X a:Stack INT:= stack [1,2,3,4,5] - ++X push! a + ++X push!(9,a) ++X a insert_! : (S,%) -> % ++ ++X a:Stack INT:= stack [1,2,3,4,5] - ++X insert! a + ++X insert!(8,a) ++X a inspect : % -> S ++ diff --git a/changelog b/changelog index 140b82f..1bc3146 100644 --- a/changelog +++ b/changelog @@ -1,3 +1,6 @@ +20090223 tpd src/axiom-website/patches.html 20090223.01.tpd.patch +20090223 tpd src/interp/Makefile add regression, help for Queue +20090223 tpd books/bookvol10.3 add regression, help, examples for Queue 20090222 tpd src/axiom-website/patches.html 20090222.04.tpd.patch 20090222 tpd src/interp/Makefile add regression, help for ArrayStack 20090222 tpd books/bookvol10.3 add regression, help, examples for ArrayStack diff --git a/src/algebra/Makefile.pamphlet b/src/algebra/Makefile.pamphlet index 4ed8ac9..c0ad0df 100644 --- a/src/algebra/Makefile.pamphlet +++ b/src/algebra/Makefile.pamphlet @@ -16454,6 +16454,7 @@ SPADHELP=\ ${HELP}/PartialFraction.help \ ${HELP}/Permanent.help ${HELP}/Permutation.help \ ${HELP}/Polynomial.help ${HELP}/Quaternion.help \ + ${HELP}/Queue.help \ ${HELP}/RadixExpansion.help ${HELP}/RealClosure.help \ ${HELP}/RealSolvePackage.help ${HELP}/RegularTriangularSet.help \ ${HELP}/RomanNumeral.help ${HELP}/Segment.help \ @@ -16522,6 +16523,7 @@ REGRESS=\ Permanent.regress Permutation.regress \ PlaneAlgebraicCurvePlot.regress Plot.regress \ Polynomial.regress Quaternion.regress \ + Queue.regress \ RadixExpansion.regress RealClosure.regress \ RealSolvePackage.regress RegularTriangularSet.regress \ RomanNumeral.regress Segment.regress \ @@ -17302,6 +17304,15 @@ ${HELP}/Quaternion.help: ${BOOKS}/bookvol10.3.pamphlet >${INPUT}/Quaternion.input @echo "Quaternion (QUAT)" >>${HELPFILE} +${HELP}/Queue.help: ${BOOKS}/bookvol10.3.pamphlet + @echo 7078 create Queue.help from ${BOOKS}/bookvol10.3.pamphlet + @${TANGLE} -R"Queue.help" ${BOOKS}/bookvol10.3.pamphlet \ + >${HELP}/Queue.help + @-cp ${HELP}/Queue.help ${HELP}/QUEUE.help + @${TANGLE} -R"Queue.input" ${BOOKS}/bookvol10.3.pamphlet \ + >${INPUT}/Queue.input + @echo "Queue (QUEUE)" >>${HELPFILE} + ${HELP}/RadixExpansion.help: ${BOOKS}/bookvol10.3.pamphlet @echo 7067 create RadixExpansion.help from \ ${BOOKS}/bookvol10.3.pamphlet diff --git a/src/axiom-website/patches.html b/src/axiom-website/patches.html index 03f2830..0ed5c8f 100644 --- a/src/axiom-website/patches.html +++ b/src/axiom-website/patches.html @@ -961,5 +961,7 @@ bookvol10.3 add regression, help, examples for Stack<br/> bookvol10.2 add documentation<br/> <a href="patches/20090222.04.tpd.patch">20090222.04.tpd.patch</a> bookvol10.3 add regression, help, examples for ArrayStack<br/> +<a href="patches/20090223.01.tpd.patch">20090223.01.tpd.patch</a> +bookvol10.3 add regression, help, examples for Queue<br/> </body> </html> _______________________________________________ Axiom-developer mailing list Axiom-developer@nongnu.org http://lists.nongnu.org/mailman/listinfo/axiom-developer