module JAS
jruby interface to JAS
.
Constants
- CC
complex big rational numbers
- CR
generic complex numbers
- DD
big decimal numbers
big rational numbers
- ZZ
define some shortcuts big integers
Public Instance Methods
Create JAS
AlgebraicNumber as ring element.
# File examples/jas.rb 2448 def AN(m,z=0,field=false,pr=nil) 2449 if m.is_a? RingElem 2450 m = m.elem; 2451 end 2452 if z.is_a? RingElem 2453 z = z.elem; 2454 end 2455 if z != 0 and ( z == true or z == false ) 2456 field = z; 2457 z = 0; 2458 end 2459 #puts "m.getClass() = " + str(m.getClass().getName()); 2460 #puts "field = " + str(field); 2461 if m.is_a? AlgebraicNumber 2462 mf = AlgebraicNumberRing.new(m.factory().modul,m.factory().isField()); 2463 else 2464 if field 2465 mf = AlgebraicNumberRing.new(m,field); 2466 else 2467 mf = AlgebraicNumberRing.new(m); 2468 end 2469 end 2470 #puts "mf = " + mf.toString(); 2471 if z == 0 2472 r = AlgebraicNumber.new(mf); 2473 else 2474 r = AlgebraicNumber.new(mf,z); 2475 end 2476 return RingElem.new(r); 2477 end
Create JAS
BigComplex as ring element.
# File examples/jas.rb 332 def CC(re=BigRational.new(),im=BigRational.new()) 333 if re == 0 334 re = BigRational.new(); 335 end 336 if im == 0 337 im = BigRational.new(); 338 end 339 if re.is_a? Array 340 if re[0].is_a? Array 341 if re.size > 1 342 im = QQ( re[1] ); 343 end 344 re = QQ( re[0] ); 345 else 346 re = QQ(re); 347 # re = makeJasArith( re ); 348 end 349 end 350 if im.is_a? Array 351 im = QQ( im ); 352 # im = makeJasArith( im ); 353 end 354 if re.is_a? Numeric 355 re = QQ(re); 356 end 357 if im.is_a? Numeric 358 im = QQ(im); 359 end 360 if re.is_a? RingElem 361 re = re.elem; 362 end 363 if im.is_a? RingElem 364 im = im.elem; 365 end 366 if im.isZERO() 367 if re.isZERO() 368 c = BigComplex.new(); 369 else 370 c = BigComplex.new(re); 371 end 372 else 373 c = BigComplex.new(re,im); 374 end 375 return RingElem.new(c); 376 end
Create JAS
generic Complex as ring element.
# File examples/jas.rb 382 def CR(re=BigRational.new(),im=BigRational.new(),ring=nil) 383 if re == 0 384 re = BigRational.new(); 385 end 386 if im == 0 387 im = BigRational.new(); 388 end 389 if re.is_a? Array 390 if re[0].is_a? Array 391 if re.size > 1 392 im = QQ( re[1] ); 393 end 394 re = QQ( re[0] ); 395 else 396 re = QQ(re); 397 # re = makeJasArith( re ); 398 end 399 end 400 if im.is_a? Array 401 im = QQ( im ); 402 # im = makeJasArith( im ); 403 end 404 if re.is_a? RingElem 405 re = re.elem; 406 end 407 if im.is_a? RingElem 408 im = im.elem; 409 end 410 if ring == nil 411 ring = re.factory(); 412 end 413 r = ComplexRing.new(ring); 414 if im.isZERO() 415 if re.isZERO() 416 c = Complex.new(r); 417 else 418 c = Complex.new(r,re); 419 end 420 else 421 c = Complex.new(r,re,im); 422 end 423 return RingElem.new(c); 424 end
Create JAS
BigDecimal as ring element.
# File examples/jas.rb 430 def DD(d=0) 431 if d.is_a? RingElem 432 d = d.elem; 433 end 434 if d.is_a? Float 435 d = d.to_s; 436 end 437 #puts "d type(#{d}) = #{d.class}"; 438 if d == 0 439 r = BigDecimal.new(); 440 else 441 r = BigDecimal.new(d); 442 end 443 return RingElem.new(r); 444 end
Create JAS
Finite Field element as ring element. FF
has p<sup>n</sup> elements.
# File examples/jas.rb 2489 def FF(p,n,z=0) 2490 if p.is_a? RingElem 2491 p = p.elem; 2492 end 2493 if n.is_a? RingElem 2494 n = n.elem; 2495 end 2496 if z.is_a? RingElem 2497 z = z.elem; 2498 end 2499 if z.is_a? AlgebraicNumber 2500 z = z.val; 2501 #puts "z = " + z.ring.toScript(); 2502 end 2503 if p == 0 2504 raise ArgumentError, "No finite ring." 2505 end 2506 if n == 0 2507 raise ArgumentError, "No finite ring." 2508 end 2509 field = true; 2510 if !PrimeInteger.isPrime(p) 2511 field = false; 2512 #raise ArgumentError, "{p} not prime." 2513 end 2514 mf = $finiteFields[ [p,n] ]; 2515 if mf == nil 2516 cf = GF(p).ring; 2517 mf = PolyUfdUtil.algebraicNumberField(cf,n); 2518 $finiteFields[ [p,n] ] = mf; 2519 #puts "mf = " + mf.toScript(); 2520 end 2521 if z == 0 2522 r = AlgebraicNumber.new(mf); 2523 else 2524 r = AlgebraicNumber.new(mf,z); 2525 #puts "r = " + r.toScript(); 2526 end 2527 return RingElem.new(r); 2528 end
Create JAS
ModInteger as field element.
# File examples/jas.rb 278 def GF(m,z=0) 279 return ZM(m,z,true); 280 end
Create JAS
ModInt as field element.
# File examples/jas.rb 292 def GFI(m,z=0) 293 return ZM(m,z,true); 294 end
Create JAS
ModLong as field element.
# File examples/jas.rb 285 def GFL(m,z=0) 286 return ZM(m,z,true); 287 end
Create JAS
polynomial Local as ring element.
# File examples/jas.rb 2723 def LC(ideal,d=0,n=1) 2724 if ideal == nil 2725 raise ArgumentError, "No ideal given." 2726 end 2727 if ideal.is_a? SimIdeal 2728 ideal = Ideal.new(ideal.pset); 2729 #ideal.doGB(); 2730 end 2731 #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n"; 2732 if ideal.getList().get(0).ring.is_a? LocalRing 2733 lc = LocalRing.new( ideal.getList().get(0).ring.ideal ); 2734 else 2735 lc = LocalRing.new(ideal); 2736 end 2737 if d.is_a? Array 2738 if n != 1 2739 puts "#{n} ignored\n"; 2740 end 2741 if d.size > 1 2742 n = d[1]; 2743 end 2744 d = d[0]; 2745 end 2746 if d.is_a? RingElem 2747 d = d.elem; 2748 end 2749 if n.is_a? RingElem 2750 n = n.elem; 2751 end 2752 if d == 0 2753 r = Local.new(lc); 2754 else 2755 if n == 1 2756 r = Local.new(lc,d); 2757 else 2758 r = Local.new(lc,d,n); 2759 end 2760 end 2761 return RingElem.new(r); 2762 end
Create JAS
MultiVarPowerSeries as ring element.
# File examples/jas.rb 5858 def MPS(cofac,names,truncate=nil,&f) 5859 cf = cofac; 5860 if cofac.is_a? RingElem 5861 cf = cofac.elem.factory(); 5862 elsif cofac.is_a? Ring 5863 cf = cofac.ring; 5864 end 5865 vars = names; 5866 if vars.is_a? String 5867 vars = GenPolynomialTokenizer.variableList(vars); 5868 end 5869 nv = vars.size; 5870 if truncate.is_a? RingElem 5871 truncate = truncate.elem; 5872 end 5873 if truncate == nil 5874 ps = MultiVarPowerSeriesRing.new(cf,nv,vars); 5875 else 5876 ps = MultiVarPowerSeriesRing.new(cf,nv,vars,truncate); 5877 end 5878 if f == nil 5879 r = ps.getZERO(); 5880 else 5881 r = MultiVarPowerSeries.new(ps,MCoeff.new(ps,&f)); 5882 #puts "r = " + str(r); 5883 end 5884 return RingElem.new(r); 5885 5886 end
Create JAS
GenMatrix ring element.
# File examples/jas.rb 5927 def Mat(cofac,n,m,v=nil) 5928 cf = cofac; 5929 if cofac.is_a? RingElem 5930 cf = cofac.elem.factory(); 5931 elsif cofac.is_a? Ring 5932 cf = cofac.ring; 5933 end 5934 if n.is_a? RingElem 5935 n = n.elem; 5936 end 5937 if m.is_a? RingElem 5938 m = m.elem; 5939 end 5940 if v.is_a? RingElem 5941 v = v.elem; 5942 end 5943 #puts "cf type(#{cf}) = #{cf.class}"; 5944 if v.is_a? Array 5945 v = rbarray2arraylist(v,cf,rec=2); 5946 end 5947 mr = GenMatrixRing.new(cf,n,m); 5948 if v == nil 5949 r = GenMatrix.new(mr); 5950 else 5951 r = GenMatrix.new(mr,v); 5952 end 5953 return RingElem.new(r); 5954 end
Create JAS
BigOctonion as ring element.
# File examples/jas.rb 498 def Oct(ro=0,io=0) 499 cf = BigQuaternionRing.new(); 500 if ro == 0 501 ro = BigQuaternion.new(cf); 502 end 503 if io == 0 504 io = BigQuaternion.new(cf); 505 end 506 if ro.is_a? Array 507 if ro[0].is_a? Array 508 if ro.size > 1 509 io = QQ( ro[1] ); 510 end 511 ro = QQ( ro[0] ); 512 else 513 ro = QQ(ro); 514 # re = makeJasArith( re ); 515 end 516 end 517 if io.is_a? Array 518 io = QQ( io ); 519 # im = makeJasArith( im ); 520 end 521 if ro.is_a? RingElem 522 ro = ro.elem; 523 end 524 if io.is_a? RingElem 525 io = io.elem; 526 end 527 c = BigOctonion.new(ro,io); 528 return RingElem.new(c); 529 end
Create JAS
UnivPowerSeries as ring element.
# File examples/jas.rb 5792 def PS(cofac,name,truncate=nil,&f) #=nil,truncate=nil) 5793 cf = cofac; 5794 if cofac.is_a? RingElem 5795 cf = cofac.elem.factory(); 5796 end 5797 if cofac.is_a? Ring 5798 cf = cofac.ring; 5799 end 5800 if truncate.is_a? RingElem 5801 truncate = truncate.elem; 5802 end 5803 if truncate == nil 5804 ps = UnivPowerSeriesRing.new(cf,name); 5805 else 5806 ps = UnivPowerSeriesRing.new(cf,truncate,name); 5807 end 5808 #puts "ps type(#{ps}) = #{ps.class}\n"; 5809 #puts "f type(#{f}) = #{f.class}\n"; 5810 if f == nil 5811 r = ps.getZERO(); 5812 else 5813 #Bug in JRuby 1.5.6? move outside method 5814 r = UnivPowerSeries.new(ps,Coeff.new(cf,&f)); 5815 end 5816 return RingElem.new(r); 5817 5818 end
Create JAS
BigRational as ring element.
# File examples/jas.rb 299 def QQ(d=0,n=1) 300 if d.is_a? Rational 301 if n != 1 302 puts "#{n} ignored\n"; 303 end 304 if d.denominator != 1 305 n = d.denominator; 306 end 307 d = d.numerator; 308 end 309 if d.is_a? RingElem 310 d = d.elem; 311 end 312 if n.is_a? RingElem 313 n = n.elem; 314 end 315 if n == 1 316 if d == 0 317 r = BigRational.new(); 318 else 319 r = BigRational.new(d); 320 end 321 else 322 d = BigRational.new(d); 323 n = BigRational.new(n); 324 r = d.divide(n); # BigRational.new(d,n); only for short integers 325 end 326 return RingElem.new(r); 327 end
Create JAS
BigQuaternion as ring element.
# File examples/jas.rb 450 def Quat(re=BigRational.new(),im=BigRational.new(),jm=BigRational.new(),km=BigRational.new()) 451 if re == 0 452 re = BigRational.new(); 453 end 454 if im == 0 455 im = BigRational.new(); 456 end 457 if jm == 0 458 jm = BigRational.new(); 459 end 460 if km == 0 461 km = BigRational.new(); 462 end 463 if re.is_a? Numeric 464 re = QQ(re); 465 # re = makeJasArith( re ); 466 end 467 if im.is_a? Numeric 468 im = QQ( im ); 469 end 470 if jm.is_a? Numeric 471 jm = QQ( jm ); 472 end 473 if km.is_a? Numeric 474 kim = QQ( km ); 475 # im = makeJasArith( im ); 476 end 477 if re.is_a? RingElem 478 re = re.elem; 479 end 480 if im.is_a? RingElem 481 im = im.elem; 482 end 483 if jm.is_a? RingElem 484 jm = jm.elem; 485 end 486 if km.is_a? RingElem 487 km = km.elem; 488 end 489 cf = BigQuaternionRing.new(); 490 c = BigQuaternion.new(cf, re,im,jm,km); 491 return RingElem.new(c); 492 end
Create JAS
polynomial Residue as ring element.
# File examples/jas.rb 2692 def RC(ideal,r=0) 2693 if ideal == nil 2694 raise ArgumentError, "No ideal given." 2695 end 2696 if ideal.is_a? SimIdeal 2697 #puts "ideal.pset = " + str(ideal.pset) + "\n"; 2698 #ideal = Java::EduJasApplication::Ideal.new(ideal.ring,ideal.list); 2699 ideal = Ideal.new(ideal.pset); 2700 #ideal.doGB(); 2701 end 2702 #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n"; 2703 if ideal.getList().get(0).ring.is_a? ResidueRing 2704 rc = ResidueRing.new( ideal.getList().get(0).ring.ideal ); 2705 else 2706 rc = ResidueRing.new(ideal); 2707 end 2708 if r.is_a? RingElem 2709 r = r.elem; 2710 end 2711 if r == 0 2712 r = Residue.new(rc); 2713 else 2714 r = Residue.new(rc,r); 2715 end 2716 return RingElem.new(r); 2717 end
Create JAS
rational function Quotient as ring element.
# File examples/jas.rb 2590 def RF(pr,d=0,n=1) 2591 if d.is_a? Array 2592 if n != 1 2593 puts "#{} ignored\n"; 2594 end 2595 if d.size > 1 2596 n = d[1]; 2597 end 2598 d = d[0]; 2599 end 2600 if d.is_a? RingElem 2601 d = d.elem; 2602 end 2603 if n.is_a? RingElem 2604 n = n.elem; 2605 end 2606 if pr.is_a? RingElem 2607 pr = pr.elem; 2608 end 2609 if pr.is_a? Ring 2610 pr = pr.ring; 2611 end 2612 qr = QuotientRing.new(pr); 2613 if d == 0 2614 r = Quotient.new(qr); 2615 else 2616 if n == 1 2617 r = Quotient.new(qr,d); 2618 else 2619 r = Quotient.new(qr,d,n); 2620 end 2621 end 2622 return RingElem.new(r); 2623 end
Create JAS
regular ring Product as ring element.
# File examples/jas.rb 2894 def RR(flist,n=1,r=0) 2895 if not n.is_a? Integer 2896 r = n; 2897 n = 1; 2898 end 2899 if flist == nil 2900 raise ArgumentError, "No list given." 2901 end 2902 if flist.is_a? Array 2903 flist = rbarray2arraylist( flist.map { |x| x.factory() }, rec=1); 2904 ncop = 0; 2905 else 2906 ncop = n; 2907 end 2908 if flist.is_a? RingElem 2909 flist = flist.elem; 2910 flist = flist.factory(); 2911 ncop = n; 2912 end 2913 #puts "flist = " + str(flist); 2914 #puts "ncop = " + str(ncop); 2915 if ncop == 0 2916 pr = ProductRing.new(flist); 2917 else 2918 pr = ProductRing.new(flist,ncop); 2919 end 2920 #puts "r type(#{r}) = #{r.class}\n"; 2921 if r.is_a? RingElem 2922 r = r.elem; 2923 end 2924 begin 2925 #puts "r.class() = #{r.class}\n"; 2926 if r.is_a? Product 2927 #puts "r.val = #{r.val}\n"; 2928 r = r.val; 2929 end 2930 rescue 2931 #pass; 2932 end 2933 #puts "r = " + r.to_s; 2934 if r == 0 2935 r = Product.new(pr); 2936 else 2937 r = Product.new(pr,r); 2938 end 2939 return RingElem.new(r); 2940 end
Create JAS
RealAlgebraicNumber as ring element.
# File examples/jas.rb 2547 def RealN(m,i,r=0) 2548 if m.is_a? RingElem 2549 m = m.elem; 2550 end 2551 if r.is_a? RingElem 2552 r = r.elem; 2553 end 2554 if i.is_a? Array 2555 i = rbarray2arraylist(i,BigRational.new(0),1); 2556 i = Interval.new(i[0],i[1]); 2557 end 2558 #puts "m.getClass() = " + m.getClass().getName().to_s; 2559 if m.is_a? RealAlgebraicNumber 2560 mf = RealAlgebraicRing.new(m.factory().algebraic.modul,i); 2561 else 2562 mf = RealAlgebraicRing.new(m,i); 2563 end 2564 if r == 0 2565 rr = RealAlgebraicNumber.new(mf); 2566 else 2567 rr = RealAlgebraicNumber.new(mf,r); 2568 end 2569 return RingElem.new(rr); 2570 end
Create JAS
polynomial SolvableLocal as ring element.
# File examples/jas.rb 2799 def SLC(ideal,d=0,n=1) 2800 if ideal == nil 2801 raise ArgumentError, "No ideal given." 2802 end 2803 if ideal.is_a? SolvIdeal 2804 ideal = SolvableIdeal.new(ideal.pset); 2805 #ideal.doGB(); 2806 end 2807 #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n"; 2808 if ideal.getList().get(0).ring.is_a? SolvableLocalRing 2809 lc = SolvableLocalRing.new( ideal.getList().get(0).ring.ideal ); 2810 else 2811 lc = SolvableLocalRing.new(ideal); 2812 end 2813 if d.is_a? Array 2814 if n != 1 2815 puts "#{n} ignored\n"; 2816 end 2817 if d.size > 1 2818 n = d[1]; 2819 end 2820 d = d[0]; 2821 end 2822 if d.is_a? RingElem 2823 d = d.elem; 2824 end 2825 if n.is_a? RingElem 2826 n = n.elem; 2827 end 2828 if d == 0 2829 r = SolvableLocal.new(lc); 2830 else 2831 if n == 1 2832 r = SolvableLocal.new(lc,d); 2833 else 2834 r = SolvableLocal.new(lc,d,n); 2835 end 2836 end 2837 return RingElem.new(r); 2838 end
Create JAS
polynomial SolvableLocalResidue as ring element.
# File examples/jas.rb 2844 def SLR(ideal,d=0,n=1) 2845 if ideal == nil 2846 raise ArgumentError, "No ideal given." 2847 end 2848 if ideal.is_a? SolvIdeal 2849 ideal = SolvableIdeal.new(ideal.pset); 2850 #ideal.doGB(); 2851 end 2852 cfr = ideal.getList().get(0).ring; 2853 #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n"; 2854 if n == true 2855 isfield = true; 2856 n = 1; 2857 end 2858 if cfr.is_a? SolvableLocalResidueRing 2859 lc = SolvableLocalResidueRing.new( cfr.ideal ); 2860 else 2861 lc = SolvableLocalResidueRing.new(ideal); 2862 end 2863 if d.is_a? Array 2864 if n != 1 2865 puts "#{n} ignored\n"; 2866 end 2867 if d.size > 1 2868 n = d[1]; 2869 end 2870 d = d[0]; 2871 end 2872 if d.is_a? RingElem 2873 d = d.elem; 2874 end 2875 if n.is_a? RingElem 2876 n = n.elem; 2877 end 2878 if d == 0 2879 r = SolvableLocalResidue.new(lc); 2880 else 2881 if n == 1 2882 r = SolvableLocalResidue.new(lc,d); 2883 else 2884 r = SolvableLocalResidue.new(lc,d,n); 2885 end 2886 end 2887 return RingElem.new(r); 2888 end
Create JAS
polynomial SolvableResidue as ring element.
# File examples/jas.rb 2768 def SRC(ideal,r=0) 2769 if ideal == nil 2770 raise ArgumentError, "No ideal given." 2771 end 2772 if ideal.is_a? SolvIdeal 2773 #puts "ideal.pset = " + str(ideal.pset) + "\n"; 2774 #ideal = Java::EduJasApplication::Ideal.new(ideal.ring,ideal.list); 2775 ideal = SolvableIdeal.new(ideal.pset); 2776 #ideal.doGB(); 2777 end 2778 #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n"; 2779 if ideal.getList().get(0).ring.is_a? SolvableResidueRing 2780 rc = SolvableResidueRing.new( ideal.getList().get(0).ring.ideal ); 2781 else 2782 rc = SolvableResidueRing.new(ideal); 2783 end 2784 if r.is_a? RingElem 2785 r = r.elem; 2786 end 2787 if r == 0 2788 r = SolvableResidue.new(rc); 2789 else 2790 r = SolvableResidue.new(rc,r); 2791 end 2792 return RingElem.new(r); 2793 end
Create JAS
rational function SolvableQuotient as ring element.
# File examples/jas.rb 2629 def SRF(pr,d=0,n=1) 2630 if d.is_a? Array 2631 if n != 1 2632 puts "#{} ignored\n"; 2633 end 2634 if d.size > 1 2635 n = d[1]; 2636 end 2637 d = d[0]; 2638 end 2639 if d.is_a? RingElem 2640 d = d.elem; 2641 end 2642 if n.is_a? RingElem 2643 n = n.elem; 2644 end 2645 if pr.is_a? RingElem 2646 pr = pr.elem; 2647 end 2648 if pr.is_a? Ring 2649 pr = pr.ring; 2650 end 2651 qr = SolvableQuotientRing.new(pr); 2652 #puts "qr is associative: " + qr.isAssociative().to_s; 2653 #if not qr.isAssociative() 2654 # puts "warning: qr is not associative"; 2655 #end 2656 if d == 0 2657 r = SolvableQuotient.new(qr); 2658 else 2659 if n == 1 2660 r = SolvableQuotient.new(qr,d); 2661 else 2662 r = SolvableQuotient.new(qr,d,n); 2663 end 2664 end 2665 return RingElem.new(r); 2666 end
Create JAS
GenVector ring element.
# File examples/jas.rb 5899 def Vec(cofac,n,v=nil) 5900 cf = cofac; 5901 if cofac.is_a? RingElem 5902 cf = cofac.elem.factory(); 5903 elsif cofac.is_a? Ring 5904 cf = cofac.ring; 5905 end 5906 if n.is_a? RingElem 5907 n = n.elem; 5908 end 5909 if v.is_a? RingElem 5910 v = v.elem; 5911 end 5912 if v.is_a? Array 5913 v = rbarray2arraylist(v,cf,rec=1); 5914 end 5915 vr = GenVectorModul.new(cf,n); 5916 if v == nil 5917 r = GenVector.new(vr); 5918 else 5919 r = GenVector.new(vr,v); 5920 end 5921 return RingElem.new(r); 5922 end
Create JAS
polynomial WordResidue as ring element.
# File examples/jas.rb 6541 def WRC(ideal,r=0) 6542 if ideal == nil 6543 raise ArgumentError, "No ideal given." 6544 end 6545 if ideal.is_a? WordPolyIdeal 6546 #puts "ideal = " + str(ideal) + "\n"; 6547 #ideal = Java::EduJasApplication::WordIdeal.new(ideal.ring,ideal.list); 6548 ideal = ideal.ideal; 6549 #ideal.doGB(); 6550 end 6551 if not ideal.is_a? WordIdeal 6552 raise ArgumentError, "No word ideal given." 6553 end 6554 #puts "ideal.getList().get(0).ring.ideal = #{ideal.getList().get(0).ring.ideal}\n"; 6555 if ideal.getList().get(0).ring.is_a? WordResidueRing 6556 rc = WordResidueRing.new( ideal.getList().get(0).ring.ideal ); 6557 else 6558 rc = WordResidueRing.new(ideal); 6559 end 6560 if r.is_a? RingElem 6561 r = r.elem; 6562 end 6563 if r == 0 6564 r = WordResidue.new(rc); 6565 else 6566 r = WordResidue.new(rc,r); 6567 end 6568 return RingElem.new(r); 6569 end
Create JAS
ModInteger as ring element.
# File examples/jas.rb 223 def ZM(m,z=0,field=false) 224 if m.is_a? RingElem 225 m = m.elem; 226 end 227 if z.is_a? RingElem 228 z = z.elem; 229 end 230 if z != 0 and ( z == true or z == false ) 231 field = z; 232 z = 0; 233 end 234 if m < ModLongRing::MAX_LONG 235 if m < ModIntRing::MAX_INT 236 if field 237 mf = ModIntRing.new(m,field); 238 else 239 mf = ModIntRing.new(m); 240 end 241 r = ModInt.new(mf,z); 242 else 243 if field 244 mf = ModLongRing.new(m,field); 245 else 246 mf = ModLongRing.new(m); 247 end 248 r = ModLong.new(mf,z); 249 end 250 else 251 if field 252 mf = ModIntegerRing.new(m,field); 253 else 254 mf = ModIntegerRing.new(m); 255 end 256 r = ModInteger.new(mf,z); 257 end 258 return RingElem.new(r); 259 end
Create JAS
ModInt as ring element.
# File examples/jas.rb 271 def ZMI(m,z=0,field=false) 272 return ZM(m,z,field); 273 end
Create JAS
ModLong as ring element.
# File examples/jas.rb 264 def ZML(m,z=0,field=false) 265 return ZM(m,z,field); 266 end
Create JAS
BigInteger as ring element.
# File examples/jas.rb 206 def ZZ(z=0) 207 if z.is_a? RingElem 208 z = z.elem; 209 end 210 if z == 0 211 r = Java::EduJasArith::BigInteger.new(); 212 else 213 #puts "z = #{z} : #{z.class} " 214 r = Java::EduJasArith::BigInteger.new(z); 215 end 216 return RingElem.new(r); 217 end
Inject variables for generators in given environment.
# File examples/jas.rb 80 def inject_gens(env) 81 env.class.instance_eval( "attr_accessor :generators;" ) 82 if env.generators == nil 83 env.generators = {}; 84 end 85 #puts "existing generators(#{env}): " + env.generators.keys().join(", "); 86 redef = [] 87 for i in self.gens() 88 begin 89 ivs = nameFromValue(i); 90 if ivs == nil 91 next 92 end; 93 #puts "string2: #{ivs} = " + ivs.class.to_s; 94 #puts "string3: #{ivs} = " + (env.instance_eval( "#{ivs};" )); 95 if env.generators[ ivs ] != nil 96 #puts "redefining global variable #{ivs}"; 97 redef << ivs; 98 end 99 env.generators[ ivs ] = i; 100 env.instance_eval( "def #{ivs}; @generators[ '#{ivs}' ]; end" ) 101 #puts "def #{ivs}; @generators[ '#{ivs}' ]; end" 102 #puts "@generators[ '#{ivs}' ] = #{i}" 103 if self.class.auto_lowervar 104 first = ivs.slice(0,1); 105 if first.count('A-Z') > 0 106 first = first.downcase 107 ivl = first + ivs.slice(1,ivs.length); 108 puts "warning: '" + str(ivs) + "' additionaly defined as '" + str(ivl) + "' to avoid constant semantics" 109 if env.generators[ ivl ] != nil 110 #puts "redefining global variable #{ivl}"; 111 redef << ivl; 112 end 113 env.generators[ ivl ] = i; 114 env.instance_eval( "def #{ivl}; @generators[ '#{ivs}' ]; end" ) 115 end 116 end 117 rescue => e 118 #puts "error: #{ivs} = " + i.to_s + ", class = " + i.class.to_s; 119 puts "error: #{ivs} = " + i.to_s + ", e = " + e.to_s; 120 end 121 end 122 puts "globally(#{env}) defined variables: " + env.generators.keys().join(", "); 123 if redef.size > 0 124 puts "WARN: redefined variables: " + redef.join(", "); 125 end 126 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. Otherwise, item is returned unchanged.
# File examples/jas.rb 2994 def makeJasArith(item) 2995 #puts "item type(#{item}) = #{item.class}\n"; 2996 if item.is_a? Integer 2997 return BigInteger.new( item ); 2998 end 2999 if item.is_a? Rational 3000 return BigRational.new( item.numerator ).divide( BigRational.new( item.denominator ) ); 3001 end 3002 if item.is_a? Float # ?? what to do ?? 3003 return BigDecimal.new( item.to_s ); 3004 end 3005 if item.is_a? Array 3006 if item.size > 2 3007 puts "len(item) > 2, remaining items ignored\n"; 3008 end 3009 puts "item[0] type(#{item[0]}) = #{item[0].class}\n"; 3010 if item.size > 1 3011 re = makeJasArith( item[0] ); 3012 if not re.isField() 3013 re = BigRational.new( re.val ); 3014 end 3015 im = makeJasArith( item[1] ); 3016 if not im.isField() 3017 im = BigRational.new( im.val ); 3018 end 3019 jasArith = BigComplex.new( re, im ); 3020 else 3021 re = makeJasArith( item[0] ); 3022 if not re.isField() 3023 re = BigRational.new( re.val ); 3024 end 3025 jasArith = BigComplex.new( re ); 3026 end 3027 return jasArith; 3028 end 3029 puts "unknown item type(#{item}) = #{item.class}\n"; 3030 return item; 3031 end
Get a meaningful name from a value.
i ist the given value.
# File examples/jas.rb 133 def nameFromValue(i) 134 ivs = i.to_s 135 #puts "string1: #{ivs} = " + ivs.class.to_s; 136 ivs = ivs.gsub(" ",""); 137 ivs = ivs.gsub("\n",""); 138 ivs = ivs.gsub(",",""); 139 ivs = ivs.gsub("(",""); 140 ivs = ivs.gsub(")",""); 141 ivs = ivs.gsub("+",""); 142 #ivs = ivs.gsub("*",""); 143 ivs = ivs.gsub("/","div"); 144 #ivs = ivs.gsub("|","div"); 145 ivs = ivs.gsub("{",""); 146 ivs = ivs.gsub("}",""); 147 ivs = ivs.gsub("[",""); 148 ivs = ivs.gsub("]",""); 149 i = ivs.index("BigO"); 150 if i #and i > 0 151 ivs = ivs[0,i]; 152 #puts "BigO index = #{i}"; 153 end 154 if ivs == "1" 155 ivs = "one" 156 end 157 if ivs[0] == "1"[0] and not ivs.match(/\A[0-9].*/) 158 r = ivs[1,ivs.size-1].to_s; 159 ivs = "one" 160 if r != nil 161 ivs = ivs + r 162 end 163 end 164 #if ivs[0,2] == "0i1"[0,2] or ivs[0,2] == "0I1"[0,2] 165 if ivs == "0i1" or ivs == "0I1" 166 ivs = "i" 167 end 168 #puts "string: #{ivs} of " + i.to_s; 169 if ivs.include?("|") or ivs.match(/\A[0-9].*/) 170 #puts "string2: #{ivs} = " + ivs.class.to_s; 171 ivs = nil 172 end 173 return ivs 174 end
Turn off automatic parallel threads usage.
# File examples/jas.rb 70 def noThreads() 71 puts "nt = ", ComputerThreads.NO_THREADS; 72 ComputerThreads.setNoThreads(); #NO_THREADS = #0; #1; #true; 73 puts "\nnt = ", ComputerThreads.NO_THREADS; 74 puts 75 end
Convert a Ruby array to a Java ArrayList.
If list is a Ruby array, it is converted, else list is left unchanged.
# File examples/jas.rb 2948 def rbarray2arraylist(list,fac=nil,rec=1) 2949 #puts "list type(#{list}) = #{list.class}\n"; 2950 if list.is_a? Array 2951 ll = ArrayList.new(); 2952 for e in list 2953 t = true; 2954 if e.is_a? RingElem 2955 t = false; 2956 e = e.elem; 2957 end 2958 if e.is_a? Array 2959 if rec <= 1 2960 e = makeJasArith(e); 2961 else 2962 t = false; 2963 e = rbarray2arraylist(e,fac,rec-1); 2964 end 2965 end 2966 begin 2967 #n = e.getClass().getSimpleName(); 2968 if e.is_a? ArrayList 2969 t = false; 2970 end 2971 rescue 2972 #pass; 2973 end 2974 if t and fac != nil 2975 #puts "e.p(#{e}) = #{e.class}, #{fac.toScriptFactory()}\n"; 2976 e = fac.parse( str(e) ); #or makeJasArith(e) ? 2977 end 2978 ll.add(e); 2979 end 2980 list = ll; 2981 end 2982 #puts "list type(#{list}) = #{list.class}\n"; 2983 return list 2984 end
Configure the log4j system and start logging.
BasicConfigurator from log4j version 1 is no more supported, please use log4j2 configuration.
# File examples/jas.rb 43 def startLog() 44 #puts "BasicConfigurator from log4j version 1 is no more supported, please use log4j2 configuration"; 45 end
Mimic Python str() function.
# File examples/jas.rb 52 def str(s) 53 return s.to_s; 54 end
Terminate the running thread pools.
# File examples/jas.rb 61 def terminate() 62 ComputerThreads.terminate(); 63 end