Main Content

gfsub

Subtract polynomials over Galois field

Description

c = gfsub(a,b,p) calculates a minus b. a and b can be represented as polynomial character vectors.

Note

This function performs computations in GF(pm), where p is prime. To work in GF(2m), apply the - operator to Galois arrays of equal size. For details, see Example: Addition and Subtraction.

example

c = gfsub(a,b,p,len) subtracts row vectors and returns a row vector of length len. The output c is a truncated or extended representation of the answer. If the row vector corresponding to the answer has fewer than len entries (including zeros), extra zeros are added at the end; if it has more than len entries, entries from the end are removed.

c = gfsub(a,b,field) calculates a minus b, where a and b are the exponential format of two elements of GF(pm), relative to some primitive element of GF(pm). p is a prime number and m is a positive integer. field is the matrix listing all elements of GF(pm), arranged relative to the same primitive element. c is the exponential format of the answer, relative to the same primitive element. See Representing Elements of Galois Fields for an explanation of these formats. If a and b are matrices of the same size, the function treats each element independently.

Examples

collapse all

Calculate (2+3x+x2)-(4+2x+3x2) over GF(5).

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

     3     1     3

Subtract the two polynomials and display the first two elements.

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

     3     1

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);

Subtract A4 from A2. The result is A7.

g = gfsub(2,4,field)
g = 
7

Input Arguments

collapse all

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

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 Representation of Polynomials in Communications Toolbox or numeric vector.

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

Output length, specified as a positive integer.

Data Types: double

All elements of GF(pm) relative to a primitive element, specified as a matrix.

Data Types: double

Output Arguments

collapse all

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

Version History

Introduced before R2006a