<commit_before>/* A small utility to visualize diff between M_pi(k) and RM_pi(k + 1) */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>

#include "log.h"
#include "common.h"
#include "ideals.h"

#define WITH_Ms       1
#define WITH_RMs      (1 << 1)

char* package = "M_pi(k) diff RM_pi(k + 1) structure visualizer";
char* version = "0.0.1";
char* progname = NULL;

/* global debug level */
int debug = 0;

static int handle_cmdline(int *argc, char ***argv);

int main(int argc, char **argv) {
    unsigned long long i, j;

    IDEAL* Rad;
    IDEAL* pp;
    IDEAL** Ms;
    IDEAL** RMs;

    /* learn who we really are */
    progname = (char *)strrchr(argv[0], '/');
    progname = progname ? (progname + 1) : argv[0];

    /* handle cmdline */
    handle_cmdline(&argc, &argv);

    /* initializing needed things */
    init_constants(p, l, lambda);

    Ms   = (IDEAL**) malloc(numofMs*sizeof(IDEAL*));
    RMs  = (IDEAL**) malloc(numofMs*sizeof(IDEAL*));

    if (Ms == NULL || RMs == NULL) {
        fprintf(stderr, "Unable to allocate memory for ideals' arrays.\n");
        exit(EXIT_FAILURE);
    }

    /* do the job */
    dbg_msg("Computing Ms...\n");
    for (i = 0; i < numofMs; ++i) {
        pp = ideal_create(q);
        ideal_init(pp, pi, m, i);
        Ms[i] = pp;
    }

    dbg_msg("Computing Rad...\n");
    pp = ideal_create(q);
    ideal_init(pp, p, l, l*(p - 1) - 1);
    Rad = pp;

    dbg_msg("Computing RMs...\n");
    for (i = 0; i < numofMs; ++i) {
        pp = ideal_create(q);
        ideal_product(pp, Rad, Ms[i], p);
        RMs[i] = pp;
    }

    for (i = 0; i < (numofMs - 1); ++i) {
        if (!ideal_isequal(Ms[i], RMs[i + 1])) {
            ideal_diff(Ms[i], Ms[i], RMs[i + 1]);
            fprintf(stdout, "M_%llu(%lu,%llu) diff Rad*M_%llu(%lu,%llu)\t\t= ", pi, m, i, pi, m, i + 1);
            ideal_print(Ms[i]);

            fprintf(stdout, "Indexes in diff:");
            for (j = 0; j < q; ++j) {
                if (Ms[i]->u_s[j])
                    fprintf(stdout, " u_%llu", j);
            }
            fprintf(stdout, ".\n\n");
        }
    }

    /* do cleanup */
    dbg_msg_l(5, "Freeing Ms...\n");
    for (i = 0; i < numofMs; ++i) {
        ideal_free(Ms[i]);
    }
    free(Ms);

    dbg_msg_l(5, "Freeing Rad...\n");
    ideal_free(Rad);

    dbg_msg_l(5, "Freeing RMs...\n");
    for (i = 0; i < numofMs; ++i) {
        ideal_free(RMs[i]);
    }<commit_msg>M_RM_diff 0.0.2: print out full diff only when -D option given, otherwise print only indexes from diff<commit_after>/* A small utility to visualize diff between M_pi(k) and RM_pi(k + 1) */
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
#include <string.h>
#include <getopt.h>

#include "log.h"
#include "common.h"
#include "ideals.h"

#define WITH_Ms       1
#define WITH_RMs      (1 << 1)

char* package = "M_pi(k) diff RM_pi(k + 1) structure visualizer";
char* version = "0.0.2";
char* progname = NULL;

/* global debug level */
int debug = 0;

static int handle_cmdline(int *argc, char ***argv);

int main(int argc, char **argv) {
    unsigned long long i, j;

    IDEAL* Rad;
    IDEAL* pp;
    IDEAL** Ms;
    IDEAL** RMs;

    /* learn who we really are */
    progname = (char *)strrchr(argv[0], '/');
    progname = progname ? (progname + 1) : argv[0];

    /* handle cmdline */
    handle_cmdline(&argc, &argv);

    /* initializing needed things */
    init_constants(p, l, lambda);

    Ms   = (IDEAL**) malloc(numofMs*sizeof(IDEAL*));
    RMs  = (IDEAL**) malloc(numofMs*sizeof(IDEAL*));

    if (Ms == NULL || RMs == NULL) {
        fprintf(stderr, "Unable to allocate memory for ideals' arrays.\n");
        exit(EXIT_FAILURE);
    }

    /* do the job */
    dbg_msg("Computing Ms...\n");
    for (i = 0; i < numofMs; ++i) {
        pp = ideal_create(q);
        ideal_init(pp, pi, m, i);
        Ms[i] = pp;
    }

    dbg_msg("Computing Rad...\n");
    pp = ideal_create(q);
    ideal_init(pp, p, l, l*(p - 1) - 1);
    Rad = pp;

    dbg_msg("Computing RMs...\n");
    for (i = 0; i < numofMs; ++i) {
        pp = ideal_create(q);
        ideal_product(pp, Rad, Ms[i], p);
        RMs[i] = pp;
    }

    for (i = 0; i < (numofMs - 1); ++i) {
        if (!ideal_isequal(Ms[i], RMs[i + 1])) {
            ideal_diff(Ms[i], Ms[i], RMs[i + 1]);
            fprintf(stdout, "M_%llu(%lu,%llu) diff Rad*M_%llu(%lu,%llu)\t\t= ", pi, m, i, pi, m, i + 1);

            DEBUG_CALL(ideal_print(Ms[i]));
            DEBUG_CALL(fprintf(stdout, "Indexes in diff:"));

            for (j = 0; j < q; ++j) {
                if (Ms[i]->u_s[j])
                    fprintf(stdout, " u_%llu", j);
            }
            fprintf(stdout, ".\n\n");
        }
    }

    /* do cleanup */
    dbg_msg_l(5, "Freeing Ms...\n");
    for (i = 0; i < numofMs; ++i) {
        ideal_free(Ms[i]);
    }
    free(Ms);

    dbg_msg_l(5, "Freeing Rad...\n");
    ideal_free(Rad);

    dbg_msg_l(5, "Freeing RMs...\n");
    for (i = 0; i < numofMs; ++i) {
        ideal_free(RMs[i]);
    }
{'fraction_non_alphanumeric': 0.1896006326611309, 'fraction_numerical': 0.011269276393831554, 'mean_word_length': 2.2039265357821405, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6287446', 'n_tokens_mistral': 2072, 'n_tokens_neox': 1956, 'n_words': 496}