Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

6/25/24 assignment math 480 #3

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 58 additions & 12 deletions 6_18_2024_catalan/catalan.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import itertools


def parenthesizations(n):
"""
Returns a set of all possible parenthesizations of length n.

Parameters:
n (int): The length of the parenthesizations.

"""
"""
Returns:
A set of strings, where each inner string represents a valid parenthesization of length n.

Expand All @@ -17,16 +19,20 @@ def parenthesizations(n):
if n == 0:
return {""}
else:
# TODO
pass
result = set()
for i in range(n):
for left in parenthesizations(i):
for right in parenthesizations(n - 1 - i):
result.add('(' + left + ')' + right)
return result


def product_orders(n):
"""
Returns a set of all possible ways to multiply of n elements.

Parameters:
n (int): The number of elements multiplied.

n (int): The number of elements multiplied.
Returns:
A set of strings where each string represents a way to multiply n elements.

Expand All @@ -41,8 +47,17 @@ def product_orders(n):
elif n == 2:
return {"?*?"}
else:
# TODO
pass
result = set()
for i in range(1, n):
for left in product_orders(i):
for right in product_orders(n - i):
if left == '?':
result.add(left+ '*(' + right + ')')
elif right == '?':
result.add('(' + left + ')*' + right)
else:
result.add('('+ left +')*('+ right+')')
return result

def permutations_avoiding_231(n):
"""
Expand All @@ -61,8 +76,20 @@ def permutations_avoiding_231(n):
if n < 3:
return set(itertools.permutations(range(1, n+1)))
else:
# TODO
pass
result = set()

for i in set(itertools.permutations(range(1, n+1))):
result.add(i)
for j in range(2, n):
for k in range(j):
if i[k] > i[j]:
for l in range(k+1, j):
if i[l] > i[j] and i[l] > i[k]:
result.add(i)
result.remove(i)

return result


def triangulations(n):
"""
Expand All @@ -76,13 +103,32 @@ def triangulations(n):
A set of tuple of pairs, where each pair represents an internal edge in the triangulation.

Example:
>>> triangulations(3)
>>> triangulations(5)
{((0, 3), (1, 3)), ((1, 4), (2, 4)), ((1, 3), (1, 4)), ((0, 2), (2, 4)), ((0, 2), (0, 3))}
"""
if n < 3:
return set()
elif n == 3:
return {tuple()}
else:
pass
# TODO
result = set()
for i in range(n-2):
for j in range(i+2, n):
if i != 0 or j != n-1:
edge = (i, j)
polygon1_size = j-i+1
polygon2_size = n-(j-i)+1
for polygon1 in triangulations(polygon1_size):
for polygon2 in triangulations(polygon2_size):
modfied_polygon2 = tuple()
for (k,l) in polygon2:
k= (i-k)%n
l= (i-l)%n
smaller = min(k,l)
larger = max(k,l)
modfied_polygon2 += ((smaller,larger),)
result.add(tuple(sorted(polygon1 + (edge,) + ((smaller,larger),))))
result.add(tuple(sorted(polygon1 + modfied_polygon2 + (edge,))))
return result


2 changes: 1 addition & 1 deletion 6_20_2024_SYT/main.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.5"
"version": "3.11.9"
}
},
"nbformat": 4,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
parenthesization,valid
(),1
)(,0
((,0
)),0
17 changes: 17 additions & 0 deletions 6_25_2024_parenthesization_pytorch/data/parenthesizations_2.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
parenthesization,valid
()(),1
(()),1
)))(,0
())(,0
)(((,0
))(),0
(((),0
()((,0
)()(,0
)((),0
(()(,0
())),0
((((,0
))((,0
)))),0
)()),0
65 changes: 65 additions & 0 deletions 6_25_2024_parenthesization_pytorch/data/parenthesizations_3.csv
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
parenthesization,valid
()()(),1
()(()),1
(())(),1
(()()),1
((())),1
))))((,0
())()(,0
()((((,0
)))()(,0
()()((,0
))((((,0
)()))),0
()(((),0
)))((),0
)(((((,0
)())(),0
))(()(,0
)(()(),0
())(((,0
)()((),0
()(()(,0
))()((,0
)((()(,0
)))(((,0
)()(((,0
(((()),0
()())(,0
)))))(,0
())))(,0
((())(,0
(()))),0
(((((),0
(()()(,0
())))),0
))()(),0
(())((,0
())()),0
)(())),0
((()((,0
))())(,0
(()(((,0
(()((),0
()))(),0
()())),0
)(()((,0
()))((,0
))))(),0
)((((),0
)))()),0
)())((,0
((()(),0
)))))),0
)()))(,0
)()()(,0
))(()),0
(()))(,0
())((),0
)()()),0
)(())(,0
)((()),0
))())),0
(((()(,0
((((((,0
))(((),0
Loading