Contact
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
| Download
Project: Sage Days 82
Views: 259

Intro to research based coding in Sage

Create the combinatorial class of 3x3 alternating sign matrices

A3 = AlternatingSignMatrices(3)
A3

Use a for loop to display all the 3x3 alternating sign matrices

for a in A3: print a
#tab complete and define 4x4 alternating sign matrices A4 = Altern

unrank(28) gives us the 28th (starting at 0) alternating sign matrix in A4

asm = A4.unrank(28); asm
asm.height_function()
%html <h4> Put ? after a function to see the documentation. Put ?? after a function to see the documentation and code. </h4>

Put ? after a function to see the documentation. Put ?? after a function to see the documentation and code.

asm.height_function?

In the below block, put your cursor at the end and hit tab to see what alternating sign matrix methods start with 'to'

asm.to
asm.to_fully_packed_loop()
asm
asm.gyration()
asm.gyration??
animate(a2.to_fully_packed_loop() for a2 in asm.gyration_orbit())
A3.gyration_orbit_sizes()

Construct the lattice of 4x4 alternating sign matrices

l4 = A4.lattice()
l4.cardinality()
l4.plot(label_elements = False)
h4 = l4.hasse_diagram() show(h4)
j4 = l4.join_irreducibles_poset()
plot(j4)

Construct the same poset using the tetrahedral poset code, then test it is isomorphic to our previous construction

a4 = posets.TetrahedralPoset(4, 'green','yellow','blue','orange') a4.is_isomorphic(j4)

Construct the TSSCPP tetrahedral poset

t4 = posets.TetrahedralPoset(4, 'green','yellow','red','orange') t4.plot()
oit4 = t4.order_ideals_lattice() oit4.cardinality()
ll = [len(orb) for orb in j4.rowmotion_orbits()]
sorted(ll)
A4.gyration_orbit_sizes()
def row_gyr_orb_size(n): A = AlternatingSignMatrices(n) lat = A.lattice() j = lat.join_irreducibles_poset() rowlist = [len(orb) for orb in j.rowmotion_orbits()] rowlist = sorted(rowlist) gyrlist = A.gyration_orbit_sizes() gyrlist.sort() print gyrlist return rowlist==gyrlist
for i in [1..5]: row_gyr_orb_size(i)
myasm = AlternatingSignMatrix([[0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0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 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0]])
ld = myasm.to_dyck_word(algorithm = 'last_diagonal')
print(ld)
lp = myasm.to_dyck_word??
type(lp)
myasm.to_monotone_triangle().pp()
myasm.to_fully_packed_loop()
myasm.
print(fpl)
P6 = Permutations(6)
mean([p.number_of_fixed_points() for p in P6])
1
P100 = Permutations(100)
mean([P100.random_element().number_of_fixed_points() for i in range(10000)])
201/200
P = Permutations()
sample??
File: /projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/misc/prandom.py Source: def sample(population, k): r""" Chooses k unique random elements from a population sequence. Returns a new list containing elements from the population while leaving the original population unchanged. The resulting list is in selection order so that all sub-slices will also be valid random samples. This allows raffle winners (the sample) to be partitioned into grand prize and second place winners (the subslices). Members of the population need not be hashable or unique. If the population contains repeats, then each occurrence is a possible selection in the sample. To choose a sample in a range of integers, use xrange as an argument. This is especially fast and space efficient for sampling from a large population: sample(xrange(10000000), 60) EXAMPLES:: sage: sample(["Here", "I", "come", "to", "save", "the", "day"], 3) ['Here', 'to', 'day'] sage: sample(xrange(2^30), 7) [357009070, 558990255, 196187132, 752551188, 85926697, 954621491, 624802848] """ return _pyrand().sample(population, k)
P.random_element()
Error in lines 1-1 Traceback (most recent call last): File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/smc_sagews/sage_server.py", line 976, in execute exec compile(block+'\n', '', 'single') in namespace, locals File "", line 1, in <module> File "/projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/categories/infinite_enumerated_sets.py", line 62, in random_element raise NotImplementedError("infinite set") NotImplementedError: infinite set
p.random_element??
File: /projects/sage/sage-7.3/local/lib/python2.7/site-packages/sage/combinat/permutation.py Source: def random_element(self): """ EXAMPLES:: sage: Permutations(4).random_element() [1, 2, 4, 3] """ return self.element_class(self, sample(xrange(1,self.n+1), self.n))