enum.c 2.55 KB
Newer Older
QuentinH's avatar
c  
QuentinH committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
#include <stdio.h>
#include <stdlib.h>
#include "tools_parser.h"
#include "tools.h"
// #include "monomials.h"
#include "monomial_new.h"
// int convert_gray_code(int n)
// {
//     return n ^ (n >> 1);
// }

struct polynomial_system {
    int n;                      /* # variables   */
    int v;                      /* # linear variables */
    char ** variable_name;      /* array of strings, size n */
    int D;                      /* max degree of any monomial */
    int m;                      /* # polynomials */
    bool ** poly;               /* array of polynomials, size m */   
    struct monomial_ctx_t * mono; /* description of the monomials */
};



// Give A matrix values with monomial sol input 
bool **update_mat(bool **poly, monomial_t sol, struct polynomial_system *poly_sys)
{
    bool **res;

    // Aloccate res
    res = malloc(sizeof(bool *)* poly_sys->m);
    for (int i = 0; i < poly_sys->m; i++)
        res[i] = malloc(sizeof(bool) * poly_sys->v);
    
    int cpt_i = -1;

    // update poly
    for (int i = 0; i < poly_sys->m * poly_sys->v; i++)
    {
        // check if there is 1 in polynome
        bool cur = poly[i][0];
        for (int j = 1; j < monomial_rank_degD(poly_sys->n, poly_sys->mono); j++)
        {
            if (poly[i][j] == 1)
            {
                if (monomial_gcd(sol, monomial_unrank(poly_sys->mono, j) == sol))
                    cur ^= 1;
            }
        }
        if (i % poly_sys->v == 0)
            cpt_i++;
        
        res[cpt_i][i%poly_sys->v] = cur;

    }
    return res;
}

//TODO
monomial_t solve(monomial_t sol, struct polynomial_system *poly_sys)
{
    if (sol == -1)
        return -1;

    return;
}

monomial_t enum_recur(monomial_t a, int b, int v, struct polynomial_system *poly_sys)
{
    if (v == 0)
        return a;
    a = a << 1;
    a ^= b;
    monomial_t sol1 = enum_recur(a, 0, v-1, poly_sys);
    monomial_t sol2 = enum_recur(a, 1, v-1, poly_sys);

    monomial_t tmp = solve(sol1, poly_sys);
    if (tmp == -1)
        tmp = solve(sol2, poly_sys);
    return tmp;
}


monomial_t enumerate(struct polynomial_system *poly_sys)
{
    monomial_t a = 0;
    monomial_t sol1 = enum_recur(a, 0, poly_sys->n - 1, poly_sys);
    monomial_t sol2 = enum_recur(a, 1, poly_sys->n - 1, poly_sys);
    if (sol1 != -1)
        return sol1;
    if (sol2 != -1)
        return sol2;
    printf("No solution found\n");
    return -1;
}


int main()
{
    // for (int n = 0; n < 16; n++)
    // {
    //     printf("n = %d, ng = %d\n", n, convert_gray_code(n));
    // }
    printf("%d\n", 1 << 1);
    return 0;
}