주요 콘텐츠

gfadd

R2026b

Add polynomials over Galois field

Description

c = gfadd(a,b) adds two GF(2) polynomials, a and b.

c = gfadd(a,b,p) adds two GF(p) polynomials, a and b.

example

c = gfadd(a,b,p,len) adds row vectors a and b and returns a row vector of length len.

c = gfadd(a,b,field) adds two GF(pm) elements.

Examples

collapse all

Sum 2+3x+x2 and 4+2x+3x2 over GF(5).

x = gfadd([2 3 1],[4 2 3],5)
x = 1×3

     1     0     4

Add the two polynomials and display the first two elements.

y = gfadd([2 3 1],[4 2 3],5,2)
y = 1×2

     1     0

For prime number p and exponent m, create a matrix listing all elements of GF(p^m) given primitive polynomial 2+2x+x2.

p = 3;
m = 2;
primpoly = [2 2 1];
field = gftuple((-1:p^m-2)',primpoly,p);

Sum A2 and A4. The result is A.

g = gfadd(2,4,field)
g = 
1

Input Arguments

collapse all

Galois field polynomial, specified as a row vector, character vector, or string. a can be either a polynomial character vector or numeric vector. For more information, see Representation of Polynomials in Communications Toolbox.

a and b must both be GF(p) polynomials or GF(pm) polynomials, where p is prime. The value of p is as specified when included, 2 when omitted, or implied when field is specified.

Example: [1 2 3 4] is the polynomial 1+2x+3x2+4x3 in GF(5) expressed as a row vector.

Data Types: double | char | string

Galois field polynomial, specified as a row vector, character vector, or string. b can be either a polynomial character vector or numeric vector. For more information, see Representation of Polynomials in Communications Toolbox.

a and b must both be GF(p) polynomials or GF(pm) polynomials, where p is prime. The value of p is as specified when included, 2 when omitted, or implied when field is specified.

Example: '1 + x' is a polynomial in GF(24) expressed as a character vector.

Data Types: double | char | string

Prime number, specified as a scalar prime number.

Data Types: double

Length of output GF polynomial, specified as an integer.

  • If the output row vector corresponding to the GF polynomial has fewer than len elements, extra zeros are added at the end to extend the representation of the GF polynomial.

  • If the output row vector corresponding to the GF polynomial has more thanlen elements, entries from the end are removed to truncate the representation of the GF polynomial..

  • If len is negative, all high-order zeros are removed.

Data Types: double

m-tuple of all elements in GF(pm), specified as a matrix. field is the matrix listing all elements of GF(pm), arranged relative to the same primitive element. To generate the m-tuple of all elements in GF(pm), use

field =gftuple([-1:p^m-2]',m,p)
where m is a positive integer. The coefficients, specified in exponential format, represent the field elements in GF(pm). For an explanation of these formats, see Representing Elements of Galois Fields.

Data Types: double

Output Arguments

collapse all

Galois field polynomial, returned as a row vector of the polynomial coefficients in order of ascending powers.

Tips

Version History

Introduced before R2006a