Converting tropical numbers to rational numbers

Questions and problems about using polymake go here.
EnisKaya
Posts: 7
Joined: 27 Jan 2025, 16:03

Converting tropical numbers to rational numbers

Postby EnisKaya » 27 Jan 2025, 16:14

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!

blorenz
Developer
Posts: 149
Joined: 10 Jan 2011, 17:21

Re: Converting tropical numbers to rational numbers

Postby blorenz » 27 Jan 2025, 16:26

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

EnisKaya
Posts: 7
Joined: 27 Jan 2025, 16:03

Re: Converting tropical numbers to rational numbers

Postby EnisKaya » 27 Jan 2025, 20:02

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!


Return to “Helpdesk”