001/*
002 * $Id$
003 */
004
005package edu.jas.ufd;
006
007
008import java.util.ArrayList;
009import java.util.List;
010
011import junit.framework.Test;
012import junit.framework.TestCase;
013import junit.framework.TestSuite;
014
015
016import edu.jas.arith.BigInteger;
017import edu.jas.arith.ModInteger;
018import edu.jas.arith.ModIntegerRing;
019import edu.jas.arith.ModLong;
020import edu.jas.arith.ModLongRing;
021import edu.jas.arith.PrimeList;
022import edu.jas.kern.ComputerThreads;
023import edu.jas.poly.GenPolynomial;
024import edu.jas.poly.GenPolynomialRing;
025import edu.jas.poly.PolyUtil;
026import edu.jas.poly.TermOrder;
027
028
029/**
030 * HenselMultUtil tests with JUnit. Two separate classes because of package
031 * dependency.
032 * @see edu.jas.application.HenselMultUtilTest
033 * @author Heinz Kredel
034 */
035
036public class HenselMultUtilTest extends TestCase {
037
038
039    /**
040     * main.
041     */
042    public static void main(String[] args) {
043        junit.textui.TestRunner.run(suite());
044        ComputerThreads.terminate();
045    }
046
047
048    /**
049     * Constructs a <CODE>HenselMultUtilTest</CODE> object.
050     * @param name String.
051     */
052    public HenselMultUtilTest(String name) {
053        super(name);
054    }
055
056
057    /**
058     */
059    public static Test suite() {
060        TestSuite suite = new TestSuite(HenselMultUtilTest.class);
061        return suite;
062    }
063
064
065    TermOrder tord = new TermOrder(TermOrder.INVLEX);
066
067
068    GenPolynomialRing<BigInteger> dfac;
069
070
071    GenPolynomialRing<BigInteger> cfac;
072
073
074    GenPolynomialRing<GenPolynomial<BigInteger>> rfac;
075
076
077    BigInteger ai;
078
079
080    BigInteger bi;
081
082
083    BigInteger ci;
084
085
086    BigInteger di;
087
088
089    BigInteger ei;
090
091
092    GenPolynomial<BigInteger> a;
093
094
095    GenPolynomial<BigInteger> b;
096
097
098    GenPolynomial<BigInteger> c;
099
100
101    GenPolynomial<BigInteger> d;
102
103
104    GenPolynomial<BigInteger> e;
105
106
107    int rl = 2;
108
109
110    int kl = 5;
111
112
113    int ll = 5;
114
115
116    int el = 3;
117
118
119    float q = 0.3f;
120
121
122    @Override
123    protected void setUp() {
124        a = b = c = d = e = null;
125        ai = bi = ci = di = ei = null;
126        dfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl, tord);
127        cfac = new GenPolynomialRing<BigInteger>(new BigInteger(1), rl - 1, tord);
128        rfac = new GenPolynomialRing<GenPolynomial<BigInteger>>(cfac, 1, tord);
129    }
130
131
132    @Override
133    protected void tearDown() {
134        a = b = c = d = e = null;
135        ai = bi = ci = di = ei = null;
136        dfac = null;
137        cfac = null;
138        rfac = null;
139        ComputerThreads.terminate();
140    }
141
142
143    protected static java.math.BigInteger getPrime1() {
144        return PrimeList.getLongPrime(60, 93);
145    }
146
147
148    protected static java.math.BigInteger getPrime2() {
149        return PrimeList.getLongPrime(30, 35);
150    }
151
152
153    /**
154     * Test multivariate Hensel lifting monic case list.
155     */
156    public void testHenselLiftingMonicList() {
157        java.math.BigInteger p;
158        //p = getPrime1();
159        p = new java.math.BigInteger("19");
160        //p = new java.math.BigInteger("5");
161        BigInteger m = new BigInteger(p);
162
163        ModIntegerRing pm = new ModIntegerRing(p, false);
164        //ModLongRing pl = new ModLongRing(p, false);
165        GenPolynomialRing<ModInteger> pfac = new GenPolynomialRing<ModInteger>(pm, 4, tord, new String[] {
166                "w", "x", "y", "z" });
167        //GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(),pfac);
168
169        BigInteger mi = m;
170        long k = 5L;
171        //long d = 3L;
172        java.math.BigInteger pk = p.pow((int) k);
173        //m = new BigInteger(pk);
174
175        ModIntegerRing pkm = new ModIntegerRing(pk, false);
176        //ModLongRing pkl = new ModLongRing(pk, false);
177        GenPolynomialRing<ModInteger> pkfac = new GenPolynomialRing<ModInteger>(pkm, pfac);
178        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
179
180        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
181        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
182
183        //ModLong v = pl.fromInteger(3L);
184        ModInteger v = pkm.fromInteger(3L);
185        List<BigInteger> V = new ArrayList<BigInteger>(1);
186        V.add(new BigInteger(3L));
187        if (pkfac.nvar > 2) {
188            V.add(new BigInteger(5L)); //pkm.fromInteger(5L));
189        }
190        if (pkfac.nvar > 3) {
191            V.add(new BigInteger(7L)); //pkm.fromInteger(7L));
192        }
193        //System.out.println("V = " + V);
194
195        GenPolynomial<ModInteger> ap;
196        GenPolynomial<ModInteger> cp;
197        //GenPolynomial<ModInteger> rp;
198
199        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
200
201        for (int i = 1; i < 2; i++) {
202            //a = dfac.random(kl + 7 * i, ll, el + 1, q).abs();
203            //b = dfac.random(kl + 7 * i, ll, el + 0, q).abs();
204            //c = dfac.random(kl + 7 * i, ll, el + 2, q).abs();
205            a = dfac.parse(" ( z^2 + y^2 + 4 x^3 - x + 1 + w ) ");
206            b = dfac.parse(" ( z + y + x^2 + 10 + w ) ");
207            //c = dfac.parse(" z + x + (y - 2)*(2 + y) ");
208
209            A.add(a);
210            A.add(b);
211            //A.add(c);
212            //System.out.println("A          = " + A);
213            A = ufd.coPrime(A);
214            //System.out.println("coprime(A) = " + A);
215            if (A.size() == 0) {
216                continue;
217            }
218            c = A.get(0).multiply(A.get(1));
219            //c = dfac.parse(" y^2 + x^2 ");
220            cp = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, c);
221            //System.out.println("c          = " + c);
222
223            List<GenPolynomial<ModInteger>> Ap = new ArrayList<GenPolynomial<ModInteger>>(A.size());
224            for (GenPolynomial<BigInteger> ai : A) {
225                ap = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, ai);
226                Ap.add(ap);
227            }
228            //System.out.println("A mod p^k  = " + Ap);
229            //System.out.println("v = " + v + ", vp = " + vp);
230            GenPolynomialRing<ModInteger> ckfac = pkfac.contract(1);
231            v = pkm.fromInteger( V.get(2).getVal() );
232            List<GenPolynomial<ModInteger>> Ae = new ArrayList<GenPolynomial<ModInteger>>(A.size());
233            for (GenPolynomial<ModInteger> a : Ap) {
234                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
235                Ae.add(ae);
236            }
237            //System.out.println("A(v) mod p^k = " + Ae);
238            ckfac = ckfac.contract(1);
239            v = pkm.fromInteger( V.get(1).getVal() );
240            List<GenPolynomial<ModInteger>> Ae1 = new ArrayList<GenPolynomial<ModInteger>>(A.size());
241            for (GenPolynomial<ModInteger> a : Ae) {
242                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
243                Ae1.add(ae);
244            }
245            Ae = Ae1;
246            //System.out.println("A(v,v) mod p^k = " + Ae);
247            ckfac = ckfac.contract(1);
248            v = pkm.fromInteger( V.get(0).getVal() );
249            Ae1 = new ArrayList<GenPolynomial<ModInteger>>(A.size());
250            for (GenPolynomial<ModInteger> a : Ae) {
251                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
252                Ae1.add(ae);
253            }
254            Ae = Ae1;
255            //System.out.println("A(v,v,v) mod p^k = " + Ae);
256
257            try {
258                List<GenPolynomial<ModInteger>> lift;
259                lift = HenselMultUtil.<ModInteger> liftHenselMonic(c, cp, Ae, V, k); // 5 is max
260                //System.out.println("\nliftMultiHensel:");
261                //System.out.println("lift   = " + lift);
262                //System.out.println("A      = " + A);
263                boolean t = HenselMultUtil.<ModInteger> isHenselLift(c, cp, Ae, lift);
264                assertTrue("isHenselLift: ", t);
265            } catch (ArithmeticException e) {
266                // ok, can happen
267            } catch (NoLiftingException e) {
268                // can now happen: fail("" + e);
269                System.out.println("e = " + e);
270            }
271        }
272    }
273
274
275    /**
276     * Test multivariate Hensel lifting list, 2 variables.
277     */
278    public void testHenselLifting2List() {
279        java.math.BigInteger p;
280        //p = getPrime1();
281        p = new java.math.BigInteger("19");
282        //p = new java.math.BigInteger("5");
283        BigInteger m = new BigInteger(p);
284
285        ModIntegerRing pm = new ModIntegerRing(p, false);
286        GenPolynomialRing<ModInteger> pfac = new GenPolynomialRing<ModInteger>(pm, 2, tord, new String[] {
287                "x", "y" });
288        GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), pfac);
289        GenPolynomialRing<GenPolynomial<BigInteger>> irfac = ifac.recursive(ifac.nvar - 1);
290
291        BigInteger mi = m;
292        long k = 5L;
293        //long d = 3L;
294        java.math.BigInteger pk = p.pow((int) k);
295        //m = new BigInteger(pk);
296        //System.out.println("m = " + m + " = " + p + "^" + k);
297
298        ModIntegerRing pkm = new ModIntegerRing(pk, false);
299        //ModLongRing pkl = new ModLongRing(pk, false);
300        GenPolynomialRing<ModInteger> pkfac = new GenPolynomialRing<ModInteger>(pkm, pfac);
301        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
302
303        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
304        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
305
306        //ModLong v = pl.fromInteger(3L);
307        ModInteger v = pkm.fromInteger(3L);
308        List<BigInteger> V = new ArrayList<BigInteger>(1);
309        V.add(new BigInteger(3L));
310        //System.out.println("V = " + V);
311
312        GenPolynomial<ModInteger> ap;
313        GenPolynomial<ModInteger> cp;
314        //GenPolynomial<ModInteger> rp;
315
316        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
317
318        for (int i = 1; i < 2; i++) {
319            a = dfac.parse(" ( x^3 y - 1 ) ");
320            b = dfac.parse(" ( 1 + y ) ");
321            e = dfac.parse(" ( y^2 - x ) ");
322
323            A.add(a);
324            A.add(b);
325            A.add(e);
326            //System.out.println("A          = " + A);
327            A = ufd.coPrime(A);
328            //System.out.println("coprime(A) = " + A); // polynomials are rearranged
329            if (A.size() == 0) {
330                continue;
331            }
332            c = A.get(0).multiply(A.get(1)).multiply(A.get(2));
333            //c = dfac.parse(" y^2 + x^2 ");
334            cp = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, c);
335            //System.out.println("c          = " + c);
336            //System.out.println("cp         = " + cp);
337            GenPolynomial<GenPolynomial<BigInteger>> cr = PolyUtil.<BigInteger> recursive(irfac, c);
338            GenPolynomial<GenPolynomial<BigInteger>> crr = PolyUtil.<BigInteger> switchVariables(cr);
339            //System.out.println("crr = " + crr);
340            GenPolynomial<BigInteger> cl = crr.leadingBaseCoefficient();
341            //System.out.println("cl         = " + cl + ", cl.ring = " + cl.ring);
342
343            FactorAbstract<BigInteger> factorizer = FactorFactory.getImplementation(new BigInteger());
344            List<GenPolynomial<BigInteger>> CF = factorizer.factorsRadical(cl);
345            //System.out.println("CF         = " + CF);
346
347            List<GenPolynomial<BigInteger>> CL = new ArrayList<GenPolynomial<BigInteger>>(2);
348            CL.add(CF.get(0));
349            CL.add(CF.get(2));
350            CL.add(CF.get(1));
351            //CL.add( CF.get(0) );
352            //System.out.println("CL         = " + CL);
353
354            List<GenPolynomial<ModInteger>> Ap = new ArrayList<GenPolynomial<ModInteger>>(A.size());
355            for (GenPolynomial<BigInteger> ai : A) {
356                ap = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, ai);
357                Ap.add(ap);
358            }
359            //System.out.println("A mod p^k  = " + Ap);
360            //System.out.println("v = " + v + ", V = " + V);
361
362            GenPolynomialRing<ModInteger> ckfac = pkfac.contract(1);
363
364            v = pkm.fromInteger( V.get(0).getVal() );
365            List<GenPolynomial<ModInteger>> Ae = new ArrayList<GenPolynomial<ModInteger>>(A.size());
366            for (GenPolynomial<ModInteger> a : Ap) { // Ap
367                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
368                Ae.add(ae);
369            }
370            //System.out.println("A(v) mod p^k = " + Ae);
371
372            try {
373                List<GenPolynomial<ModInteger>> lift;
374                lift = HenselMultUtil.<ModInteger> liftHensel(c, cp, Ae, V, k, CL); // 5 is max
375                //System.out.println("\nliftMultiHensel:");
376                //System.out.println("lift   = " + lift);
377                //System.out.println("A      = " + A);
378                boolean t = HenselMultUtil.<ModInteger> isHenselLift(c, cp, Ae, lift);
379                assertTrue("isHenselLift: ", t);
380            } catch (ArithmeticException e) {
381                // ok, can happen
382                System.out.println("e = " + e);
383            } catch (NoLiftingException e) {
384                // can now happen: 
385                fail("" + e);
386                System.out.println("e = " + e);
387            }
388        }
389    }
390
391
392    /**
393     * Test multivariate Hensel lifting list, 3 variables.
394     */
395    public void xtestHenselLifting3List() {
396        java.math.BigInteger p;
397        //p = getPrime1();
398        p = new java.math.BigInteger("19");
399        //p = new java.math.BigInteger("5");
400        BigInteger m = new BigInteger(p);
401
402        ModIntegerRing pm = new ModIntegerRing(p, false);
403        GenPolynomialRing<ModInteger> pfac = new GenPolynomialRing<ModInteger>(pm, 3, tord, new String[] {
404                "x", "y", "z" });
405        GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), pfac);
406        GenPolynomialRing<GenPolynomial<BigInteger>> irfac = ifac.recursive(ifac.nvar - 1);
407
408        BigInteger mi = m;
409        long k = 3L;
410        //long d = 3L;
411        java.math.BigInteger pk = p.pow((int) k);
412        //m = new BigInteger(pk);
413        //System.out.println("m = " + m);
414
415        ModIntegerRing pkm = new ModIntegerRing(pk, false);
416        //ModLongRing pkl = new ModLongRing(pk, false);
417        GenPolynomialRing<ModInteger> pkfac = new GenPolynomialRing<ModInteger>(pkm, pfac);
418        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
419
420        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
421        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
422
423        //ModLong v = pl.fromInteger(3L);
424        ModInteger v = pkm.fromInteger(3L);
425        List<BigInteger> V = new ArrayList<BigInteger>(1);
426        V.add(new BigInteger(3L));
427        if (pkfac.nvar > 2) {
428            V.add(new BigInteger(5L)); //pkm.fromInteger(5L));
429        }
430        if (pkfac.nvar > 3) {
431            V.add(new BigInteger(7L)); //pkm.fromInteger(7L));
432        }
433        //System.out.println("V = " + V);
434
435        GenPolynomial<ModInteger> ap;
436        GenPolynomial<ModInteger> cp;
437        //GenPolynomial<ModInteger> rp;
438
439        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
440
441        for (int i = 1; i < 2; i++) {
442            //a = dfac.random(kl + 7 * i, ll, el + 1, q).abs();
443            //b = dfac.random(kl + 7 * i, ll, el + 0, q).abs();
444            //c = dfac.random(kl + 7 * i, ll, el + 2, q).abs();
445            //a = dfac.parse(" ( z^2 + y^2 + 4 x^3 - x + 1 + w ) ");
446            //b = dfac.parse(" ( z y x + x^2 + 10 + w ) ");
447            a = dfac.parse(" ( x^3 z - y ) ");
448            //a = dfac.parse(" ( x - y ) ");
449            b = dfac.parse(" ( 1 + y + z ) ");
450            e = dfac.parse(" ( z^2 y - x ) ");
451
452            A.add(a);
453            A.add(b);
454            A.add(e);
455            //System.out.println("A          = " + A);
456            A = ufd.coPrime(A);
457            //System.out.println("coprime(A) = " + A); // polynomials are rearranged
458            if (A.size() == 0) {
459                continue;
460            }
461            c = A.get(0).multiply(A.get(1)).multiply(A.get(2));
462            //c = dfac.parse(" y^2 + x^2 ");
463            cp = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, c);
464            //System.out.println("c          = " + c);
465            GenPolynomial<GenPolynomial<BigInteger>> cr = PolyUtil.<BigInteger> recursive(irfac, c);
466            GenPolynomial<GenPolynomial<BigInteger>> crr = PolyUtil.<BigInteger> switchVariables(cr);
467            //System.out.println("crr = " + crr);
468            GenPolynomial<BigInteger> cl = crr.leadingBaseCoefficient();
469            //System.out.println("cl         = " + cl + ", cl.ring = " + cl.ring);
470
471            FactorAbstract<BigInteger> factorizer = FactorFactory.getImplementation(new BigInteger());
472            List<GenPolynomial<BigInteger>> CF = factorizer.factorsRadical(cl);
473            //System.out.println("CF         = " + CF);
474
475            List<GenPolynomial<BigInteger>> CL = new ArrayList<GenPolynomial<BigInteger>>(2);
476            CL.add(CF.get(0));
477            CL.add(CF.get(2));
478            CL.add(CF.get(1));
479            //System.out.println("CL         = " + CL);
480
481            List<GenPolynomial<ModInteger>> Ap = new ArrayList<GenPolynomial<ModInteger>>(A.size());
482            for (GenPolynomial<BigInteger> ai : A) {
483                ap = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, ai);
484                Ap.add(ap);
485            }
486            //System.out.println("A mod p^k  = " + Ap);
487            //System.out.println("v = " + v + ", V = " + V);
488
489            GenPolynomialRing<ModInteger> ckfac = pkfac.contract(1);
490            //v = pkm.fromInteger( V.get(2) );
491            List<GenPolynomial<ModInteger>> Ae = new ArrayList<GenPolynomial<ModInteger>>(A.size());
492            //for ( GenPolynomial<ModInteger> a : Ap ) {
493            //     GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac,a,v);
494            //     Ae.add(ae);
495            //}
496            //System.out.println("A(v) mod p^k = " + Ae);
497            //ckfac = ckfac.contract(1);
498
499            Ae = Ap;
500            v = pkm.fromInteger( V.get(1).getVal() );
501            List<GenPolynomial<ModInteger>> Ae1 = new ArrayList<GenPolynomial<ModInteger>>(A.size());
502            for (GenPolynomial<ModInteger> a : Ae) {
503                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
504                Ae1.add(ae);
505            }
506            Ae = Ae1;
507            //System.out.println("A(v) mod p^k = " + Ae);
508            ckfac = ckfac.contract(1);
509
510            v = pkm.fromInteger( V.get(0).getVal() );
511            Ae1 = new ArrayList<GenPolynomial<ModInteger>>(A.size());
512            for (GenPolynomial<ModInteger> a : Ae) { // Ap
513                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
514                Ae1.add(ae);
515            }
516            Ae = Ae1;
517            //System.out.println("A(v,v) mod p^k = " + Ae);
518
519            try {
520                List<GenPolynomial<ModInteger>> lift;
521                lift = HenselMultUtil.<ModInteger> liftHensel(c, cp, Ae, V, k, CL); // 5 is max
522                //System.out.println("\nliftMultiHensel:");
523                //System.out.println("lift   = " + lift);
524                //System.out.println("A      = " + A);
525                boolean t = HenselMultUtil.<ModInteger> isHenselLift(c, cp, Ae, lift);
526                assertTrue("isHenselLift: ", t);
527            } catch (ArithmeticException e) {
528                // ok, can happen
529                System.out.println("e = " + e);
530            } catch (NoLiftingException e) {
531                // can now happen: 
532                fail("" + e);
533                System.out.println("e = " + e);
534            }
535        }
536    }
537
538
539    /**
540     * Test multivariate Hensel lifting list, 4 variables.
541     */
542    public void xtestHenselLifting4List() {
543        java.math.BigInteger p;
544        //p = getPrime1();
545        p = new java.math.BigInteger("19");
546        //p = new java.math.BigInteger("5");
547        BigInteger m = new BigInteger(p);
548
549        ModIntegerRing pm = new ModIntegerRing(p, false);
550        GenPolynomialRing<ModInteger> pfac = new GenPolynomialRing<ModInteger>(pm, 4, tord, new String[] {
551                "x", "y", "z", "w" });
552        GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), pfac);
553        GenPolynomialRing<GenPolynomial<BigInteger>> irfac = ifac.recursive(ifac.nvar - 1);
554
555        BigInteger mi = m;
556        long k = 3L;
557        //long d = 3L;
558        java.math.BigInteger pk = p.pow((int) k);
559        //m = new BigInteger(pk);
560        //System.out.println("m = " + m);
561
562        ModIntegerRing pkm = new ModIntegerRing(pk, false);
563        //ModLongRing pkl = new ModLongRing(pk, false);
564        GenPolynomialRing<ModInteger> pkfac = new GenPolynomialRing<ModInteger>(pkm, pfac);
565        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
566
567        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
568        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
569
570        //ModLong v = pl.fromInteger(3L);
571        ModInteger v = pkm.fromInteger(3L);
572        List<BigInteger> V = new ArrayList<BigInteger>(1);
573        V.add(new BigInteger(3L));
574        if (pkfac.nvar > 2) {
575            V.add(new BigInteger(5L)); //pkm.fromInteger(5L));
576        }
577        if (pkfac.nvar > 3) {
578            V.add(new BigInteger(7L)); // pkm.fromInteger(7L));
579        }
580        //System.out.println("V = " + V);
581
582        GenPolynomial<ModInteger> ap;
583        GenPolynomial<ModInteger> cp;
584        //GenPolynomial<ModInteger> rp;
585
586        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
587
588        for (int i = 1; i < 2; i++) {
589            a = dfac.parse(" ( x^3 w - y ) ");
590            b = dfac.parse(" ( 1 + y + z + w ) ");
591            e = dfac.parse(" ( z^2 y w - x ) ");
592
593            A.add(a);
594            A.add(b);
595            A.add(e);
596            //System.out.println("A          = " + A);
597            A = ufd.coPrime(A);
598            //System.out.println("coprime(A) = " + A); // polynomials are rearranged
599            if (A.size() == 0) {
600                continue;
601            }
602            c = A.get(0).multiply(A.get(1)).multiply(A.get(2));
603            cp = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, c);
604            //System.out.println("c          = " + c);
605            GenPolynomial<GenPolynomial<BigInteger>> cr = PolyUtil.<BigInteger> recursive(irfac, c);
606            GenPolynomial<GenPolynomial<BigInteger>> crr = PolyUtil.<BigInteger> switchVariables(cr);
607            //System.out.println("crr = " + crr);
608            GenPolynomial<BigInteger> cl = crr.leadingBaseCoefficient();
609            //System.out.println("cl         = " + cl + ", cl.ring = " + cl.ring);
610
611            FactorAbstract<BigInteger> factorizer = FactorFactory.getImplementation(new BigInteger());
612            List<GenPolynomial<BigInteger>> CF = factorizer.factorsRadical(cl);
613            //System.out.println("CF         = " + CF);
614
615            List<GenPolynomial<BigInteger>> CL = new ArrayList<GenPolynomial<BigInteger>>(2);
616            CL.add(CF.get(0));
617            CL.add(CF.get(2));
618            CL.add(CF.get(1));
619            //System.out.println("CL         = " + CL);
620
621            List<GenPolynomial<ModInteger>> Ap = new ArrayList<GenPolynomial<ModInteger>>(A.size());
622            for (GenPolynomial<BigInteger> ai : A) {
623                ap = PolyUtil.<ModInteger> fromIntegerCoefficients(pkfac, ai);
624                Ap.add(ap);
625            }
626            //System.out.println("A mod p^k  = " + Ap);
627            //System.out.println("v = " + v + ", V = " + V);
628
629            GenPolynomialRing<ModInteger> ckfac = pkfac.contract(1);
630            v = pkm.fromInteger( V.get(2).getVal() );
631            List<GenPolynomial<ModInteger>> Ae = new ArrayList<GenPolynomial<ModInteger>>(A.size());
632            for (GenPolynomial<ModInteger> a : Ap) {
633                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
634                Ae.add(ae);
635            }
636            //System.out.println("A(v) mod p^k = " + Ae);
637            ckfac = ckfac.contract(1);
638
639            v = pkm.fromInteger( V.get(1).getVal() );
640            List<GenPolynomial<ModInteger>> Ae1 = new ArrayList<GenPolynomial<ModInteger>>(A.size());
641            for (GenPolynomial<ModInteger> a : Ae) {
642                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
643                Ae1.add(ae);
644            }
645            Ae = Ae1;
646            //System.out.println("A(v,v) mod p^k = " + Ae);
647            ckfac = ckfac.contract(1);
648
649            v = pkm.fromInteger( V.get(0).getVal() );
650            Ae1 = new ArrayList<GenPolynomial<ModInteger>>(A.size());
651            for (GenPolynomial<ModInteger> a : Ae) { // Ap
652                GenPolynomial<ModInteger> ae = PolyUtil.<ModInteger> evaluateMain(ckfac, a, v);
653                Ae1.add(ae);
654            }
655            Ae = Ae1;
656            //System.out.println("A(v,v,v) mod p^k = " + Ae);
657
658            try {
659                List<GenPolynomial<ModInteger>> lift;
660                lift = HenselMultUtil.<ModInteger> liftHensel(c, cp, Ae, V, k, CL); // 5 is max
661                //System.out.println("\nliftMultiHensel:");
662                //System.out.println("lift   = " + lift);
663                //System.out.println("A      = " + A);
664                boolean t = HenselMultUtil.<ModInteger> isHenselLift(c, cp, Ae, lift);
665                assertTrue("isHenselLift: ", t);
666            } catch (ArithmeticException e) {
667                // ok, can happen
668                System.out.println("e = " + e);
669            } catch (NoLiftingException e) {
670                // can now happen: 
671                fail("" + e);
672                System.out.println("e = " + e);
673            }
674        }
675    }
676
677
678    /**
679     * Test univariate and multivariate Hensel lifting list, 2 variables.
680     */
681    public void testHenselLifting2FullList() {
682        java.math.BigInteger p;
683        //p = getPrime1();
684        p = new java.math.BigInteger("19");
685        //p = new java.math.BigInteger("5");
686        BigInteger m = new BigInteger(p);
687
688        ModLongRing pm = new ModLongRing(p, false);
689        GenPolynomialRing<ModLong> pfac = new GenPolynomialRing<ModLong>(pm, 2, tord,
690                        new String[] { "x", "y" });
691        GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), pfac);
692        GenPolynomialRing<GenPolynomial<BigInteger>> irfac = ifac.recursive(ifac.nvar - 1);
693        GenPolynomialRing<BigInteger> icfac = ifac.contract(ifac.nvar - 1);
694        GenPolynomialRing<ModLong> pcfac = pfac.contract(pfac.nvar - 1);
695
696        BigInteger mi = m;
697        long k = 5L;
698        //long d = 3L;
699        java.math.BigInteger pk = p.pow((int) k);
700        //m = new BigInteger(pk);
701        //System.out.println("m = " + m + " = " + p + "^" + k);
702
703        ModLongRing pkm = new ModLongRing(pk, false);
704        GenPolynomialRing<ModLong> pkfac = new GenPolynomialRing<ModLong>(pkm, pfac);
705        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
706
707        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
708        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
709
710        ModLong v = pkm.fromInteger(3L);
711        List<BigInteger> V = new ArrayList<BigInteger>(1);
712        V.add(new BigInteger(3L));
713        //System.out.println("V = " + V);
714
715        GenPolynomial<ModLong> ap;
716        GenPolynomial<ModLong> cp;
717        //GenPolynomial<ModLong> rp;
718
719        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
720
721        for (int i = 1; i < 2; i++) {
722            a = dfac.parse(" ( x^3 y - 1 ) ");
723            b = dfac.parse(" ( 1 + y ) ");
724            e = dfac.parse(" ( y^2 - x ) ");
725
726            A.add(a);
727            A.add(b);
728            A.add(e);
729            //System.out.println("A          = " + A);
730            A = ufd.coPrime(A);
731            //System.out.println("coprime(A) = " + A); // polynomials are rearranged
732            if (A.size() == 0) {
733                continue;
734            }
735            c = A.get(0).multiply(A.get(1)).multiply(A.get(2));
736            cp = PolyUtil.<ModLong> fromIntegerCoefficients(pkfac, c);
737            //System.out.println("c          = " + c);
738            GenPolynomial<GenPolynomial<BigInteger>> cr = PolyUtil.<BigInteger> recursive(irfac, c);
739            GenPolynomial<GenPolynomial<BigInteger>> crr = PolyUtil.<BigInteger> switchVariables(cr);
740            //System.out.println("crr        = " + crr);
741            GenPolynomial<BigInteger> cl = crr.leadingBaseCoefficient();
742            //System.out.println("cl         = " + cl + ", cl.ring = " + cl.ring);
743
744            FactorAbstract<BigInteger> factorizer = FactorFactory.getImplementation(new BigInteger());
745            List<GenPolynomial<BigInteger>> CF = factorizer.factorsRadical(cl);
746            //System.out.println("CF         = " + CF);
747
748            List<GenPolynomial<BigInteger>> CL = new ArrayList<GenPolynomial<BigInteger>>(2);
749            CL.add(CF.get(0));
750            CL.add(CF.get(2));
751            CL.add(CF.get(1));
752            //CL.add( CF.get(0) );
753            //System.out.println("CL         = " + CL);
754
755            List<GenPolynomial<ModLong>> Apk = new ArrayList<GenPolynomial<ModLong>>(A.size());
756            for (GenPolynomial<BigInteger> ai : A) {
757                ap = PolyUtil.<ModLong> fromIntegerCoefficients(pkfac, ai);
758                Apk.add(ap);
759            }
760            //System.out.println("A mod p^k = " + Apk);
761            //System.out.println("v = " + v + ", V = " + V);
762
763            GenPolynomialRing<ModLong> ckfac = pkfac.contract(1);
764
765            v = pkm.fromInteger( V.get(0).getVal() );
766            List<GenPolynomial<ModLong>> Ae = new ArrayList<GenPolynomial<ModLong>>(A.size());
767            for (GenPolynomial<ModLong> a : Apk) { // Ap
768                GenPolynomial<ModLong> ae = PolyUtil.<ModLong> evaluateMain(ckfac, a, v);
769                Ae.add(ae);
770            }
771            //System.out.println("A(v) mod p^k = " + Ae);
772
773            List<GenPolynomial<ModLong>> Ap = new ArrayList<GenPolynomial<ModLong>>(A.size());
774            for (GenPolynomial<BigInteger> ai : PolyUtil.<ModLong> integerFromModularCoefficients(icfac, Ae)) {
775                ap = PolyUtil.<ModLong> fromIntegerCoefficients(pcfac, ai);
776                Ap.add(ap);
777            }
778            //System.out.println("A(v) mod p = " + Ap);
779
780            try {
781                List<GenPolynomial<ModLong>> lift;
782                lift = HenselMultUtil.<ModLong> liftHenselFull(c, Ap, V, k, CL); // 5 is max
783                //System.out.println("\nliftMultiHensel:");
784                //System.out.println("lift   = " + lift);
785                //System.out.println("A      = " + A);
786                boolean t = HenselMultUtil.<ModLong> isHenselLift(c, cp, Ap, lift);
787                assertTrue("isHenselLift: ", t);
788            } catch (ArithmeticException e) {
789                // ok, can happen
790                System.out.println("e = " + e);
791            } catch (NoLiftingException e) {
792                // can now happen: 
793                fail("" + e);
794                System.out.println("e = " + e);
795            }
796        }
797    }
798
799
800    /**
801     * Test univariate and multivariate Hensel lifting list, 3 variables.
802     */
803    public void testHenselLifting3FullList() {
804        java.math.BigInteger p;
805        //p = getPrime1();
806        p = new java.math.BigInteger("19");
807        //p = new java.math.BigInteger("5");
808        BigInteger m = new BigInteger(p);
809
810        ModLongRing pm = new ModLongRing(p, false);
811        GenPolynomialRing<ModLong> pfac = new GenPolynomialRing<ModLong>(pm, 3, tord, new String[] { "x",
812                "y", "z" });
813        GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), pfac);
814        GenPolynomialRing<GenPolynomial<BigInteger>> irfac = ifac.recursive(ifac.nvar - 1);
815        GenPolynomialRing<BigInteger> icfac = ifac.contract(ifac.nvar - 1);
816        GenPolynomialRing<ModLong> pcfac = pfac.contract(pfac.nvar - 1);
817
818        BigInteger mi = m;
819        long k = 5L;
820        //long d = 3L;
821        java.math.BigInteger pk = p.pow((int) k);
822        //m = new BigInteger(pk);
823        //System.out.println("m = " + m + " = " + p + "^" + k);
824
825        ModLongRing pkm = new ModLongRing(pk, false);
826        GenPolynomialRing<ModLong> pkfac = new GenPolynomialRing<ModLong>(pkm, pfac);
827        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
828
829        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
830        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
831
832        ModLong v = pkm.fromInteger(3L);
833        List<BigInteger> V = new ArrayList<BigInteger>(1);
834        V.add(new BigInteger(3L));
835        if (pkfac.nvar > 2) {
836            V.add(new BigInteger(5L)); //pkm.fromInteger(5L));
837        }
838        //System.out.println("V = " + V);
839
840        GenPolynomial<ModLong> ap;
841        GenPolynomial<ModLong> cp;
842        //GenPolynomial<ModLong> rp;
843
844        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
845
846        for (int i = 1; i < 2; i++) {
847            a = dfac.parse(" ( x^3 z - y ) ");
848            b = dfac.parse(" ( 1 + y + z ) ");
849            e = dfac.parse(" ( z^2 y - x ) ");
850
851            A.add(a);
852            A.add(b);
853            A.add(e);
854            //System.out.println("A          = " + A);
855            A = ufd.coPrime(A);
856            //System.out.println("coprime(A) = " + A); // polynomials are rearranged
857            if (A.size() == 0) {
858                continue;
859            }
860            c = A.get(0).multiply(A.get(1)).multiply(A.get(2));
861            cp = PolyUtil.<ModLong> fromIntegerCoefficients(pkfac, c);
862            //System.out.println("c          = " + c);
863            //System.out.println("cp         = " + cp);
864            GenPolynomial<GenPolynomial<BigInteger>> cr = PolyUtil.<BigInteger> recursive(irfac, c);
865            GenPolynomial<GenPolynomial<BigInteger>> crr = PolyUtil.<BigInteger> switchVariables(cr);
866            //System.out.println("crr        = " + crr);
867            GenPolynomial<BigInteger> cl = crr.leadingBaseCoefficient();
868            //System.out.println("cl         = " + cl + ", cl.ring = " + cl.ring);
869
870            FactorAbstract<BigInteger> factorizer = FactorFactory.getImplementation(new BigInteger());
871            List<GenPolynomial<BigInteger>> CF = factorizer.factorsRadical(cl);
872            //System.out.println("CF         = " + CF);
873
874            List<GenPolynomial<BigInteger>> CL = new ArrayList<GenPolynomial<BigInteger>>(2);
875            CL.add(CF.get(0));
876            CL.add(CF.get(2));
877            CL.add(CF.get(1));
878            //System.out.println("CL         = " + CL);
879
880            List<GenPolynomial<ModLong>> Apk = new ArrayList<GenPolynomial<ModLong>>(A.size());
881            for (GenPolynomial<BigInteger> ai : A) {
882                ap = PolyUtil.<ModLong> fromIntegerCoefficients(pkfac, ai);
883                Apk.add(ap);
884            }
885            //System.out.println("A mod p^k  = " + Apk);
886            //System.out.println("v = " + v + ", V = " + V);
887
888            GenPolynomialRing<ModLong> ckfac = pkfac.contract(1);
889            List<GenPolynomial<ModLong>> Ae = new ArrayList<GenPolynomial<ModLong>>(A.size());
890
891            Ae = Apk;
892            v = pkm.fromInteger( V.get(0).getVal() );
893            List<GenPolynomial<ModLong>> Ae1 = new ArrayList<GenPolynomial<ModLong>>(A.size());
894            for (GenPolynomial<ModLong> a : Ae) {
895                GenPolynomial<ModLong> ae = PolyUtil.<ModLong> evaluateMain(ckfac, a, v);
896                Ae1.add(ae);
897            }
898            Ae = Ae1;
899            //System.out.println("A(v) mod p^k = " + Ae);
900            GenPolynomial<ModLong> cpp = PolyUtil.<ModLong> evaluateMain(ckfac, cp, v);
901            //System.out.println("cpp        = " + cpp);
902            ckfac = ckfac.contract(1);
903
904            v = pkm.fromInteger( V.get(1).getVal() );
905            Ae1 = new ArrayList<GenPolynomial<ModLong>>(A.size());
906            for (GenPolynomial<ModLong> a : Ae) { // Ap
907                GenPolynomial<ModLong> ae = PolyUtil.<ModLong> evaluateMain(ckfac, a, v);
908                Ae1.add(ae);
909            }
910            Ae = Ae1;
911            //System.out.println("A(v,v) mod p^k = " + Ae);
912            GenPolynomial<ModLong> cppp = PolyUtil.<ModLong> evaluateMain(ckfac, cpp, v);
913            //System.out.println("cppp       = " + cppp);
914
915            List<GenPolynomial<ModLong>> Ap = new ArrayList<GenPolynomial<ModLong>>(A.size());
916            for (GenPolynomial<BigInteger> ai : PolyUtil.<ModLong> integerFromModularCoefficients(icfac, Ae)) {
917                ap = PolyUtil.<ModLong> fromIntegerCoefficients(pcfac, ai);
918                Ap.add(ap);
919            }
920            //System.out.println("A(v,v) mod p = " + Ap);
921            GenPolynomial<ModLong> cpppp = PolyUtil.<ModLong> fromIntegerCoefficients(pcfac,
922                            PolyUtil.<ModLong> integerFromModularCoefficients(icfac, cppp));
923            //System.out.println("cpppp      = " + cpppp);
924
925            GenPolynomial<ModLong> aa = pcfac.getONE();
926            for (GenPolynomial<ModLong> x : Ap) {
927                aa = aa.multiply(x);
928            }
929            assertTrue("prod(A(v,v)) mod p = " + aa + ", cpppp = " + cpppp + ", aa != cpppp: ",
930                            cpppp.equals(aa));
931
932            try {
933                List<GenPolynomial<ModLong>> lift;
934                lift = HenselMultUtil.<ModLong> liftHenselFull(c, Ap, V, k, CL); // 5 is max
935                //System.out.println("\nliftMultiHensel:");
936                //System.out.println("lift   = " + lift);
937                //System.out.println("A      = " + A);
938                boolean t = HenselMultUtil.<ModLong> isHenselLift(c, cp, Ap, lift);
939                assertTrue("isHenselLift: ", t);
940            } catch (ArithmeticException e) {
941                // ok, can happen
942                System.out.println("e = " + e);
943            } catch (NoLiftingException e) {
944                // can now happen: 
945                fail("" + e);
946                System.out.println("e = " + e);
947            }
948        }
949    }
950
951
952    /**
953     * Test univariate and multivariate Hensel lifting list, 3 variables.
954     */
955    public void testHenselLifting4FullList() {
956        java.math.BigInteger p;
957        //p = getPrime1();
958        p = new java.math.BigInteger("19");
959        //p = new java.math.BigInteger("5");
960        BigInteger m = new BigInteger(p);
961
962        ModLongRing pm = new ModLongRing(p, false);
963        GenPolynomialRing<ModLong> pfac = new GenPolynomialRing<ModLong>(pm, 4, tord, new String[] { "x",
964                "y", "z", "w" });
965        GenPolynomialRing<BigInteger> ifac = new GenPolynomialRing<BigInteger>(new BigInteger(), pfac);
966        GenPolynomialRing<GenPolynomial<BigInteger>> irfac = ifac.recursive(ifac.nvar - 1);
967        GenPolynomialRing<BigInteger> icfac = ifac.contract(ifac.nvar - 1);
968        GenPolynomialRing<ModLong> pcfac = pfac.contract(pfac.nvar - 1);
969
970        BigInteger mi = m;
971        long k = 5L;
972        //long d = 3L;
973        java.math.BigInteger pk = p.pow((int) k);
974        //m = new BigInteger(pk);
975        //System.out.println("m = " + m);
976
977        ModLongRing pkm = new ModLongRing(pk, false);
978        GenPolynomialRing<ModLong> pkfac = new GenPolynomialRing<ModLong>(pkm, pfac);
979        dfac = new GenPolynomialRing<BigInteger>(mi, pfac);
980
981        //GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getProxy(mi);
982        GreatestCommonDivisor<BigInteger> ufd = GCDFactory.getImplementation(mi);
983
984        ModLong v = pkm.fromInteger(3L);
985        List<BigInteger> V = new ArrayList<BigInteger>(1);
986        V.add(new BigInteger(3L));
987        if (pkfac.nvar > 2) {
988            V.add(new BigInteger(5L)); //pkm.fromInteger(5L));
989        }
990        if (pkfac.nvar > 3) {
991            V.add(new BigInteger(7L)); //pkm.fromInteger(7L));
992        }
993        //System.out.println("V = " + V);
994
995        GenPolynomial<ModLong> ap;
996        GenPolynomial<ModLong> cp;
997        //GenPolynomial<ModLong> rp;
998
999        List<GenPolynomial<BigInteger>> A = new ArrayList<GenPolynomial<BigInteger>>();
1000
1001        for (int i = 1; i < 2; i++) {
1002            a = dfac.parse(" ( x^3 w - y ) ");
1003            b = dfac.parse(" ( 1 + y + z + w ) ");
1004            e = dfac.parse(" ( z^2 y w - x ) ");
1005
1006            A.add(a);
1007            A.add(b);
1008            A.add(e);
1009            //System.out.println("A          = " + A);
1010            A = ufd.coPrime(A);
1011            //System.out.println("coprime(A) = " + A); // polynomials are rearranged
1012            if (A.size() == 0) {
1013                continue;
1014            }
1015            c = A.get(0).multiply(A.get(1)).multiply(A.get(2));
1016            cp = PolyUtil.<ModLong> fromIntegerCoefficients(pkfac, c);
1017            //System.out.println("c          = " + c);
1018            GenPolynomial<GenPolynomial<BigInteger>> cr = PolyUtil.<BigInteger> recursive(irfac, c);
1019            GenPolynomial<GenPolynomial<BigInteger>> crr = PolyUtil.<BigInteger> switchVariables(cr);
1020            //System.out.println("crr = " + crr);
1021            GenPolynomial<BigInteger> cl = crr.leadingBaseCoefficient();
1022            //System.out.println("cl         = " + cl + ", cl.ring = " + cl.ring);
1023
1024            FactorAbstract<BigInteger> factorizer = FactorFactory.getImplementation(new BigInteger());
1025            List<GenPolynomial<BigInteger>> CF = factorizer.factorsRadical(cl);
1026            //System.out.println("CF         = " + CF);
1027
1028            List<GenPolynomial<BigInteger>> CL = new ArrayList<GenPolynomial<BigInteger>>(2);
1029            CL.add(CF.get(0));
1030            CL.add(CF.get(2));
1031            CL.add(CF.get(1));
1032            //System.out.println("CL         = " + CL);
1033
1034            List<GenPolynomial<ModLong>> Apk = new ArrayList<GenPolynomial<ModLong>>(A.size());
1035            for (GenPolynomial<BigInteger> ai : A) {
1036                ap = PolyUtil.<ModLong> fromIntegerCoefficients(pkfac, ai);
1037                Apk.add(ap);
1038            }
1039            //System.out.println("A mod p^k  = " + Apk);
1040            //System.out.println("v = " + v + ", V = " + V);
1041
1042            GenPolynomialRing<ModLong> ckfac = pkfac.contract(1);
1043            v = pkm.fromInteger( V.get(0).getVal() );
1044            List<GenPolynomial<ModLong>> Ae = new ArrayList<GenPolynomial<ModLong>>(A.size());
1045            for (GenPolynomial<ModLong> a : Apk) {
1046                GenPolynomial<ModLong> ae = PolyUtil.<ModLong> evaluateMain(ckfac, a, v);
1047                Ae.add(ae);
1048            }
1049            //System.out.println("A(v) mod p^k = " + Ae);
1050            ckfac = ckfac.contract(1);
1051
1052            v = pkm.fromInteger( V.get(1).getVal() );
1053            List<GenPolynomial<ModLong>> Ae1 = new ArrayList<GenPolynomial<ModLong>>(A.size());
1054            for (GenPolynomial<ModLong> a : Ae) {
1055                GenPolynomial<ModLong> ae = PolyUtil.<ModLong> evaluateMain(ckfac, a, v);
1056                Ae1.add(ae);
1057            }
1058            Ae = Ae1;
1059            //System.out.println("A(v,v) mod p^k = " + Ae);
1060            ckfac = ckfac.contract(1);
1061
1062            v = pkm.fromInteger( V.get(2).getVal() );
1063            Ae1 = new ArrayList<GenPolynomial<ModLong>>(A.size());
1064            for (GenPolynomial<ModLong> a : Ae) { // Ap
1065                GenPolynomial<ModLong> ae = PolyUtil.<ModLong> evaluateMain(ckfac, a, v);
1066                Ae1.add(ae);
1067            }
1068            Ae = Ae1;
1069            //System.out.println("A(v,v,v) mod p^k = " + Ae);
1070
1071            List<GenPolynomial<ModLong>> Ap = new ArrayList<GenPolynomial<ModLong>>(A.size());
1072            for (GenPolynomial<BigInteger> ai : PolyUtil.<ModLong> integerFromModularCoefficients(icfac, Ae)) {
1073                ap = PolyUtil.<ModLong> fromIntegerCoefficients(pcfac, ai);
1074                Ap.add(ap);
1075            }
1076            //System.out.println("A(v,v,v) mod p = " + Ap);
1077
1078            try {
1079                List<GenPolynomial<ModLong>> lift;
1080                //lift = HenselMultUtil.<ModLong> liftHensel(c, cp, Ae, V, k, CL); // 5 is max
1081                lift = HenselMultUtil.<ModLong> liftHenselFull(c, Ap, V, k, CL); // 5 is max
1082                //System.out.println("\nliftMultiHensel:");
1083                //System.out.println("lift   = " + lift);
1084                //System.out.println("A      = " + A);
1085                boolean t = HenselMultUtil.<ModLong> isHenselLift(c, cp, Ap, lift);
1086                assertTrue("isHenselLift: ", t);
1087            } catch (ArithmeticException e) {
1088                // ok, can happen
1089                System.out.println("e = " + e);
1090            } catch (NoLiftingException e) {
1091                // can now happen: 
1092                fail("" + e);
1093                System.out.println("e = " + e);
1094            }
1095        }
1096    }
1097
1098}