next | previous | forward | backward | up | top | index | toc | Macaulay2 website
SLPexpressions :: evaluate(SLProgram,MutableMatrix,MutableMatrix)

evaluate(SLProgram,MutableMatrix,MutableMatrix) -- evaluate a straight-line program

Synopsis

Description

This method evaluates an object of type SLProgram on a given input. The two matrices inp and out should both be mutable, of the same sizes, and be defined over the same ring.

i1 : declareVariable X; declareVariable C;
i3 : XpC = X+C

o3 = (X + C)

o3 : SumGate
i4 : XXC = productGate{X,X,C}

o4 = (X * X * C)

o4 : ProductGate
i5 : detXCCX = detGate{{X,C},{C,X}}

o5 = det| X C |
        | C X |

o5 : DetGate
i6 : XoC = X/C

     X
o6 = -
     C

o6 : DivideGate
i7 : slp = makeSLProgram(matrix{{C,X}},matrix{{XXC,detXCCX,XoC,XpC+2}})

o7 = SLProgram{cache => CacheTable{}              }
               constant positions => {-3}
               constants => | 2 |
               number of inputs => 2
               number of outputs => 4
               RawSLProgram => SLProgram (
                                 consts+vars: 3
                                 noninput nodes: 5
                                 output nodes: 4
                                 )

               variable positions => {-1, -2}

o7 : SLProgram
i8 : inp = mutableMatrix{{1.2,-1}}

o8 = | 1.2 -1 |

o8 : MutableMatrix
i9 : out = mutableMatrix(ring inp,1,4)

o9 = | 0 0 0 0 |

o9 : MutableMatrix
i10 : evaluate(slp,inp,out)
i11 : clean_0.001(out - mutableMatrix {{1.2, -.44, -.833333, 2.2}}) == 0

o11 = true

The straight-line program can also be evaluated at different inputs in different rings:

i12 : inp = mutableMatrix{{-5,3}}

o12 = | -5 3 |

o12 : MutableMatrix
i13 : out = mutableMatrix(ring inp,1,4)

o13 = 0

o13 : MutableMatrix
i14 : evaluate(slp, inp, out)
i15 : out

o15 = | -45 -66 3 0 |

o15 : MutableMatrix

See also