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

expression compiler: refrain from generating fields for variables in the context that arent referenced in the particular sub-expression or any of its contained(descendent) expressions #354

Closed crowlogic closed 5 months ago

crowlogic commented 6 months ago

for example, the following variables

  public Integer  p;
  public Integer  q;
  public Real     α;
  public Real     z;

dont need to be generated as part of this class

package arb.functions.real;

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

public class factorℝ2 implements
                      Function<Integer, Real>
{
  private boolean isInitialized;
  public Integer  n;
  public Integer  p;
  public Integer  q;
  public Real     α;
  public Real     β;
  public Real     z;

  public Real evaluate(Integer in, int order, int bits, Real result)
  {
    if (!isInitialized)
    {
      initialize();
    }

    return β.get(in).risingFactorial(n, bits, result);
  }

  public void initialize()
  {
    if (isInitialized)
    {
      throw new AssertionError("Already initialized");
    }
    else if (β == null)
    {
      throw new AssertionError("β is null");
    }
    else
    {
      isInitialized = true;
    }
  }
}