source: git/HOWTO-libsingular @ c7d29b

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