9 9 CHAPTER 1 MACSYMA Primer for VAX/UNIX adapted and edited by Richard J. Fateman _U_n_i_v_e_r_s_i_t_y _o_f _C_a_l_i_f_o_r_n_i_a _B_e_r_k_e_l_e_y from material by Joel Moses _M_a_s_s_a_c_h_u_s_e_t_t_s _I_n_s_t_i_t_u_t_e _o_f _T_e_c_h_n_o_l_o_g_y _1._1. _I_n_t_r_o_d_u_c_t_i_o_n MACSYMA (pronounced ``maxima"[1]) is a large computer program designed for the manipulation of algebraic expres- sions. You can use MACSYMA for manipulation algebraic ex- pressions involving constants, variables, and functions. It can differentiate, integrate, take limits, solve equations, factor polynomials, expand functions in power series, and perform many other operations. You can use a programming language to extend MACSYMA's capabilities to new domains. Only a few of the system's many capabilities will be described in this primer. A more complete discussion of the features may be found in the MACSYMA Reference Manual. Ad- ditionally, information about each command is available through an on-line documentation retrieval command, _d_e_s_c_r_i_b_e. To see a blurb on, for example, _e_x_p_a_n_d, type _d_e_s_c_r_i_b_e(_e_x_p_a_n_d); to the system. For some commands, an _e_x_a_m_- _p_l_e is also available, and can be viewed by typing, for in- stance, _e_x_a_m_p_l_e(_e_x_p_a_n_d); ____________________ 9 [1] (The acronym stands for Project MAC's SYmbolic MAni- pulation System. ``MAC" itself is an acronym, usually cited as meaning Man and Computer or Machine Aided Cognition. The Laboratory for Computer Science at the Massachusetts Insti- tute of Technology was known as Project MAC during the ini- tial development of MACSYMA.) 9MACSYMA Primer for VAX/UNIX 1-2 MACSYMA Primer for VAX/UNIX 1-1 _1._2. _S_t_a_r_t_i_n_g _U_p On most VAX/UNIX systems, the system may be loaded by typing _v_a_x_i_m_a to the shell prompt. It may be necessary to type /_u_s_r/_u_c_b/_v_a_x_i_m_a or some similar pathname on your sys- tem. If you expect to be using vaxima much, you should in- clude in your .login script, a line setting the system vari- able VAXIMA to the home directory for vaxima documentation and programs. For example, setenv VAXIMA /na/mac A few seconds after typing _v_a_x_i_m_a, the system will re- turn with a heading and prompt resembling the text below. 9________________________________________________________ % vaxima vaxima 2.04 Sun Jul 12 23:25:20 1982 (c1) ________________________________________________________ 9 The number 2.04 is a version identification number which will change from time to time, as will the day and date of the system construction. The label (c1) is a name being as- signed automatically to your first command. (C labels are used for user-input commands, d-labels for MACSYMA output expressions.) _1._3. _T_y_p_i_n_g _E_x_p_r_e_s_s_i_o_n_s Suppose you wanted to work with the expression (x+1)839. You could type it in by using Fortran-style syntax as fol- lows: 9________________________________________________________ (c1) (x+1)**3; ________________________________________________________ 9 The ``;'' and the ``carriage return ''terminates your com- mand, and prompts MACSYMA to evaluate your expression, sim- plify it, and display the result. The character ``$'' may also be used to end a command line, in which case the result will be computed but not displayed. Printed: May 31, 1986 MACSYMA Primer for VAX/UNIX 1-2 In this case of command c1 above, the evaluation and simplification processes leave the expression unchanged, and MACSYMA responds with the display below. 9________________________________________________________ 3 (d1) (x + 1) (c2) ________________________________________________________ 9 Note that the expression is normally printed in a two- dimensional format with raised superscripts. This usually makes the expression easier to understand than a linear for- mat, although as you will see in later displays, it some- times requires some effort. There is a more readable (but slower) typesetting display facility which requires more a elaborate computer terminal than the usual character-display type. The result is assigned a label _d_1 which may be used in subsequent commands. An important observation: the system is assigning values to the names _c_1, _d_1, etc. You should avoid using these same names for other purposes in your computa- tions. MACSYMA also automatically prompts you with the next line label, _c_2. _1._4. _Y_o_u_r _N_e_x_t _C_o_m_m_a_n_d One of the many commands available in MACSYMA is the _e_x_p_a_n_d command, which converts an expression to an equivalent one, but with certain changes in the form. Most commands have the form of a ``function" being applied to some arguments. In this case, the expression labelled _d_1 above is the single argument to _e_x_p_a_n_d. 9________________________________________________________ (c2) expand(d1); 3 2 (d2) x + 3 x + 3 x + 1 ________________________________________________________ 9 9 9 Printed: May 31, 1986 MACSYMA Primer for VAX/UNIX 1-3 _1._5. _T_y_p_i_n_g _E_r_r_o_r_s Before getting too involved, you should realize that if you make a mistake in typing, you can delete erroneous char- acters by using your standard UNIX erase, kill, word-kill, etc. characters. (Typically backspace, control-U, control- W, respectively) If you wish to delete all lines of a multi-line command, typing ?? will give you a freshly re- typed line label. If you make a mistake but type the semi-colon and re- turn before you notice, the system will provide a message: 9________________________________________________________ (c2) expand((d1); expand (( d1) ***$*** syntax error please rephrase or edit. (c2) ________________________________________________________ 9 If you are a novice at using the computer, you should prob- ably retype the expression. Editing involves the use of one of the system text editors, and is described in the manual. _1._6. _M_o_r_e _C_o_m_m_a_n_d_s Let us consider a few additional commands and facili- ties. To differentiate an expression, use the _d_i_f_f command. _D_i_f_f(_e_x_p_r,_v_a_r) differentiates an expression with respect to the variable _v_a_r. 9________________________________________________________ (c3) sin(x)*cos(x); (d3) cos(x) sin(x) (c4) diff(%,x); 2 2 (d4) cos (x) - sin (x) ________________________________________________________ 9 Note the use of the symbol % in line _c_4. This symbol is a shorthand for the previous expression computed, which in this case is _d_3. Printed: May 31, 1986 MACSYMA Primer for VAX/UNIX 1-4 To differentiate an expression twice, use _d_i_f_f(_e_x_p_r,_v_a_r,_2). 9________________________________________________________ (c5) diff(d3,x,2); (d5) - 4 cos(x) sin(x) ________________________________________________________ 9 The concept of differentiation i