[genius] Thu Oct 03 17:15:40 2013 Jiri (George) Lebl <jirka 5z com>



commit 2378d2bcc77e10ac091b1f2e893dd571d7856ba7
Author: Jiri (George) Lebl <jirka 5z com>
Date:   Thu Oct 3 17:16:56 2013 -0500

    Thu Oct 03 17:15:40 2013  Jiri (George) Lebl <jirka 5z com>
    
        * lib/linear_algebra/linear_algebra.gel: Implement
          KroneckerProduct (alias TensorProduct)
    
        * help/C/genius.xml: Document KroneckerProduct and add a few
          wikipedia links and some minor improvements.
    
        * src/geniustests.txt: add tests

 ChangeLog                             |   10 +++++++
 help/C/genius.xml                     |   46 ++++++++++++++++++++++++++++++---
 lib/library-strings.c                 |    1 +
 lib/linear_algebra/linear_algebra.gel |   19 +++++++++++--
 src/geniustests.txt                   |    5 +++
 5 files changed, 74 insertions(+), 7 deletions(-)
---
diff --git a/ChangeLog b/ChangeLog
index 86daf81..7e863fd 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,13 @@
+Thu Oct 03 17:15:40 2013  Jiri (George) Lebl <jirka 5z com>
+
+       * lib/linear_algebra/linear_algebra.gel: Implement
+         KroneckerProduct (alias TensorProduct)
+
+       * help/C/genius.xml: Document KroneckerProduct and add a few
+         wikipedia links and some minor improvements.
+
+       * src/geniustests.txt: add tests
+
 Wed Oct 02 17:36:54 2013  Jiri (George) Lebl <jirka 5z com>
 
        * configure.in: bump version 
diff --git a/help/C/genius.xml b/help/C/genius.xml
index 45941c2..acdb705 100644
--- a/help/C/genius.xml
+++ b/help/C/genius.xml
@@ -6073,12 +6073,33 @@ determinant.
         </varlistentry>
 
         <varlistentry>
+         <term><anchor id="gel-function-KroneckerProduct"/>KroneckerProduct</term>
+         <listitem>
+          <synopsis>KroneckerProduct (M, N)</synopsis>
+          <para>Aliases: <function>TensorProduct</function></para>
+         <para>
+                 Compute the Kronecker product (tensor product in standard basis)
+                 of two matrices.
+         </para>
+          <para>
+           See
+           <ulink url="http://en.wikipedia.org/wiki/Kronecker_product";>Wikipedia</ulink>, 
+           <ulink url="http://planetmath.org/encyclopedia/KroneckerProduct.html";>Planetmath</ulink> or
+           <ulink url="http://mathworld.wolfram.com/KroneckerProduct.html";>Mathworld</ulink> for more 
information.
+          </para>
+         </listitem>
+        </varlistentry>
+
+
+        <varlistentry>
          <term><anchor id="gel-function-LUDecomposition"/>LUDecomposition</term>
          <listitem>
           <synopsis>LUDecomposition (A, L, U)</synopsis>
           <para>
-           Get the LU decomposition of <varname>A</varname>
-           and store the result in the <varname>L</varname> and
+                 Get the LU decomposition of <varname>A</varname>, that is
+                 find a lower triangular matrix and upper triangular
+                 matrix whose product is <varname>A</varname>
+           Store the result in the <varname>L</varname> and
            <varname>U</varname> which should be references.  It returns <constant>true</constant>
            if successful.
            For example suppose that A is a square matrix, then after running:
@@ -6104,6 +6125,7 @@ determinant.
          </para>
           <para>
            See
+           <ulink url="http://en.wikipedia.org/wiki/LU_decomposition";>Wikipedia</ulink>,
            <ulink url="http://planetmath.org/encyclopedia/LUDecomposition.html";>Planetmath</ulink> or
            <ulink url="http://mathworld.wolfram.com/LUDecomposition.html";>Mathworld</ulink> for more 
information.
          </para>
@@ -6217,6 +6239,7 @@ function of two arguments or it can be a matrix giving a sesquilinear form.
          </para>
           <para>
            See
+           <ulink url="http://en.wikipedia.org/wiki/QR_decomposition";>Wikipedia</ulink> or
            <ulink url="http://planetmath.org/encyclopedia/QRDecomposition.html";>Planetmath</ulink> or
            <ulink url="http://mathworld.wolfram.com/QRDecomposition.html";>Mathworld</ulink> for more 
information.
          </para>
@@ -6338,7 +6361,11 @@ function of two arguments or it can be a matrix giving a sesquilinear form.
          <term><anchor id="gel-function-SmithNormalFormField"/>SmithNormalFormField</term>
          <listitem>
           <synopsis>SmithNormalFormField (A)</synopsis>
-          <para>Smith Normal Form for fields (will end up with 1's on the diagonal).</para>
+          <para>Returns the Smith normal form of a matrix over fields (will end up with 1's on the 
diagonal).</para>
+          <para>
+           See
+           <ulink url="http://en.wikipedia.org/wiki/Smith_normal_form";>Wikipedia</ulink> for more 
information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -6346,7 +6373,11 @@ function of two arguments or it can be a matrix giving a sesquilinear form.
          <term><anchor id="gel-function-SmithNormalFormInteger"/>SmithNormalFormInteger</term>
          <listitem>
           <synopsis>SmithNormalFormInteger (M)</synopsis>
-          <para>Smith Normal Form for square integer matrices (not its characteristic).</para>
+          <para>Return the Smith normal form for square integer matrices over integers (not its 
characteristic).</para>
+          <para>
+           See
+           <ulink url="http://en.wikipedia.org/wiki/Smith_normal_form";>Wikipedia</ulink> for more 
information.
+          </para>
          </listitem>
         </varlistentry>
 
@@ -6368,6 +6399,7 @@ conjugated and the nonconjugated version is used for the first row to give a
 Hermitian matrix (if the first element is real of course).</para>
           <para>
            See
+           <ulink url="http://en.wikipedia.org/wiki/Toeplitz_matrix";>Wikipedia</ulink> or
            <ulink url="http://planetmath.org/encyclopedia/ToeplitzMatrix.html";>Planetmath</ulink> for more 
information.
           </para>
          </listitem>
@@ -6381,6 +6413,7 @@ Hermitian matrix (if the first element is real of course).</para>
           <para>Calculate the trace of a matrix.  That is the sum of the diagonal elements.</para>
           <para>
            See
+           <ulink url="http://en.wikipedia.org/wiki/Trace_(linear_algebra)">Wikipedia</ulink> or
            <ulink url="http://planetmath.org/encyclopedia/Trace.html";>Planetmath</ulink> for more 
information.
           </para>
          </listitem>
@@ -6394,6 +6427,7 @@ Hermitian matrix (if the first element is real of course).</para>
           <userinput>.'</userinput> operator.</para>
           <para>
            See
+           <ulink url="http://en.wikipedia.org/wiki/Transpose";>Wikipedia</ulink> or
            <ulink url="http://planetmath.org/encyclopedia/Transpose.html";>Planetmath</ulink> for more 
information.
           </para>
          </listitem>
@@ -6405,6 +6439,10 @@ Hermitian matrix (if the first element is real of course).</para>
           <synopsis>VandermondeMatrix (v)</synopsis>
           <para>Aliases: <function>vander</function></para>
           <para>Return the Vandermonde matrix.</para>
+          <para>
+           See
+           <ulink url="http://en.wikipedia.org/wiki/Vandermonde_matrix";>Wikipedia</ulink> for more 
information.
+          </para>
          </listitem>
         </varlistentry>
 
diff --git a/lib/library-strings.c b/lib/library-strings.c
index 69459c2..2aefb17 100644
--- a/lib/library-strings.c
+++ b/lib/library-strings.c
@@ -128,6 +128,7 @@ char *fake = N_("Is a matrix skew-Hermitian");
 char *fake = N_("Is a matrix unitary");
 char *fake = N_("Get the Jordan block corresponding to lambda and n");
 char *fake = N_("Get the kernel (nullspace) of a linear transform");
+char *fake = N_("Compute the Kronecker product of two matrices");
 char *fake = N_("Get the LU decomposition of A and store the result in the L and U which should be 
references.  If not possible returns false.");
 char *fake = N_("Get the i-j minor of a matrix");
 char *fake = N_("Return the columns that are not the pivot columns of a matrix");
diff --git a/lib/linear_algebra/linear_algebra.gel b/lib/linear_algebra/linear_algebra.gel
index 4223111..85d732f 100644
--- a/lib/linear_algebra/linear_algebra.gel
+++ b/lib/linear_algebra/linear_algebra.gel
@@ -138,9 +138,22 @@ function DirectSum(M,N...) = (
 )
 
 # (Kronecker) Tensor product of two matrices
-#FIXME!
-# function KroneckerProduct(M,N) = TensorProduct(M,N)
-# function TensorProduct(M,N) = Null
+SetHelp ("KroneckerProduct", "linear_algebra", "Compute the Kronecker product of two matrices")
+function KroneckerProduct(M,N) = (
+  if IsNull (M) or IsNull(N) then return null
+  else if not IsMatrix (M) or not IsMatrix(N) then
+    (error ("KroneckerProduct: M and N must be matrices or vectors");bailout);
+  R = null;
+  for j=1 to rows(M) do (
+    for k=1 to columns(M) do (
+      R@(j,k) := M@(j,k)*N
+    )
+  );
+  ExpandMatrix(R)
+)
+SetHelpAlias("KroneckerProduct", "TensorProduct")
+TensorProduct = KroneckerProduct
+
 
 # Checks to see if a matrix/value is invertible
 # Note that given an integer matrix, returns true iff it is invertible OVER THE INTEGERS,
diff --git a/src/geniustests.txt b/src/geniustests.txt
index 0885970..7294d77 100644
--- a/src/geniustests.txt
+++ b/src/geniustests.txt
@@ -1130,6 +1130,11 @@ FindRootBisection (`(x)=x^2-1,-1,0.9,10^-20,10000000)            [true,-1.0,68]
 FindRootBisection (`(x)=x^2-1,0,10^2000,10^-20,1000)@(1)       false
 FindRootBisection (`(x)=x^2+1,-1,1,0.01,100)                   
FindRootBisection((`(x)=((x^2)+1)),-1,1,0.01,100)
 c=0;for x = 0 to 0.3 by 0.1 do ( for y=0.0 to 0.3 by 0.1 do (c=c+1); c)                16
+KroneckerProduct([2],[3])                                      [6]
+KroneckerProduct([11,22;33,44],[1,2;3,4])                      
[11,22,22,44;33,44,66,88;33,66,44,88;99,132,132,176]
+KroneckerProduct([-1,2],[1,2;3,4])                             [-1,-2,2,4;-3,-4,6,8]
+KroneckerProduct(null,[1,2;3,4])+0                             ((null)+0)
+KroneckerProduct([0],null)+0                                   ((null)+0)
 load "nullspacetest.gel"                                       true
 load "longtest.gel"                                            true
 load "testprec.gel"                                            true


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]