diff --git a/src/main/java/arb/expressions/Compiler.java b/src/main/java/arb/expressions/Compiler.java index c0f78f386..270825349 100644 --- a/src/main/java/arb/expressions/Compiler.java +++ b/src/main/java/arb/expressions/Compiler.java @@ -509,6 +509,10 @@ public static MethodVisitor loadBitsParameterOntoStack(MethodVisitor methodVisit { CompiledExpressionClassLoader loader = context != null ? context.classLoader : new CompiledExpressionClassLoader(); + if ( context != null && context.classLoader == null ) + { + context.classLoader = loader; + } return (Class) loader.defineClass(className, bytecodes); // return (Class) loader.findClass(className); } diff --git a/src/main/java/arb/expressions/Expression.java b/src/main/java/arb/expressions/Expression.java index f3d8112f9..57d5e5c31 100644 --- a/src/main/java/arb/expressions/Expression.java +++ b/src/main/java/arb/expressions/Expression.java @@ -254,7 +254,6 @@ public static ClassVisitor constructClassVisitor() public Node rootNode; - public boolean variablesDeclared = false; boolean verboseTrace = false; @@ -992,10 +991,10 @@ protected ClassVisitor generateEvaluationMethod(ClassVisitor classVisitor) throw { assert false : "gone surfing"; } - function.rootNode = (Node) rootNode.spliceInto(function); - function.className = className + "func"; + function.rootNode = (Node) rootNode.spliceInto(function); + function.className = className + "func"; function.rootNode.isResult = true; - + // Generate the implementation function.generate(); @@ -1011,9 +1010,8 @@ protected ClassVisitor generateEvaluationMethod(ClassVisitor classVisitor) throw { String fieldName = entry.getKey(); Class fieldType = entry.getValue().getClass(); - mv.visitInsn(DUP); - loadThisOntoStack(mv); - loadFieldOntoStack(mv, fieldName, fieldType); + Compiler.duplicateTopOfTheStack(mv); + loadThisFieldOntoStack(mv, fieldName, fieldType); Compiler.putField(mv, function.className, fieldName, fieldType); } } @@ -1026,6 +1024,8 @@ protected ClassVisitor generateEvaluationMethod(ClassVisitor classVisitor) throw // Return the new function instance mv.visitInsn(ARETURN); + + function.defineClass(); } else { @@ -2025,7 +2025,7 @@ protected Expression storeInstructions(ClassVisitor classVisitor) if (context == null) { - context = new Context(); + context = new Context(); } if (Expression.trace) @@ -2061,7 +2061,7 @@ protected Expression storeInstructions(ClassVisitor classVisitor) if (context == null) { - context = new Context(); + context = new Context(); } if (Expression.trace) diff --git a/src/main/java/arb/expressions/nodes/VariableNode.java b/src/main/java/arb/expressions/nodes/VariableNode.java index f35d1738f..e5793ef4b 100644 --- a/src/main/java/arb/expressions/nodes/VariableNode.java +++ b/src/main/java/arb/expressions/nodes/VariableNode.java @@ -591,7 +591,7 @@ else if (ascendentInput) { returnType = reference.type(); } - assert !returnType.isInterface() : "returnType is " + returnType + " and therefore cannot be instantiated"; + //assert !returnType.isInterface() : "returnType is " + returnType + " and therefore cannot be instantiated"; assert returnType != null : "returnType is null for " + this; assert returnType != Object.class : "TODO: tried to return " + returnType diff --git a/src/main/java/arb/functions/real/RealFunctional.java b/src/main/java/arb/functions/real/RealFunctional.java index 03fd77f2b..e23cc0dde 100644 --- a/src/main/java/arb/functions/real/RealFunctional.java +++ b/src/main/java/arb/functions/real/RealFunctional.java @@ -29,4 +29,14 @@ public static RealFunctional express(String name, String expression, Cont return Function.express(Object.class, RealFunction.class, RealFunctional.class, name, expression, context); } + public default RealFunction evaluate() + { + return evaluate(null, 0); + } + + public default RealFunction evaluate(int bits) + { + return evaluate(null, bits); + } + } \ No newline at end of file diff --git a/src/main/java/arb/functions/real/RealNullaryFunctional.java b/src/main/java/arb/functions/real/RealNullaryFunctional.java new file mode 100644 index 000000000..7d130985b --- /dev/null +++ b/src/main/java/arb/functions/real/RealNullaryFunctional.java @@ -0,0 +1,45 @@ +package arb.functions.real; + +import arb.documentation.BusinessSourceLicenseVersionOnePointOne; +import arb.documentation.TheArb4jLibrary; +import arb.expressions.Context; +import arb.functions.Function; +import arb.functions.NullaryFunction; + +/** + * + * @see BusinessSourceLicenseVersionOnePointOne © terms of the + * {@link TheArb4jLibrary} + */ +public interface RealNullaryFunctional extends + RealFunctional, + NullaryFunction +{ + + @Override + default RealFunction evaluate(int bits) + { + return evaluate(null, 0, bits, null); + } + + public default RealFunction evaluate() + { + return evaluate(null, 0); + } + + public static RealNullaryFunctional express(String expression, Context context) + { + return express(null, expression, context); + } + + public static RealNullaryFunctional express(String expression) + { + return express(null, expression, null); + } + + public static RealNullaryFunctional express(String name, String expression, Context context) + { + return Function.express(Object.class, RealFunction.class, RealNullaryFunctional.class, name, expression, context); + } + +} diff --git a/src/test/java/arb/expressions/ExpressionTest.java b/src/test/java/arb/expressions/ExpressionTest.java index 387979aa3..f31eff10d 100644 --- a/src/test/java/arb/expressions/ExpressionTest.java +++ b/src/test/java/arb/expressions/ExpressionTest.java @@ -19,6 +19,7 @@ import arb.functions.real.RealFunction; import arb.functions.real.RealFunctional; import arb.functions.real.RealNullaryFunction; +import arb.functions.real.RealNullaryFunctional; import arb.functions.real.TestCompiledDerivative; import junit.framework.TestCase; @@ -37,8 +38,8 @@ public static void testAFractionConstantTimesAFractionConstant() f.simplify(); assertEquals("3/4", f.toString()); RationalNullaryFunction instance = f.instantiate(); - RationalFunction val = instance.evaluate(); - Fraction hmm = val.evaluate(new Fraction()); + RationalFunction val = instance.evaluate(); + Fraction hmm = val.evaluate(new Fraction()); assertEquals(0.75, hmm.doubleValue()); } @@ -165,12 +166,19 @@ public void testRealPolynomialDerivative() */ public void testRealFunctionDerivative() { - var context = new Context(Real.named("a"), - Real.named("b"), - Real.named("c")); - var x = RealFunctional.express("x->∂a*x+b*x²+c*x³/∂x", context); - var y = x.evaluate(null, 128); - assertEquals("2*a*x+b", y.toString()); + var context = new Context(Real.named("a").set(2), + Real.named("b").set(4), + Real.named("c").set(6)); + RealNullaryFunctional x = RealNullaryFunctional.express("x->∂a*x+b*x²+c*x³/∂x", context); + var poly = x.evaluate(); + + var y = poly.evaluate(new Real("2.3", + 128), + 1, + 128, + new Real()); + y.printPrecision = false; + assertEquals("115.62", y.toString()); } public void testRationalFunctionDerivative() diff --git a/todoList.txt b/todoList.txt index 6bc09593d..d46530104 100644 --- a/todoList.txt +++ b/todoList.txt @@ -3,5 +3,4 @@ TODO: builtin sykbols for the classical orthogonal polynomials "limit" is null at arb4j/arb.expressions.nodes.IntegralNode.evaluateIndefiniteIntegralAt(IntegralNode.java:217) todo: mouse wheel zooms control or whole scene expr compiler: fractional derivatices -java.lang.NoClassDefFoundError: k-2*j(k,x)funcat k-2*j(k,x).evaluate(Unknown Source)at arb4j/arb.functions.Function.evaluate(Function.java:240)at arb4j/arb.functions.Function.evaluate(Function.java:220)at arb4j/arb.functions.integer.Sequence.evaluate(Sequence.java:47)at arb4j/arb.expressions.nodes.unary.SphericalBesselFunctionNodeOfTheFirstKindTest.testj0ViaRealFunctionalExpression(SphericalBesselFunctionNodeOfTheFirstKindTest.java:24)at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)at java.base/java.lang.reflect.Method.invoke(Method.java:580)at junit@4.13.2/junit.framework.TestCase.runTest(TestCase.java:177)at junit@4.13.2/junit.framework.TestCase.runBare(TestCase.java:142)at junit@4.13.2/junit.framework.TestResult$1.protect(TestResult.java:122)at junit@4.13.2/junit.framework.TestResult.runProtected(TestResult.java:142)at junit@4.13.2/junit.framework.TestResult.run(TestResult.java:125)at junit@4.13.2/junit.framework.TestCase.run(TestCase.java:130)at junit@4.13.2/junit.framework.TestSuite.runTest(TestSuite.java:241)at junit@4.13.2/junit.framework.TestSuite.run(TestSuite.java:236)at junit@4.13.2/org.junit.internal.runners.JUnit38ClassRunner.run(JUnit38ClassRunner.java:90)at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:93)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:530)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:758)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:453)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:211)Caused by: java.lang.ClassNotFoundException: k-2*j(k,x)funcat java.base/java.lang.ClassLoader.findClass(ClassLoader.java:735)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:595)at java.base/java.lang.ClassLoader.loadClass(ClassLoader.java:528)... 22 more -arb.exceptions.UndefinedReferenceException: Undefined reference to variable 'a' at position=-1 in expression=null, independent variable is x and ascendentExpression is null, remaining='null'at arb4j/arb.expressions.nodes.VariableNode.resolveInheritedVariableReference(VariableNode.java:468)at arb4j/arb.expressions.nodes.VariableNode.resolveReference(VariableNode.java:539)at arb4j/arb.expressions.nodes.VariableNode.(VariableNode.java:115)at arb4j/arb.expressions.nodes.VariableNode.spliceInto(VariableNode.java:560)at arb4j/arb.expressions.nodes.binary.AdditionNode.spliceInto(AdditionNode.java:49)at arb4j/arb.expressions.nodes.binary.AdditionNode.spliceInto(AdditionNode.java:49)at arb4j/arb.expressions.nodes.DerivativeNode.spliceInto(DerivativeNode.java:168)at arb4j/arb.expressions.Expression.generateEvaluationMethod(Expression.java:998)at arb4j/arb.expressions.Expression.generate(Expression.java:812)at arb4j/arb.expressions.Expression.defineClass(Expression.java:595)at arb4j/arb.expressions.Expression.getInstance(Expression.java:1319)at arb4j/arb.expressions.Expression.instantiate(Expression.java:1468)at arb4j/arb.functions.Function.instantiate(Function.java:126)at arb4j/arb.functions.Function.express(Function.java:89)at arb4j/arb.functions.real.RealFunctional.express(RealFunctional.java:29)at arb4j/arb.functions.real.RealFunctional.express(RealFunctional.java:18)at arb4j/arb.expressions.ExpressionTest.testRealFunctionDerivative(ExpressionTest.java:171)at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)at java.base/java.lang.reflect.Method.invoke(Method.java:580)at junit@4.13.2/junit.framework.TestCase.runTest(TestCase.java:177)at junit@4.13.2/junit.framework.TestCase.runBare(TestCase.java:142)at junit@4.13.2/junit.framework.TestResult$1.protect(TestResult.java:122)at junit@4.13.2/junit.framework.TestResult.runProtected(TestResult.java:142)at junit@4.13.2/junit.framework.TestResult.run(TestResult.java:125)at junit@4.13.2/junit.framework.TestCase.run(TestCase.java:130)at junit@4.13.2/junit.framework.TestSuite.runTest(TestSuite.java:241)at junit@4.13.2/junit.framework.TestSuite.run(TestSuite.java:236)at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:530)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:758)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:453)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:211) +java.lang.NoSuchMethodError: 'arb.Real arb.Real.j(int, arb.Real)'at k-2*j(k,x)func.evaluate(Unknown Source)at arb4j/arb.functions.real.RealFunction.eval(RealFunction.java:222)at arb4j/arb.expressions.nodes.unary.SphericalBesselFunctionNodeOfTheFirstKindTest.testj0ViaRealFunctionalExpression(SphericalBesselFunctionNodeOfTheFirstKindTest.java:25)at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)at java.base/java.lang.reflect.Method.invoke(Method.java:580)at junit@4.13.2/junit.framework.TestCase.runTest(TestCase.java:177)at junit@4.13.2/junit.framework.TestCase.runBare(TestCase.java:142)at junit@4.13.2/junit.framework.TestResult$1.protect(TestResult.java:122)at junit@4.13.2/junit.framework.TestResult.runProtected(TestResult.java:142)at junit@4.13.2/junit.framework.TestResult.run(TestResult.java:125)at junit@4.13.2/junit.framework.TestCase.run(TestCase.java:130)at junit@4.13.2/junit.framework.TestSuite.runTest(TestSuite.java:241)at junit@4.13.2/junit.framework.TestSuite.run(TestSuite.java:236)at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:128)at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:40)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:530)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:758)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:453)at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:211)