Peter Bruin on Tue, 17 Nov 2015 12:24:48 +0100


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

Flm_sub, FpM_sub


Bonjour,

PARI currently has functions Flm_add and FpM_add, but no corresponding
functions Flm_sub and FpM_sub.  I found myself needing these (for LQUP
decomposition based on matrix multiplication), so I implemented them;
see the attached patch.

There currently do not seem to be other places inside the PARI library
where we can immediately use these new functions.  However, this could
easily change in the future, so I hope they can still be included.

Thanks,

Peter


>From b7eebf37372d9e67e92792a0339855350d1671b3 Mon Sep 17 00:00:00 2001
From: Peter Bruin <P.J.Bruin@math.leidenuniv.nl>
Date: Tue, 17 Nov 2015 11:44:19 +0100
Subject: [PATCH] new functions Flm_sub and FpM_sub

---
 doc/usersch5.tex       |    7 +++++++
 src/basemath/FpV.c     |   18 ++++++++++++++++++
 src/headers/paridecl.h |    2 ++
 3 files changed, 27 insertions(+)

diff --git a/doc/usersch5.tex b/doc/usersch5.tex
index fa6978e..be519ec 100644
--- a/doc/usersch5.tex
+++ b/doc/usersch5.tex
@@ -3579,6 +3579,10 @@ the \kbd{ZC} $x$ and reduce modulo $p$ to obtain an \kbd{FpC}.
 \fun{GEN}{FpV_sub}{GEN x, GEN y, GEN p} same as \kbd{FpC\_sub}, returning and
 \kbd{FpV}.
 
+\fun{GEN}{FpM_sub}{GEN x, GEN y, GEN p} subtracts the two \kbd{ZM}s~\kbd{x}
+and \kbd{y} (assumed to have compatible dimensions), and reduce modulo
+\kbd{p} to obtain an \kbd{FpM}.
+
 \fun{GEN}{FpC_Fp_mul}{GEN x, GEN y, GEN p} multiplies the \kbd{ZC}~\kbd{x}
 (seen as a column vector) by the \typ{INT}~\kbd{y} and reduce modulo \kbd{p} to
 obtain an \kbd{FpC}.
@@ -3813,6 +3817,9 @@ $0$.
 \fun{GEN}{Flm_add}{GEN x, GEN y, ulong p} adds \kbd{x} and \kbd{y}
 (assumed to have compatible dimensions).
 
+\fun{GEN}{Flm_sub}{GEN x, GEN y, ulong p} subtracts \kbd{x} and \kbd{y}
+(assumed to have compatible dimensions).
+
 \fun{GEN}{Flm_mul}{GEN x, GEN y, ulong p} multiplies  \kbd{x} and \kbd{y}
 (assumed to have compatible dimensions).
 
diff --git a/src/basemath/FpV.c b/src/basemath/FpV.c
index 77a8b34..4bb689c 100644
--- a/src/basemath/FpV.c
+++ b/src/basemath/FpV.c
@@ -186,6 +186,15 @@ FpV_sub(GEN x, GEN y, GEN p)
 }
 
 GEN
+FpM_sub(GEN x, GEN y, GEN p)
+{
+  long i, l = lg(x);
+  GEN z = cgetg(l, t_MAT);
+  for (i = 1; i < l; i++) gel(z, i) = FpC_sub(gel(x, i), gel(y, i), p);
+  return z;
+}
+
+GEN
 Flv_sub(GEN x, GEN y, ulong p)
 {
   long i, l = lg(x);
@@ -228,6 +237,15 @@ Flm_add(GEN x, GEN y, ulong p)
   return z;
 }
 
+GEN
+Flm_sub(GEN x, GEN y, ulong p)
+{
+  long i, l = lg(x);
+  GEN z = cgetg(l, t_MAT);
+  for (i = 1; i < l; i++) gel(z, i) = Flv_sub(gel(x, i), gel(y, i), p);
+  return z;
+}
+
 /********************************************************************/
 /**                                                                **/
 /**                           MULTIPLICATION                       **/
diff --git a/src/headers/paridecl.h b/src/headers/paridecl.h
index 8b7c2ca..9f55dc3 100644
--- a/src/headers/paridecl.h
+++ b/src/headers/paridecl.h
@@ -671,6 +671,7 @@ GEN     Flm_center(GEN z, ulong p, ulong ps2);
 GEN     Flm_mul(GEN x, GEN y, ulong p);
 GEN     Flm_neg(GEN y, ulong p);
 GEN     Flm_powu(GEN x, ulong n, ulong p);
+GEN     Flm_sub(GEN x, GEN y, ulong p);
 GEN     Flm_to_mod(GEN z, ulong pp);
 GEN     Flm_transpose(GEN x);
 GEN     Flv_add(GEN x, GEN y, ulong p);
@@ -700,6 +701,7 @@ void    FpM_center_inplace(GEN z, GEN p, GEN pov2);
 GEN     FpM_mul(GEN x, GEN y, GEN p);
 GEN     FpM_powu(GEN x, ulong n, GEN p);
 GEN     FpM_red(GEN z, GEN p);
+GEN     FpM_sub(GEN x, GEN y, GEN p);
 GEN     FpM_to_mod(GEN z, GEN p);
 GEN     FpMs_FpC_mul(GEN M, GEN B, GEN p);
 GEN     FpMs_FpCs_solve(GEN M, GEN B, long nbrow, GEN p);
-- 
1.7.9.5