Skip to content

Commit

Permalink
Add additional ipython-with-reprs usage
Browse files Browse the repository at this point in the history
  • Loading branch information
mhostetter committed Nov 8, 2022
1 parent 01f86f1 commit 83cf2fc
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 215 deletions.
10 changes: 5 additions & 5 deletions docs/basic-usage/array-classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ and :func:`~galois.GR` (future).

A :obj:`~galois.FieldArray` subclass is created using the class factory function :func:`~galois.GF`.

.. ipython:: python
.. ipython-with-reprs:: int,poly,power

GF = galois.GF(3**5)
print(GF.properties)
Expand Down Expand Up @@ -66,7 +66,7 @@ with :obj:`~galois.FieldArray.irreducible_poly`.

A :obj:`~galois.FieldArray` instance is created using `GF`'s constructor.

.. ipython:: python
.. ipython-with-reprs:: int,poly,power

x = GF([23, 78, 163, 124])
x
Expand Down Expand Up @@ -94,13 +94,13 @@ alternate constructors use `PascalCase` while other classmethods use `snake_case

For example, to generate a random array of given shape call :func:`~galois.FieldArray.Random`.

.. ipython:: python
.. ipython-with-reprs:: int,poly,power

GF.Random((2, 3))
GF.Random((3, 2), seed=1)

Or, create an identity matrix using :func:`~galois.FieldArray.Identity`.

.. ipython:: python
.. ipython-with-reprs:: int,poly,power

GF.Identity(4)

Expand Down
25 changes: 9 additions & 16 deletions docs/basic-usage/array-creation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -8,31 +8,35 @@ the finite field :math:`\mathrm{GF}(3^5)`.

GF = galois.GF(3**5)
print(GF.properties)
alpha = GF.primitive_element; alpha

Create a scalar
---------------

A single finite field element (a scalar) is a 0-D :obj:`~galois.FieldArray`. They are created by passing a single
:obj:`~galois.typing.ElementLike` object to `GF`'s constructor.
:obj:`~galois.typing.ElementLike` object to `GF`'s constructor. A finite field scalar may also be created by exponentiating
the primitive element to a scalar power.

.. ipython-with-reprs:: int,poly,power

a = GF(17); a
a = GF("x^2 + 2x + 2"); a
a.ndim
GF(17)
GF("x^2 + 2x + 2")
alpha ** 222

Create a new array
------------------

Array-Like objects
Array-like objects
..................

A :obj:`~galois.FieldArray` can be created from various :obj:`~galois.typing.ArrayLike` objects.
A finite field array may also be created by exponentiating the primitive element to a an array of powers.

.. ipython-with-reprs:: int,poly,power

GF([17, 4, 148, 205])
GF([["x^2 + 2x + 2", 4], ["x^4 + 2x^3 + x^2 + x + 1", 205]])
alpha ** np.array([[222, 69], [54, 24]])

Polynomial coefficients
.......................
Expand All @@ -51,17 +55,6 @@ into length-:math:`m` vectors over :math:`\mathrm{GF}(p)`.

GF([17, 4]).vector()

Primitive element powers
........................

A :obj:`~galois.FieldArray` can also be created from the powers of a primitive element :math:`\alpha`.

.. ipython-with-reprs:: int,poly,power

alpha = GF.primitive_element; alpha
powers = np.array([222, 69, 54, 24]); powers
alpha ** powers

NumPy array
...........

Expand Down
20 changes: 10 additions & 10 deletions docs/basic-usage/element-representation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ coefficient as the most-significant digit and zero-degree coefficient as the lea
GF = galois.GF(3**5)
GF(17)
GF("α^2 + + 2")
GF("x^2 + 2x + 2")
# Integer/polynomial equivalence
p = 3; p**2 + 2*p + 2 == 17
Expand All @@ -106,7 +106,7 @@ This is useful, however it can become cluttered for large arrays.
GF = galois.GF(3**5, display="poly")
GF(17)
GF("α^2 + + 2")
GF("x^2 + 2x + 2")
# Integer/polynomial equivalence
p = 3; p**2 + 2*p + 2 == 17
Expand Down Expand Up @@ -139,8 +139,8 @@ In prime fields, the elements are displayed as :math:`\{0, 1, \alpha, \alpha^2,
.. ipython:: python
GF.display("int");
α = GF.primitive_element; α
α**23
alpha = GF.primitive_element; alpha
alpha ** 23
In extension fields, the elements are displayed as :math:`\{0, 1, \alpha, \alpha^2, \dots, \alpha^{p^m-2}\}`.

Expand All @@ -152,8 +152,8 @@ In extension fields, the elements are displayed as :math:`\{0, 1, \alpha, \alpha
.. ipython:: python
GF.display("int");
α = GF.primitive_element; α
α**222
alpha = GF.primitive_element; alpha
alpha ** 222
Vector representation
---------------------
Expand All @@ -166,16 +166,16 @@ The vector representation is accessed using the :func:`~galois.FieldArray.vector
.. ipython:: python
GF = galois.GF(3**5, display="poly")
GF("α^2 + + 2")
GF("α^2 + + 2").vector()
GF("x^2 + 2x + 2")
GF("x^2 + 2x + 2").vector()
An N-D array over :math:`\mathrm{GF}(p^m)` is converted to a (N + 1)-D array over :math:`\mathrm{GF}(p)` with the added dimension having
size :math:`m`. The first value of the vector is the highest-degree coefficient.

.. ipython:: python
GF(["α^2 + + 2", "^4 + α"])
GF(["α^2 + + 2", "^4 + α"]).vector()
GF(["x^2 + 2x + 2", "2x^4 + x"])
GF(["x^2 + 2x + 2", "2x^4 + x"]).vector()
Arrays can be created from the vector representation using the :func:`~galois.FieldArray.Vector` classmethod.

Expand Down
Loading

0 comments on commit 83cf2fc

Please sign in to comment.