Lists And Randomness In M2 Tue June 18

### Simple M2 Exercises and solutions

#### Do the following with a minimal number of code lines

- Output all prime numbers smaller or equal to 100

`for i from 1 to 100 do (if isPrime i then print i)`

- Output all odd prime numbers smaller or equal to 100

`for i from 1 to 100 do (if isPrime i and odd i then print i)`

- Compute a primary decomposition of the ideal $\langle x^2 - xy, xy - y^2 \rangle$ and find the dimensions of the dimensions of its components.

```
R = QQ[x,y]
I = ideal (x^2 - x*y, x*y - y^2)
dim \ primaryDecomposition I
```

#### Explore randomness in Macaulay2:

- read the help for "random(List, Ring)"

`help "random(List, Ring)"`

- create a list of 100 ideals generated by three random quadrics in $\mathbb{Q}[x,y,z]$

```
R = QQ[x,y,z];
lQ = for i from 1 to 100 list ideal (for i to 3 list random (2, R))
```

*create a list of 100 ideals generated by three random quadrics in $\mathbb{Z}_3[x,y,z]$

```
R = ZZ/3[x,y,z];
lZ = for i from 1 to 100 list ideal (for i to 3 list random (2, R))
```

- Compute the Krull dimensions of the 200 varieties,

```
dim \ lQ
lZ / dim
```

- Explain the result:

In $\mathbb{Z}_3$ there are only finitely many polynomials and thus the probability of sampling an ideal that is not a complete intersection is non-zero, for instance if two of the random polynomials are the same.