Kernel Hello World - BrentBaccala/Singular GitHub Wiki

  • We assume that you have installed Singular from the sources as described in Step by Step Installation Instructions for Singular.

  • We first describe to add a debugging screen output to a given arithmetic function.

    • In the file libpolys/coeffs/coeffs.h we add a screen output to the function n_Add (which adds two numbers): Change

      static inline number n_Add(number a, number b, const coeffs r) { assume(r != NULL); assume(r->cfAdd!=NULL); return r->cfAdd(a, b, r); }

      into

      static inline number n_Add(number a, number b, const coeffs r) { assume(r != NULL); assume(r->cfAdd!=NULL); Print("n_Add(a,b,r), a: "); n_Print(a,r); PrintLn(); return r->cfAdd(a, b, r); }

    • Compile Singular by make

    • Start Singular by ./Singular/Singular

    • Try out the screen output by ring r; number n=1; number m=2; n+m;

  • We now discuss how to add an experimental function to Singular, which will be accessible in the interpreter:

    • Add your function to the file extra.cc.
    • We add the following function, which will add the squares of two polynomials:

/==================== myadd ==================================/ if(strcmp(sys_cmd,"myadd")==0) { // input: h, output: res

  // 1st argument
  assume( h->Typ() != POLY_CMD);
  poly p1 = (poly)h->Data(); h = h->next;
  // 2nd argument
  assume( h->Typ() != POLY_CMD);
  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
  • Compile Singular by make

  • Start Singular by ./Singular/Singular

  • Try out your function by ring r=0,(x,y),dp; system("myadd", x, y);

  • We now discuss how to add a function to Singular, which should stay there permanently:

    1. embed into Singular interpreter
  • Computer Algebra System SINGULAR * **************************************/ / @file myadd.h doxy docu for myadd */ #include <kernel/structs.h>

poly myadd (const poly p2, const poly p2, ring r); BOOLEAN myadd (leftv h, leftv res); #endif

  1. as a loadable module