Skip to content

Commit

Permalink
https://github.com/crowlogic/arb4j/issues/253
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlogic committed Nov 28, 2024
1 parent 2a69e5a commit c173745
Show file tree
Hide file tree
Showing 7 changed files with 193 additions and 266 deletions.
15 changes: 12 additions & 3 deletions native/Real.i
Original file line number Diff line number Diff line change
Expand Up @@ -653,14 +653,23 @@ import arb.utensils.Utensils;
return res;
}

public Real add( Integer z, int bits, Real result )
{
arblib.arb_add_fmpz(result, this, z.swigCPtr, bits);
public Real add( Integer i, int bits, Real result )
{
assert i != null : "exponent is null";
assert result != null : "result is null";
assert i.swigCPtr != 0 : "exponent's pointer is null";
assert result.swigCPtr != 0 : "result's pointer is null";
arblib.arb_pow_fmpz(result, this, i.swigCPtr, bits);
arblib.arb_add_fmpz(result, this, i.swigCPtr, bits);
return result;
}

public Real pow( Integer i, int bits, Real result )
{
assert i != null : "exponent is null";
assert result != null : "result is null";
assert i.swigCPtr != 0 : "exponent's pointer is null";
assert result.swigCPtr != 0 : "result's pointer is null";
arblib.arb_pow_fmpz(result, this, i.swigCPtr, bits);
return result;
}
Expand Down
15 changes: 12 additions & 3 deletions src/main/java/arb/Real.java
Original file line number Diff line number Diff line change
Expand Up @@ -680,14 +680,23 @@ public RealPolynomial sub(Real a, int bits, RealPolynomial res)
return res;
}

public Real add( Integer z, int bits, Real result )
{
arblib.arb_add_fmpz(result, this, z.swigCPtr, bits);
public Real add( Integer i, int bits, Real result )
{
assert i != null : "exponent is null";
assert result != null : "result is null";
assert i.swigCPtr != 0 : "exponent's pointer is null";
assert result.swigCPtr != 0 : "result's pointer is null";
arblib.arb_pow_fmpz(result, this, i.swigCPtr, bits);
arblib.arb_add_fmpz(result, this, i.swigCPtr, bits);
return result;
}

public Real pow( Integer i, int bits, Real result )
{
assert i != null : "exponent is null";
assert result != null : "result is null";
assert i.swigCPtr != 0 : "exponent's pointer is null";
assert result.swigCPtr != 0 : "result's pointer is null";
arblib.arb_pow_fmpz(result, this, i.swigCPtr, bits);
return result;
}
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/arb/expressions/Compiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
import arb.functions.rational.ComplexRationalHypergeometricFunction;
import arb.functions.rational.LommelPolynomial;
import arb.functions.rational.RationalHypergeometricFunction;
import arb.functions.real.RealFunction;
import arb.utensils.Utensils;

/**
Expand Down Expand Up @@ -329,6 +330,7 @@ public static String getMethodDescriptor(Class<?> ret, Class<?>... args)
typePrefixes.put(ComplexFraction.class, "fℂ");
typePrefixes.put(SphericalBesselFunction.class, "sph");
typePrefixes.put(IntegerPolynomial.class, "Xℤ");
typePrefixes.put(RealFunction.class, "funcℝ");
}

public static String getVariablePrefix(Class<?> type)
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/arb/expressions/nodes/VariableNode.java
Original file line number Diff line number Diff line change
Expand Up @@ -286,11 +286,14 @@ public void generateReferenceToIndeterminantVariable(MethodVisitor mv)
}
else
{
assert !(reference.type.isInterface()
|| reference.type == Object.class) : "reference type "
+ reference.type
+ " should not be an Object or an interface";
expression.allocateIntermediateVariable(mv, reference.type);
if (reference.type.equals(Object.class))
{
Compiler.loadInputParameter(mv);
}
else
{
expression.allocateIntermediateVariable(mv, reference.type);
}
}
Compiler.invokeVirtualMethod(mv, reference.type, "identity", reference.type);
}
Expand Down
152 changes: 152 additions & 0 deletions src/main/java/arb/functions/real/TestCompiledDerivative.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
package arb.functions.real;

import arb.Initializable;
import arb.Integer;
import arb.Real;
import arb.Typesettable;
import arb.documentation.BusinessSourceLicenseVersionOnePointOne;
import arb.documentation.TheArb4jLibrary;
import arb.expressions.nodes.DerivativeNode;
import junit.framework.TestCase;

/**
* Decompiled {@link DerivativeNode} test function
*
* @see BusinessSourceLicenseVersionOnePointOne © terms of the
* {@link TheArb4jLibrary}
*/
public class TestCompiledDerivative implements
RealFunctional<Object, RealFunction>,
Typesettable,
AutoCloseable,
Initializable
{
public boolean isInitialized;
public final Integer cℤ2 = new Integer("3");
public final Integer cℤ1 = new Integer("2");
public final Integer cℤ4 = new Integer("1");
public final Integer cℤ3 = new Integer("0");
public Real a;
public Real b;
public Real c;
public Real ifuncℝ4 = new Real();
public Real ifuncℝ5 = new Real();
public Integer iℤ2 = new Integer();
public Real ifuncℝ6 = new Real();
public Integer iℤ1 = new Integer();
public Real ifuncℝ7 = new Real();
public Real ifuncℝ1 = new Real();
public Real ifuncℝ2 = new Real();
public Real ifuncℝ3 = new Real();
public Real ifuncℝ8 = new Real();

public static void main(String args[])
{
try ( TestCompiledDerivative derivative = new TestCompiledDerivative())
{
derivative.a = Real.named("a").set(2);
derivative.b = Real.named("b").set(4);
derivative.c = Real.named("c").set(6);

RealFunction d = derivative.evaluate(null, 128);
double val = d.eval(2.3);
TestCase.assertEquals(115.61999999999998, val);
System.out.format("%s(2.3)=%s\n", d, val);
}

}

@Override
public Class<RealFunction> coDomainType()
{
return RealFunction.class;
}

@Override
public RealFunction evaluate(Object in, int order, int bits, RealFunction result)
{
if (!isInitialized)
{
initialize();
}
RealFunction realFunction = new RealFunction()
{

@Override
public Real evaluate(Real input, int order, int bits, Real res)
{

return a.add(b.mul(cℤ1.mul(input.pow(cℤ1.sub(cℤ4, bits, iℤ1), bits, ifuncℝ1), bits, ifuncℝ2), bits, ifuncℝ3),
bits,
ifuncℝ4)
.add(c.mul(cℤ2.mul(input.pow(cℤ2.sub(cℤ4, bits, iℤ2), bits, ifuncℝ5), bits, ifuncℝ6), bits, ifuncℝ7),
bits,
ifuncℝ8);

}

@Override
public String toString()
{
return TestCompiledDerivative.this.toString();
}
};
return realFunction;
}

@Override
public void initialize()
{
if (isInitialized)
{
throw new AssertionError("Already initialized");
}
else if (a == null)
{
throw new AssertionError("x-∂a*x+b*x²+c*x³⁄∂x.a is null");
}
else if (b == null)
{
throw new AssertionError("x-∂a*x+b*x²+c*x³⁄∂x.b is null");
}
else if (c == null)
{
throw new AssertionError("x-∂a*x+b*x²+c*x³⁄∂x.c is null");
}
else
{
isInitialized = true;
}
}

@Override
public void close()
{
cℤ2.close();
cℤ1.close();
cℤ4.close();
cℤ3.close();
ifuncℝ4.close();
ifuncℝ5.close();
iℤ2.close();
ifuncℝ6.close();
iℤ1.close();
ifuncℝ7.close();
ifuncℝ1.close();
ifuncℝ2.close();
ifuncℝ3.close();
ifuncℝ8.close();
}

@Override
public String toString()
{
return "x➔∂a*x+b*x²+c*x³/∂x";
}

@Override
public String typeset()
{
return "a + b \\cdot 2 \\cdot {x}^{(\\left(2-1\\right))} + c \\cdot 3 \\cdot {x}^{(\\left(3-1\\right))}";
}
}
Loading

0 comments on commit c173745

Please sign in to comment.