Page 1 of 1

Converting tropical numbers to rational numbers

Posted: 27 Jan 2025, 16:14
by EnisKaya
Hi all,

Consider the following (tropical) number

$n = valuation(12,3);

When I type "print $n -> type -> full_name;", I get "TropicalNumber<Min, Rational>", as expected.

In the cases I'm interested in, the result will always be an integer, and I'd like to see it as a rational number. In other words, I'd like to coerce nonzero tropical numbers into the field of rational numbers. How can I do that?

Thanks in advance!

Re: Converting tropical numbers to rational numbers

Posted: 27 Jan 2025, 16:26
by blorenz
Hi,

you can convert the tropical number with the generic convert_to<...> function:

Code: Select all

polytope > $t = new TropicalNumber<Max>(5); polytope > print convert_to<Rational>($t); 5
You can also directly convert to an integer and it will error if it is not integral. The same function can also convert containers of tropical numbers, e.g. matrices or vectors.

Best,
Benjamin

Re: Converting tropical numbers to rational numbers

Posted: 27 Jan 2025, 20:02
by EnisKaya
Hi,

you can convert the tropical number with the generic convert_to<...> function:

Code: Select all

polytope > $t = new TropicalNumber<Max>(5); polytope > print convert_to<Rational>($t); 5
You can also directly convert to an integer and it will error if it is not integral. The same function can also convert containers of tropical numbers, e.g. matrices or vectors.

Best,
Benjamin

Wonderful, thanks a lot!