Macaulay2 » Documentation
Packages » Macaulay2Doc » The Macaulay2 language » system facilities » top level loop » capture
next | previous | forward | backward | up | index | toc

capture -- evaluate Macaulay2 code and capture the output

Description

This function evaluates the given Macaulay2 code within the same process in order to speed up tasks such as generating example results or checking the package tests.

i1 : (err, output) = capture examples(resolution, Ideal) 

o1 = (false,                                                                 
             i1 : -- examples for tag: freeResolution(Ideal)
                  -- /build/reproducible-path/macaulay2-1.26.05+ds/M2/Macaula
                  R = QQ[a..d];

             i2 : I = ideal(c^2-b*d, b*c-a*d, b^2-a*c)

                          2                    2
             o2 = ideal (c  - b*d, b*c - a*d, b  - a*c)

             o2 : Ideal of R

             i3 : M = R^1/I

             o3 = cokernel | c2-bd bc-ad b2-ac |

                                         1
             o3 : R-module, quotient of R

             i4 : C = freeResolution M

                   1      3      2
             o4 = R  <-- R  <-- R
                                 
                  0      1      2

             o4 : Complex

             i5 : length C

             o5 = 2

             i6 : betti C

                         0 1 2
             o6 = total: 1 3 2
                      0: 1 . .
                      1: . 3 2

             o6 : BettiTally

             i7 : dd^C

                       1                             3
             o7 = 0 : R  <------------------------- R  : 1
                            | b2-ac bc-ad c2-bd |

                       3                     2
                  1 : R  <----------------- R  : 2
                            {2} | -c d  |
                            {2} | b  -c |
                            {2} | -a b  |

             o7 : ComplexMap

             i8 : assert isWellDefined C

             i9 : assert(prune HH C == complex M)

             i10 : assert(length HH C == 0)

             i11 : f = augmentationMap C

                                                                  1
             o11 = 0 : cokernel | c2-bd bc-ad b2-ac | <--------- R  : 0
                                                         | 1 |

             o11 : ComplexMap

             i12 : assert isWellDefined f

             i13 : assert(source f === C)

             i14 : assert(target f == complex M)

             i15 : aC = cone f

                          1      3      2
             o15 = M <-- R  <-- R  <-- R
                                        
                   0     1      2      3

             o15 : Complex

             i16 : assert(HH aC == 0)

             i17 : assert(freeResolution I == C)

             i18 : assert(resolution complex M == freeResolution M)

             i19 : C' = freeResolution module I

                    3      2
             o19 = R  <-- R
                           
                   0      1

             o19 : Complex

             i20 : assert isWellDefined C'

             i21 : assert(C' != C)

             i22 : assert(betti naiveTruncation(C, 1, infinity) == betti C'[-

             i23 : S = ZZ/101[a,b];

             i24 : R = S/(a^3+b^3);

             i25 : C = freeResolution (coker vars R, LengthLimit => 7)

                    1      2      2      2      2      2      2      2
             o25 = R  <-- R  <-- R  <-- R  <-- R  <-- R  <-- R  <-- R
                                                                     
                   0      1      2      3      4      5      6      7

             o25 : Complex

             i26 : length C

             o26 = 7

             i27 : betti C

                          0 1 2 3 4 5 6 7
             o27 = total: 1 2 2 2 2 2 2 2
                       0: 1 2 1 . . . . .
                       1: . . 1 2 1 . . .
                       2: . . . . 1 2 1 .
                       3: . . . . . . 1 2

             o27 : BettiTally

             i28 : dd^C

                        1               2
             o28 = 0 : R  <----------- R  : 1
                             | a b |

                        2                     2
                   1 : R  <----------------- R  : 2
                             {1} | -b a2 |
                             {1} | a  b2 |

                        2                      2
                   2 : R  <------------------ R  : 3
                             {2} | a2 -b2 |
                             {3} | b  a   |

                        2                     2
                   3 : R  <----------------- R  : 4
                             {4} | -a b2 |
                             {4} | b  a2 |

                        2                      2
                   4 : R  <------------------ R  : 5
                             {5} | -a2 b2 |
                             {6} | b   a  |

                        2                     2
                   5 : R  <----------------- R  : 6
                             {7} | -a b2 |
                             {7} | b  a2 |

                        2                      2
                   6 : R  <------------------ R  : 7
                             {8} | -a2 b2 |
                             {9} | b   a  |

             o28 : ComplexMap

             i29 : E = ZZ/101[e_1..e_6, SkewCommutative => true];

             i30 : I = ideal(e_4*e_5-e_4*e_6+e_5*e_6,
                       e_2*e_3-e_2*e_6+e_3*e_6,
                       e_1*e_3-e_1*e_5+e_3*e_5,
                       e_1*e_2-e_1*e_4+e_2*e_4)

             o30 = ideal (e e  - e e  + e e , e e  - e e  + e e , e e  - e e 
                           4 5    4 6    5 6   2 3    2 6    3 6   1 3    1 5
                   ----------------------------------------------------------
                   - e e  + e e )
                      1 4    2 4

             o30 : Ideal of E

             i31 : F = freeResolution(I, LengthLimit => 5)

                    1      4      10      21      45      91
             o31 = E  <-- E  <-- E   <-- E   <-- E   <-- E
                                                          
                   0      1      2       3       4       5

             o31 : Complex

             i32 : assert isWellDefined F

             i33 : assert isHomogeneous F

             i34 : betti F

                          0 1  2  3  4  5
             o34 = total: 1 4 10 21 45 91
                       0: 1 .  .  .  .  .
                       1: . 4 10 15 20 25
                       2: . .  .  6 25 66

             o34 : BettiTally

             i35 : S = QQ[x,y,Dx,Dy, WeylAlgebra => {{x,Dx}, {y,Dy}}];

             i36 : I = ideal(x*Dy, y*Dx)

             o36 = ideal (x*Dy, y*Dx)

             o36 : Ideal of S

             i37 : F = freeResolution comodule I

                    1      2      4      4      1
             o37 = S  <-- S  <-- S  <-- S  <-- S
                                                
                   0      1      2      3      4

             o37 : Complex

             i38 : assert isWellDefined F

             i39 : dd^F

                        1                   2
             o39 = 0 : S  <--------------- S  : 1
                             | xDy yDx |

                        2                                                    
                   1 : S  <--------------------------------------------------
                             {2} | yDx^2Dy+2Dx^2  xyDxDy+2xDx-yDy-2 y2Dx^2   
                             {2} | -xDxDy^2-2Dy^2 -x2Dy^2           -xyDxDy+x

                        4                               4
                   2 : S  <--------------------------- S  : 3
                             {6} | x   y   0   0   |
                             {6} | -Dx 0   y   0   |
                             {6} | 0   -Dy 0   x   |
                             {6} | 0   0   -Dy -Dx |

                        4                   1
                   3 : S  <--------------- S  : 4
                             {7} | y   |
                             {7} | -x  |
                             {7} | Dx  |
                             {7} | -Dy |

             o39 : ComplexMap

             i40 : 
     ------------------------------------------------------------------------
                                                    )

     y2/packages/Complexes/ChainComplexDoc.m2:1115:0




































































































     1])










































































      + e e , e e 
         3 5   1 2
     -------------





















































                              4
     ----------------------- S  : 2
               xy2Dx-y2  |
     Dx-2yDy+2 -x2yDy+x2 |

o1 : Sequence
i2 : assert not err

If UserMode => false given, the dictionaries available to the user will not be affected by the evaluation and collectGarbage is called afterwards.

Errors occurred while evaluating str do not cause an error outside of capture.

i3 : (err, output) = capture /// stderr << "Checking a false statement:" << endl; 1/0 ///

o3 = (true,                                                            )
            i1 :  stderr << "Checking a false statement:" << endl; 1/0 
            Checking a false statement:
            currentString:1:51:(3):[4]: error: division by zero


o3 : Sequence
i4 : assert err

Certain examples or tests might not be compatible with capture. In such cases, use the string -* no-capture-flag *- somewhere within str so that the code is run in a separate Macaulay2 subprocess instead.

See also

Ways to use capture:

  • capture(List)
  • capture(Net)
  • capture(String)
  • capture(TestInput)

For the programmer

The object capture is a method function with options.


The source of this document is in /build/reproducible-path/macaulay2-1.26.05+ds/M2/Macaulay2/packages/Macaulay2Doc/functions/examples-doc.m2:134:0.