[Applied Algebra] MQ equation solution on GF(2): Wu elimination method implementation

F 2 \mathbb{F}_2 F2Realization of Wu Elimination Method of Upper MQ Equation


Due to the difficulty of solving the MQ problem with the Groebner-based method, we have tried the MQ-to-SAT method and the MQ-to-SMT method to solve the problem, but the solution effect is still limited. After further research, we designed a solution algorithm based on the Wu elimination method ; More importantly, we have identified the next path: only by sticking to the path of experimental algorithm can we hope to improve F 2 \mathbb{F}_2F2Solving such NP-problems on the MQ equation;

The source code of this article: the implementation of the Wu elimination method of the MQ equation


F 2 \mathbb{F}_2F2The Difficulty of Searching for the Solution of the Upper MQ Equation

Let's first look at F 2 \mathbb{F}_2F2The solution distribution characteristics of the above MQ equation: In the figure, we do not really show the relative position of the solution (because it is in nnin n -dimensional space, which cannot be visualized), we put nnA point in n -dimensional space (inF 2 n \mathbb{F}^n_2F2nabove) embedded in xxon the x- axis, sonnAdjacent points in the n -dimensional space do not reflect the adjacency on the line, but it does not hinder our intuitive understanding of the random distribution characteristics of the number of equations that can be satisfied by the solution. It can be seen that to find M = 16 M =16M=The point of 16 (that is, the solution of the equation) is a difficult search problem;

insert image description here


Wu elimination method to solve F 2 \mathbb{F}_2F2On the MQ problem

The core algorithm of Wu's elimination method is "quasi-division". We assume that there is a polynomial f , g ∈ k [ x 1 , . . . , xn ] f, g \in k[x_1,...,x_n]f,gk[x1,...,xn] , they all contain the variablexi x_{i}xi, also assuming that the variable xi x_{i}xiThe item order of is the most front, which is the next variable to be eliminated, then we use the quasi-division method REM ⁡ ( f , g , xi ) \operatorname{REM}(f,g,x_i)REM ( f ,g,xi) can get the quotient and remainder polynomials q , rq, rof the quasi-division resultq,r , whererrr is without variablexi x_ixi, so we get the elimination result (of course what we don't want to see is r = 0 r=0r=0 ); Note that the Wu elimination method is often more efficient than the Groebner basis method in practical applications[1];

We assume that the existing polynomial equations g 1 , . . . , gm ∈ k [ x 1 , . . . , xn ] g_{1},..., g_{m} \in k[x_1,..., x_n]g1,...,gmk[x1,...,xn] , we hope to obtain the feature column in the following form through the method of zero elimination:

f 1 = f 1 ( x 1 ) f 2 = f 2 ( x 1 , x 2 ) ⋮ f n = f n ( x 1 , … , x n ) \begin{aligned} f_{1} &=f_{1}(x_{1}) \\ f_{2} &=f_{2}(x_{1}, x_{2}) \\ & \vdots \\ f_{n} &=f_{n}(x_{1}, \ldots, x_{n}) \end{aligned} f1f2fn=f1(x1)=f2(x1,x2)=fn(x1,,xn)

We expect f 1 ≠ 0 , . . . , fn ≠ 0 f_{1} \neq 0,..., f_{n} \neq 0f1=0,...,fn=0 , so that we can solvex 1 . . . xn x_{1}...x_{n}x1...xn, but in reality, the system of polynomial equations g 1 , . . . , gm g_{1},..., g_{m}g1,...,gmWith multiple feature columns, we have a high probability of not getting such a strict triangular column (our experiments have also proved this point), in most cases, we can only get a triangular column of the following form:

f 1 = f 1 ( x 1 ) = 0 f 2 = f 2 ( x 1 , x 2 ) = 0 ⋮ f n = f n ( x 1 , … , x i ) = 0 ⋮ f n = f n ( x 1 , … , x n − 1 ) ≠ 0 f n = f n ( x 1 , … , x n − 1 , x n ) ≠ 0 \begin{aligned} f_{1} &=f_{1}(x_{1}) = 0 \\ f_{2} &=f_{2}(x_{1}, x_{2}) = 0 \\ & \vdots \\ f_{n} &=f_{n}(x_{1}, \ldots, x_{i}) = 0 \\ & \vdots \\ f_{n} &=f_{n}(x_{1}, \ldots, x_{n-1}) \neq 0 \\ f_{n} &=f_{n}(x_{1}, \ldots, x_{n-1}, x_{n}) \neq 0 \end{aligned} f1f2fnfnfn=f1(x1)=0=f2(x1,x2)=0=fn(x1,,xi)=0=fn(x1,,xn1)=0=fn(x1,,xn1,xn)=0

Such a triangular sequence is also a characteristic sequence of the original equation system, but we cannot rely on it to solve the original equation; we will discuss later that if we want to find a strict triangular sequence, its essence is a search problem (we I originally wanted to escape the original solution space search problem by eliminating elements, but fell into another search problem, so the intuitive feeling is that the essence of the MQ problem is a search problem);

insert image description here

Example. 1. (Wu elimination method to find the feature sequence) : consider k [ x 1 . . . x 4 ] k[x_1...x_4]k[x1...x4] on polynomial equations: orderP = { P 1 , P 2 , P 3 } \mathcal{P}=\{P_{1}, P_{2}, P_{3}\}P={ P1,P2,P3} , where

P 1 = x 1 x 4 2 + x 4 2 − x 1 x 2 x 4 − x 2 x 4 + x 1 x 2 + 3 x 2 P 2 = x 1 x 4 + x 3 − x 1 x 2 P 3 = x 3 x 4 − 2 x 2 2 − x 1 x 2 − 1 \begin{aligned} &P_{1}=x_{1} x_{4}^{2}+x_{4}^{2}-x_{1} x_{2} x_{4}-x_{2} x_{4}+x_{1} x_{2}+3 x_{2} \\ &P_{2}=x_{1} x_{4}+x_{3}-x_{1} x_{2} \\ &P_{3}=x_{3} x_{4}-2 x_{2}^{2}-x_{1} x_{2}-1 \end{aligned} P1=x1x42+x42x1x2x4x2x4+x1x2+3x _2P2=x1x4+x3x1x2P3=x3x42x _22x1x21

The elimination process is as follows (input polynomial set P \mathcal{P}P , the output feature columnC \mathcal{C}C):

P = F 1 = { P 1 , P 2 , P 3 } ⊂ F 2 = { P 1 , ⋯   , P 5 } ⊂ F 3 = { P 1 , ⋯   , P 6 } B 1 = [ P 2 ] B 2 = [ P 4 , P 2 ] B 3 = [ P 6 , P 4 , P 2 ] = C R 1 = { P 4 , P 5 } R 2 = { P 6 } R 3 = ∅ , \begin{aligned} \mathcal{P}=&\mathcal{F}_{1}=\{P_{1}, P_{2}, P_{3}\} \quad \subset \mathcal{F}_{2}=\{P_{1}, \cdots, P_{5}\} \quad \subset \mathcal{F}_{ {3}}=\{P_{1}, \cdots, P_{ {6}}\} \\ &\mathcal{B}_{1}=[P_{2}] \quad \quad \quad \mathcal{B}_{2}=[P_{4}, P_{2}] \quad \quad \quad \mathcal{B}_{3}=[P_{6}, P_{4}, P_{2}]=\mathcal{C}\\ &\mathcal{R}_{1}=\{P_{4}, P_{5}\} \quad \quad \quad \mathcal{R}_{2}=\{P_{6}\} \quad \quad \quad \mathcal{R}_{3}=\varnothing, \end{aligned} P=F1={ P1,P2,P3}F2={ P1,,P5}F3={ P1,,P6}B1=[P2]B2=[P4,P2]B3=[P6,P4,P2]=CR1={ P4,P5}R2={ P6}R3=,

where, P 4 = REM ⁡ ( P 1 , P 2 , x 4 ) P_4 = \operatorname{REM}(P_1,P_2,x_4)P4=REM ( P1,P2,x4) ,P 4 = REM ⁡ ( P 3 , P 2 , x 4 ) P_4 = \operatorname{REM}(P_3,P_2,x_4)P4=REM ( P3,P2,x4) , andP 6 = REM ⁡ ( P 4 , P 5 , x 3 ) P_6 = \operatorname{REM}(P_4,P_5,x_3)P6=REM ( P4,P5,x3) ; Finally we can get the triangular feature column:

C = [ C 1 , C 2 , C 3 ] = [ x 1 ( 2 x 1 x 2 2 + 2 x 2 2 − 2 x 1 x 2 + x 1 + 1 ) x 1 x 3 2 + x 3 2 − x 1 2 x 2 x 3 − x 1 x 2 x 3 + x 1 3 x 2 + 3 x 1 2 x 2 ] x 1 x 4 + x 3 − x 1 x 2 . \begin{aligned} \mathbb{C} &=[C_{1}, C_{2}, C_{3}] \\ &=[\begin{array}{l} x_{1}(2 x_{1} x_{2}^{2}+2 x_{2}^{2}-2 x_{1} x_{2}+x_{1}+1) \\ x_{1} x_{3}^{2}+x_{3}^{2}-x_{1}^{2} x_{2} x_{3}-x_{1} x_{2} x_{3}+x_{1}^{3} x_{2}+3 x_{1}^{2} x_{2}] \\ x_{1} x_{4}+x_{3}-x_{1} x_{2} \end{array}. \end{aligned} C=[C1,C2,C3]=[x1( 2x _1x22+2x _222x _1x2+x1+1)x1x32+x32x12x2x3x1x2x3+x13x2+3x _12x2]x1x4+x3x1x2.

The algorithm for finding feature columns we used in the above example is formalized as follows, where BasSet ⁡ ( F , ord ) \operatorname{BasSet}(\mathcal{F}, ord)BasSet(F,or d ) is according to the item orderord ordor dFind the system of equationsF \mathcal{F}The essence of the base column of F is to find the next division formula used for quasi-division.

insert image description here
As we said earlier, the feature columns calculated by the above algorithm are not necessarily strict triangular columns. In fact, it is very difficult to find a strict triangular column (although it often exists in the solution of MQ problems); So is there an algorithm that must find a strict triangular sequence? Obviously, you only need to follow the item order x 1 , . . . , xn x_1,...,x_nx1,...,xn, it is enough to do pairwise elimination of variables one by one, but this kind of calculation complexity is very high, we now assume that F \mathcal{F}F is the number of argumentsnnn , the number of equationsmmThe equation system of m , the first round of eliminationx 1 x_1x1After that we get C m 2 C^{2}_mCm2equations, the second round of elimination x 2 x_2x2Then we get C m ( m − 1 ) 2 C^{2}_{m(m-1)}Cm(m1)2equations (of course, there will be 0 equations, but even if it is 0 equations, we only get it after the quasi-division operation)... and so on, for nnn variables, the computational complexity of the elimination algorithm isO ( mn ) \mathcal{O}(m^n)O(mn ), this is simply more complex than the violent search solutionO ( m 2 n ) \mathcal{O}(m2^n)Of ( m 2n )is also higher;

Based on the above analysis, we can see that the computational complexity is O ( mn ) \mathcal{O}(m^n)O(mThe search strategy of the elimination algorithm of n )is breadth-first, that is, it must find out the characteristic elimination polynomial of each variable, which is actually unnecessary, because in fact, only the one corresponding to the strict triangular sequence needs to be found" Elimination path" is enough, so we designed a depth-first elimination algorithm;

During the running of the Wu elimination algorithm, the schematic diagram of the change of the number of elimination polynomials corresponding to the variables arranged according to the order of items, we start from x 1 x_1x1Start to eliminate, expect to get non-zero fn f_nfn, in this process, the number of polynomials will expand rapidly at the beginning, and then decrease quickly as the number of variables decreases, so that our elimination path often ends up at a certain xi x_i in the middlexiWhen the 0 polynomial is obtained and terminated (as shown in the path w 2 w_2w2Shown) We expect to find the path w 1 w_1 through depth-first searchw1, to get a strict non-zero triangular feature column:

insert image description here
The implementation of the depth-first Wu-elimination algorithm is as follows:

while VAR_ELIMINATED != ITEMS_VARS_USED[-1]:
    print(' ============  '+ str(VAR_ELIMINATED) +'  ================= ');
    INDEX_VAR = ITEMS_VARS_USED.index(VAR_ELIMINATED);
    print('R_m = '+str(len(CHARASTIC_SETS[VAR_ELIMINATED])));
    print('R_m+1 = '+str(len(CHARASTIC_SETS[ITEMS_VARS_USED[INDEX_VAR+1]])));
    if RUNNING_TIMES>50000:break;
    # --- checking stopping ---
    VAR_ELIMINATED_NEXT = ITEMS_VARS_USED[ ITEMS_VARS_USED.index(VAR_ELIMINATED_START)+1 ];
    if len(CHARSET_NUM_RECORD[VAR_ELIMINATED_NEXT])>2000:
        if CHARSET_NUM_RECORD[VAR_ELIMINATED_NEXT][-2000] == len(CHARASTIC_SETS[VAR_ELIMINATED_NEXT]):
           VAR_ELIMINATED_START = ITEMS_VARS_USED[ ITEMS_VARS_USED.index(VAR_ELIMINATED_START) +1];
           VAR_ELIMINATED = VAR_ELIMINATED_START;continue;
    if len(CHARASTIC_SETS[VAR_ELIMINATED])<2:
        VAR_ELIMINATED = VAR_ELIMINATED_START;continue; # back-tracing;
    if len(CHARASTIC_SETS[ITEMS_VARS_USED[-4]])>200 and (ITEMS_VARS_USED.index(VAR_ELIMINATED_START) < ITEMS_VARS_USED.index(ITEMS_VARS_USED[-5])):
        VAR_ELIMINATED_START = ITEMS_VARS_USED[-5];
        VAR_ELIMINATED = VAR_ELIMINATED_START;continue;
    # --- choosing polynomials ---
    if VAR_ELIMINATED==VAR_ELIMINATED_START:POLYNOMIAL_WUBAS = CHARASTIC_SETS[VAR_ELIMINATED][ np.random.randint( len(CHARASTIC_SETS[VAR_ELIMINATED]) ) ];
    POLYNOMIAL_DIV   = CHARASTIC_SETS[VAR_ELIMINATED][ np.random.randint( len(CHARASTIC_SETS[VAR_ELIMINATED]) ) ];
    while POLYNOMIAL_DIV == POLYNOMIAL_WUBAS:POLYNOMIAL_DIV = CHARASTIC_SETS[VAR_ELIMINATED][ np.random.randint( len(CHARASTIC_SETS[VAR_ELIMINATED]) ) ];
    INDEX_i = CHARASTIC_SETS[VAR_ELIMINATED].index(POLYNOMIAL_WUBAS);INDEX_j = CHARASTIC_SETS[VAR_ELIMINATED].index(POLYNOMIAL_DIV);
    while (VAR_ELIMINATED,(INDEX_i,INDEX_j)) in VISITED_POINTS:
        if VAR_ELIMINATED==VAR_ELIMINATED_START:POLYNOMIAL_WUBAS = CHARASTIC_SETS[VAR_ELIMINATED][ np.random.randint( len(CHARASTIC_SETS[VAR_ELIMINATED]) ) ];
        POLYNOMIAL_DIV   = CHARASTIC_SETS[VAR_ELIMINATED][ np.random.randint( len(CHARASTIC_SETS[VAR_ELIMINATED]) ) ];
        while POLYNOMIAL_DIV == POLYNOMIAL_WUBAS:POLYNOMIAL_DIV = CHARASTIC_SETS[VAR_ELIMINATED][ np.random.randint( len(CHARASTIC_SETS[VAR_ELIMINATED]) ) ];
        INDEX_i = CHARASTIC_SETS[VAR_ELIMINATED].index(POLYNOMIAL_WUBAS);INDEX_j = CHARASTIC_SETS[VAR_ELIMINATED].index(POLYNOMIAL_DIV);
        RUNNING_TIMES_VIS+=1;
        if RUNNING_TIMES_VIS>2000:
            NEED_TO_BACKT = True;RUNNING_TIMES_VIS=0;break;
    if NEED_TO_BACKT:
        NEED_TO_BACKT = False;
        VAR_ELIMINATED_START = ITEMS_VARS_USED[ ITEMS_VARS_USED.index(VAR_ELIMINATED_START) +1];
        VAR_ELIMINATED = VAR_ELIMINATED_START;continue;        
    CHARSET_NUM_RECORD[ITEMS_VARS_USED[INDEX_VAR+1]].append( len(CHARASTIC_SETS[ITEMS_VARS_USED[INDEX_VAR+1]]) );
    VISITED_POINTS.append( (VAR_ELIMINATED,(INDEX_i,INDEX_j)) );
    # --- Doing reduction on x_n ---
    POLYNOMIAL_QUO,POLYNOMIAL_REM = pseudo_division(POLYNOMIAL_WUBAS,POLYNOMIAL_DIV,VAR_ELIMINATED);
    if POLYNOMIAL_REM==0 or (POLYNOMIAL_REM in CHARASTIC_SETS[ITEMS_VARS_USED[INDEX_VAR+1]]):
        VAR_ELIMINATED = VAR_ELIMINATED_START;continue; # back-tracing;
    CHARASTIC_SETS[ITEMS_VARS_USED[INDEX_VAR+1]].append(POLYNOMIAL_REM);
    VAR_ELIMINATED = ITEMS_VARS_USED[INDEX_VAR+1];
    POLYNOMIAL_WUBAS = POLYNOMIAL_REM;
    RUNNING_TIMES+=1;print('Running --- '+str(RUNNING_TIMES));
    if VAR_ELIMINATED==ITEMS_VARS_USED[-1]:print(POLYNOMIAL_REM);

In fact, our above code adopts the idea of ​​depth-first, real-time detection of the location of the elimination. When the elimination process has passed the peak area of ​​the number of characteristic equations of the elimination, the number of equations decreases sharply, and it is easier at this time get 0 00 polynomial, then we need to adjust the starting position of the search, and properly carry out the strategy of breadth first, so that it is easier to obtain strict feature columns, the following is form = 16, n = 8 m=16,n=8m=16,n=As a result of running the MQ equations of 8 , the equations were successfully solved:

 ============  t1  ================= 
R_m = 16
R_m+1 = 0
Running --- 1
 ============  t2  ================= 
R_m = 1
R_m+1 = 0
 ============  t1  ================= 
R_m = 16
R_m+1 = 1
Running --- 2
 ============  t2  ================= 
R_m = 2
R_m+1 = 0
Running --- 3
 ============  t3  ================= 
R_m = 1
R_m+1 = 0
 ============  t1  ================= 
R_m = 16
R_m+1 = 2
Running --- 4
 ============  t2  ================= 
R_m = 3
R_m+1 = 1
Running --- 5
 ============  t3  ================= 
R_m = 2
R_m+1 = 0
Running --- 6
 ============  t4  ================= 
R_m = 1
R_m+1 = 0
 ============  t1  ================= 
R_m = 16
R_m+1 = 3
... ... 

... ...
============  t5  ================= 
R_m = 533
R_m+1 = 41
... ...
 ============  t5  ================= 
R_m = 533
R_m+1 = 41
Running --- 13272
 ============  t6  ================= 
R_m = 42
R_m+1 = 5
Running --- 13273
 ============  t7  ================= 
R_m = 6
R_m+1 = 0
Running --- 13274
f_n = t8 + 1;

Among them, the order of variable elimination items is t 1 , . . . , t 8 t_1,...,t_8t1,...,t8, R m \mathcal{R}_m RmRepresents the current variable corresponding to the characteristic polynomial fm f_mfmThe number of (non-zero), R m + 1 \mathcal{R}_{m+1}Rm+1Represents the characteristic polynomial fm + 1 f_{m+1} corresponding to the current variablefm+1(non-zero) number; finally get fn = t 8 + 1 = 0 f_n = t_8+1=0fn=t8+1=0 , which meanst 8 = 1 t_8 = 1t8=1 , and then substituting the previous equations one by one to solve all the solutions (according to the zero point theorem, this is the original equation system (in the problem it is0 00- dimensional ideal) corresponds to the cluster);


Summarize

In the process of solving the MQ equation by the Wu elimination method, when we use the quasi-division operation to eliminate variables according to a certain item order, we cannot always get non-0 00 polynomial, then the elimination will be interrupted, so that you can't get a non-zero00 triangular column to solve the equation in reverse, so we have to use the search problem processing strategy to solve this problem;


references

[1] Ideals, Varieties, and Algorithms,2004,DA Cox and Little, J. and D O’Shea;

[2] Algorithm design and analysis of satisfiability problems, 1997, He Simin;

Guess you like

Origin blog.csdn.net/hanss2/article/details/124844547