axiom-developer
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Axiom-developer] 20080218.01.tpd.patch (add function examples)


From: daly
Subject: [Axiom-developer] 20080218.01.tpd.patch (add function examples)
Date: Mon, 18 Feb 2008 00:33:19 -0600

Function examples for array1.spad and fr.spad

DONE )d op flexibleArray
DONE )d op irreducibleFactor
DONE )d op nthExponent
DONE )d op nilFactor
DONE )d op nthFlag
DONE )d op oneDimensionalArray
DONE )d op physicalLength
DONE )d op physicalLength!
DONE )d op primeFactor
DONE )d op shrinkable
DONE )d op sqfrFactor


SOME )d op coerce
SOME )d op expand
SOME )d op exponent
SOME )d op factorList
SOME )d op factors
SOME )d op length
SOME )d op makeFR
SOME )d op map
SOME )d op nthFactor
SOME )d op numberOfFactors
SOME )d op reduce
SOME )d op scan
SOME )d op select
SOME )d op unit

Tim

============================================================================
diff --git a/changelog b/changelog
index 5323199..101d2dc 100644
--- a/changelog
+++ b/changelog
@@ -1,3 +1,5 @@
+20080218 tpd src/algebra/array1.spad add function examples
+20080218 tpd src/algebra/fr.spad add function examples
 20080217 wxh src/interp/i-intern.boot upload proper file. 
 20080217 tpd src/algebra/string.spad add function examples
 20080217 tpd src/algebra/curve.spad add function examples
diff --git a/src/algebra/array1.spad.pamphlet b/src/algebra/array1.spad.pamphlet
index 10456d7..b4adc3d 100644
--- a/src/algebra/array1.spad.pamphlet
+++ b/src/algebra/array1.spad.pamphlet
@@ -52,15 +52,18 @@ Note that this code is not included in the generated 
catdef.spad file.
 
 (DEFUN |PRIMARR;#;$Nni;1| (|x| |$|) (QVSIZE |x|)) 
 
-(PUT (QUOTE |PRIMARR;minIndex;$I;2|) (QUOTE |SPADreplace|) (QUOTE (XLAM (|x|) 
0))) 
+(PUT (QUOTE |PRIMARR;minIndex;$I;2|)
+ (QUOTE |SPADreplace|) (QUOTE (XLAM (|x|) 0))) 
 
 (DEFUN |PRIMARR;minIndex;$I;2| (|x| |$|) 0) 
 
-(PUT (QUOTE |PRIMARR;empty;$;3|) (QUOTE |SPADreplace|) (QUOTE (XLAM NIL 
(GETREFV 0)))) 
+(PUT (QUOTE |PRIMARR;empty;$;3|)
+ (QUOTE |SPADreplace|) (QUOTE (XLAM NIL (GETREFV 0)))) 
 
 (DEFUN |PRIMARR;empty;$;3| (|$|) (GETREFV 0)) 
 
-(DEFUN |PRIMARR;new;NniS$;4| (|n| |x| |$|) (SPADCALL (GETREFV |n|) |x| 
(QREFELT |$| 12))) 
+(DEFUN |PRIMARR;new;NniS$;4| (|n| |x| |$|)
+ (SPADCALL (GETREFV |n|) |x| (QREFELT |$| 12))) 
 
 (PUT (QUOTE |PRIMARR;qelt;$IS;5|) (QUOTE |SPADreplace|) (QUOTE ELT)) 
 
@@ -78,13 +81,136 @@ Note that this code is not included in the generated 
catdef.spad file.
 
 (DEFUN |PRIMARR;setelt;$I2S;8| (|x| |i| |s| |$|) (SETELT |x| |i| |s|)) 
 
-(DEFUN |PRIMARR;fill!;$S$;9| (|x| |s| |$|) (PROG (|i| #1=#:G82338) (RETURN 
(SEQ (SEQ (LETT |i| 0 |PRIMARR;fill!;$S$;9|) (LETT #1# (QVMAXINDEX |x|) 
|PRIMARR;fill!;$S$;9|) G190 (COND ((QSGREATERP |i| #1#) (GO G191))) (SEQ (EXIT 
(SETELT |x| |i| |s|))) (LETT |i| (QSADD1 |i|) |PRIMARR;fill!;$S$;9|) (GO G190) 
G191 (EXIT NIL)) (EXIT |x|))))) 
-
-(DEFUN |PrimitiveArray| (#1=#:G82348) (PROG NIL (RETURN (PROG (#2=#:G82349) 
(RETURN (COND ((LETT #2# (|lassocShiftWithFunction| (LIST (|devaluate| #1#)) 
(HGET |$ConstructorCache| (QUOTE |PrimitiveArray|)) (QUOTE |domainEqualList|)) 
|PrimitiveArray|) (|CDRwithIncrement| #2#)) ((QUOTE T) (|UNWIND-PROTECT| (PROG1 
(|PrimitiveArray;| #1#) (LETT #2# T |PrimitiveArray|)) (COND ((NOT #2#) (HREM 
|$ConstructorCache| (QUOTE |PrimitiveArray|)))))))))))) 
-
-(DEFUN |PrimitiveArray;| (|#1|) (PROG (|DV$1| |dv$| |$| #1=#:G82347 |pv$|) 
(RETURN (PROGN (LETT |DV$1| (|devaluate| |#1|) . #2=(|PrimitiveArray|)) (LETT 
|dv$| (LIST (QUOTE |PrimitiveArray|) |DV$1|) . #2#) (LETT |$| (GETREFV 35) . 
#2#) (QSETREFV |$| 0 |dv$|) (QSETREFV |$| 3 (LETT |pv$| (|buildPredVector| 0 0 
(LIST (|HasCategory| |#1| (QUOTE (|SetCategory|))) (|HasCategory| |#1| (QUOTE 
(|ConvertibleTo| (|InputForm|)))) (LETT #1# (|HasCategory| |#1| (QUOTE 
(|OrderedSet|))) . #2#) (OR #1# (|HasCategory| |#1| (QUOTE (|SetCategory|)))) 
(|HasCategory| (|Integer|) (QUOTE (|OrderedSet|))) (AND (|HasCategory| |#1| 
(LIST (QUOTE |Evalable|) (|devaluate| |#1|))) (|HasCategory| |#1| (QUOTE 
(|SetCategory|)))) (OR (AND (|HasCategory| |#1| (LIST (QUOTE |Evalable|) 
(|devaluate| |#1|))) #1#) (AND (|HasCategory| |#1| (LIST (QUOTE |Evalable|) 
(|devaluate| |#1|))) (|HasCategory| |#1| (QUOTE (|SetCategory|))))))) . #2#)) 
(|haddProp| |$ConstructorCache| (QUOTE |PrimitiveArray|) (LIST |DV$1|) (CONS!
 1 |$|)) (|stuffDomainSlots| |$|) (QSETREFV |$| 6 |#1|) |$|)))) 
-
-(MAKEPROP (QUOTE |PrimitiveArray|) (QUOTE |infovec|) (LIST (QUOTE #(NIL NIL 
NIL NIL NIL NIL (|local| |#1|) (|NonNegativeInteger|) |PRIMARR;#;$Nni;1| 
(|Integer|) |PRIMARR;minIndex;$I;2| |PRIMARR;empty;$;3| |PRIMARR;fill!;$S$;9| 
|PRIMARR;new;NniS$;4| |PRIMARR;qelt;$IS;5| |PRIMARR;elt;$IS;6| 
|PRIMARR;qsetelt!;$I2S;7| |PRIMARR;setelt;$I2S;8| (|Mapping| 6 6 6) (|Boolean|) 
(|List| 6) (|Equation| 6) (|List| 21) (|Mapping| 19 6) (|Mapping| 19 6 6) 
(|UniversalSegment| 9) (|Void|) (|Mapping| 6 6) (|InputForm|) (|OutputForm|) 
(|String|) (|SingleInteger|) (|List| |$|) (|Union| 6 (QUOTE "failed")) (|List| 
9))) (QUOTE #(|~=| 0 |swap!| 6 |sorted?| 13 |sort!| 24 |sort| 35 |size?| 46 
|setelt| 52 |select| 66 |sample| 72 |reverse!| 76 |reverse| 81 
|removeDuplicates| 86 |remove| 91 |reduce| 103 |qsetelt!| 124 |qelt| 131 
|position| 137 |parts| 156 |new| 161 |more?| 167 |minIndex| 173 |min| 178 
|merge| 184 |members| 197 |member?| 202 |maxIndex| 208 |max| 213 |map!| 219 
|map| 225 |less?| 238 |lat!
ex| 244 |insert| 249 |indices| 263 |index?| 268 |hash| 274 |first| 279 |find| 
284 |fill!| 290 |every?| 296 |eval| 302 |eq?| 328 |entry?| 334 |entries| 340 
|empty?| 345 |empty| 350 |elt| 354 |delete| 373 |count| 385 |copyInto!| 397 
|copy| 404 |convert| 409 |construct| 414 |concat| 419 |coerce| 442 |any?| 447 
|>=| 453 |>| 459 |=| 465 |<=| 471 |<| 477 |#| 483)) (QUOTE ((|shallowlyMutable| 
. 0) (|finiteAggregate| . 0))) (CONS (|makeByteWordVec2| 7 (QUOTE (0 0 0 0 0 0 
3 0 0 7 4 0 0 7 1 2 4))) (CONS (QUOTE #(|OneDimensionalArrayAggregate&| 
|FiniteLinearAggregate&| |LinearAggregate&| |IndexedAggregate&| |Collection&| 
|HomogeneousAggregate&| |OrderedSet&| |Aggregate&| |EltableAggregate&| 
|Evalable&| |SetCategory&| NIL NIL |InnerEvalable&| NIL NIL |BasicType&|)) 
(CONS (QUOTE #((|OneDimensionalArrayAggregate| 6) (|FiniteLinearAggregate| 6) 
(|LinearAggregate| 6) (|IndexedAggregate| 9 6) (|Collection| 6) 
(|HomogeneousAggregate| 6) (|OrderedSet|) (|Aggregate|) (|EltableAggregate| 9 
6) (|!
Evalable| 6) (|SetCategory|) (|Type|) (|Eltable| 9 6) (|Inner!
Evalable| 6 6) (|CoercibleTo| 29) (|ConvertibleTo| 28) (|BasicType|))) 
(|makeByteWordVec2| 34 (QUOTE (2 1 19 0 0 1 3 0 26 0 9 9 1 1 3 19 0 1 2 0 19 24 
0 1 1 3 0 0 1 2 0 0 24 0 1 1 3 0 0 1 2 0 0 24 0 1 2 0 19 0 7 1 3 0 6 0 25 6 1 3 
0 6 0 9 6 17 2 0 0 23 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 1 2 1 0 6 0 1 2 0 
0 23 0 1 4 1 6 18 0 6 6 1 3 0 6 18 0 6 1 2 0 6 18 0 1 3 0 6 0 9 6 16 2 0 6 0 9 
14 2 1 9 6 0 1 3 1 9 6 0 9 1 2 0 9 23 0 1 1 0 20 0 1 2 0 0 7 6 13 2 0 19 0 7 1 
1 5 9 0 10 2 3 0 0 0 1 2 3 0 0 0 1 3 0 0 24 0 0 1 1 0 20 0 1 2 1 19 6 0 1 1 5 9 
0 1 2 3 0 0 0 1 2 0 0 27 0 1 3 0 0 18 0 0 1 2 0 0 27 0 1 2 0 19 0 7 1 1 1 30 0 
1 3 0 0 0 0 9 1 3 0 0 6 0 9 1 1 0 34 0 1 2 0 19 9 0 1 1 1 31 0 1 1 5 6 0 1 2 0 
33 23 0 1 2 0 0 0 6 12 2 0 19 23 0 1 3 6 0 0 20 20 1 2 6 0 0 21 1 3 6 0 0 6 6 1 
2 6 0 0 22 1 2 0 19 0 0 1 2 1 19 6 0 1 1 0 20 0 1 1 0 19 0 1 0 0 0 11 2 0 0 0 
25 1 2 0 6 0 9 15 3 0 6 0 9 6 1 2 0 0 0 9 1 2 0 0 0 25 1 2 1 7 6 0 1 2 0 7 23 0 
1 3 0 0 0 0 9 1 1 0 0 0 1 1 2 28 0 1 1 0 0 2!
0 1 1 0 0 32 1 2 0 0 6 0 1 2 0 0 0 0 1 2 0 0 0 6 1 1 1 29 0 1 2 0 19 23 0 1 2 3 
19 0 0 1 2 3 19 0 0 1 2 1 19 0 0 1 2 3 19 0 0 1 2 3 19 0 0 1 1 0 7 0 8)))))) 
(QUOTE |lookupComplete|))) 
+(DEFUN |PRIMARR;fill!;$S$;9| (|x| |s| |$|)
+ (PROG (|i| #1=#:G82338)
+  (RETURN
+   (SEQ
+    (SEQ
+     (LETT |i| 0 |PRIMARR;fill!;$S$;9|)
+     (LETT #1# (QVMAXINDEX |x|) |PRIMARR;fill!;$S$;9|)
+     G190
+     (COND ((QSGREATERP |i| #1#) (GO G191)))
+     (SEQ (EXIT (SETELT |x| |i| |s|)))
+     (LETT |i| (QSADD1 |i|) |PRIMARR;fill!;$S$;9|)
+     (GO G190)
+     G191
+    (EXIT NIL))
+   (EXIT |x|)))))
+
+(DEFUN |PrimitiveArray| (#1=#:G82348)
+ (PROG NIL
+  (RETURN 
+   (PROG (#2=#:G82349)
+    (RETURN
+     (COND
+      ((LETT #2# 
+        (|lassocShiftWithFunction|
+          (LIST (|devaluate| #1#))
+          (HGET |$ConstructorCache| (QUOTE |PrimitiveArray|))
+          (QUOTE |domainEqualList|))
+         |PrimitiveArray|)
+        (|CDRwithIncrement| #2#))
+      ((QUOTE T)
+        (|UNWIND-PROTECT|
+         (PROG1
+          (|PrimitiveArray;| #1#)
+          (LETT #2# T |PrimitiveArray|))
+         (COND
+          ((NOT #2#)
+            (HREM |$ConstructorCache| (QUOTE |PrimitiveArray|)))))))))))) 
+
+(DEFUN |PrimitiveArray;| (|#1|)
+ (PROG (|DV$1| |dv$| |$| #1=#:G82347 |pv$|)
+  (RETURN
+   (PROGN 
+    (LETT |DV$1| (|devaluate| |#1|) . #2=(|PrimitiveArray|))
+    (LETT |dv$| (LIST (QUOTE |PrimitiveArray|) |DV$1|) . #2#)
+    (LETT |$| (GETREFV 35) . #2#)
+    (QSETREFV |$| 0 |dv$|)
+    (QSETREFV |$| 3
+     (LETT |pv$|
+      (|buildPredVector| 0 0
+       (LIST 
+        (|HasCategory| |#1| (QUOTE (|SetCategory|)))
+        (|HasCategory| |#1| (QUOTE (|ConvertibleTo| (|InputForm|))))
+        (LETT #1# (|HasCategory| |#1| (QUOTE (|OrderedSet|))) . #2#)
+        (OR #1# (|HasCategory| |#1| (QUOTE (|SetCategory|))))
+        (|HasCategory| (|Integer|) (QUOTE (|OrderedSet|)))
+        (AND (|HasCategory| |#1| (LIST (QUOTE |Evalable|) (|devaluate| |#1|)))
+             (|HasCategory| |#1| (QUOTE (|SetCategory|))))
+        (OR 
+         (AND 
+          (|HasCategory| |#1| (LIST (QUOTE |Evalable|) (|devaluate| |#1|)))
+          #1#)
+         (AND
+          (|HasCategory| |#1| (LIST (QUOTE |Evalable|) (|devaluate| |#1|)))
+          (|HasCategory| |#1| (QUOTE (|SetCategory|)))))))
+      . #2#))
+    (|haddProp| |$ConstructorCache|
+     (QUOTE |PrimitiveArray|) (LIST |DV$1|) (CONS 1 |$|))
+    (|stuffDomainSlots| |$|)
+    (QSETREFV |$| 6 |#1|)
+    |$|)))) 
+
+(MAKEPROP (QUOTE |PrimitiveArray|) (QUOTE |infovec|)
+ (LIST 
+  (QUOTE
+   #(NIL NIL NIL NIL NIL NIL (|local| |#1|) (|NonNegativeInteger|)
+     |PRIMARR;#;$Nni;1| (|Integer|) |PRIMARR;minIndex;$I;2|
+     |PRIMARR;empty;$;3| |PRIMARR;fill!;$S$;9| |PRIMARR;new;NniS$;4|
+     |PRIMARR;qelt;$IS;5| |PRIMARR;elt;$IS;6| |PRIMARR;qsetelt!;$I2S;7|
+     |PRIMARR;setelt;$I2S;8| (|Mapping| 6 6 6) (|Boolean|) (|List| 6)
+     (|Equation| 6) (|List| 21) (|Mapping| 19 6) (|Mapping| 19 6 6)
+     (|UniversalSegment| 9) (|Void|) (|Mapping| 6 6) (|InputForm|)
+     (|OutputForm|) (|String|) (|SingleInteger|) (|List| |$|)
+     (|Union| 6 (QUOTE "failed")) (|List| 9)))
+  (QUOTE
+   #(|~=| 0 |swap!| 6 |sorted?| 13 |sort!| 24 |sort| 35 |size?| 46 |setelt|
+     52 |select| 66 |sample| 72 |reverse!| 76 |reverse| 81 |removeDuplicates|
+     86 |remove| 91 |reduce| 103 |qsetelt!| 124 |qelt| 131 |position| 137
+     |parts| 156 |new| 161 |more?| 167 |minIndex| 173 |min| 178 |merge| 184
+     |members| 197 |member?| 202 |maxIndex| 208 |max| 213 |map!| 219 |map|
+     225 |less?| 238 |latex| 244 |insert| 249 |indices| 263 |index?| 268
+     |hash| 274 |first| 279 |find| 284 |fill!| 290 |every?| 296 |eval| 302
+     |eq?| 328 |entry?| 334 |entries| 340 |empty?| 345 |empty| 350 |elt| 354
+     |delete| 373 |count| 385 |copyInto!| 397 |copy| 404 |convert| 409
+     |construct| 414 |concat| 419 |coerce| 442 |any?| 447 |>=| 453 |>| 459
+     |=| 465 |<=| 471 |<| 477 |#| 483))
+ (QUOTE ((|shallowlyMutable| . 0) (|finiteAggregate| . 0)))
+ (CONS 
+   (|makeByteWordVec2| 7 (QUOTE (0 0 0 0 0 0 3 0 0 7 4 0 0 7 1 2 4)))
+   (CONS
+    (QUOTE #(|OneDimensionalArrayAggregate&| |FiniteLinearAggregate&|
+     |LinearAggregate&| |IndexedAggregate&| |Collection&|
+     |HomogeneousAggregate&| |OrderedSet&| |Aggregate&| |EltableAggregate&|
+     |Evalable&| |SetCategory&| NIL NIL |InnerEvalable&| NIL NIL |BasicType&|))
+    (CONS
+     (QUOTE
+      #((|OneDimensionalArrayAggregate| 6) (|FiniteLinearAggregate| 6)
+        (|LinearAggregate| 6) (|IndexedAggregate| 9 6) (|Collection| 6)
+        (|HomogeneousAggregate| 6) (|OrderedSet|) (|Aggregate|)
+        (|EltableAggregate| 9 6) (|Evalable| 6) (|SetCategory|) (|Type|)
+        (|Eltable| 9 6) (|InnerEvalable| 6 6) (|CoercibleTo| 29)
+        (|ConvertibleTo| 28) (|BasicType|)))
+     (|makeByteWordVec2| 34 
+      (QUOTE
+       (2 1 19 0 0 1 3 0 26 0 9 9 1 1 3 19 0 1 2 0 19 24 0 1 1 3 0 0 1 2 0 0
+        24 0 1 1 3 0 0 1 2 0 0 24 0 1 2 0 19 0 7 1 3 0 6 0 25 6 1 3 0 6 0 9
+        6 17 2 0 0 23 0 1 0 0 0 1 1 0 0 0 1 1 0 0 0 1 1 1 0 0 1 2 1 0 6 0 1
+        2 0 0 23 0 1 4 1 6 18 0 6 6 1 3 0 6 18 0 6 1 2 0 6 18 0 1 3 0 6 0 9
+        6 16 2 0 6 0 9 14 2 1 9 6 0 1 3 1 9 6 0 9 1 2 0 9 23 0 1 1 0 20 0 1
+        2 0 0 7 6 13 2 0 19 0 7 1 1 5 9 0 10 2 3 0 0 0 1 2 3 0 0 0 1 3 0 0
+        24 0 0 1 1 0 20 0 1 2 1 19 6 0 1 1 5 9 0 1 2 3 0 0 0 1 2 0 0 27 0 1
+        3 0 0 18 0 0 1 2 0 0 27 0 1 2 0 19 0 7 1 1 1 30 0 1 3 0 0 0 0 9 1 3
+        0 0 6 0 9 1 1 0 34 0 1 2 0 19 9 0 1 1 1 31 0 1 1 5 6 0 1 2 0 33 23
+        0 1 2 0 0 0 6 12 2 0 19 23 0 1 3 6 0 0 20 20 1 2 6 0 0 21 1 3 6 0 0
+        6 6 1 2 6 0 0 22 1 2 0 19 0 0 1 2 1 19 6 0 1 1 0 20 0 1 1 0 19 0 1
+        0 0 0 11 2 0 0 0 25 1 2 0 6 0 9 15 3 0 6 0 9 6 1 2 0 0 0 9 1 2 0 0
+        0 25 1 2 1 7 6 0 1 2 0 7 23 0 1 3 0 0 0 0 9 1 1 0 0 0 1 1 2 28 0 1
+        1 0 0 20 1 1 0 0 32 1 2 0 0 6 0 1 2 0 0 0 0 1 2 0 0 0 6 1 1 1 29 0
+        1 2 0 19 23 0 1 2 3 19 0 0 1 2 3 19 0 0 1 2 1 19 0 0 1 2 3 19 0 0 1
+        2 3 19 0 0 1 1 0 7 0 8))))))
+ (QUOTE |lookupComplete|))) 
 @
 \section{package PRIMARR2 PrimitiveArrayFunctions2}
 <<package PRIMARR2 PrimitiveArrayFunctions2>>=
@@ -98,26 +224,37 @@ PrimitiveArrayFunctions2(A, B): Exports == Implementation 
where
   VB ==> PrimitiveArray B
   O2 ==> FiniteLinearAggregateFunctions2(A, VA, B, VB)
   Exports ==> with
-    scan   : ((A, B) -> B, VA, B) -> VB
-       ++ scan(f,a,r) successively applies
-       ++ \spad{reduce(f,x,r)} to more and more leading sub-arrays
-       ++ x of primitive array \spad{a}.
-       ++ More precisely, if \spad{a} is \spad{[a1,a2,...]}, then
-       ++ \spad{scan(f,a,r)} returns
-       ++ \spad{[reduce(f,[a1],r),reduce(f,[a1,a2],r),...]}.
-    reduce : ((A, B) -> B, VA, B) -> B
-       ++ reduce(f,a,r) applies function f to each
-       ++ successive element of the
-       ++ primitive array \spad{a} and an accumulant initialized to r.
-       ++ For example,
-       ++ \spad{reduce(_+$Integer,[1,2,3],0)}
-       ++ does \spad{3+(2+(1+0))}. Note: third argument r
-       ++ may be regarded as the
-       ++ identity element for the function f.
-    map    : (A -> B, VA) -> VB
-       ++ map(f,a) applies function f to each member of primitive array
-       ++ \spad{a} resulting in a new primitive array over a
-       ++ possibly different underlying domain.
+   scan : ((A, B) -> B, VA, B) -> VB
+    ++ scan(f,a,r) successively applies
+    ++ \spad{reduce(f,x,r)} to more and more leading sub-arrays
+    ++ x of primitive array \spad{a}.
+    ++ More precisely, if \spad{a} is \spad{[a1,a2,...]}, then
+    ++ \spad{scan(f,a,r)} returns
+    ++ \spad{[reduce(f,[a1],r),reduce(f,[a1,a2],r),...]}.
+    ++
+    ++E T1:=PrimitiveArrayFunctions2(Integer,Integer)
+    ++E adder(a:Integer,b:Integer):Integer == a+b
+    ++E scan(adder,[i for i in 1..10],0)$T1
+   
+   reduce : ((A, B) -> B, VA, B) -> B
+    ++ reduce(f,a,r) applies function f to each
+    ++ successive element of the
+    ++ primitive array \spad{a} and an accumulant initialized to r.
+    ++ For example, \spad{reduce(_+$Integer,[1,2,3],0)}
+    ++ does \spad{3+(2+(1+0))}. Note: third argument r
+    ++ may be regarded as the identity element for the function f.
+    ++
+    ++E T1:=PrimitiveArrayFunctions2(Integer,Integer)
+    ++E adder(a:Integer,b:Integer):Integer == a+b
+    ++E reduce(adder,[i for i in 1..10],0)$T1
+
+   map : (A -> B, VA) -> VB
+    ++ map(f,a) applies function f to each member of primitive array
+    ++ \spad{a} resulting in a new primitive array over a
+    ++ possibly different underlying domain.
+    ++
+    ++E T1:=PrimitiveArrayFunctions2(Integer,Integer)
+    ++E map(x+->x+2,[i for i in 1..10])$T1
 
   Implementation ==> add
     map(f, v)       == map(f, v)$O2
@@ -132,12 +269,26 @@ PrimitiveArrayFunctions2(A, B): Exports == Implementation 
where
 ++ of comma-delimited sequences of values.
 Tuple(S:Type): CoercibleTo(PrimitiveArray S) with
   coerce: PrimitiveArray S -> %
-       ++ coerce(a) makes a tuple from primitive array a
+   ++ coerce(a) makes a tuple from primitive array a
+   ++
+   ++E t1:PrimitiveArray(Integer):= [i for i in 1..10]
+   ++E t2:=coerce(t1)$Tuple(Integer)
+
   select: (%, NonNegativeInteger) -> S
-       ++ select(x,n) returns the n-th element of tuple x.
-       ++ tuples are 0-based
+   ++ select(x,n) returns the n-th element of tuple x.
+   ++ tuples are 0-based
+   ++
+   ++E t1:PrimitiveArray(Integer):= [i for i in 1..10]
+   ++E t2:=coerce(t1)$Tuple(Integer)
+   ++E select(t2,3)
+
   length: % -> NonNegativeInteger
-       ++ length(x) returns the number of elements in tuple x
+   ++ length(x) returns the number of elements in tuple x
+   ++
+   ++E t1:PrimitiveArray(Integer):= [i for i in 1..10]
+   ++E t2:=coerce(t1)$Tuple(Integer)
+   ++E length(t2)
+
   if S has SetCategory then SetCategory
  == add
   Rep := Record(len : NonNegativeInteger, elts : PrimitiveArray S)
@@ -182,15 +333,36 @@ IndexedFlexibleArray(S:Type, mn: Integer): Exports == 
Implementation where
   N ==> NonNegativeInteger
   U ==> UniversalSegment Integer
   Exports ==
-    Join(OneDimensionalArrayAggregate S,ExtensibleLinearAggregate S) with
-      flexibleArray : List S -> %
-       ++ flexibleArray(l) creates a flexible array from the list of elements l
-      physicalLength : % -> NonNegativeInteger
-       ++ physicalLength(x) returns the number of elements x can accomodate 
before growing
-      physicalLength_!: (%, I) -> %
-       ++ physicalLength!(x,n) changes the physical length of x to be n and 
returns the new array.
-      shrinkable: Boolean -> Boolean
-       ++ shrinkable(b) sets the shrinkable attribute of flexible arrays to b 
and returns the previous value
+   Join(OneDimensionalArrayAggregate S,ExtensibleLinearAggregate S) with
+    flexibleArray : List S -> %
+     ++ flexibleArray(l) creates a flexible array from the list of elements l
+     ++
+     ++E T1:=IndexedFlexibleArray(Integer,20)
+     ++E flexibleArray([i for i in 1..10])$T1
+
+    physicalLength : % -> NonNegativeInteger
+     ++ physicalLength(x) returns the number of elements x can 
+     ++ accomodate before growing
+     ++
+     ++E T1:=IndexedFlexibleArray(Integer,20)
+     ++E t2:=flexibleArray([i for i in 1..10])$T1
+     ++E physicalLength t2
+
+    physicalLength_!: (%, I) -> %
+     ++ physicalLength!(x,n) changes the physical length of x to be n and
+     ++ returns the new array.
+     ++
+     ++E T1:=IndexedFlexibleArray(Integer,20)
+     ++E t2:=flexibleArray([i for i in 1..10])$T1
+     ++E physicalLength!(t2,15)
+
+    shrinkable: Boolean -> Boolean
+     ++ shrinkable(b) sets the shrinkable attribute of flexible arrays to b
+     ++ and returns the previous value
+     ++
+     ++E T1:=IndexedFlexibleArray(Integer,20)
+     ++E shrinkable(false)$T1
+
   Implementation == add
     Rep := Record(physLen:I, logLen:I, f:A)
     shrinkable? : Boolean := true
@@ -256,7 +428,8 @@ IndexedFlexibleArray(S:Type, mn: Integer): Exports == 
Implementation where
        negative?(n := r.logLen) => error "internal bug in flexible array"
        2*n+2 > r.physLen => r
        not shrinkable? => r
-       if n < r.logLen then error "cannot shrink flexible array to indicated 
size"
+       if n < r.logLen 
+         then error "cannot shrink flexible array to indicated size"
        n = 0 => empty()
        r.physLen := n
        y := newa(n::N, a := r.f)
@@ -911,10 +1084,16 @@ o $AXIOM/doc/src/algebra/array1.spad.dvi
 OneDimensionalArray(S:Type): Exports == Implementation where
   ARRAYMININDEX ==> 1       -- if you want to change this, be my guest
   Exports == OneDimensionalArrayAggregate S with
-    oneDimensionalArray: List S -> %
-       ++ oneDimensionalArray(l) creates an array from a list of elements l
-    oneDimensionalArray: (NonNegativeInteger, S) -> %
-       ++ oneDimensionalArray(n,s) creates an array from n copies of element s
+   oneDimensionalArray: List S -> %
+    ++ oneDimensionalArray(l) creates an array from a list of elements l
+    ++
+    ++E oneDimensionalArray [i**2 for i in 1..10]
+  
+   oneDimensionalArray: (NonNegativeInteger, S) -> %
+    ++ oneDimensionalArray(n,s) creates an array from n copies of element s
+    ++
+    ++E oneDimensionalArray(10,0.0)
+
   Implementation == IndexedOneDimensionalArray(S, ARRAYMININDEX) add
     oneDimensionalArray(u) ==
       n := #u
@@ -938,26 +1117,37 @@ OneDimensionalArrayFunctions2(A, B): Exports == 
Implementation where
   O2 ==> FiniteLinearAggregateFunctions2(A, VA, B, VB)
 
   Exports ==> with
-    scan   : ((A, B) -> B, VA, B) -> VB
-       ++ scan(f,a,r) successively applies
-       ++ \spad{reduce(f,x,r)} to more and more leading sub-arrays
-       ++ x of one-dimensional array \spad{a}.
-       ++ More precisely, if \spad{a} is \spad{[a1,a2,...]}, then
-       ++ \spad{scan(f,a,r)} returns
-       ++ \spad{[reduce(f,[a1],r),reduce(f,[a1,a2],r),...]}.
-    reduce : ((A, B) -> B, VA, B) -> B
-       ++ reduce(f,a,r) applies function f to each
-       ++ successive element of the
-       ++ one-dimensional array \spad{a} and an accumulant initialized to r.
-       ++ For example,
-       ++ \spad{reduce(_+$Integer,[1,2,3],0)}
-       ++ does \spad{3+(2+(1+0))}. Note: third argument r
-       ++ may be regarded as the
-       ++ identity element for the function f.
-    map    : (A -> B, VA) -> VB
-       ++ map(f,a) applies function f to each member of one-dimensional array
-       ++ \spad{a} resulting in a new one-dimensional array over a
-       ++ possibly different underlying domain.
+   scan   : ((A, B) -> B, VA, B) -> VB
+    ++ scan(f,a,r) successively applies
+    ++ \spad{reduce(f,x,r)} to more and more leading sub-arrays
+    ++ x of one-dimensional array \spad{a}.
+    ++ More precisely, if \spad{a} is \spad{[a1,a2,...]}, then
+    ++ \spad{scan(f,a,r)} returns
+    ++ \spad{[reduce(f,[a1],r),reduce(f,[a1,a2],r),...]}.
+    ++
+    ++E T1:=OneDimensionalArrayFunctions2(Integer,Integer)
+    ++E adder(a:Integer,b:Integer):Integer == a+b
+    ++E scan(adder,[i for i in 1..10],0)$T1
+
+   reduce : ((A, B) -> B, VA, B) -> B
+    ++ reduce(f,a,r) applies function f to each
+    ++ successive element of the
+    ++ one-dimensional array \spad{a} and an accumulant initialized to r.
+    ++ For example, \spad{reduce(_+$Integer,[1,2,3],0)}
+    ++ does \spad{3+(2+(1+0))}. Note: third argument r
+    ++ may be regarded as the identity element for the function f.
+    ++
+    ++E T1:=OneDimensionalArrayFunctions2(Integer,Integer)
+    ++E adder(a:Integer,b:Integer):Integer == a+b
+    ++E reduce(adder,[i for i in 1..10],0)$T1
+
+   map : (A -> B, VA) -> VB
+    ++ map(f,a) applies function f to each member of one-dimensional array
+    ++ \spad{a} resulting in a new one-dimensional array over a
+    ++ possibly different underlying domain.
+    ++
+    ++E T1:=OneDimensionalArrayFunctions2(Integer,Integer)
+    ++E map(x+->x+2,[i for i in 1..10])$T1
 
   Implementation ==> add
     map(f, v)       == map(f, v)$O2
diff --git a/src/algebra/fr.spad.pamphlet b/src/algebra/fr.spad.pamphlet
index ad4853a..8c4c8f0 100644
--- a/src/algebra/fr.spad.pamphlet
+++ b/src/algebra/fr.spad.pamphlet
@@ -669,97 +669,151 @@ Factored(R: IntegralDomain): Exports == Implementation 
where
 
   Exports ==> Join(IntegralDomain, DifferentialExtension R, Algebra R,
                    FullyEvalableOver R, FullyRetractableTo R) with
-    expand: % -> R
-      ++ expand(f) multiplies the unit and factors together, yielding an
-      ++ "unfactored" object. Note: this is purposely not called 
\spadfun{coerce} which would
-      ++ cause the interpreter to do this automatically.
-
-    exponent:  % -> Integer
-      ++ exponent(u) returns the exponent of the first factor of
-      ++ \spadvar{u}, or 0 if the factored form consists solely of a unit.
-
-    makeFR  : (R, List FF) -> %
-      ++ makeFR(unit,listOfFactors) creates a factored object (for
-      ++ use by factoring code).
-
-    factorList : % -> List FF
-      ++ factorList(u) returns the list of factors with flags (for
-      ++ use by factoring code).
-
-    nilFactor: (R, Integer) -> %
-      ++ nilFactor(base,exponent) creates a factored object with
-      ++ a single factor with no information about the kind of
-      ++ base (flag = "nil").
-
-    factors: % -> List Record(factor:R, exponent:Integer)
-      ++ factors(u) returns a list of the factors in a form suitable
-      ++ for iteration. That is, it returns a list where each element
-      ++ is a record containing a base and exponent.  The original
-      ++ object is the product of all the factors and the unit (which
-      ++ can be extracted by \axiom{unit(u)}).
-
-    irreducibleFactor: (R, Integer) -> %
-      ++ irreducibleFactor(base,exponent) creates a factored object with
-      ++ a single factor whose base is asserted to be irreducible
-      ++ (flag = "irred").
-
-    nthExponent: (%, Integer) -> Integer
-      ++ nthExponent(u,n) returns the exponent of the nth factor of
-      ++ \spadvar{u}.  If \spadvar{n} is not a valid index for a factor
-      ++ (for example, less than 1 or too big), 0 is returned.
-
-    nthFactor:  (%,Integer) -> R
-      ++ nthFactor(u,n) returns the base of the nth factor of
-      ++ \spadvar{u}.  If \spadvar{n} is not a valid index for a factor
-      ++ (for example, less than 1 or too big), 1 is returned.  If
-      ++ \spadvar{u} consists only of a unit, the unit is returned.
-
-    nthFlag:    (%,Integer) -> fUnion
-      ++ nthFlag(u,n) returns the information flag of the nth factor of
-      ++ \spadvar{u}.  If \spadvar{n} is not a valid index for a factor
-      ++ (for example, less than 1 or too big), "nil" is returned.
-
-    numberOfFactors : %  -> NonNegativeInteger
-      ++ numberOfFactors(u) returns the number of factors in \spadvar{u}.
-
-    primeFactor:   (R,Integer) -> %
-      ++ primeFactor(base,exponent) creates a factored object with
-      ++ a single factor whose base is asserted to be prime
-      ++ (flag = "prime").
-
-    sqfrFactor:   (R,Integer) -> %
-      ++ sqfrFactor(base,exponent) creates a factored object with
-      ++ a single factor whose base is asserted to be square-free
-      ++ (flag = "sqfr").
-
-    flagFactor: (R,Integer, fUnion) -> %
-      ++ flagFactor(base,exponent,flag) creates a factored object with
-      ++ a single factor whose base is asserted to be properly
-      ++ described by the information flag.
-
-    unit:    % -> R
-      ++ unit(u) extracts the unit part of the factorization.
-
-    unitNormalize: % -> %
-      ++ unitNormalize(u) normalizes the unit part of the factorization.
-      ++ For example, when working with factored integers, this operation will
-      ++ ensure that the bases are all positive integers.
-
-    map:     (R -> R, %) -> %
-      ++ map(fn,u) maps the function \userfun{fn} across the factors of
-      ++ \spadvar{u} and creates a new factored object. Note: this clears
-      ++ the information flags (sets them to "nil") because the effect of
-      ++ \userfun{fn} is clearly not known in general.
+   expand: % -> R
+    ++ expand(f) multiplies the unit and factors together, yielding an
+    ++ "unfactored" object. Note: this is purposely not called 
+    ++ \spadfun{coerce} which would cause the interpreter to do this 
+    ++ automatically.
+    ++
+    ++E f:=nilFactor(y-x,3)
+    ++E expand(f)
+
+   exponent:  % -> Integer
+    ++ exponent(u) returns the exponent of the first factor of
+    ++ \spadvar{u}, or 0 if the factored form consists solely of a unit.
+    ++
+    ++E f:=nilFactor(y-x,3)
+    ++E exponent(f)
+
+   makeFR  : (R, List FF) -> %
+    ++ makeFR(unit,listOfFactors) creates a factored object (for
+    ++ use by factoring code).
+    ++
+    ++E f:=nilFactor(x-y,3)
+    ++E g:=factorList f
+    ++E makeFR(z,g)
+
+   factorList : % -> List FF
+    ++ factorList(u) returns the list of factors with flags (for
+    ++ use by factoring code).
+    ++
+    ++E f:=nilFactor(x-y,3)
+    ++E factorList f
+
+   nilFactor: (R, Integer) -> %
+    ++ nilFactor(base,exponent) creates a factored object with
+    ++ a single factor with no information about the kind of
+    ++ base (flag = "nil").
+    ++
+    ++E nilFactor(24,2)
+    ++E nilFactor(x-y,3)
+
+   factors: % -> List Record(factor:R, exponent:Integer)
+    ++ factors(u) returns a list of the factors in a form suitable
+    ++ for iteration. That is, it returns a list where each element
+    ++ is a record containing a base and exponent.  The original
+    ++ object is the product of all the factors and the unit (which
+    ++ can be extracted by \axiom{unit(u)}).
+    ++
+    ++E f:=x*y^3-3*x^2*y^2+3*x^3*y-x^4
+    ++E factors f
+    ++E g:=makeFR(z,factorList f)
+    ++E factors g
+
+   irreducibleFactor: (R, Integer) -> %
+    ++ irreducibleFactor(base,exponent) creates a factored object with
+    ++ a single factor whose base is asserted to be irreducible
+    ++ (flag = "irred").
+    ++
+    ++E a:=irreducibleFactor(3,1)
+    ++E nthFlag(a,1)
+
+   nthExponent: (%, Integer) -> Integer
+    ++ nthExponent(u,n) returns the exponent of the nth factor of
+    ++ \spadvar{u}.  If \spadvar{n} is not a valid index for a factor
+    ++ (for example, less than 1 or too big), 0 is returned.
+    ++
+    ++E a:=factor 9720000
+    ++E nthExponent(a,2)
+
+   nthFactor:  (%,Integer) -> R
+    ++ nthFactor(u,n) returns the base of the nth factor of
+    ++ \spadvar{u}.  If \spadvar{n} is not a valid index for a factor
+    ++ (for example, less than 1 or too big), 1 is returned.  If
+    ++ \spadvar{u} consists only of a unit, the unit is returned.
+    ++
+    ++E a:=factor 9720000
+    ++E nthFactor(a,2)
+
+   nthFlag:    (%,Integer) -> fUnion
+    ++ nthFlag(u,n) returns the information flag of the nth factor of
+    ++ \spadvar{u}.  If \spadvar{n} is not a valid index for a factor
+    ++ (for example, less than 1 or too big), "nil" is returned.
+    ++
+    ++E a:=factor 9720000
+    ++E nthFlag(a,2)
+
+   numberOfFactors : %  -> NonNegativeInteger
+    ++ numberOfFactors(u) returns the number of factors in \spadvar{u}.
+    ++
+    ++E a:=factor 9720000
+    ++E numberOfFactors a
+
+   primeFactor:   (R,Integer) -> %
+    ++ primeFactor(base,exponent) creates a factored object with
+    ++ a single factor whose base is asserted to be prime
+    ++ (flag = "prime").
+    ++
+    ++E a:=primeFactor(3,4)
+    ++E nthFlag(a,1)
+
+   sqfrFactor:   (R,Integer) -> %
+    ++ sqfrFactor(base,exponent) creates a factored object with
+    ++ a single factor whose base is asserted to be square-free
+    ++ (flag = "sqfr").
+    ++
+    ++E a:=sqfrFactor(3,5)
+    ++E nthFlag(a,1)
+
+   flagFactor: (R,Integer, fUnion) -> %
+    ++ flagFactor(base,exponent,flag) creates a factored object with
+    ++ a single factor whose base is asserted to be properly
+    ++ described by the information flag.
+
+   unit:    % -> R
+    ++ unit(u) extracts the unit part of the factorization.
+    ++
+    ++E f:=x*y^3-3*x^2*y^2+3*x^3*y-x^4
+    ++E unit f
+    ++E g:=makeFR(z,factorList f)
+    ++E unit g
+
+   unitNormalize: % -> %
+    ++ unitNormalize(u) normalizes the unit part of the factorization.
+    ++ For example, when working with factored integers, this operation will
+    ++ ensure that the bases are all positive integers.
+
+   map:     (R -> R, %) -> %
+    ++ map(fn,u) maps the function \userfun{fn} across the factors of
+    ++ \spadvar{u} and creates a new factored object. Note: this clears
+    ++ the information flags (sets them to "nil") because the effect of
+    ++ \userfun{fn} is clearly not known in general.
+    ++
+    ++E m(a:Factored Polynomial Integer):Factored Polynomial Integer == a^2
+    ++E f:=x*y^3-3*x^2*y^2+3*x^3*y-x^4
+    ++E map(m,f)
+    ++E g:=makeFR(z,factorList f)
+    ++E map(m,g)
 
     -- the following operations are conditional on R
 
-    if R has GcdDomain then GcdDomain
-    if R has RealConstant then RealConstant
-    if R has UniqueFactorizationDomain then UniqueFactorizationDomain
+   if R has GcdDomain then GcdDomain
+   if R has RealConstant then RealConstant
+   if R has UniqueFactorizationDomain then UniqueFactorizationDomain
 
-    if R has ConvertibleTo InputForm then ConvertibleTo InputForm
+   if R has ConvertibleTo InputForm then ConvertibleTo InputForm
 
-    if R has IntegerNumberSystem then
+   if R has IntegerNumberSystem then
       rational?    : % -> Boolean
         ++ rational?(u) tests if \spadvar{u} is actually a
         ++ rational number (see \spadtype{Fraction Integer}).
@@ -771,9 +825,9 @@ Factored(R: IntegralDomain): Exports == Implementation where
         ++ rationalIfCan(u) returns a rational number if u
         ++ really is one, and "failed" otherwise.
 
-    if R has Eltable(%, %) then Eltable(%, %)
-    if R has Evalable(%) then Evalable(%)
-    if R has InnerEvalable(Symbol, %) then InnerEvalable(Symbol, %)
+   if R has Eltable(%, %) then Eltable(%, %)
+   if R has Evalable(%) then Evalable(%)
+   if R has InnerEvalable(Symbol, %) then InnerEvalable(Symbol, %)
 
   Implementation ==> add
 




reply via email to

[Prev in Thread] Current Thread [Next in Thread]