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: handle nested nAry functions #347

Closed crowlogic closed 6 months ago

crowlogic commented 6 months ago
   F                   = RealFunction.express("F", "z➔Σ(n➔zⁿ*∏k➔α[k]₍ₙ₎{k=1…p}/n!*∏k➔β[k]₍ₙ₎{k=1…q}){n=0…N}", context);

its better to require the arrow to come after the indexing variable of a Nary operator, that makes it such that its easier to read for whoevers reading it and also the parser doesnt have to keep track of how much other { characters to ignore before it gets to the one meant for it

new class arb.expressions.nodes.Variable at pos -1
parseRoot z➔Σ(zⁿ*∏α[k]₍ₙ₎{k=1…p}/n!*∏β[k]₍ₙ₎{k=1…q}){n=0…N}
new class arb.expressions.nodes.nary.Sum at pos 3
new class arb.expressions.nodes.LiteralConstant at pos 19
new class arb.expressions.nodes.Variable at pos 21
new class arb.expressions.nodes.Variable at pos 24
Exception in thread "main" arb.exceptions.UndefinedReferenceException: Undefined reference to variable 'n' in Expression[expression=z➔Σ(zⁿ*∏α[k]₍ₙ₎{k=1…p}/n!*∏β[k]₍ₙ₎{k=1…q}){n=0…N}, className=F, functionName=F, recursive=false, functionClass=interface arb.functions.real.RealFunction], independent variable is z and parentExpression is null
    at arb4j/arb.expressions.nodes.Variable.resolveReference(Variable.java:280)
    at arb4j/arb.expressions.nodes.Variable.<init>(Variable.java:117)
    at arb4j/arb.expressions.Expression.newVariable(Expression.java:1272)
    at arb4j/arb.expressions.Expression.resolveFunctionOrVariableReference(Expression.java:1441)
    at arb4j/arb.expressions.Expression.evaluate(Expression.java:570)
    at arb4j/arb.expressions.Expression.exponentiate(Expression.java:701)
    at arb4j/arb.expressions.Expression.multiplyAndDivide(Expression.java:1210)
    at arb4j/arb.expressions.Expression.exponentiateMultiplyAndDivide(Expression.java:741)
    at arb4j/arb.expressions.Expression.resolve(Expression.java:526)
    at arb4j/arb.expressions.Expression.parseRoot(Expression.java:693)
    at arb4j/arb.expressions.Compiler.express(Compiler.java:143)
    at arb4j/arb.expressions.Compiler.express(Compiler.java:156)
    at arb4j/arb.expressions.Compiler.express(Compiler.java:109)
    at arb4j/arb.expressions.Expression.instantiate(Expression.java:150)
    at arb4j/arb.functions.real.RealFunction.express(RealFunction.java:635)
    at arb4j/arb.functions.real.RealFunction.express(RealFunction.java:630)
    at arb4j/arb.functions.polynomials.HypergeometricPolynomialSequence.<init>(HypergeometricPolynomialSequence.java:62)
    at arb4j/arb.functions.polynomials.HypergeometricPolynomialSequence.main(HypergeometricPolynomialSequence.java:32)
crowlogic commented 6 months ago

in NAryOperation

  protected String parseFactorExpression()
  {
    int length   = expression.expression.length();
    int startPos = expression.position;
    /**
     * TODO: read until first rightArrow character, the chars between the operator
     * symbol and the arrow are the indexing-variable, when it gets to the end of
     * the expression and the range is expressed {n=a...b} the variable n must match
     * the name that was designated with the arrow , this keeps the parser markovian
     * so that it doesnt have to keep track of how deep the inner expression goes
     * without knowing what the index variable is
     */
    while (expression.character != '{' && expression.position < length)
    {
      expression.nextCharacter();
    }

    return expression.expression.substring(startPos, expression.position).trim();
  }
crowlogic commented 6 months ago
new class arb.expressions.nodes.Variable at pos -1
parseRoot z➔Σn➔zⁿ*∏k➔α[k]₍ₙ₎{k=1…p}/n!*∏k➔β[k]₍ₙ₎{k=1…q}{n=0…N}
new class arb.expressions.nodes.nary.Sum at pos 3
Exception in thread "main" java.lang.AssertionError: TODO: set index with parseName then move the expression.position so that it points to the first character after the arrow
    at arb4j/arb.expressions.nodes.nary.NAryOperation.parseFactorExpression(NAryOperation.java:178)
    at arb4j/arb.expressions.nodes.nary.NAryOperation.<init>(NAryOperation.java:158)
    at arb4j/arb.expressions.nodes.nary.Sum.<init>(Sum.java:35)
    at arb4j/arb.expressions.Expression.evaluate(Expression.java:561)
    at arb4j/arb.expressions.Expression.exponentiate(Expression.java:701)
    at arb4j/arb.expressions.Expression.exponentiateMultiplyAndDivide(Expression.java:740)
    at arb4j/arb.expressions.Expression.resolve(Expression.java:526)
    at arb4j/arb.expressions.Expression.parseRoot(Expression.java:693)
    at arb4j/arb.expressions.Compiler.express(Compiler.java:143)
    at arb4j/arb.expressions.Compiler.express(Compiler.java:156)