NAME

Math::GF::Zn - Elements for arithmetics over Zn

SYNOPSIS

use Math::GF;
my $field = Math::GF->new(order => 7);

# one is-a Math::GF::Zn because 7 is a prime
my $one = $field->multiplicative_neutral;

DESCRIPTION

This module implements elements and operations over a Galois Field based on primes. You are not supposed to generate instances of this class directly, but only through Math::GF (see "SYNOPSIS" above for an example).

OPERATORS

This module overrides some arithmetic and comparison operators, namely:

+ - * / **
== != eq

Additionally, the stringification operator "" is overloaded too.

METHODS

In the following, $e is supposed to be a Math::GF::Zn object.

assert_compatibility

my $n = $e->assert_compatibility($other_element);

Assert the compatibility of this object $e with $other_element. It is defined as follows:

  • $other_element is-a Math::GF::Zn

  • $other_element is based on the same field, i.e. it has the same "n" as $e.

Throws an error if the conditions are not met.

Returns "n" (sparing you to call it if you need it). As this is a prime integer, it will always evaluate as true in Perl.

divided_by

my $d = $e->divided_by($other_element);

Evaluate $e divided by $other_element. Calls "assert_compatibility". Used in the implementation of the / overloaded operator.

equal_to

my $bool = $e->equal_to($other_element);

Asses equality of $e and $other_element. Calls "assert_compatibility". Used in the implementation of the == and eq overloaded operators.

field

my $field = $e->field;

Accessor for the field where this element belongs.

i

my $i = $e->i;

The reference value for the multiplicative inverse of this object.

inv

my $inv = $e->inv;

A Math::GF::Zn element belonging to the same "field" that is the multiplicative inverse of this object.

minus

my $difference = $e->minus($other_element);

Evaluate difference of $e and $other_element. Calls "assert_compatibility". Used in the implementation of the - overloaded operator.

n

my $n = $e->n;

Prime integer at the base of Zn. Same as $e->field->order.

not_equal_to

my $bool = $e->not_equal_to($other_element);

Asses disequality of $e and $other_element. Calls "assert_compatibility". Used in the implementation of the != overloaded operator.

o

my $i = $e->o;

The reference value for the additive inverse (opposite) of this object.

opp

my $opp = $e->opp;

A Math::GF::Zn element belonging to the same "field" that is the additive inverse of this object.

plus

my $sum = $e->plus($other_element);

Evaluate sum of $e and $other_element. Calls "assert_compatibility". Used in the implementation of the + overloaded operator.

stringify

my $string = $e->stringify;

Get a string representation of the object. It does just return "v". Used in the implementation of the "" overloaded operator.

times

my $prod = $e->times($other_element);

Evaluate product of $e and $other_element. Calls "assert_compatibility". Used in the implementation of the * overloaded operator.

to_power

my $pow = $e->to_power($exp);

Evaluate the power of $e to $exp. Used in the implementation of the ** overloaded operator.

v

my $v = $e->v;

A reference value for this object. In case of element of Zn, it is actually a meaningful integer value that can be used for operations modulo "n".

BUGS AND LIMITATIONS

Report bugs through GitHub (patches welcome).

SEE ALSO

Math::GF.

AUTHOR

Flavio Poletti <polettix@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2017, 2018 by Flavio Poletti <polettix@cpan.org>

This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.

This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.