Module JAS
In: examples/jas.rb

jruby interface to JAS.

Methods

AN   CC   CR   DD   GF   LC   MPS   Mat   Oct   PS   QQ   Quat   RC   RF   RR   RealN   Vec   ZM   ZZ   makeJasArith   noThreads   rbarray2arraylist   startLog   str   terminate  

Classes and Modules

Class JAS::Coeff
Class JAS::CommutativeModule
Class JAS::EF
Class JAS::MCoeff
Class JAS::MultiSeriesRing
Class JAS::PSIdeal
Class JAS::ParamIdeal
Class JAS::PolyRing
Class JAS::Ring
Class JAS::RingElem
Class JAS::SeriesRing
Class JAS::SimIdeal
Class JAS::SolvPolyRing
Class JAS::SolvableIdeal
Class JAS::SolvableModule
Class JAS::SolvableRing
Class JAS::SolvableSubModule
Class JAS::SubModule
Class JAS::WordIdeal
Class JAS::WordPolyRing
Class JAS::WordRing

Public Instance methods

Create JAS AlgebraicNumber as ring element.

[Source]

      # File examples/jas.rb, line 1362
1362: def AN(m,z=0,field=false,pr=nil)
1363:     if m.is_a? RingElem
1364:         m = m.elem;
1365:     end
1366:     if z.is_a? RingElem
1367:         z = z.elem;
1368:     end
1369:     if z != 0 and ( z == true or z == false )
1370:         field = z;
1371:         z = 0;
1372:     end
1373:     #puts "m.getClass() = " + str(m.getClass().getName());
1374:     #puts "field = " + str(field);
1375:     if m.getClass().getSimpleName() == "AlgebraicNumber"
1376:         mf = AlgebraicNumberRing.new(m.factory().modul,m.factory().isField());
1377:     else
1378:         if field
1379:             mf = AlgebraicNumberRing.new(m,field);
1380:         else
1381:             mf = AlgebraicNumberRing.new(m);
1382:         end
1383:     end
1384:     #puts "mf = " + mf.toString();
1385:     if z == 0
1386:         r = AlgebraicNumber.new(mf);
1387:     else
1388:         r = AlgebraicNumber.new(mf,z);
1389:     end
1390:     return RingElem.new(r);
1391: end

Create JAS BigComplex as ring element.

[Source]

     # File examples/jas.rb, line 158
158: def CC(re=BigRational.new(),im=BigRational.new())
159:     if re == 0
160:         re = BigRational.new();
161:     end
162:     if im == 0
163:         im = BigRational.new();
164:     end
165:     if re.is_a? Array 
166:         if re[0].is_a? Array 
167:             if re.size > 1
168:                 im = QQ( re[1] );
169:             end
170:             re = QQ( re[0] );
171:         else
172:             re = QQ(re);
173: #        re = makeJasArith( re );
174:         end
175:     end
176:     if im.is_a? Array 
177:         im = QQ( im );
178: #        im = makeJasArith( im );
179:     end
180:     if re.is_a? Numeric
181:         re = QQ(re);
182:     end
183:     if im.is_a? Numeric
184:         im = QQ(im);
185:     end
186:     if re.is_a? RingElem
187:         re = re.elem;
188:     end
189:     if im.is_a? RingElem
190:         im = im.elem;
191:     end
192:     if im.isZERO()
193:         if re.isZERO()
194:             c = BigComplex.new();
195:         else
196:             c = BigComplex.new(re);
197:         end
198:     else
199:         c = BigComplex.new(re,im);
200:     end
201:     return RingElem.new(c);
202: end

Create JAS generic Complex as ring element.

[Source]

     # File examples/jas.rb, line 208
208: def CR(re=BigRational.new(),im=BigRational.new(),ring=nil)
209:     if re == 0
210:         re = BigRational.new();
211:     end
212:     if im == 0
213:         im = BigRational.new();
214:     end
215:     if re.is_a? Array 
216:         if re[0].is_a? Array 
217:             if re.size > 1
218:                 im = QQ( re[1] );
219:             end
220:             re = QQ( re[0] );
221:         else
222:             re = QQ(re);
223: #        re = makeJasArith( re );
224:         end
225:     end
226:     if im.is_a? Array 
227:         im = QQ( im );
228: #        im = makeJasArith( im );
229:     end
230:     if re.is_a? RingElem
231:         re = re.elem;
232:     end
233:     if im.is_a? RingElem
234:         im = im.elem;
235:     end
236:     if ring == nil
237:         ring = re.factory();
238:     end
239:     r = ComplexRing.new(ring);
240:     if im.isZERO()
241:         if re.isZERO()
242:             c = Complex.new(r);
243:         else
244:             c = Complex.new(r,re);
245:         end
246:     else
247:         c = Complex.new(r,re,im);
248:     end
249:     return RingElem.new(c);
250: end

Create JAS BigDecimal as ring element.

[Source]

     # File examples/jas.rb, line 256
256: def DD(d=0)
257:     if d.is_a? RingElem
258:         d = d.elem;
259:     end
260:     if d.is_a? Float
261:         d = d.to_s;
262:     end
263:     #puts "d type(#{d}) = #{d.class}";
264:     if d == 0
265:        r = BigDecimal.new();
266:     else
267:        r = BigDecimal.new(d);
268:     end
269:     return RingElem.new(r);
270: end

Create JAS ModInteger as field element.

[Source]

     # File examples/jas.rb, line 117
117: def GF(m,z=0)
118:     return ZM(m,z,true);
119: end

Create JAS polynomial Local as ring element.

[Source]

      # File examples/jas.rb, line 1516
1516: def LC(ideal,d=0,n=1)
1517:     if ideal == nil
1518:         raise ValueError, "No ideal given."
1519:     end
1520:     if ideal.is_a? SimIdeal
1521:         ideal = Ideal.new(ideal.pset);
1522:         #ideal.doGB();
1523:     end
1524:     #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n";
1525:     if ideal.getList().get(0).ring.getClass().getSimpleName() == "LocalRing"
1526:         lc = LocalRing.new( ideal.getList().get(0).ring.ideal );
1527:     else
1528:         lc = LocalRing.new(ideal);
1529:     end
1530:     if d.is_a? Array
1531:         if n != 1
1532:             puts "#{n} ignored\n";
1533:         end
1534:         if d.size > 1
1535:             n = d[1];
1536:         end
1537:         d = d[0];
1538:     end
1539:     if d.is_a? RingElem
1540:         d = d.elem;
1541:     end
1542:     if n.is_a? RingElem
1543:         n = n.elem;
1544:     end
1545:     if d == 0
1546:         r = Local.new(lc);
1547:     else
1548:         if n == 1
1549:             r = Local.new(lc,d);
1550:         else
1551:             r = Local.new(lc,d,n);
1552:         end
1553:     end
1554:     return RingElem.new(r);
1555: end

Create JAS MultiVarPowerSeries as ring element.

[Source]

      # File examples/jas.rb, line 3705
3705: def MPS(cofac,names,truncate=nil,&f)
3706:     cf = cofac;
3707:     if cofac.is_a? RingElem
3708:         cf = cofac.elem.factory();
3709:     elsif cofac.is_a? Ring
3710:         cf = cofac.ring;
3711:     end
3712:     vars = names;
3713:     if vars.is_a? String
3714:        vars = GenPolynomialTokenizer.variableList(vars);
3715:     end
3716:     nv = vars.size;
3717:     if truncate.is_a? RingElem
3718:         truncate = truncate.elem;
3719:     end
3720:     if truncate == nil
3721:         ps = MultiVarPowerSeriesRing.new(cf,nv,vars);
3722:     else
3723:         ps = MultiVarPowerSeriesRing.new(cf,nv,vars,truncate);
3724:     end
3725:     if f == nil
3726:         r = ps.getZERO();
3727:     else
3728:         r = MultiVarPowerSeries.new(ps,MCoeff.new(ps,&f));
3729:         #puts "r = " + str(r);
3730:     end
3731:     return RingElem.new(r);
3732: 
3733: end

Create JAS GenMatrix ring element.

[Source]

      # File examples/jas.rb, line 3769
3769: def Mat(cofac,n,m,v=nil)
3770:     cf = cofac;
3771:     if cofac.is_a? RingElem
3772:         cf = cofac.elem.factory();
3773:     elsif cofac.is_a? Ring
3774:         cf = cofac.ring;
3775:     end
3776:     if n.is_a? RingElem
3777:         n = n.elem;
3778:     end
3779:     if m.is_a? RingElem
3780:         m = m.elem;
3781:     end
3782:     if v.is_a? RingElem
3783:         v = v.elem;
3784:     end
3785:     #puts "cf type(#{cf}) = #{cf.class}";
3786:     if v.is_a? Array
3787:         v = rbarray2arraylist(v,cf,rec=2);
3788:     end
3789:     mr = GenMatrixRing.new(cf,n,m);
3790:     if v == nil
3791:         r = GenMatrix.new(mr);
3792:     else
3793:         r = GenMatrix.new(mr,v);
3794:     end
3795:     return RingElem.new(r);
3796: end

Create JAS BigOctonion as ring element.

[Source]

     # File examples/jas.rb, line 323
323: def Oct(ro=BigQuaternion.new(),io=BigQuaternion.new())
324:     if ro == 0
325:         ro = BigQuaternion.new();
326:     end
327:     if io == 0
328:         io = BigQuaternion.new();
329:     end
330:     if ro.is_a? Array 
331:         if ro[0].is_a? Array 
332:             if ro.size > 1
333:                 io = QQ( ro[1] );
334:             end
335:             ro = QQ( ro[0] );
336:         else
337:             ro = QQ(ro);
338: #        re = makeJasArith( re );
339:         end
340:     end
341:     if io.is_a? Array 
342:         io = QQ( io );
343: #        im = makeJasArith( im );
344:     end
345:     if ro.is_a? RingElem
346:         ro = ro.elem;
347:     end
348:     if io.is_a? RingElem
349:         io = io.elem;
350:     end
351:     c = BigOctonion.new(ro,io);
352:     return RingElem.new(c);
353: end

Create JAS UnivPowerSeries as ring element.

[Source]

      # File examples/jas.rb, line 3656
3656: def PS(cofac,name,truncate=nil,&f) #=nil,truncate=nil)
3657:     cf = cofac;
3658:     if cofac.is_a? RingElem
3659:         cf = cofac.elem.factory();
3660:     end
3661:     if cofac.is_a? Ring
3662:         cf = cofac.ring;
3663:     end
3664:     if truncate.is_a? RingElem
3665:         truncate = truncate.elem;
3666:     end
3667:     if truncate == nil
3668:         ps = UnivPowerSeriesRing.new(cf,name);
3669:     else
3670:         ps = UnivPowerSeriesRing.new(cf,truncate,name);
3671:     end
3672:     #puts "ps type(#{ps}) = #{ps.class}\n";
3673:     #puts "f  type(#{f}) = #{f.class}\n";
3674:     if f == nil
3675:         r = ps.getZERO();
3676:     else
3677:         #Bug in JRuby 1.5.6? move outside method
3678:         r = UnivPowerSeries.new(ps,Coeff.new(cf,&f));
3679:     end
3680:     return RingElem.new(r);
3681: 
3682: end

Create JAS BigRational as ring element.

[Source]

     # File examples/jas.rb, line 124
124: def QQ(d=0,n=1)
125:     if d.is_a? Rational 
126:         if n != 1
127:             puts "#{n} ignored\n";
128:         end
129:         if d.denominator != 1
130:             n = d.denominator;
131:         end
132:         d = d.numerator;
133:     end
134:     if d.is_a? RingElem
135:         d = d.elem;
136:     end
137:     if n.is_a? RingElem
138:         n = n.elem;
139:     end
140:     if n == 1
141:         if d == 0
142:             r = BigRational.new();
143:         else
144:             r = BigRational.new(d);
145:         end
146:     else
147:         d = BigRational.new(d);
148:         n = BigRational.new(n);
149:         r = d.divide(n); # BigRational.new(d,n); only for short integers
150:     end
151:     return RingElem.new(r);
152: end

Create JAS BigQuaternion as ring element.

[Source]

     # File examples/jas.rb, line 276
276: def Quat(re=BigRational.new(),im=BigRational.new(),jm=BigRational.new(),km=BigRational.new())
277:     if re == 0
278:         re = BigRational.new();
279:     end
280:     if im == 0
281:         im = BigRational.new();
282:     end
283:     if jm == 0
284:         jm = BigRational.new();
285:     end
286:     if km == 0
287:         km = BigRational.new();
288:     end
289:     if re.is_a? Numeric 
290:         re = QQ(re);
291: #        re = makeJasArith( re );
292:     end
293:     if im.is_a? Numeric 
294:         im = QQ( im );
295:     end
296:     if jm.is_a? Numeric
297:         jm = QQ( jm );
298:     end
299:     if km.is_a? Numeric
300:        kim = QQ( km );
301: #        im = makeJasArith( im );
302:     end
303:     if re.is_a? RingElem
304:         re = re.elem;
305:     end
306:     if im.is_a? RingElem
307:         im = im.elem;
308:     end
309:     if jm.is_a? RingElem
310:         jm = jm.elem;
311:     end
312:     if km.is_a? RingElem
313:         km = km.elem;
314:     end
315:     c = BigQuaternion.new(re,im,jm,km);
316:     return RingElem.new(c);
317: end

Create JAS polynomial Residue as ring element.

[Source]

      # File examples/jas.rb, line 1485
1485: def RC(ideal,r=0)
1486:     if ideal == nil
1487:         raise ValueError, "No ideal given."
1488:     end
1489:     if ideal.is_a? SimIdeal
1490:         #puts "ideal.pset = " + str(ideal.pset) + "\n";
1491:         #ideal = Java::EduJasApplication::Ideal.new(ideal.ring,ideal.list);
1492:         ideal = Ideal.new(ideal.pset);
1493:         #ideal.doGB();
1494:     end
1495:     #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n";
1496:     if ideal.getList().get(0).ring.getClass().getSimpleName() == "ResidueRing"
1497:         rc = ResidueRing.new( ideal.getList().get(0).ring.ideal );
1498:     else
1499:         rc = ResidueRing.new(ideal);
1500:     end
1501:     if r.is_a? RingElem
1502:         r = r.elem;
1503:     end
1504:     if r == 0
1505:         r = Residue.new(rc);
1506:     else
1507:         r = Residue.new(rc,r);
1508:     end
1509:     return RingElem.new(r);
1510: end

Create JAS rational function Quotient as ring element.

[Source]

      # File examples/jas.rb, line 1436
1436: def RF(pr,d=0,n=1)
1437:     if d.is_a? Array
1438:         if n != 1
1439:             puts "#{} ignored\n";
1440:         end
1441:         if d.size > 1
1442:             n = d[1];
1443:         end
1444:         d = d[0];
1445:     end
1446:     if d.is_a? RingElem
1447:         d = d.elem;
1448:     end
1449:     if n.is_a? RingElem
1450:         n = n.elem;
1451:     end
1452:     if pr.is_a? RingElem
1453:         pr = pr.elem;
1454:     end
1455:     if pr.is_a? Ring
1456:         pr = pr.ring;
1457:     end
1458:     qr = QuotientRing.new(pr);
1459:     if d == 0
1460:         r = Quotient.new(qr);
1461:     else
1462:         if n == 1
1463:             r = Quotient.new(qr,d);
1464:         else
1465:             r = Quotient.new(qr,d,n);
1466:         end
1467:     end
1468:     return RingElem.new(r);
1469: end

Create JAS regular ring Product as ring element.

[Source]

      # File examples/jas.rb, line 1561
1561: def RR(flist,n=1,r=0)
1562:     if not n.is_a? Integer
1563:         r = n;
1564:         n = 1;
1565:     end
1566:     if flist == nil
1567:         raise ValueError, "No list given."
1568:     end
1569:     if flist.is_a? Array
1570:         flist = rbarray2arraylist( flist.map { |x| x.factory() }, rec=1);
1571:         ncop = 0;
1572:     else
1573:         ncop = n;
1574:     end
1575:     if flist.is_a? RingElem
1576:         flist = flist.elem;
1577:         flist = flist.factory();
1578:         ncop = n;
1579:     end
1580:     #puts "flist = " + str(flist);
1581:     #puts "ncop  = " + str(ncop);
1582:     if ncop == 0
1583:         pr = ProductRing.new(flist);
1584:     else
1585:         pr = ProductRing.new(flist,ncop);
1586:     end
1587:     #puts "r type(#{r}) = #{r.class}\n";
1588:     if r.is_a? RingElem
1589:         r = r.elem;
1590:     end
1591:     begin
1592:         #puts "r.class() = #{r.class}\n";
1593:         if r.getClass().getSimpleName() == "Product"
1594:             #puts "r.val = #{r.val}\n";
1595:             r = r.val;
1596:         end
1597:     rescue
1598:         #pass;
1599:     end
1600:     #puts "r = " + r.to_s;
1601:     if r == 0
1602:         r = Product.new(pr);
1603:     else
1604:         r = Product.new(pr,r);
1605:     end
1606:     return RingElem.new(r);
1607: end

Create JAS RealAlgebraicNumber as ring element.

[Source]

      # File examples/jas.rb, line 1406
1406: def RealN(m,i,r=0)
1407:     if m.is_a? RingElem
1408:         m = m.elem;
1409:     end
1410:     if r.is_a? RingElem
1411:         r = r.elem;
1412:     end
1413:     if i.is_a? Array
1414:         il = BigRational.new(i[0]);
1415:         ir = BigRational.new(i[1]);
1416:         i = Interval.new(il,ir);
1417:     end
1418:     #puts "m.getClass() = " + m.getClass().getName().to_s;
1419:     if m.getClass().getSimpleName() == "RealAlgebraicNumber"
1420:         mf = RealAlgebraicRing.new(m.factory().algebraic.modul,i);
1421:     else
1422:         mf = RealAlgebraicRing.new(m,i);
1423:     end
1424:     if r == 0
1425:         rr = RealAlgebraicNumber.new(mf);
1426:     else
1427:         rr = RealAlgebraicNumber.new(mf,r);
1428:     end
1429:     return RingElem.new(rr);
1430: end

Create JAS GenVector ring element.

[Source]

      # File examples/jas.rb, line 3744
3744: def Vec(cofac,n,v=nil)
3745:     cf = cofac;
3746:     if cofac.is_a? RingElem
3747:         cf = cofac.elem.factory();
3748:     elsif cofac.is_a? Ring
3749:         cf = cofac.ring;
3750:     end
3751:     if n.is_a? RingElem
3752:         n = n.elem;
3753:     end
3754:     if v.is_a? RingElem
3755:         v = v.elem;
3756:     end
3757:     vr = GenVectorModul.new(cf,n);
3758:     if v == nil
3759:         r = GenVector.new(vr);
3760:     else
3761:         r = GenVector.new(vr,v);
3762:     end
3763:     return RingElem.new(r);
3764: end

Create JAS ModInteger as ring element.

[Source]

     # File examples/jas.rb, line 93
 93: def ZM(m,z=0,field=false)
 94:     if m.is_a? RingElem
 95:         m = m.elem;
 96:     end
 97:     if z.is_a? RingElem
 98:         z = z.elem;
 99:     end
100:     if z != 0 and ( z == true or z == false )
101:         field = z;
102:         z = 0;
103:     end
104:     if field
105:         mf = ModIntegerRing.new(m,field);
106:     else
107:         mf = ModIntegerRing.new(m);
108:     end
109:     r = ModInteger.new(mf,z);
110:     return RingElem.new(r);
111: end

Create JAS BigInteger as ring element.

[Source]

    # File examples/jas.rb, line 81
81: def ZZ(z=0)
82:     if z.is_a? RingElem
83:         z = z.elem;
84:     end
85:     r = BigInteger.new(z);
86:     return RingElem.new(r);
87: end

Construct a jas.arith object.

If item is an ruby array then a BigComplex is constructed. If item is a ruby float then a BigDecimal is constructed.

[Source]

      # File examples/jas.rb, line 1660
1660: def makeJasArith(item)
1661:     #puts "item type(#{item}) = #{item.class}\n";
1662:     if item.is_a? Integer
1663:         return BigInteger.new( item );
1664:     end
1665:     if item.is_a? Rational
1666:         return BigRational.new( item.numerator ).divide( BigRational.new( item.denominator ) );
1667:     end
1668:     if item.is_a? Float  # ?? what to do ??
1669:         return BigDecimal.new( item.to_s );
1670:     end
1671:     if item.is_a? Array
1672:         if item.size > 2
1673:             puts "len(item) > 2, remaining items ignored\n";
1674:         end
1675:         puts "item[0] type(#{item[0]}) = #{item[0].class}\n";
1676:         if item.size > 1
1677:             re = makeJasArith( item[0] );
1678:             if not re.isField()
1679:                 re = BigRational.new( re.val );
1680:             end
1681:             im = makeJasArith( item[1] );
1682:             if not im.isField()
1683:                 im = BigRational.new( im.val );
1684:             end
1685:             jasArith = BigComplex.new( re, im );
1686:         else
1687:             re = makeJasArith( item[0] );
1688:             if not re.isField()
1689:                 re = BigRational.new( re.val );
1690:             end
1691:             jasArith = BigComplex.new( re );
1692:         end
1693:         return jasArith;
1694:     end
1695:     puts "unknown item type(#{item}) = #{item.class}\n";
1696:     return item;
1697: end

Turn off automatic parallel threads usage.

[Source]

    # File examples/jas.rb, line 52
52: def noThreads()
53:     puts "nt = ", ComputerThreads.NO_THREADS;
54:     ComputerThreads.setNoThreads(); #NO_THREADS = #0; #1; #true;
55:     puts "\nnt = ", ComputerThreads.NO_THREADS;
56:     puts
57: end

Convert a Ruby array to a Java ArrayList.

If list is a Ruby array, it is converted, else list is left unchanged.

[Source]

      # File examples/jas.rb, line 1615
1615: def rbarray2arraylist(list,fac=nil,rec=1)
1616:     #puts "list type(#{list}) = #{list.class}\n";
1617:     if list.is_a? Array
1618:        ll = ArrayList.new();
1619:        for e in list
1620:            t = true;
1621:            if e.is_a? RingElem
1622:                t = false;
1623:                e = e.elem;
1624:            end
1625:            if e.is_a? Array
1626:                if rec <= 1
1627:                    e = makeJasArith(e);
1628:                else
1629:                    t = false;
1630:                    e = rbarray2arraylist(e,fac,rec-1);
1631:                end
1632:            end
1633:            begin
1634:                n = e.getClass().getSimpleName();
1635:                if n == "ArrayList"
1636:                    t = false;
1637:                end
1638:            rescue
1639:                #pass;
1640:            end
1641:            if t and fac != nil
1642:                #puts "e.p(#{e}) = #{e.class}\n";
1643:                e = fac.parse( str(e) ); #or makeJasArith(e) ?
1644:            end
1645:            ll.add(e);
1646:        end
1647:        list = ll;
1648:     end
1649:     #puts "list type(#{list}) = #{list.class}\n";
1650:     return list
1651: end

Configure the log4j system and start logging.

[Source]

    # File examples/jas.rb, line 27
27: def startLog()
28:     BasicConfigurator.configure();
29: end

Mimic Python str() function.

[Source]

    # File examples/jas.rb, line 36
36: def str(s)
37:     return s.to_s;
38: end

Terminate the running thread pools.

[Source]

    # File examples/jas.rb, line 45
45: def terminate()
46:     ComputerThreads.terminate();
47: end

[Validate]