File: format.demo

package info (click to toggle)
maxima-sage 5.45.1-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, sid, trixie
  • size: 113,788 kB
  • sloc: lisp: 440,833; fortran: 14,665; perl: 14,369; tcl: 10,997; sh: 4,475; makefile: 2,520; ansic: 447; python: 262; xml: 59; awk: 37; sed: 17
file content (79 lines) | stat: -rw-r--r-- 2,921 bytes parent folder | download | duplicates (16)
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
/* -*- Mode: Macsyma -*- */

/*************************************************************************************
 Demo of Format package
*************************************************************************************/

/***********************************************************************
 General restructuring */
format((a+b*x)*(c-x)^2,%poly(x),factor);
format((1+2*eps*(q+r*cos(g))^2)^4,%series(eps,2),%trig(g),factor);
format((1+2*a+a^2)*b + a*(1+2*b+b^2),%sum,%product,%factor);
format(expand((1+a)^2/(1+b)^2),%ratsimp,%factor);
t1:expand((1+x^4)*y^2+(1+x^8)*y^4)$
format(t1,%p(y),%f);
format(t1,%p(y),%f(a^2-2));
format(expand((a+x)^3-a^3),%f-a^3);

/* Contrast power series & Taylor series: */
format((1+sin(x)-x)^3,%series(x,3),%f);
format((1+sin(x)-x)^3,%taylor(x,3),%f);
/***********************************************************************
 Focussing simplifications on subexpressions*/
foo:x^2*sin(y)^4-2*x^2*sin(y)^2+x^4*cos(y)^4-2*x^4*cos(y)^2+x^4+x^2+1$
trigsimp(foo);
format(foo,%p(x),trigsimp);

sqrtp(f):=not(atom(f)) and part(f,0)='sqrt$
first(solve(a*x^2+b*x-(b-2*a)/4,x));
format(%,%rhs,%preformat(%p(match(sqrtp))),%match(sqrtp),%arg(1),%f);

/***********************************************************************
 Subtemplates & template chains. Compare: */
t2:expand((1+a)^2*(1+x)^2/(1+b^2)/(1+y)^2)$
format(t2,%r[%p(x)],%f);
format(t2,%r[[%p(x),%f]]);

/* Contrast these subtemplates */
l1:[1+2*a+a^2,1+2*b+b^2,1+2*c+c^2]$
format(l1,%list,%f);
format(l1,%list[%noop,%f]);
format(l1,%list[%noop,%ditto(%f)]);

/* Contrast various templates & subtemplate usage */
format((1+a)^2/(1+2*b+b^2),%frac[expand,%f]);
format((1+a)^2/(1+2*b+b^2),%expression[expand,%f]);
format((1+a)^2/(1+2*b+b^2),%denom,%f);
format((1+a)^2/(1+2*b+b^2),%num,expand);

/***********************************************************************
 Bags: Lists, Relations & Matrices */

format([a=b,c=d,e=f],%equation);
format(%,%list);

format(1+2*a+a^2 < 1+2*b+b^2,%rel("<")[%f]);
format(1+2*a+a^2 < 1+2*b+b^2,%rhs("<"),%f);
format(1+2*a+a^2 < 1+2*b+b^2,%lhs("<"),%f);
format(1+2*a+a^2 = 1+2*b+b^2,%lhs,%f);
m1:matrix([a^2+2*a+1=q,b^2+2*b+1=r],[c^2+2*c+1=s,d^2+2*d+1=t])$
format(m1,%equation,%matrix[%list[%factor]]);
format(m1,%eq,%element(1,1),%f);
format(m1,%equation,%matrix[%noop,%list[%noop,%factor]]);
format(m1,%eq,%element(2,2),%f);

/***********************************************************************
 Conditionals */
format(a*(1+2*x+x^2)+b*(1+2*y+y^2),%sum,%if(lambda([xx],freeof(x,xx)))[%f,%subst(x=q)]);

/***********************************************************************
 User defined patterns */
put(%myrectform,
     lambda([expr],
       block([pair:rectformlist(expr)],
          format_piece(pair[1]) +%I* format_piece(pair[2]))),
     formatter)$
format(expand((1+a)^2+%I*(1+b)^2),%myrectform,%sqfr);

/* Clean up */
(remvalue(t1,t2,foo,m1),kill(%myrectform),remfunction(sqrtp))$