Using Macaulay2 from within R : the m2r package Christopher ONeill - - PowerPoint PPT Presentation

using macaulay2 from within r the m2r package
SMART_READER_LITE
LIVE PREVIEW

Using Macaulay2 from within R : the m2r package Christopher ONeill - - PowerPoint PPT Presentation

Using Macaulay2 from within R : the m2r package Christopher ONeill University of California Davis coneill@math.ucdavis.edu Joint with David Kahle and Jeff Sommars Mathematics Research Communities on Algebraic Statistics August 3, 2017


slide-1
SLIDE 1

Using Macaulay2 from within R: the m2r package

Christopher O’Neill

University of California Davis coneill@math.ucdavis.edu Joint with David Kahle and Jeff Sommars Mathematics Research Communities on Algebraic Statistics

August 3, 2017

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 1 / 20

slide-2
SLIDE 2

R and Macaulay2

R: a statistician’s best friend Data storage and manipulation, array calculations, data analysis, . . .

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 2 / 20

slide-3
SLIDE 3

R and Macaulay2

R: a statistician’s best friend Data storage and manipulation, array calculations, data analysis, . . . Macaulay2: an algebraic geometer’s best friend Polynomial ideals, Gr¨

  • bner bases, Hilbert functions, . . .

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 2 / 20

slide-4
SLIDE 4

R and Macaulay2

R: a statistician’s best friend Data storage and manipulation, array calculations, data analysis, . . . Macaulay2: an algebraic geometer’s best friend Polynomial ideals, Gr¨

  • bner bases, Hilbert functions, . . .

Algebraic statisticians: best of both worlds

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 2 / 20

slide-5
SLIDE 5

Running Macaulay2 from R the old way

R version 3.3.0 ... >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 3 / 20

slide-6
SLIDE 6

Running Macaulay2 from R the old way

R version 3.3.0 ... > library("algstat") >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 3 / 20

slide-7
SLIDE 7

Running Macaulay2 from R the old way

R version 3.3.0 ... > library("algstat") > code <- "R = QQ[x,y,z] I = ideal(xˆ2, x*y, xˆ3*yˆ2) gens gb I" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 3 / 20

slide-8
SLIDE 8

Running Macaulay2 from R the old way

R version 3.3.0 ... > library("algstat") > code <- "R = QQ[x,y,z] I = ideal(xˆ2, x*y, xˆ3*yˆ2) gens gb I" > m2(code) [1] "R" [1] "ideal(xˆ2,x*y,xˆ3*yˆ2)" [1] "matrix {{x*y, xˆ2}}"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 3 / 20

slide-9
SLIDE 9

Running Macaulay2 from R the old way

R version 3.3.0 ... > library("algstat") > code <- "R = QQ[x,y,z] I = ideal(xˆ2, x*y, xˆ3*yˆ2) gens gb I" > m2(code) [1] "R" [1] "ideal(xˆ2,x*y,xˆ3*yˆ2)" [1] "matrix {{x*y, xˆ2}}"

m2Code.m2

f = "m2Out" << "" f << toString( R = QQ[x,y,z] ) << endl f << toString( I = ideal(xˆ2, x*y, xˆ3*yˆ2) ) << endl f << toString( gens gb I ) << endl f << close

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 3 / 20

slide-10
SLIDE 10

The m2r package in action

R version 3.3.0 ... >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 4 / 20

slide-11
SLIDE 11

The m2r package in action

R version 3.3.0 ... > library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 found in /usr/local/macaulay2/bin >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 4 / 20

slide-12
SLIDE 12

The m2r package in action

R version 3.3.0 ... > library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 found in /usr/local/macaulay2/bin > start_m2() Starting M2... done. >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 4 / 20

slide-13
SLIDE 13

The m2r package in action

R version 3.3.0 ... > library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 found in /usr/local/macaulay2/bin > start_m2() Starting M2... done. > m2("1+1") [1] "2" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 4 / 20

slide-14
SLIDE 14

The m2r package in action

R version 3.3.0 ... > library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 found in /usr/local/macaulay2/bin > start_m2() Starting M2... done. > m2("1+1") [1] "2" > m2("a = 5") [1] "5" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 4 / 20

slide-15
SLIDE 15

The m2r package in action

R version 3.3.0 ... > library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 found in /usr/local/macaulay2/bin > start_m2() Starting M2... done. > m2("1+1") [1] "2" > m2("a = 5") [1] "5" > m2("a") [1] "5"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 4 / 20

slide-16
SLIDE 16

Under the hood: sockets

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-17
SLIDE 17

Under the hood: sockets

m2_start()

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-18
SLIDE 18

Under the hood: sockets

m2_start() launch M2 process

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-19
SLIDE 19

Under the hood: sockets

m2_start() launch M2 process wait for available connection

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-20
SLIDE 20

Under the hood: sockets

m2_start() launch M2 process wait for available connection create server socket

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-21
SLIDE 21

Under the hood: sockets

m2_start() launch M2 process wait for available connection create server socket wait for client connection

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-22
SLIDE 22

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket create server socket wait for client connection

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-23
SLIDE 23

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket create server socket wait for client connection

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-24
SLIDE 24

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket wait for message from server create server socket wait for client connection

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-25
SLIDE 25

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket wait for message from server create server socket wait for client connection send "1.0.0"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-26
SLIDE 26

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket wait for message from server create server socket wait for client connection send "1.0.0" wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-27
SLIDE 27

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket wait for message from server receive "1.0.0" create server socket wait for client connection send "1.0.0" wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-28
SLIDE 28

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket wait for message from server receive "1.0.0" verify version match create server socket wait for client connection send "1.0.0" wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-29
SLIDE 29

Under the hood: sockets

m2_start() launch M2 process wait for available connection connect to socket wait for message from server receive "1.0.0" verify version match return from m2_start() create server socket wait for client connection send "1.0.0" wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 5 / 20

slide-30
SLIDE 30

Under the hood: sockets

wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-31
SLIDE 31

Under the hood: sockets

m2("1+1") wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-32
SLIDE 32

Under the hood: sockets

m2("1+1") send "1+1" to server wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-33
SLIDE 33

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-34
SLIDE 34

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response wait for input from client receive "1+1" from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-35
SLIDE 35

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response wait for input from client receive "1+1" from client evaluate "1+1" to "2"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-36
SLIDE 36

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response wait for input from client receive "1+1" from client evaluate "1+1" to "2" send "2" to client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-37
SLIDE 37

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response wait for input from client receive "1+1" from client evaluate "1+1" to "2" send "2" to client wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-38
SLIDE 38

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response receive "2" from server wait for input from client receive "1+1" from client evaluate "1+1" to "2" send "2" to client wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-39
SLIDE 39

Under the hood: sockets

m2("1+1") send "1+1" to server wait for response receive "2" from server return "2" from m2() wait for input from client receive "1+1" from client evaluate "1+1" to "2" send "2" to client wait for input from client

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 6 / 20

slide-40
SLIDE 40

Under the hood: sockets

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 7 / 20

slide-41
SLIDE 41

Under the hood: sockets

>

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 7 / 20

slide-42
SLIDE 42

Under the hood: sockets

> m2("a = 5") [1] "5" > m2("a") [1] "5" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 7 / 20

slide-43
SLIDE 43

Under the hood: sockets

> m2("a = 5") [1] "5" > m2("a") [1] "5" > m2("1+") Error: Macaulay2 Error! >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 7 / 20

slide-44
SLIDE 44

Under the hood: sockets

> m2("a = 5") [1] "5" > m2("a") [1] "5" > m2("1+") Error: Macaulay2 Error! > m2("2+1") [1] "3"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 7 / 20

slide-45
SLIDE 45

Under the hood: sockets

>

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 8 / 20

slide-46
SLIDE 46

Under the hood: sockets

> start_m2() Starting M2... done. > m2("1+1") [1] "2" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 8 / 20

slide-47
SLIDE 47

Under the hood: sockets

> start_m2() Starting M2... done. > m2("1+1") [1] "2" >

  • So. . . now what?

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 8 / 20

slide-48
SLIDE 48

Under the hood: sockets

> start_m2() Starting M2... done. > m2("1+1") [1] "2" >

  • So. . . now what?

New features since creation: Lots of convenience functions High-level parser Cloud computing

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 8 / 20

slide-49
SLIDE 49

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 9 / 20

slide-50
SLIDE 50

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > m2("R = QQ[x,y,z]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 9 / 20

slide-51
SLIDE 51

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > m2("R = QQ[x,y,z]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" > m2("I = ideal(xˆ2, x*y, xˆ3*yˆ2)") [1] "ideal map((R)ˆ1,(R)ˆ{{-2},{-2},{-5}},{{xˆ2, x*y, xˆ3*yˆ2}})" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 9 / 20

slide-52
SLIDE 52

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > m2("R = QQ[x,y,z]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" > m2("I = ideal(xˆ2, x*y, xˆ3*yˆ2)") [1] "ideal map((R)ˆ1,(R)ˆ{{-2},{-2},{-5}},{{xˆ2, x*y, xˆ3*yˆ2}})" > m2("gens gb I") [1] "map((R)ˆ1,(R)ˆ{{-2},{-2}},{{x*y, xˆ2}})"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 9 / 20

slide-53
SLIDE 53

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > m2("R = QQ[x,y,z]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" > m2("I = ideal(xˆ2, x*y, xˆ3*yˆ2)") [1] "ideal map((R)ˆ1,(R)ˆ{{-2},{-2},{-5}},{{xˆ2, x*y, xˆ3*yˆ2}})" > m2("gens gb I") [1] "map((R)ˆ1,(R)ˆ{{-2},{-2}},{{x*y, xˆ2}})"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 9 / 20

slide-54
SLIDE 54

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-55
SLIDE 55

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > (R <- ring("x", "y", "z", coefring = "QQ")) M2 Ring: QQ[x,y,z], grevlex order >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-56
SLIDE 56

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > (R <- ring("x", "y", "z", coefring = "QQ")) M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-57
SLIDE 57

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > (R <- ring("x", "y", "z", coefring = "QQ")) M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > (mygens <- gb(I)) x y xˆ2 >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-58
SLIDE 58

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > (R <- ring("x", "y", "z", coefring = "QQ")) M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > (mygens <- gb(I)) x y xˆ2 > mygens[[2]] xˆ2

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-59
SLIDE 59

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > (R <- ring("x", "y", "z", coefring = "QQ")) M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > (mygens <- gb(I)) x y xˆ2 > mygens[[2]] ← − mpoly xˆ2

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-60
SLIDE 60

Convenience functions

> m2("a = 5") [1] "5" > m2("a") [1] "5" > (R <- ring("x", "y", "z", coefring = "QQ")) M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > (mygens <- gb(I)) ← − mpolylist x y xˆ2 > mygens[[2]] ← − mpoly xˆ2

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 10 / 20

slide-61
SLIDE 61

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 11 / 20

slide-62
SLIDE 62

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > radical(I) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < x > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 11 / 20

slide-63
SLIDE 63

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > radical(I) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < x > > saturate(I,ideal("xˆ5")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < 1 > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 11 / 20

slide-64
SLIDE 64

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > radical(I) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < x > > saturate(I,ideal("xˆ5")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < 1 > > I+I M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2, xˆ2, x y, xˆ3 yˆ2 > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 11 / 20

slide-65
SLIDE 65

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > radical(I) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < x > > saturate(I,ideal("xˆ5")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generator : < 1 > > I+I M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2, xˆ2, x y, xˆ3 yˆ2 > > gb(I+I) x y xˆ2

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 11 / 20

slide-66
SLIDE 66

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 12 / 20

slide-67
SLIDE 67

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > primary_decomposition(I) M2 List of ideals of QQ[x,y,z] (grevlex) : < x > < xˆ2, y > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 12 / 20

slide-68
SLIDE 68

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > primary_decomposition(I) M2 List of ideals of QQ[x,y,z] (grevlex) : < x > < xˆ2, y > > dimension(I) [1] 2 >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 12 / 20

slide-69
SLIDE 69

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > primary_decomposition(I) M2 List of ideals of QQ[x,y,z] (grevlex) : < x > < xˆ2, y > > dimension(I) [1] 2 > ring("x", "y", "z", coefring = "QQ", code = TRUE) m2rintring00000002 = QQ[x,y,z,MonomialOrder=>{GRevLex=>3}] >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 12 / 20

slide-70
SLIDE 70

Convenience functions

> (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > primary_decomposition(I) M2 List of ideals of QQ[x,y,z] (grevlex) : < x > < xˆ2, y > > dimension(I) [1] 2 > ring("x", "y", "z", coefring = "QQ", code = TRUE) m2rintring00000002 = QQ[x,y,z,MonomialOrder=>{GRevLex=>3}] > dimension(I, code = TRUE) dim(m2rintideal00000001)

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 12 / 20

slide-71
SLIDE 71

The parser

>

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 13 / 20

slide-72
SLIDE 72

The parser

> m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2)) [,1] [,2] [1,] 1 3 [2,] 2 4 M2 Matrix over ZZ[] >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 13 / 20

slide-73
SLIDE 73

The parser

> m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2)) [,1] [,2] [1,] 1 3 [2,] 2 4 M2 Matrix over ZZ[] > m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2), code = TRUE) m2rintmatrix00000002 = matrix {{(1),(3)},{(2),(4)}} >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 13 / 20

slide-74
SLIDE 74

The parser

> m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2)) [,1] [,2] [1,] 1 3 [2,] 2 4 M2 Matrix over ZZ[] > m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2), code = TRUE) m2rintmatrix00000002 = matrix {{(1),(3)},{(2),(4)}} > m2("m2rintmatrix00000002 = matrix {{(1),(3)},{(2),(4)}}") [1] "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 13 / 20

slide-75
SLIDE 75

The parser

> m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2)) [,1] [,2] [1,] 1 3 [2,] 2 4 M2 Matrix over ZZ[] > m2_matrix(matrix(c(1,2,3,4), nrow = 2, ncol = 2), code = TRUE) m2rintmatrix00000002 = matrix {{(1),(3)},{(2),(4)}} > m2("m2rintmatrix00000002 = matrix {{(1),(3)},{(2),(4)}}") [1] "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_parse("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [,1] [,2] [1,] 1 3 [2,] 2 4 M2 Matrix over ZZ[]

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 13 / 20

slide-76
SLIDE 76

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-77
SLIDE 77

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-78
SLIDE 78

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-79
SLIDE 79

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-80
SLIDE 80

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-81
SLIDE 81

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-82
SLIDE 82

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-83
SLIDE 83

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-84
SLIDE 84

The parser

Parsing "map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})" > m2_tokenize("map((ZZ)ˆ2,(ZZ)ˆ2,{{1, 3}, {2, 4}})") [1] "map" "(" "(" "ZZ" ")" "ˆ" "2" "," "(" "ZZ" [11] ")" "ˆ" "2" "," "{" "{" "1" "," "3" "}" [21] "," "{" "2" "," "4" "}" "}" ")"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 14 / 20

slide-85
SLIDE 85

The parser

>

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 15 / 20

slide-86
SLIDE 86

The parser

> m2_parse(m2("x")) M2 Symbol: x >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 15 / 20

slide-87
SLIDE 87

The parser

> m2_parse(m2("x")) M2 Symbol: x > m2_parse(m2("ZZ")) M2 Ring: ZZ[], grevlex order >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 15 / 20

slide-88
SLIDE 88

The parser

> m2_parse(m2("x")) M2 Symbol: x > m2_parse(m2("ZZ")) M2 Ring: ZZ[], grevlex order > m2("m2rintring00000002 = QQ[x,y,z,MonomialOrder=>{GRevLex=>3}]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 15 / 20

slide-89
SLIDE 89

The parser

> m2_parse(m2("x")) M2 Symbol: x > m2_parse(m2("ZZ")) M2 Ring: ZZ[], grevlex order > m2("m2rintring00000002 = QQ[x,y,z,MonomialOrder=>{GRevLex=>3}]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" > m2_parse(m2("m2rintring00000002")) M2 Ring: QQ[x,y,z], grevlex order >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 15 / 20

slide-90
SLIDE 90

The parser

> m2_parse(m2("x")) M2 Symbol: x > m2_parse(m2("ZZ")) M2 Ring: ZZ[], grevlex order > m2("m2rintring00000002 = QQ[x,y,z,MonomialOrder=>{GRevLex=>3}]") [1] "QQ(monoid[x..z, Degrees => {3:1}, Heft => {1}, MonomialOrder => VerticalList{MonomialSize => 32, GRevLex => {3:1}, Position => Up}, DegreeRank => 1])" > m2_parse(m2("m2rintring00000002")) M2 Ring: QQ[x,y,z], grevlex order > m2("ideal({xˆ2+2*x,2*x+3})") [1] "ideal map((m2rintring00000002)ˆ1,(m2rintring00000002)ˆ{{-2}, {-1}},{{xˆ2+2*x, 2*x+3}})"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 15 / 20

slide-91
SLIDE 91

Parser “extensibility”

> m2("ideal({xˆ2+2*x,2*x+3})") [1] "ideal map((m2rintring00000002)ˆ1,(m2rintring00000002)ˆ{{-2}, {-1}},{{xˆ2+2*x, 2*x+3}})"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 16 / 20

slide-92
SLIDE 92

Parser “extensibility”

> m2("ideal({xˆ2+2*x,2*x+3})") [1] "ideal map((m2rintring00000002)ˆ1,(m2rintring00000002)ˆ{{-2}, {-1}},{{xˆ2+2*x, 2*x+3}})" m2_parse_function.m2_map <- function(x) { R1 <- x[[1]] R2 <- x[[2]] . . . m2_structure( mat, m2_name = "", m2_class = "m2_matrix", m2_meta = list( ring = R1 ), base_class = "matrix" ) }

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 16 / 20

slide-93
SLIDE 93

Parser “extensibility”

> m2("ideal({xˆ2+2*x,2*x+3})") [1] "ideal map((m2rintring00000002)ˆ1,(m2rintring00000002)ˆ{{-2}, {-1}},{{xˆ2+2*x, 2*x+3}})"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 16 / 20

slide-94
SLIDE 94

Parser “extensibility”

> m2("ideal({xˆ2+2*x,2*x+3})") [1] "ideal map((m2rintring00000002)ˆ1,(m2rintring00000002)ˆ{{-2}, {-1}},{{xˆ2+2*x, 2*x+3}})" m2_parse_function.m2_ideal <- function(x) { m2_structure( m2_name = "", m2_class = "m2_ideal", m2_meta = list( ring = m2_meta(x[[1]], "ring"), gens = structure(x[[1]][1,], class = "mpolyList") ) ) }

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 16 / 20

slide-95
SLIDE 95

m2r is now in the cloud!

>

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-96
SLIDE 96

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-97
SLIDE 97

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-98
SLIDE 98

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. > m2("a = 5") [1] "5" >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-99
SLIDE 99

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. > m2("a = 5") [1] "5" > m2("a") [1] "5"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-100
SLIDE 100

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. > m2("a = 5") [1] "5" > m2("a") [1] "5"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-101
SLIDE 101

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. > m2("a = 5") [1] "5" > m2("a") [1] "5"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-102
SLIDE 102

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. > m2("a = 5") [1] "5" > m2("a") [1] "5"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-103
SLIDE 103

m2r is now in the cloud!

> library("m2r") Loading required package: mpoly Loading required package: stringr please cite mpoly if you use it; see citation("mpoly") M2 not found; defaulting to cloud. Use set_m2r_path("/path/to/m2") to run M2 locally. > start_m2() Connecting to M2 in the cloud... done. > m2("a = 5") [1] "5" > m2("a") [1] "5"

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 17 / 20

slide-104
SLIDE 104

More fancy features out there: reference functions

>

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-105
SLIDE 105

More fancy features out there: reference functions

> R <- ring("x", "y", "z", coefring = "QQ") M2 Ring: QQ[x,y,z], grevlex order >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-106
SLIDE 106

More fancy features out there: reference functions

> R <- ring("x", "y", "z", coefring = "QQ") M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-107
SLIDE 107

More fancy features out there: reference functions

> R <- ring("x", "y", "z", coefring = "QQ") M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > gb(I) x y xˆ2 >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-108
SLIDE 108

More fancy features out there: reference functions

> R <- ring("x", "y", "z", coefring = "QQ") M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > gb(I) x y xˆ2 > (J <- ideal.("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Pointer Object ExternalString : ideal map((m2rintring00000001)ˆ1,(m2rin... M2 Name : m2rintideal00000004 M2 Class : Ideal (Type) >

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-109
SLIDE 109

More fancy features out there: reference functions

> R <- ring("x", "y", "z", coefring = "QQ") M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > gb(I) x y xˆ2 > (J <- ideal.("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Pointer Object ExternalString : ideal map((m2rintring00000001)ˆ1,(m2rin... M2 Name : m2rintideal00000004 M2 Class : Ideal (Type) > gb(J) x y xˆ2

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-110
SLIDE 110

More fancy features out there: reference functions

> R <- ring("x", "y", "z", coefring = "QQ") M2 Ring: QQ[x,y,z], grevlex order > (I <- ideal("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Ideal of ring QQ[x,y,z] (grevlex) with generators : < xˆ2, x y, xˆ3 yˆ2 > > gb(I) x y xˆ2 > (J <- ideal.("xˆ2", "x*y", "xˆ3*yˆ2")) M2 Pointer Object ExternalString : ideal map((m2rintring00000001)ˆ1,(m2rin... M2 Name : m2rintideal00000004 M2 Class : Ideal (Type) > gb(J) x y xˆ2 m2_parse(J) − → I

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 18 / 20

slide-111
SLIDE 111

Thank you MRC!

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 19 / 20

slide-112
SLIDE 112

References

  • D. Kahle, C. O’Neill, and J. Sommars (2017)

A computer algebra system for R: Macaulay2 and the m2r package

  • submitted. Available at [arXiv:1706.07797].
  • D. Grayson and M. Stillman (2006)

Macaulay2, a software system for research in algebraic geometry, available at http://www.math.uiuc.edu/Macaulay2/.

  • D. Kahle (2013)

mpoly: Multivariate polynomials in R The R Journal 5 (1), 162–170. R Core Team (2014) R: A language and environment for statistical computing R Foundation for Statistical Computing, Vienna, Austria

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 20 / 20

slide-113
SLIDE 113

References

  • D. Kahle, C. O’Neill, and J. Sommars (2017)

A computer algebra system for R: Macaulay2 and the m2r package

  • submitted. Available at [arXiv:1706.07797].
  • D. Grayson and M. Stillman (2006)

Macaulay2, a software system for research in algebraic geometry, available at http://www.math.uiuc.edu/Macaulay2/.

  • D. Kahle (2013)

mpoly: Multivariate polynomials in R The R Journal 5 (1), 162–170. R Core Team (2014) R: A language and environment for statistical computing R Foundation for Statistical Computing, Vienna, Austria Thanks!

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 20 / 20

slide-114
SLIDE 114

YOU should request lots of features!

https://github.com/coneill-math/m2r

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 20 / 20

slide-115
SLIDE 115

YOU should request lots of features!

https://github.com/coneill-math/m2r

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 20 / 20

slide-116
SLIDE 116

YOU should request lots of features!

https://github.com/coneill-math/m2r

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 20 / 20

slide-117
SLIDE 117

YOU should request lots of features!

https://github.com/coneill-math/m2r

Christopher O’Neill (UC Davis) The m2r package August 3, 2017 20 / 20