source: git/Tst/Manual/Writing_procedures_and_libraries.tst @ 0d6b7fc

fieker-DuValspielwiese Release-4-3-2p2
Last change on this file since 0d6b7fc was 894057, checked in by Oleksandr Motsak <motsak@…>, 13 years ago
ADD: Tests from online manual (res+stat on mamawutz): short ones Tst/Manual/s.lst
  • Property mode set to 100644
File size: 2.3 KB
Line 
1LIB "tst.lib"; tst_init();
2proc milnorNumber (poly g)
3{
4   "Milnor number:";
5   return(vdim(std(jacob(g))));
6}
7
8proc tjurinaNumber
9{
10   "Tjurina number:";
11   return(vdim(std(jacob(#[1])+#[1])));
12}
13
14proc milnor_tjurina (poly f)
15{
16   ideal j=jacob(f);
17   list L=vdim(std(j)),vdim(std(j+f));
18   return(L);
19}
20
21proc real_sols (number b, number c)
22"USAGE: real_sols (b,c);  b,c number
23ASSUME: active basering has characteristic 0
24RETURN: list: first entry is an integer (the number of different real
25        solutions). If this number is non-negative, the list has as second
26        entry a ring in which the list SOL of real solutions of x^2+bx+c=0
27        is stored (as floating point number, precision 30 digits).
28NOTE:   This procedure calls laguerre_solve from solve.lib.
29"
30{
31  def oldring = basering;  // assign name to the ring active when
32                           // calling the procedure
33  number disc = b^2-4*c;
34  if (disc>0) { int n_of_sols = 2; }
35  if (disc==0) { int n_of_sols = 1; }
36  string s = nameof(var(1));  // name of first ring variable
37  if (disc>=0) {
38    execute("ring rinC =(complex,30),("+s+"),lp;");
39    if (not(defined(laguerre_solve))) { LIB "solve.lib"; }
40    poly f = x2+imap(oldring,b)*x+imap(oldring,c);
41                        // f is a local ring-dependent variable
42    list SOL = laguerre_solve(f,30);
43    export SOL;         // make SOL a global ring-dependent variable
44                        // such variables are still accessible when the
45                        // ring is among the return values of the proc
46    setring oldring;
47    return(list(n_of_sols,rinC));
48  }
49  else {
50    return(list(0));
51  }
52}
53
54//
55// We now apply the procedures which are defined by the
56// lines of code above:
57//
58ring r = 0,(x,y),ds;
59poly f = x7+y7+(x-y)^2*x2y2;
60
61milnorNumber(f);
62tjurinaNumber(f);
63milnor_tjurina(f);     // a list containing Milnor and Tjurina number
64
65def L=real_sols(2,1);
66L[1];                  // number of real solutions of x^2+2x+1
67def R1=L[2];
68setring R1;
69listvar(R1);           // only global ring-dependent objects are still alive
70SOL;                   // the real solutions
71
72setring r;
73L=real_sols(1,1);
74L[1];                  // number of reals solutions of x^2+x+1
75
76setring r;
77L=real_sols(1,-5);
78L[1];                  // number of reals solutions of x^2+x-5
79def R3=L[2];
80setring R3; SOL;       // the real solutions
81tst_status(1);$
Note: See TracBrowser for help on using the repository browser.