In [3]:
from __future__ import division, print_function
import sys, os
import numpy as np
a = get_ipython().magic(u'pwd')
sys.path.append('/'.join(os.path.dirname(os.path.abspath(a)).split('/')))
from GrobnerSolver.polys.multi_cheb import MultiCheb
from GrobnerSolver.polys.multi_power import MultiPower
from GrobnerSolver.polys.grev import GrevlexGen
from GrobnerSolver.grobner.grobner import Grobner
from GrobnerSolver.grobner import maxheap
import pandas as pd
from scipy.linalg import lu

ggen = GrevlexGen(2,np.array([5,5]))

#f0, f1 = y - 2*x, 1+2*x*y

a1 = np.array([[0,-2],[1,0]])
a2 = np.array([[1,0],[0,2]])

c1= MultiPower(a1.T)
c2 = MultiPower(a2.T)

grob = Grobner([c1,c2])

grob.add_s_to_matrix()
grob.matrix = grob.matrix.loc[:, (grob.matrix != 0).any(axis=0)]

grob.add_r_to_matrix()
grob.matrix = grob.matrix.loc[:, (grob.matrix != 0).any(axis=0)]

grob_mat = np.flip(grob.matrix.values,axis=1) # Flip due to bad ordering in grevlex generator

new_mat_index = grob.matrix.columns.values[::-1]

# Put correct order on table
ord_mat = grob.matrix[['[2 2]','[1 3]', '[2 1]', '[1 2]','[0 3]', '[2 0]', '[1 1]', '[0 2]','[1 0]', '[0 1]', '[0 0]']]

grob_mat = ord_mat.values
new_mat_index = ord_mat.columns.values

new_mat = np.vstack((grob_mat[3:], grob_mat[:3])) # Put R on top for reduction

P,L,U = lu(new_mat)
P_argmax = np.argmax(P,axis=0)



print(new_mat_index)
print(U[-3:])


Power
(2, 2)
[[ 0. -0.  0.  0. -0.]
 [ 0. -0. -0.  1.  0.]
 [ 0. -0. -2.  0. -0.]
 [ 0. -0. -0.  0.  0.]
 [-0. -0. -0. -0. -0.]]
(2, 1)
[[-0.  0. -0.  0.  0.]
 [-0. -0.  1.  0.  0.]
 [ 0. -2. -0. -0.  0.]
 [ 0. -0.  0. -0. -0.]
 [-0. -0. -0. -0.  0.]]
(1, 2)
[[ 0. -0. -0.  1.  0.]
 [ 0. -0. -2.  0. -0.]
 [ 0. -0. -0. -0.  0.]
 [-0. -0. -0.  0.  0.]
 [-0. -0.  0.  0.  0.]]
(2, 0)
[[ 0. -0.  0.  0. -0.]
 [-0.  1.  0.  0. -0.]
 [-2.  0.  0.  0. -0.]
 [-0.  0.  0.  0. -0.]
 [-0. -0. -0. -0.  0.]]
(1, 1)
[[-0.  0.  1.  0.  0.]
 [ 0. -2. -0. -0.  0.]
 [-0. -0. -0. -0.  0.]
 [-0. -0.  0.  0.  0.]
 [ 0.  0. -0.  0.  0.]]
(0, 2)
(1, 0)
[[-0.  1.  0.  0. -0.]
 [-2.  0.  0. -0. -0.]
 [-0.  0.  0. -0. -0.]
 [-0.  0.  0. -0. -0.]
 [ 0.  0.  0. -0. -0.]]
(0, 1)
(0, 0)
['[2 2]' '[1 3]' '[2 1]' '[1 2]' '[0 3]' '[2 0]' '[1 1]' '[0 2]' '[1 0]'
 '[0 1]' '[0 0]']
[[ 0.   0.   0.   0.   0.   0.   2.   0.   0.   0.   1. ]
 [ 0.   0.   0.   0.   0.   0.   0.  -0.5  0.   0.  -0.5]
 [ 0.   0.   0.   0.   0.   0.   0.   0.  -2.   1.   0. ]]

The above code corresponds to the groebner basis:

2xy + 1, -2x^2 - 1/2, x - 2y

which is correct.

Questions

PLU shapes, which to grab when obviously not square,

co-prime deconstruction, condition working?

Do I need to order the U matrix by index?

So we could redue the matrix and just grab the reduced s's. Your grobner basis is the originals F's and new S's.

Do primality check,

This may not be reduced Groebner but still Groebner.

TODO

Primality check in code remove pandas


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]:


In [ ]: