File: test_operators.mac

package info (click to toggle)
maxima 5.47.0-9
  • links: PTS
  • area: main
  • in suites: forky, sid
  • size: 193,104 kB
  • sloc: lisp: 434,678; fortran: 14,665; tcl: 10,990; sh: 4,577; makefile: 2,763; ansic: 447; java: 328; python: 262; perl: 201; xml: 60; awk: 28; sed: 15; javascript: 2
file content (56 lines) | stat: -rw-r--r-- 1,876 bytes parent folder | download | duplicates (7)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
/* Original version of this file copyright 1999 by Michael Wester,
 * and retrieved from http://www.math.unm.edu/~wester/demos/Operators/problems.macsyma
 * circa 2006-10-23.
 *
 * Released under the terms of the GNU General Public License, version 2,
 * per message dated 2007-06-03 from Michael Wester to Robert Dodier
 * (contained in the file wester-gpl-permission-message.txt).
 *
 * See: "A Critique of the Mathematical Abilities of CA Systems"
 * by Michael Wester, pp 25--60 in
 * "Computer Algebra Systems: A Practical Guide", edited by Michael J. Wester
 * and published by John Wiley and Sons, Chichester, United Kingdom, 1999.
 */
/* ----------[ M a c s y m a ]---------- */
/* ---------- Initialization ---------- */
showtime: all$
prederror: false$
/* ---------- Operators ---------- */
load(opalg)$
f(x):= exp(x);
g(x):= x^2;
/* (f + 2 g)(y) => e^y + 2 y^2 */
(f + 2*g)(y);
/* (f o g)(y) => e^(y^2) */
(f . g)(y);
remfunction(f, g)$
/* Linear differential operator */
L: (diffop(x) - 1) . (diffop(x) + 2);
/* => f'' + f' - 2 f */
depends(f, x);
L(f);
remove(f, dependency)$
/* => g''(y) + g'(y) - 2 g(y) */
subst(x = y, L)(g(y));
/* => 2 A [(1 + z) cos(z^2) - (1 + 2 z^2) sin(z^2)] */
subst(x = z, L)(A * sin(z^2));
/* Truncated Taylor series operator */
T: lambda([f, x, a],
          sum(subst(x = a, (diffop(x)^^k)(f(x)))/k! * (x - a)^k, k, 0, 2));
/* => f(a) + f'(a) (x - a) + f''(a) (x - a)^2/2 */
T(f, x, a);
/* => g(b) + g'(b) (y - b) + g''(b) (y - b)^2/2 */
T(g, y, b);
/* => sin(c) + cos(c) (z - c) - sin(c) (z - c)^2/2 */
T(sin, z, c);
remvalue(L, T)$
/* Define the binary infix operator ~ so that x ~ y => sqrt(x^2 + y^2) */
infix("~")$
"~"(x, y):= sqrt(x^2 + y^2)$
3 ~ 4;
/* Make it associative: 3 ~ 4 ~ 12 => 13 */
3 ~ 4 ~ 12;
/* Define the matchfix pair of operators | and | so that | x | => abs(x) */
matchfix("|", "|")$
"|"(x):= abs(x)$
| -2 |;