~ubuntu-branches/debian/squeeze/maxima/squeeze

« back to all changes in this revision

Viewing changes to demo/array.dem

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2006-10-18 14:52:42 UTC
  • mto: (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 4.
  • Revision ID: james.westby@ubuntu.com-20061018145242-vzyrm5hmxr8kiosf
ImportĀ upstreamĀ versionĀ 5.10.0

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/* ======================================================================== */
2
2
/*  file: array.dem  */
3
 
/*  Indices problems */
4
 
 
5
 
SUBSCRMAP:TRUE$
6
 
/*
7
 
THIS BATCH FILE ILLUSTRATES VARIOUS NEW ARRAY CAPABILITIES AVAILABLE
8
 
 
9
 
WHICH ARE COMPLETELY COMPATIBLE WITH THE EXISTING SCHEME.
10
 
 
11
 
MAPPING IN THIS CONTEXT MEANS DISTRIBUTE THE NAME OVER THE STRUCTURE 
12
 
 
13
 
INDICATED BY THE SUBSCRIPTS.
14
 
 
15
 
INCLUDED ARE IMPLIED MAPPING USING LISTS AS SUBSCRIPTS,
16
 
 
17
 
GENERALIZED ELEMENT EXTRACTION FROM LIST OR MATRIX STRUCTURES,
18
 
 
19
 
IMPLIED ASSIGNMENT MAPPING, AND RECURSIVE LIST STRUCTURES.  
20
 
 
21
 
COMPATIBILITY WITH HASHED ARRAYS AND DECLARED ARRAYS IS SHOWN.
22
 
 
23
 
FIRST CONSIDER USING LIST STRUCTURES AS SUBSCRIPTS. A,B, AND C
24
 
 
25
 
BELOW CAN BE ARRAYS, HASHED ARRAYS, LIST STRUCTURES, MATRICES OR 
26
 
 
27
 
UNDEFINED.
28
 
 
29
 
*/
30
 
 
31
 
 
32
 
(A[1]:FIRST,A[2]:SECOND);
33
 
A[[1,2]],EVAL;
34
 
L:[3,2,1];
35
 
L[3];
36
 
L[1];
37
 
''L[1];
38
 
L[1],EVAL;
39
 
MIDDLE&&MAT:MATRIX([Q,V],[W,U]);
40
 
MAT[1];
41
 
MAT[[1,2],[1,2]],EVAL;
42
 
MAT[[1,2]],EVAL;
43
 
 
44
 
/*
45
 
ASSIGNMENT MAPS CAN BE CARRIED OUT WITH "::" OR (''FOO):
46
 
 
47
 
*/
48
 
D[ [1,2] ]::99;
49
 
D[1];
50
 
(''MAT):0;
51
 
Q;
52
 
MAT;
53
 
LL[''L]::L;
54
 
LL[1];
55
 
 
56
 
 
57
 
 
58
 
/*
59
 
RECURSIVE LIST STRUCTURES:
60
 
 
61
 
*/
62
 
X:[X,Y];
63
 
Y:[Y,'X];
64
 
H['X,'Y];
65
 
%,EVAL;
66
 
%,EVAL;
67
 
%,EVAL;
68
 
 
69
 
/*
70
 
MAPPING A FUNCTION ON A LIST STRUCTURE
71
 
*/
72
 
FULLMAPL(FOO,[[A,B],[C,D]]);
73
 
FULLMAPL(FUNC,'[AA+BB,'[AA,BB],[AA,BB],[3,4]]);
74
 
DSL:'[AS+BS,[DS,ES],'[GS,HS],144];
75
 
F(X):=X**2;
76
 
FUNC:F$
77
 
FULLMAPL(FUNC,DSL);
78
 
 
79
 
 
80
 
 
81
 
/*
82
 
TO COME: SHAPING, GENERAL REDUCTION, GENERAL CONTRACTION OR EXPANSION
83
 
 
84
 
(INNER AND OUTER PRODUCTS), ARITHMETIC, THE WORLD, THE UNIVERSE
85
 
 
86
 
*/
87
 
FOOBAR;
 
3
/*  indices problems */
 
4
 
 
5
subscrmap:true$
 
6
/*
 
7
this batch file illustrates various new array capabilities available
 
8
 
 
9
which are completely compatible with the existing scheme.
 
10
 
 
11
mapping in this context means distribute the name over the structure 
 
12
 
 
13
indicated by the subscripts.
 
14
 
 
15
included are implied mapping using lists as subscripts,
 
16
 
 
17
generalized element extraction from list or matrix structures,
 
18
 
 
19
implied assignment mapping, and recursive list structures.  
 
20
 
 
21
compatibility with hashed arrays and declared arrays is shown.
 
22
 
 
23
first consider using list structures as subscripts. a,b, and c
 
24
 
 
25
below can be arrays, hashed arrays, list structures, matrices or 
 
26
 
 
27
undefined.
 
28
 
 
29
*/
 
30
 
 
31
 
 
32
(a[1]:first,a[2]:second);
 
33
a[[1,2]],eval;
 
34
l:[3,2,1];
 
35
l[3];
 
36
l[1];
 
37
''l[1];
 
38
l[1],eval;
 
39
middle&&mat:matrix([q,v],[w,u]);
 
40
mat[1];
 
41
mat[[1,2],[1,2]],eval;
 
42
mat[[1,2]],eval;
 
43
 
 
44
/*
 
45
assignment maps can be carried out with "::" or (''foo):
 
46
 
 
47
*/
 
48
d[ [1,2] ]::99;
 
49
d[1];
 
50
(''mat):0;
 
51
q;
 
52
mat;
 
53
ll[''l]::l;
 
54
ll[1];
 
55
 
 
56
 
 
57
 
 
58
/*
 
59
recursive list structures:
 
60
 
 
61
*/
 
62
x:[x,y];
 
63
y:[y,'x];
 
64
h['x,'y];
 
65
%,eval;
 
66
%,eval;
 
67
%,eval;
 
68
 
 
69
/*
 
70
mapping a function on a list structure
 
71
*/
 
72
fullmapl(foo,[[a,b],[c,d]]);
 
73
fullmapl(func,'[aa+bb,'[aa,bb],[aa,bb],[3,4]]);
 
74
dsl:'[as+bs,[ds,es],'[gs,hs],144];
 
75
f(x):=x**2;
 
76
func:f$
 
77
fullmapl(func,dsl);
 
78
 
 
79
 
 
80
 
 
81
/*
 
82
to come: shaping, general reduction, general contraction or expansion
 
83
 
 
84
(inner and outer products), arithmetic, the world, the universe
 
85
 
 
86
*/
 
87
foobar;