Commit 4e3793f9 authored by QuentinH's avatar QuentinH
Browse files

lecture fichier

parent 41342b78
......@@ -17,6 +17,15 @@ struct monomial_ctx_t
int v;
};
struct polynomial_system {
int n; /* # 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 * mono; /* description of the monomials */
};
static inline monomial_t mkvar(int i)
{
return ((monomial_t) 1) << i;
......@@ -160,7 +169,94 @@ int create_monomial(int degree, int *vars, struct monomial_ctx_t *mono)
for (int i = 0; i < degree; i++)
term += mkvar(vars[i]);
int mon = monomial_rank(term, mono);
assert(hamming_weight(mono->monomials[mon]) <= 2);
assert(mon < mono->Nd[3]);
// assert(hamming_weight(mono->monomials[mon]) <= 2);
// assert(mon < mono->Nd[3]);
return mon;
}
// v number of linear variables
// struct monomial_ctx_t *reorder(struct monomial_ctx_t *mono, int D)
// {
// struct monomial_ctx_t *new = (struct monomial_ctx_t *)malloc(sizeof(struct monomial_ctx_t));
// u64 mask = 2**v;
// monomial_t *new_tab = (monomial_t *)malloc(sizeof(monomial_t) * mono->Nd[D+1]);
// for (int i = 0; i < mono->Nd[D+1]; i++)
// {
// new_tab[i] = mono->monomials[i];
// }
// }
int *known_lin(struct polynomial_system *poly_sys)
{
int *res = (int *)malloc(sizeof(int) * poly_sys->mono->Nd[D+1]);
monomial_t mask = 2**(poly_sys->v + 1) - 1;
for (int i = 0; i < poly_sys->mono->Nd[D+1]; i++)
{
monomial_t tmp = poly_sys->mono->monomials[i];
tmp &= mask;
// non linear
if (tmp == 0)
res[i] = -1;
else
res[i] = ffs(tmp);
}
return res;
}
int monomial_rank_convert(int n, int v, struct monomial_ctx_t *mono_1, struct monomial_ctx_t *mono_2)
{
monomial_t tmp = mono_1->monomials[n];
tmp = tmp >> v;
return monomial_rank(tmp, mono_2);
}
struct polynomial_system **new_poly(struct polynomial_system *poly_sys)
{
struct monomial_ctx_t *mono_A = monomial_setup(poly_sys->n - poly_sys->v, poly_sys->v, D);
struct monomial_ctx_t *mono_B = monomial_setup(poly_sys->n - poly_sys->v, poly_sys->v, D);
int *tab = known_lin(poly_sys);
bool **poly_A = (bool **)malloc(sizeof(bool) * poly_sys->m * poly_sys->v);
bool **poly_B = (bool **)malloc(sizeof(bool) * poly_sys->m);
for (int i = 0; i < poly_sys->m; i++)
{
for (int k = 0; k < poly_sys->v; k++)
{
if (k == 0)
poly_B[i] = (bool *)malloc(sizeof(bool) * poly_sys->mono->Nd[D+1]);
poly_A[i*poly_sys->v + k] = (bool *)malloc(sizeof(bool) * poly_sys->mono->Nd[D+1]);
for (int c = 0; c < poly_sys->mono->Nd[D+1]; c++)
{
if (k == 0)
poly_B[i][c] = 0;
poly_A[i*poly_sys->v + k][c] = 0;
}
for (int j = 0; j < poly_sys->mono->Nd[D+1]; j++)
{
if (tab[poly_sys->poly[i][j]] == -1)
{
int tmp = monomial_rank_convert(j, poly_sys->v, poly_sys->mono, mono_B);
poly_B[i][tmp] ^= 1;
}
else
{
int tmp = monomial_rank_convert(j, poly_sys->v, poly_sys->mono, mono_A);
poly_A[i*poly_sys->v + k][tmp] ^= 1;
}
}
}
}
struct polynomial_system *sys_A, *sys_B;
struct polynomial_system *res[2] = {sys_A, sys_B};
return res;
}
\ No newline at end of file
......@@ -121,6 +121,28 @@ struct input_poly_t * convert_input_system(struct parser_system_t * const sys, s
return input_system;
}
// m nombre de polynome
bool **convert_poly_system(struct parser_system_t * const sys, struct monomial_ctx_t *mono, int m_nb, int D)
{
bool **poly = (bool **)malloc(sizeof(bool *) * m_nb);
for (int i = 0; i < m_nb; i++)
{
poly[i] = (bool *)malloc(sizeof(bool) * get_Nd(D + 1, mono));
for (int j = 0; j < get_Nd(D + 1, mono); j++)
poly[i][j] = 0;
}
int i = 0;
struct parser_poly_t *head = sys->first;
for (struct parser_poly_t * p = head; p != NULL; p = p->next) {
for (struct parser_monomial_t *m = head; m != NULL; m = m->next) {
int mon = create_monomial(m->degree, m->vars, mono);
poly[i][mon] ^= 1;
}
i++;
}
return poly;
}
void system_to_txt(FILE * f, struct input_poly_t *sys, int size, char **variable_name, struct monomial_ctx_t * mono)
{
int n = get_Nd(2, mono) - 1;
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment