Macaulay2 » Documentation
Packages » SLPexpressions :: evaluate(SLProgram,MutableMatrix,MutableMatrix)
next | previous | forward | backward | up | index | toc

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

Synopsis

Description

This method evaluates an object of type SLProgram (missing documentation) 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 = makeInterpretedSLProgram(matrix{{C,X}},matrix{{XXC,detXCCX,XoC,XpC+2}})

o7 = InterpretedSLProgram{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 : InterpretedSLProgram
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_QQ,3}}

o12 = | -5 3 |

o12 : MutableMatrix
i13 : ring inp

o13 = QQ

o13 : Ring
i14 : out = mutableMatrix(ring inp,1,4)

o14 = 0

o14 : MutableMatrix
i15 : evaluate(slp, inp, out)
i16 : out

o16 = | -45 -16 -3/5 0 |

o16 : MutableMatrix

See also

Ways to use this method: