[Gretl-devel] Kronecker product and power

Riccardo (Jack) Lucchetti r.lucchetti at univpm.it
Thu Feb 1 04:17:16 EST 2007


Unfortunately, the recent fixes to the matrix handling code broke the
Kronecker product: if you try the following on CVS

nulldata 2
a = mnormal(2,2)
b = mnormal(2,2)
c = a ** b

it gives an error. That is because the "**" is interpreted as B_POW
instead of KRON. I "fixed" this in my local tree by the following
one-liner:

Index: lib/src/genlex.c
===================================================================
RCS file: /cvsroot/gretl/gretl/lib/src/genlex.c,v
retrieving revision 1.49
diff -u -r1.49 genlex.c
--- lib/src/genlex.c    31 Jan 2007 21:50:42 -0000      1.49
+++ lib/src/genlex.c    1 Feb 2007 08:59:58 -0000
@@ -791,7 +791,7 @@
         case '*':
            parser_getc(p);
            if (p->ch == '*') {
-               p->sym = B_POW;
+               p->sym = KRON;
                parser_getc(p);
            } else {
                p->sym = B_MUL;

but clearly this is not satisfactory, since now a = 3**2 returns an error
(understandably).

As a consequence, I propose a syntax change (and this is the reason why
I'm cc-ing the devel-list): reserve "^" for power and "**" for the
Kronecker product. I'm aware that this introduces another breakage in
backward-compatibility, but looks to me as the only clean way out. The
only alternative I can see is to put some checks in place, but even that
can become very complicated: for example, what would the intended result
of

C = A ** x

be, if A is a matrix and x is a scalar?


Riccardo (Jack) Lucchetti
Dipartimento di Economia
Facoltà di Economia "G. Fuà"
Ancona




More information about the Gretl-devel mailing list