crowlogic / arb4j

arb4j is a Java API for the arbitrary precision ball arithmetic library found at http://arblib.org
Other
1 stars 0 forks source link

make sure all functions are closed in the close() method #398

Closed crowlogic closed 2 months ago

crowlogic commented 3 months ago

A,B,C and E are missing from the close() method implementation of the P class from the JacobiPolynomialSequence implementation


import arb.Integer;
import arb.Real;
import arb.RealPolynomial;
import arb.functions.Function;

public class P implements Function<Integer, RealPolynomial> {
   private boolean isInitialized;
   Integer cℤ2;
   Integer cℤ1;
   Integer cℤ4;
   Real cℝ3;
   public Real α;
   public Real β;
   public RealPolynomial Xℝ10;
   public RealPolynomial Xℝ11;
   public RealPolynomial Xℝ12;
   public Real ℝ30;
   public RealPolynomial Xℝ4;
   public Integer ℤ2;
   public Integer ℤ3;
   public RealPolynomial Xℝ9;
   public RealPolynomial Xℝ6;
   public RealPolynomial Xℝ5;
   public RealPolynomial Xℝ8;
   public RealPolynomial Xℝ7;
   public Real ℝ29;
   public Real ℝ25;
   public Real ℝ26;
   public Real ℝ27;
   public Real ℝ28;
   public P P;
   public final A A = new A();
   public final B B = new B();
   public final C C = new C();
   public final E E = new E();

   public RealPolynomial evaluate(Integer in, int order, int bits, RealPolynomial result) {
      if (!this.isInitialized) {
         this.initialize();
      }
      return switch(in.getSignedValue()) {
         case 0 -> result.set(this.cℤ2);
         case 1 -> ((Real)this.C.evaluate(this.ℝ25.set(this.cℤ2), order, bits, this.ℝ26))
         .mul(result.identity(), bits, this.Xℝ4)
         .sub(this.β, bits, this.Xℝ5)
         .add(this.α, bits, this.Xℝ6)
         .div(this.cℝ3, bits, result);
         default -> ((RealPolynomial)this.A.evaluate(in, order, bits, this.Xℝ7))
         .mul((RealPolynomial)this.P.evaluate(in.sub(this.cℤ2, bits, this.ℤ2), order, bits, this.Xℝ8), bits, this.Xℝ9)
         .sub(
            ((Real)this.B.evaluate(this.ℝ27.set(in), order, bits, this.ℝ28))
               .mul((RealPolynomial)this.P.evaluate(in.sub(this.cℤ4, bits, this.ℤ3), order, bits, this.Xℝ10), bits, this.Xℝ11),
            bits,
            this.Xℝ12
         )
         .div((Real)this.E.evaluate(this.ℝ29.set(in), order, bits, this.ℝ30), bits, result);
      };
   }

   public P() {
      this.cℤ2 = new Integer("1");
      this.cℤ1 = new Integer("0");
      this.cℤ4 = new Integer("2");
      this.cℝ3 = new Real("2.0", 128);
      this.Xℝ10 = new RealPolynomial();
      this.Xℝ11 = new RealPolynomial();
      this.Xℝ12 = new RealPolynomial();
      this.ℝ30 = new Real();
      this.Xℝ4 = new RealPolynomial();
      this.ℤ2 = new Integer();
      this.ℤ3 = new Integer();
      this.Xℝ9 = new RealPolynomial();
      this.Xℝ6 = new RealPolynomial();
      this.Xℝ5 = new RealPolynomial();
      this.Xℝ8 = new RealPolynomial();
      this.Xℝ7 = new RealPolynomial();
      this.ℝ29 = new Real();
      this.ℝ25 = new Real();
      this.ℝ26 = new Real();
      this.ℝ27 = new Real();
      this.ℝ28 = new Real();
   }

   public void initialize() {
      if (this.isInitialized) {
         throw new AssertionError("Already initialized");
      } else if (this.α == null) {
         throw new AssertionError("α is null");
      } else if (this.β == null) {
         throw new AssertionError("β is null");
      } else {
         this.A.α = this.α;
         this.A.β = this.β;
         this.B.α = this.α;
         this.B.β = this.β;
         this.C.α = this.α;
         this.C.β = this.β;
         this.E.α = this.α;
         this.E.β = this.β;
         this.P = new P();
         this.P.α = this.α;
         this.P.β = this.β;
         this.isInitialized = true;
      }
   }

   public void close() {
      this.cℤ2.close();
      this.cℤ1.close();
      this.cℤ4.close();
      this.cℝ3.close();
      this.Xℝ10.close();
      this.Xℝ11.close();
      this.Xℝ12.close();
      this.ℝ30.close();
      this.Xℝ4.close();
      this.ℤ2.close();
      this.ℤ3.close();
      this.Xℝ9.close();
      this.Xℝ6.close();
      this.Xℝ5.close();
      this.Xℝ8.close();
      this.Xℝ7.close();
      this.ℝ29.close();
      this.ℝ25.close();
      this.ℝ26.close();
      this.ℝ27.close();
      this.ℝ28.close();
      this.P.close();
   }

   @Override
   public String toString() {
      return "P:n➔when(n=0,1,n=1,(C(1)*x-β+α)/2.0,else,(A(n)*P(n-1)-B(n)*P(n-2))/E(n))";
   }
}