README.md

tropical – Tropical Geometry in R

CRAN_Status_Badge

Overview

tropical is a new R package that provides users with methods and data structures for tropical geometry in R. Inside R, you load the package with

library(tropical)
# Using min-plus algebra.

See the bottom of this page for how to install tropical.

Basic usage

In tropical geometry, the ordinary operations of addition and multiplication are changed: the sum of two numbers is the minimum of those numbers, and the product of two numbers is their (classical) sum. To reflect this change, the ordinary plus sign +, representing classical addition, is changed to ⊕, and ordinary multiplication symbols, × or ⋅, are changed to ⊙. As an example, 1 ⊕ 5 = 1, and 1 ⊙ 5 = 6. Together, the set (ℝ ∪ ∞, ⊕, ⊙ ) forms the algebraic structure of a semiring satisfying all ring, and even field, definitions except having additive inverses.

tropical implements ⊕ as %+% and ⊙ as %.%. For example:

1 %+% 5
# [1] 1
1 %.% 5
# [1] 6

As in base R, these operations are vectorized:

1:3 %+% 3:1
# [1] 1 2 1
1:3 %.% 3:1
# [1] 4 4 4

Exponentiation is also defined as iterated multiplication (⊕), but only when natural number exponents are given, so that 53 (sometimes written 5 ⊙ 3) is 53 = 5 ⊙ 5 ⊙ 5 = 5 + 5 + 5 = 3 × 5 = 15. Example:

5 %^% 3
# [1] 15

This operation is vectorized, too.

Matrix multiplication is also defined through inner products of vectors. For two vectors x and y of the same length, their inner product is xy = ⨁(xk ⊙ yk) = min {xk + yk}. In tropical, this is given by %..% (which is the tropical analogue of R’s ordinary matrix multiplication operator %*%):

1:3 %..% 4:6
# [1] 5

This is min {1 + 4, 2 + 5, 3 + 6} = 5. From there, matrix multiplication is defined in the standard way, so that for two matrices A and B, their product C = AB has elements ci, j = aibj, where ai is the ith row of A and bj is the jth column of B. Example:

(m1 <- matrix(1:6, 2, 3))
#      [,1] [,2] [,3]
# [1,]    1    3    5
# [2,]    2    4    6
(m2 <- matrix(6:1, 3, 2))
#      [,1] [,2]
# [1,]    6    3
# [2,]    5    2
# [3,]    4    1
m1 %..% m2
#      [,1] [,2]
# [1,]    7    4
# [2,]    8    5

Sometimes tropical arithmetic is defined with ⊕ interpreted as the maximum of the two numbers, not the minimum. To change tropical’s default setting, just type:

set_plus_max()
# Using max-plus algebra.
1:3 %+% 3:1
# [1] 3 2 3

Once you use this function, all operations will have the appropriate corresponding changes. You can change it back with

set_plus_min()
# Using min-plus algebra.
1:3 %+% 3:1
# [1] 1 2 1

Feature requests and contributing

To request the implementation of a feature, file an issue! Click “Issues” at the top of this page, then “New issue”, and have at it. If you’re especially courageous, fork the project, implement your own tropical geometry methods, and submit a pull request. If you’d like to contribute but don’t know how, please email us.

Acknowledgements

This material is based upon work supported by the National Science Foundation under Grant Nos. 1622449 and 1622369.

Installation

Here’s how you can install the current developmental version of tropical:

if(!requireNamespace("devtools")) install.packages("devtools")
devtools::install_github("dkahle/tropical")


dkahle/tropical documentation built on May 21, 2019, 7:57 a.m.