# Recursive calculation of a characteristic polynomial

I am trying to calculate the characteristic polynomial of a complex arrangement of dimension 3 using recursion. But I am getting a return that doesn't make any sense to me. The code looks like this:

def threeDimChaPol(Matroid):
if Matroid.rank() <= 2:
MatGS = len(Matroid.groundset_list()) - 1
return x * (x - MatGS) * (x - 1)
HE = Matroid.groundset_list()[-1]
print HE
MatD = Matroid.delete(HE)
MatR = Matroid.contract(HE).simplify()
R = len(MatR.groundset_list()) - 1
return threeDimChaPol(MatD) - (x - 1) * (x - R)


I am feeding the function with the Matroid that comes out when I use the normalvectors of the hyperplanes of the G32 and trim it down to 4 specific hyperplanes.

I use Matroid(Matrix(NF3, G32Normals).transpose()), where I prepared a list of the G32 normalvectors in which I use a numberfield instead of a cyclotomic field for the complex numbers (the vectors are in the same order as when you get them through ReflectionGroups). I then use deletion on everything, but 0,1,2,12 and get a Matroid of rank 4 with 4 elements.

If I now use the function above it responds 12,2 as it should, because they are the things chosen out of the groundset, but instead of returning the polynomial it just writes 53466 after that.

So the return is just a number, which does not make any sense to me. Before I wrote this into a new file, double attaching the file, where this function is in, to sage solved the problem and gave the right result. When I restarted sage and attached in only once the bug would appear again. But writing the function alone with the neccessary information (Matroid and Vectors) into a new file and attaching it just gives me the 53466 return, no matter how often I attach it to sage.

Since the code is working sometimes and other times not it really confuses me where the mistake could be. Any kind of help would be greatly appreciated!

edit retag close merge delete

Sort by » oldest newest most voted

what is x ? Do you define x somewhere else ? add x = polygen(QQ,'x') to your function

more

Thanks for your reply. I'm sorry, but I forgot to mention that x = polygen(QQ,'x') already exists at the beginning of the program. The idea is that I don't have to define it again in that function (it saves runtime). Do you think that this could cause the bug? I will just write the polygen back into the function then.

The strange thing is that it seems to work in most cases. It goes wrong sometimes when the polynomial factors with 3 ones and 1 zero.

Update: It instantly seems to work now. Does that have to do anything with how python operates? I am pretty new to this so I thought that defining it global would be a good idea. I will try do do a bigger calculation and look if the bug keeps appearing. Thanks for your help!

( 2020-04-20 09:56:35 -0600 )edit