File: cannot_create_user_function_error.mrw

package info (click to toggle)
mathpiper 0.0.svn2556-2
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 7,416 kB
  • ctags: 2,729
  • sloc: java: 21,643; xml: 751; sh: 105; makefile: 5
file content (96 lines) | stat: -rw-r--r-- 2,413 bytes parent folder | download
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
%mathpiper,def="Simplify"

10 # Simplify(expr_IsList) <-- MapSingle("Simplify",expr);

15 # Simplify(Complex(_r,_i)) <-- Complex(Simplify(r),Simplify(i));

20 # Simplify((_xex) == (_yex)) <-- (Simplify(xex-yex) == 0);

20 # Simplify((_xex) > (_yex)) <-- (Simplify(xex-yex) > 0);
20 # Simplify((_xex) < (_yex)) <-- (Simplify(xex-yex) < 0);
20 # Simplify((_xex) >= (_yex)) <-- (Simplify(xex-yex) >= 0);
20 # Simplify((_xex) <= (_yex)) <-- (Simplify(xex-yex) <= 0);
20 # Simplify((_xex) !== (_yex)) <-- (Simplify(xex-yex) !== 0);

// conditionals
25 # Simplify(if (_a) _b) <-- "if" @ {Simplify(a), Simplify(b)};
25 # Simplify(_a else _b) <-- "else" @ {Simplify(a), Simplify(b)};


//Testing with Simplify(1+1/x)  
50 # Simplify(_expr) <-- 
[
    Local(s,g);

    s := MultiSimp(Eval(expr));

    If(IsRationalFunction(s) And ( Type(Numerator(s)) != "Numer") And ( Type(Denominator(s)) != "Denom"),
    [
        Echo("s ",s);
        Echo("Numerator(s) ", Numerator(s));
        Echo("Denominator(s) ", Denominator(s));
        g := Gcd(Numerator(s),Denominator(s));
        Echo("g ",g);
        If( InVerboseMode(),
          [
             Show(10,expr);
             Show(11,s);
             Show(12,Equals(s,expr));
             Show(13,g);
             NewLine();
           ]
        );

        If( s=expr,
              [
                  If( Equals(Numerator(expr),-Denominator(expr)), s := -1 );
                  /* And here one can put other simplifications, as they are developed */
              ],
              [
                  s := Simplify((Numerator(expr)/g))/Simplify(Denominator(expr)/g);

                  If(InVerboseMode(),Tell(14,s));
              ]
          );
          s;
    ],
    [
        s;
    ]
    );
];


10 # IsRationalFunction(x_IsRationalOrNumber) <-- False;
15 # IsRationalFunction(_x)_(Type(x)="/") <-- True;
60000 # IsRationalFunction(_x) <-- False;

%/mathpiper



%mathpiper_docs,name="Simplify",categories="User Functions;Expression Simplification"
*CMD Simplify --- try to simplify an expression
*STD
*CALL
	Simplify(expr)

*PARMS

{expr} -- expression to simplify

*DESC

This function tries to simplify the expression {expr} as much
as possible. It does this by grouping powers within terms, and then
grouping similar terms.

*E.G.

	In> a*b*a^2/b-a^3
	Out> (b*a^3)/b-a^3;
	In> Simplify(a*b*a^2/b-a^3)
	Out> 0;

*SEE TrigSimpCombine, RadSimp
%/mathpiper_docs