1 | initial version |
The line p(x) = []
attempts to construct a symbolic function, and when you call par(v1+v2)
, it calls p(v1+v2)
which tries to construct a symbolic function without the correct form for the arguments.
Is p
supposed to be local to the function, or are its values supposed to be remembered from one call to the next?
You define p(x) = []
, and then you never provide a way to change this: the main loop says for z in p(x-y)
, but since p(x-y)
starts off empty, the loop will never do anything.
2 | No.2 Revision |
The line p(x) = []
attempts to construct a symbolic function, and when you call par(v1+v2)
, it calls p(v1+v2)
which tries to construct a symbolic function without the correct form for the arguments.arguments. I think a dictionary would be better for this.
Is p
supposed to be local to the function, or are its values supposed to be remembered from one call to the next?
You define p(x) = []
, and then you never provide a way to change this: the main loop says for z in p(x-y)
, but since p(x-y)
starts off empty, the loop will never do anything.
3 | No.3 Revision |
The line p(x) = []
attempts to construct a symbolic function, and when you call par(v1+v2)
, it calls p(v1+v2)
which tries to construct a symbolic function without the correct form for the arguments. I think a dictionary would be better for this.
Is p
supposed to be local to the function, or are its values supposed to be remembered from one call to the next?
You define p(x) = []
, and then you never provide a way to change this: the main loop says for z in p(x-y)
, but since p(x-y)
starts off empty, the loop will never do anything.
EDIT:
You need a place to start: p(x)
can't be empty for every x
. You also need to know when you're done. Here is a start, not sure if it works:
p = {}
def initialize_p():
for x in Pos:
if x:
# The nonzero vectors should start with the trivial partition.
p[x] = [[x]]
else:
# if x is zero, don't include it in the partition.
p[x] = []
def par(x):
for y in S:
if x-y in Pos:
for z in p[x-y]:
# z should be a list, so add a new element to that list
n = z + [y]
# sort n so we don't get both [v1, v2] and [v2, v1]
n = sorted(n, key=str)
if n not in p[x]:
p[x].append(n)
return p[x]
I put this in a file called vec.sage
and did:
sage: var('v1, v2')
sage: S = [v1, v2] # why include v1+v2?
sage: Pos = [k*v1+l*v2 for k in [0,1,2] for l in [0,1,2]]
sage: %attach vec.sage
sage: initialize_p()
sage: par(v1)
[[v1]]
sage: par(v1+v2)
[[v1 + v2], [v1, v2]]
sage: par(2*v1+v2)
[[2*v1 + v2], [v1, v1 + v2], [v1, v1, v2], [2*v1, v2]]