[PPL-devel] Use of non-integers in Java

Enea Zaffanella zaffanella at cs.unipr.it
Fri Feb 22 18:09:00 CET 2013


On 02/21/2013 03:21 PM, Étienne André wrote:
> Dear PPL developers,
>
> My intern would like to link PPL with a Java program.
>
> I have some experience of using PPL with OCaml, but not with Java.
> And in particular I could not find how to use non-integers coefficients
> (but rationals instead).
> In OCaml, it was easy, e.g., using the "Gmp.Q.from_ints i j" function.
>
> But in the Java interface, I only see constructors from int, big int,
> long and string.
> How can we build some rational coefficients in the Java interface?
>
> Thank you very much,
> --
> Étienne André
> LIPN, Université Paris 13, Sorbonne Paris Cité
> http://www-lipn.univ-paris13.fr/~andre
> <http://www-lipn.univ-paris13.fr/%7Eandre>


Hello.

The coefficient of constraints/generators in the Parma Polyhedra Library 
are *integral by design* (unbounded integers as provided by GMP, in the 
default configuration). Any constraint having non-integer rational 
coefficients can be "normalized" to become a constraint with integer 
coefficients before entering the library (same for generators, possibly 
using an integral divisor for points).

This is the reason why Java class
     parma_polyhedra_library.Coefficient
only has constructors from int, long, BigInteger and String.

As for the OCaml interface, things should be similar:

type linear_expression =
| 	Variable of int
| 	Coefficient of Gmp.Z.t
| 	Unary_Plus of linear_expression
| 	Unary_Minus of linear_expression
| 	Plus of linear_expression * linear_expression
| 	Minus of linear_expression * linear_expression
| 	Times of Gmp.Z.t * linear_expression

Again, only Gmp.Z.t coefficients are allowed.

Can you clarify what you mean by:

 > In OCaml, it was easy, e.g., using the "Gmp.Q.from_ints i j" function.

If you mean that you can use the mpq datatype outside of the Parma 
Polyhedra Library, that is perfectly fine. But the library does not 
support the specification of constraints having mpq coefficients ... so 
if you managed to directly fed these rationals to the PPL interface 
there might be something going wrong.

As for Java ... I don't know if there is a "standard" rational class 
(have seen many different libraries with their own rational).

Cheers,
Enea.




More information about the PPL-devel mailing list