Skip to content

Adding an experimental function to Singular

jankoboehm edited this page Sep 1, 2014 · 13 revisions

Here we discuss how to quickly add an experimental feature to Singular to make it available in the Interpreter. Note that your function should not stay in this environment.

In the file extras.cc there is a wrapper function jjEXTENDED_SYSTEM which allows you to add your own code to be immediately available in the interpreter. Note that this will not check the types of the arguments automatically. This is usually only intended for testing purposes (it will only be active in a development version), so your code should not stay in here but should eventually move either to some proper place in some existing file (see Adding a new function to an existing file) or to a new file (see Adding a new source file to Singular) or to a dynamial module (see Adding a dynamical module to Singular).

As an example, we show how to add a function which for two polynomial a and b will compute a^2+b^2.

  • In the file extras.cc add in the function

      static BOOLEAN jjEXTENDED_SYSTEM(leftv res, leftv h)

    after some else the code

    /*==================== myadd ==================================*/
      if(strcmp(sys_cmd,"myadd")==0)
      { // input: h, output: res
    
        // test type of arguments
        if( (h!=NULL)
        && (h->Typ() == POLY_CMD)
        && (h->next!=NULL)
        && (h->next->Typ() == POLY_CMD))
        {
          // 1st argument
          poly p1 = (poly)h->Data(); h = h->next;
          // 2nd argument
          poly p2 = (poly)h->Data(); 
          poly sum = p_Add_q(pMult(p1, p1), pMult(p2, p2), currRing);
          res->rtyp=POLY_CMD;
          res->data=(void *)sum;
          return FALSE;
        }
        else
          return TRUE;
      }
      else
  • Compile Singular by doing make

  • Start Singular by ./Singular/Singular

  • Try out your function by

      ring r=0,(x,y),dp;
      system("myadd", x, y);
Clone this wiki locally