Skip to content

inverse seems to give incorrect results [solved] #11

Closed
@niekbouman

Description

@niekbouman

Update:

problem solved. Inverse was "GF11::inv" was computed as the modular inverse, but should be the negated modular inverse. (This key fact is missing in the comments in Fp_model.hpp)

Changing the following line (in Fp_model.hpp)

static mp_limb_t inv; // modulus^(-1) mod W, where W = 2^(word size)

into

static mp_limb_t inv; // -modulus^(-1) mod W, where W = 2^(word size)

would make this more clear.

original post

Hello developers,
First of all, thank you for releasing your work under the mit license.

As a sanity check, I tried to use libff for the field GF(11).
However, if I compute an inverse, I get an incorrect result.
Either I set up the field in a wrong way, or there is something wrong with the inverse function.

header file modulus.hpp:

#include <libff/algebra/fields/bigint.hpp>
auto mymodulus = libff::bigint<1>("11");

and main cpp file

#include "modulus.hpp"

//...

using namespace libff;
extern bigint<1L> mymodulus;
using GF11 = Fp_model<1L,mymodulus>;

GF11::euler = bigint<1>("5");
GF11::t = bigint<1>("5");
GF11::t_minus_1_over_2 = bigint<1>("2");
GF11::Rsquared = bigint<1>("3");
GF11::Rcubed = bigint<1>("4");
GF11::s = 1;
GF11::num_bits = 4;
GF11::inv = 3353953467947191203UL;

auto field_elem = GF11(5UL);

field_elem.inverse().print();

The program then prints 2, (clang 3.9 on mac os 10.9 mavericks)
while the multiplicative inverse of 5 in GF(11) should be 9...

best,
Niek

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions