-
Notifications
You must be signed in to change notification settings - Fork 0
5_things_I'm_glad_I_learned_SGW2011
title: 5 things I'm glad I learned SGW2011 permalink: wiki/5_things_I'm_glad_I_learned_SGW2011/ layout: wiki
Return to the Main SGW2011 page
Please write (like an answer to a FAQ) 5 things you can't believe you did not know about M2.
Branden Stone shared a neat trick with me this time! Let's say you want a function to tell the user something about the input. You can do this in one line using C syntax (<<). For example, given the function f as below,
f = t -> (
if even t == true then (<< "Your number " << t << " is even." << endl)
else (<< "Your number " << t << "i s odd." << endl)
)
evaluating f(6) and f(19) yields
i10 : f(6)
Your number 6 is even.
i11 : f(19)
Your number 19 is odd.
I wish I had known about the command prune earlier in my M2 career. Consider a module generated as the cokernel of a random map as below:
R = ZZ/101[x,y];
S = R/ideal(x^2);
M = coker random(S^1,S^{5:-3})
prune M
betti res (M, LengthLimit => 5)
betti res (prune M, LengthLimit => 5)
The output shows that the cokernel of the random map isn't minimally presented by default:
i3 : M = coker random(S^1,S^{5:-3})
o3 = cokernel | -11xy2-5y3 -33xy2-19y3 32xy2-25y3 26xy2-y3 -32xy2+46y3 |
1
o3 : S-module, quotient of S
i4 : prune M
o4 = cokernel | y3 xy2 |
1
o4 : S-module, quotient of S
At an earlier workshop, I learned two very useful commands: apply and peek. With respect to apply, I may never write a for loop again. And with peek, I will always be able to figure out the keys of a hash table!
- To determine if an element f is in an ideal I, use the colon I:f; if you get the unit ideal, you know that f is an element of I
- If an element f is in an ideal I, you can determine the coefficients of the generators of I needed to write f as a combination of the generators of I; below is an example:
i1 : R = ZZ/101[x,y]
o1 = R
o1 : PolynomialRing
i2 : I = ideal"x+y,xy-y2,x3"
2 3
o2 = ideal (x + y, x*y - y , x )
o2 : Ideal of R
Now consider the element f below; if we colon it in to I, we get the unit ideal. This tells us that f is an element of I.
i3 : f = x^3*y+x*y^3
3 3
o3 = x y + x*y
o3 : R
i4 : I:f
o4 = ideal 1
Using the // command, we can find the desired coefficients:
o4 : Ideal of R
i5 : f//gens I
o5 = {1} | x2y-xy2+y3 |
{2} | y2 |
{3} | 0 |
3 1
o5 : Matrix R <--- R
Thus, we can write our element as follows:
f = x^3*y + x*y^3 = (x^2*y - x*y^2 + y^3)*(x+y) + y^2*(x*y-y^2) + 0*x^3
- To get the elements from a matrix M, use: flatten entries M
- How to comment out a block of code: {* comments here *}
- Debugging: For example, in emacs, when an error occurs you can goto the error message and hit return to go to the error in your code.
-
Home
- Introduction
- Macaulay2 Contribution Guides
- Macaulay2 Workshop Guides
-
Macaulay2 Internals
- Building Macaulay2 from source
- Components of Macaulay2
- Case Studies
- Web servers
- Other
- Frequently Asked Questions
- Road map