~ubuntu-branches/ubuntu/karmic/maxima/karmic

« back to all changes in this revision

Viewing changes to doc/info/Expressions.texi

  • Committer: Bazaar Package Importer
  • Author(s): Camm Maguire
  • Date: 2004-11-13 18:39:14 UTC
  • mto: (2.1.2 hoary) (3.2.1 sid) (1.1.5 upstream)
  • mto: This revision was merged to the branch mainline in revision 3.
  • Revision ID: james.westby@ubuntu.com-20041113183914-ttig0evwuatnqosl
Tags: upstream-5.9.1
ImportĀ upstreamĀ versionĀ 5.9.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
28
28
@i{comma expression}.
29
29
 
30
30
@example
31
 
(C29) x:3$
32
 
(C30) joe:(x:x+1,x:x*x);
33
 
(D30) 16
34
 
(C31) joe:(if (x >17) then 2 else 4);
35
 
(D31) 4
36
 
(C32) joe:(if (x >17) then x:2 else joe:4,joe+x);
37
 
(D32) 20
 
31
(%i29) x:3$
 
32
(%i30) joe:(x:x+1,x:x*x);
 
33
(%o30) 16
 
34
(%i31) joe:(if (x >17) then 2 else 4);
 
35
(%o31) 4
 
36
(%i32) joe:(if (x >17) then x:2 else joe:4,joe+x);
 
37
(%o32) 20
38
38
@end example
39
39
 
40
40
Even loops in maxima are expressions, although the value they
41
41
return is the not too useful @code{DONE}
42
42
 
43
43
@example
44
 
(C33) joe:(x:1,for i from 1 thru 10 do (x:x*i));
45
 
(D33) DONE
 
44
(%i33) joe:(x:1,for i from 1 thru 10 do (x:x*i));
 
45
(%o33) DONE
46
46
@end example
47
47
whereas what you really want is probably to include a third
48
48
term in the @i{comma expression} which actually gives back the value.
49
49
 
50
50
@example
51
 
(C34) joe:(x:1,for i from 1 thru 10 do (x:x*i),x);
52
 
(D34) 3628800
 
51
(%i34) joe:(x:1,for i from 1 thru 10 do (x:x*i),x);
 
52
(%o34) 3628800
53
53
@end example
54
54
 
55
55
 
90
90
mechanism is rather straightforward and should be evident from the
91
91
examples below.
92
92
@example
93
 
(C1) PREFIX("DDX")$
94
 
(C2) DDX Y$
 
93
(%i1) PREFIX("DDX")$
 
94
(%i2) DDX Y$
95
95
     /* means                   "DDX"(Y) */
96
 
(C3) INFIX("<-")$
97
 
(C4) A<-DDX Y$
 
96
(%i3) INFIX("<-")$
 
97
(%i4) A<-DDX Y$
98
98
    /* means               "<-"(A,"DDX"(Y)) */
99
99
 
100
100
@end example
131
131
@example
132
132
 
133
133
 
134
 
(C20) PREFIX("DDX",180,ANY,ANY)$
135
 
 
136
 
(C21) DDXYZ;
137
 
 
138
 
(D21)                               DDX YZ
139
 
 
140
 
(C26) "ddx"(u):=u+4;
141
 
 
142
 
(D26)                           DDX u := u + 4
143
 
(C27) ddx 8;
144
 
 
145
 
(D27)                                 12
 
134
(%i20) PREFIX("DDX",180,ANY,ANY)$
 
135
 
 
136
(%i21) DDXYZ;
 
137
 
 
138
(%o21)                              DDX YZ
 
139
 
 
140
(%i26) "ddx"(u):=u+4;
 
141
 
 
142
(%o26)                          DDX u := u + 4
 
143
(%i27) ddx 8;
 
144
 
 
145
(%o27)                                12
146
146
@end example
147
147
 
148
148
 
335
335
the whole expression with the selected subexpression displayed inside
336
336
a box.  The box is actually part of the expression.
337
337
@example
338
 
(C1) DPART(X+Y/Z**2,1,2,1);
 
338
(%i1) DPART(X+Y/Z**2,1,2,1);
339
339
                       Y
340
 
(D1)                  ---- + X
 
340
(%o1)                  ---- + X
341
341
                         2
342
342
                     *****
343
343
                     * Z *
447
447
subtraction, and division (since these operators are removed from the
448
448
expression). PART(X+Y,0) or INPART(X+Y,0) yield +, though in order to
449
449
refer to the operator it must be enclosed in "s.  For example
450
 
...IF INPART(D9,0)="+" THEN ...
 
450
...IF INPART(%o9,0)="+" THEN ...
451
451
@example
452
 
(C1)  X+Y+W*Z;
453
 
(D1)                  W Z + Y + X
454
 
(C2)  INPART(D1,3,2);
455
 
(D2)                  Z
456
 
(C3)  PART(D1,1,2);
457
 
(D3)                  Z
458
 
(C4) 'LIMIT(F(X)**G(X+1),X,0,MINUS);
 
452
(%i1)  X+Y+W*Z;
 
453
(%o1)                  W Z + Y + X
 
454
(%i2)  INPART(%o1,3,2);
 
455
(%o2)                  Z
 
456
(%i3)  PART(%o1,1,2);
 
457
(%o3)                  Z
 
458
(%i4) 'LIMIT(F(X)**G(X+1),X,0,MINUS);
459
459
                                      G(X + 1)
460
 
(D4)                      LIMIT   F(X)
 
460
(%o4)                      LIMIT   F(X)
461
461
                          X ->0-
462
 
(C5) INPART(%,1,2);
463
 
(D5)                            G(X + 1)
 
462
(%i5) INPART(%,1,2);
 
463
(%o5)                            G(X + 1)
464
464
 
465
465
 
466
466
@end example
470
470
@defun ISOLATE (exp, var)
471
471
returns exp with subexpressions which are sums and
472
472
which do not contain var replaced by intermediate expression labels
473
 
(these being atomic symbols like E1, E2, ...).  This is often useful
 
473
(these being atomic symbols like %t1, %t2, ...).  This is often useful
474
474
to avoid unnecessary expansion of subexpressions which don't contain
475
475
the variable of interest.  Since the intermediate labels are bound to
476
476
the subexpressions they can all be substituted back by evaluating the
520
520
%I, and any variables declared constant in the list it returns if they
521
521
appear in exp.  The default is to omit these.
522
522
@example
523
 
(C1) LISTOFVARS(F(X[1]+Y)/G**(2+A));
524
 
(D1)                            [X[1], Y, A, G]
 
523
(%i1) LISTOFVARS(F(X[1]+Y)/G**(2+A));
 
524
(%o1)                            [X[1], Y, A, G]
525
525
 
526
526
 
527
527
@end example
568
568
sum or an equation) by exp1.  If exp1 is not itself a sum then this
569
569
form is equivalent to MULTTHRU(exp1*exp2).
570
570
@example
571
 
(C1) X/(X-Y)**2-1/(X-Y)-F(X)/(X-Y)**3;
 
571
(%i1) X/(X-Y)**2-1/(X-Y)-F(X)/(X-Y)**3;
572
572
               1        X         F(X)
573
 
(D1)       - ----- + -------- - --------
 
573
(%o1)       - ----- + -------- - --------
574
574
             X - Y          2          3
575
575
                     (X - Y)    (X - Y)
576
 
(C2) MULTTHRU((X-Y)**3,%);
 
576
(%i2) MULTTHRU((X-Y)**3,%);
577
577
                    2
578
 
(D2)       - (X - Y)  + X (X - Y) - F(X)
579
 
(C3) RATEXPAND(D2);
 
578
(%o2)       - (X - Y)  + X (X - Y) - F(X)
 
579
(%i3) RATEXPAND(%o2);
580
580
                           2
581
 
(D3)                    - Y  + X Y - F(X)
582
 
(C4) ((A+B)**10*S**2+2*A*B*S+(A*B)**2)/(A*B*S**2);
 
581
(%o3)                    - Y  + X Y - F(X)
 
582
(%i4) ((A+B)**10*S**2+2*A*B*S+(A*B)**2)/(A*B*S**2);
583
583
                         10  2              2  2
584
584
                (B  + A )   S  + 2 A B S + A  B
585
 
(D4)            --------------------------------
 
585
(%o4)            --------------------------------
586
586
                                   2
587
587
                              A B S
588
 
(C5) MULTTHRU(%);
 
588
(%i5) MULTTHRU(%);
589
589
                                          10
590
590
                        2   A B   (B  + A)
591
 
(D5)                    - + --- + -------
 
591
(%o5)                    - + --- + -------
592
592
                        S    2      A B
593
593
                            S
594
594
(notice that (B+A)**10 is not expanded)
595
 
(C6) MULTTHRU(A.(B+C.(D+E)+F));
596
 
(D6)                A . F + A . (C . (E + D)) + A . B
 
595
(%i6) MULTTHRU(A.(B+C.(D+E)+F));
 
596
(%o6)                A . F + A . (C . (E + D)) + A . B
597
597
(compare with similar example under EXPAND)
598
598
 
599
599
 
718
718
sum), or the list (if it is a list) which don't contain var and, (2)
719
719
the factors, terms, or list which do.
720
720
@example
721
 
(C1) PARTITION(2*A*X*F(X),X);
722
 
(D1)                 [ 2 A , X F(X) ]
723
 
(C2) PARTITION(A+B,X);
724
 
(D2)                 [ A + B , 0 ]
725
 
(C3) PARTITION([A,B,F(A),C],A); 
726
 
(D3)                [[B,C],[A,F(A)]]
 
721
(%i1) PARTITION(2*A*X*F(X),X);
 
722
(%o1)                 [ 2 A , X F(X) ]
 
723
(%i2) PARTITION(A+B,X);
 
724
(%o2)                 [ A + B , 0 ]
 
725
(%i3) PARTITION([A,B,F(A),C],A); 
 
726
(%o3)                [[B,C],[A,F(A)]]
727
727
 
728
728
 
729
729
@end example
744
744
with large expressions and for automatically assigning parts of an
745
745
expression to a variable without having to use the part functions.
746
746
@example
747
 
(C1) EXP:(A+B)/2+SIN(X^2)/3-LOG(1+SQRT(X+1));
 
747
(%i1) EXP:(A+B)/2+SIN(X^2)/3-LOG(1+SQRT(X+1));
748
748
                                                 2
749
749
                                            SIN(X )   B + A
750
 
(D1)               - LOG(SQRT(X + 1) + 1) + ------- + -----
 
750
(%o1)               - LOG(SQRT(X + 1) + 1) + ------- + -----
751
751
                                               3        2
752
 
(C2) PICKAPART(%,1);
753
 
(E2)                    - LOG(SQRT(X + 1) + 1)
 
752
(%i2) PICKAPART(%,1);
 
753
(%t2)                    - LOG(SQRT(X + 1) + 1)
754
754
                                    2
755
755
                               SIN(X )
756
 
(E3)                           -------
 
756
(%t3)                           -------
757
757
                                  3
758
758
                                B + A
759
 
(E4)                            -----
 
759
(%t4)                            -----
760
760
                                  2
761
 
(D4)                         E4 + E3 + E2
 
761
(%o4)                         %t4 + %t3 + %t2
762
762
 
763
763
 
764
764
@end example
788
788
If hi is one less than lo, we have an "empty product" and PRODUCT 
789
789
returns 1 rather than erring out.  Also see DESCRIBE(PRODHACK).
790
790
@example
791
 
(C1)  PRODUCT(X+I*(I+1)/2,I,1,4);
792
 
(D1)             (X + 1) (X + 3) (X + 6) (X + 10)
 
791
(%i1)  PRODUCT(X+I*(I+1)/2,I,1,4);
 
792
(%o1)             (X + 1) (X + 3) (X + 6) (X + 10)
793
793
 
794
794
 
795
795
@end example
850
850
@defun LSUM (exp, ind, list)
851
851
performs the sum of EXP for each element IND of the LIST.
852
852
@example
853
 
(C10) lsum(x^i,i,[1,2,7]);
 
853
(%i10) lsum(x^i,i,[1,2,7]);
854
854
 
855
855
                            7    2
856
 
(D10)                      x  + x  + x
 
856
(%o10)                      x  + x  + x
857
857
@end example
858
858
If the last element LIST argument does not evaluate, or does not
859
859
evaluate to a Maxima list then the answer is left in noun form
860
860
@example
861
 
(C13) lsum(i^2,i,rootsof(x^3-1));
 
861
(%i13) lsum(i^2,i,rootsof(x^3-1));
862
862
 
863
863
                     ====
864
864
                     \      2
865
 
(D13)                 >    i
 
865
(%o13)                 >    i
866
866
                     /
867
867
                     ====
868
868
                                   3