source: git/doc/HOWTO-libsingular

spielwiese
Last change on this file was 4bde6b, checked in by Hans Schoenemann <hannes@…>, 4 years ago
spelling p1
  • Property mode set to 100644
File size: 3.0 KB
Line 
1The following is valid for Singular 4-x-x:
2(for technical details see https://www.singular.uni-kl.de/Manual/modules.pdf)
3
4./configure --disable-static ....
5
6make install
7
8---------------------------------------
9how to compile and run the the example:
10libsingular-config --libs: gives the correct arguments for linking
11libsingular-config --cflags: gives the correct arguments for compiling
12g++ ...... -o tt tt.cc ....
13
14./tt
15--------------------------------------
16the example:
17#include <Singular/libsingular.h>
18main()
19{
20  // init path names etc.
21  siInit((char *)"/...lib/libSingular.so");
22
23  // construct the ring Z/32003[x,y,z]
24  // the variable names
25  char **n=(char**)omalloc(3*sizeof(char*));
26  n[0]=omStrDup("x");
27  n[1]=omStrDup("y");
28  n[2]=omStrDup("z2");
29
30  ring R=rDefault(32003,3,n);
31  // make R the default ring:
32  rChangeCurrRing(R);
33
34  // create the polynomial 1
35  poly p1=p_ISet(1,R);
36
37  // creat the polynomial 2*x^3*z^2
38  poly p2=p_ISet(2,R);
39  pSetExp(p2,1,3);
40  pSetExp(p2,3,2);
41  pSetm(p2);
42
43  // print p1 + p2
44  pWrite(p1); printf(" + \n"); pWrite(p2); printf("\n");
45
46  // compute p1+p2
47  p1=p_Add_q(p1,p2,R); p2=NULL;
48  pWrite(p1);
49
50  // clean up:
51  pDelete(&p1);
52  rKill(R);
53
54  currentVoice=feInitStdin(NULL);
55  // hook for error handling:
56  // WerrorS_callback=......; of type p(const char *)
57  int err=iiAllStart(NULL,"int ver=system(\"version\");\n",BT_proc,0);
58  if (err) errorreported = 0; // reset error handling
59  printf("interpreter returns %d\n",err);
60  idhdl h=ggetid("ver");
61  if (h!=NULL)
62    printf("singular variable ver of type %d contains %d\n",h->typ,(int)(long)IDDATA(h));
63  else
64    printf("variable ver does not exist\n");
65
66  // calling a singular-library function
67  idhdl datetime=ggetid("datetime");
68  if (datetime==NULL)
69    printf("datetime not found\n");
70  else
71  {
72    BOOLEAN res=iiMake_proc(datetime,NULL,NULL);
73    if (res) { printf("datetime return an error\n"); errorreported = 0; }
74    else      printf("datetime returned type %d, >>%s<<\n",iiRETURNEXPR.Typ(),(char *)iiRETURNEXPR.Data());
75  }
76
77  // changing a ring for the interpreter
78  // re-using n and R from above
79  R=rDefault(32003,3,n);
80  idhdl newRingHdl=enterid("R" /* ring name*/,
81                           0, /*nesting level, 0=global*/
82                           RING_CMD,
83                           &IDROOT,
84                           FALSE);
85   IDRING(newRingHdl)=R;
86   // make R the default ring (include rChangeCurrRing):
87   rSetHdl(newRingHdl);
88   myynest=1; /* <=0: interactive at eof/ >=1: non-interactive */
89   err=iiAllStart(NULL,"poly p=x;listvar();return();\n",BT_proc,0);
90
91  // calling a kernel function via the interpreter interface
92  sleftv r1; memset(&r1,0,sizeof(r1));
93  sleftv arg; memset(&arg,0,sizeof(r1));
94  arg.rtyp=STRING_CMD;
95  arg.data=omStrDup("huhu");
96  err=iiExprArith1(&r1,&arg,TYPEOF_CMD);
97  printf("interpreter returns %d\n",err);
98  if (err) errorreported = 0; // reset error handling
99  else printf("typeof returned type %d, >>%s<<\n",r1.Typ(),r1.Data());
100  // clean up r1:
101  r1.CleanUp();
102}
Note: See TracBrowser for help on using the repository browser.