Skip to content

Commit

Permalink
misc integer factorial stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
crowlogic committed Jan 28, 2024
1 parent b1e2b99 commit 24456ef
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 0 deletions.
3 changes: 3 additions & 0 deletions native/Functions.i
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ void arb_add_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
int fmpz_pow_fmpz(fmpz_t a, const fmpz_t b, const fmpz_t e);
void arb_mul_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
void arb_sub_fmpz(arb_t z, const arb_t x, const fmpz_t y, slong prec);
void fmpz_fac_ui(fmpz_t f, ulong n);
void fmpz_rfac_ui(fmpz_t r, const fmpz_t x, ulong k);
void fmpz_rfac_uiui(fmpz_t r, ulong x, ulong k);

void fmpz_mul(fmpz_t f, const fmpz_t g, const fmpz_t h);
void fmpz_divexact(fmpz_t f, const fmpz_t g, const fmpz_t h);
Expand Down
36 changes: 36 additions & 0 deletions src/main/java/arb/Integer.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,24 @@ public Real factorial(int bits, Real result)
return result;
}

public static Integer factorial(long n, Integer result)
{
arblib.fmpz_fac_ui(result.swigCPtr, n);
return result;
}

/**
* Calls this{@link #factorial(long, Integer)} putting the result into a newly
* instantiated Integer
*
* @param n
* @return
*/
public static Integer factorial(long n)
{
return factorial(n, new Integer());
}

public static Real factorial(long n, int bits, Real result)
{
arblib.arb_fac_ui(result, n, bits);
Expand Down Expand Up @@ -265,6 +283,24 @@ public Integer pow(Integer operand, int bits, Integer result)
return result;
}

/**
* Shortcut for this{@link #div(Integer, int, Integer)} since it doesnt need
* bits
*
* @param operand
* @param result
* @return
*/
public Integer div(Integer operand, Integer result)
{
return div(operand, 0, result);
}

public Integer div(Integer operand)
{
return div(operand,this);
}

/**
* Division, rounded to integer
*
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/arb/arblib.java
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ public static void arb_sub_fmpz(Real z, Real x, long y, int prec) {
arblibJNI.arb_sub_fmpz(Real.getCPtr(z), z, Real.getCPtr(x), x, y, prec);
}

public static void fmpz_fac_ui(long f, long n) {
arblibJNI.fmpz_fac_ui(f, n);
}

public static void fmpz_mul(long f, long g, long h) {
arblibJNI.fmpz_mul(f, g, h);
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/arb/arblibJNI.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public class arblibJNI {
public final static native int fmpz_pow_fmpz(long jarg1, long jarg2, long jarg3);
public final static native void arb_mul_fmpz(long jarg1, Real jarg1_, long jarg2, Real jarg2_, long jarg3, int jarg4);
public final static native void arb_sub_fmpz(long jarg1, Real jarg1_, long jarg2, Real jarg2_, long jarg3, int jarg4);
public final static native void fmpz_fac_ui(long jarg1, long jarg2);
public final static native void fmpz_mul(long jarg1, long jarg2, long jarg3);
public final static native void fmpz_divexact(long jarg1, long jarg2, long jarg3);
public final static native void fmpz_add(long jarg1, long jarg2, long jarg3);
Expand Down

0 comments on commit 24456ef

Please sign in to comment.