Field elements
Last updated
Last updated
Field element is the most fundamental datatype in Keelung.
They can be constructed with numeric literals like 3
, 42
, or -7
.
Negative numbers don't really exist in finite fields, they will be normalized to their positive counterparts after compilation. For example, -7
would become:
in GF181 where there are only 1552511030102430251236801561344621993261920897571225601
numbers.
Field elements are constructed with the following constructor under the hood:
A numeric literal represents the application of the function fromInteger
to the appropriate value of type Integer
.
A floating literal stands for an application of fromRational
to a value of type Rational
.
Example usage: fromRational 3.5
BtoF
converts to Booleans to field elements:
Example usage: 3 + 4
Example usage: 3 - 4
Example usage: 3 * 4
Example usage: 3 / 4
Example usage: recip 4
Example usage: negate 4
Since there are no negative numbers in Field
, the abs
function has the same effect as the id
function.
signum
would always return 1
on any field element.
pow
takes a Field
as the base and an Integer
as the power, and computes the exponentiation.
If you are multiplying the same stuff for more than 3 times, for example:
You should consider replacing it with:
To allow the exponentiation by squaring optimization to kick in.
Example usage: false `eq` false
or eq false true
.
You can also use EqF
, which is the underlying implementation of eq
on field elements.
neq
is implemented as such under the hood:
Since Field
is an instance of and , all methods of Num
and Fractional
works on Numbers.
Returns when two field elements are the same:
Returns when two numbers are the same: