Difference between revisions of "ApCoCoA-1:MatlabCoCoAPoly"

From ApCoCoAWiki
(Tables updated)
m (Table format change)
Line 51: Line 51:
 
<table border="1">
 
<table border="1">
 
       <tr>
 
       <tr>
         <td>ring </td><td>&nbsp;</td><td> A CoCoARing</td>
+
         <td>ring </td><td> A CoCoARing</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td>terms </td><td>&nbsp;</td><td> a polynomial representing matrix as described above.</td>
+
         <td>terms </td><td> a polynomial representing matrix as described above.</td>
 
       </tr>
 
       </tr>
 
     </table>
 
     </table>
Line 61: Line 61:
 
<table border="1">
 
<table border="1">
 
       <tr>
 
       <tr>
         <td><b>Method</b></td><td>&nbsp;</td><td><b>Operator</b></td><td><b>Description</b></td>
+
         <td><b>Method</b></td><td><b>Operator</b></td><td><b>Description</b></td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> display</td><td>&nbsp;</td><td>&nbsp;</td><td> Is used by Matlab to print a CoCoAPoly to the command window.  
+
         <td> display</td><td>&nbsp;</td><td> Is used by Matlab to print a CoCoAPoly to the command window.  
 
             E.g. when a command is not terminated by a ';'.</td>
 
             E.g. when a command is not terminated by a ';'.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> end</td><td>&nbsp;</td><td>&nbsp;</td><td> returns the last coloumn or row of CoCoAPoly array</td>
+
         <td> end</td><td>&nbsp;</td><td> returns the last coloumn or row of CoCoAPoly array</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> eq</td><td>&nbsp;</td><td>==</td><td> Compares two polynomials. Returns 1 if all attributes are equal.  
+
         <td> eq</td><td>==</td><td> Compares two polynomials. Returns 1 if all attributes are equal.  
 
             Of polynomials are not equal 0 is returned.</td>
 
             Of polynomials are not equal 0 is returned.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> ge</td><td>&nbsp;</td><td>>=</td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
+
         <td> ge</td><td>>=</td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
 
             first polynomial is greater equal the second polynomial.</td>
 
             first polynomial is greater equal the second polynomial.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> get</td><td>&nbsp;</td><td>&nbsp;</td><td>Returns the attributes of a polynomial. Syntax: get(polyVar, 'Keyword'), where polyVar is a CoCoAPoly and 'Keyword' is one of the keywords listed in table 1. Additionaly the keyword 'String' can be used. This will return the polynomial as a string. The keyword 'Latex' will return a string using Latex syntax.</td>
+
         <td> get</td><td>&nbsp;</td><td>Returns the attributes of a polynomial. Syntax: get(polyVar, 'Keyword'), where polyVar is a CoCoAPoly and 'Keyword' is one of the keywords listed in table 1. Additionaly the keyword 'String' can be used. This will return the polynomial as a string. The keyword 'Latex' will return a string using Latex syntax.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> gt</td><td>&nbsp;</td><td>></td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
+
         <td> gt</td><td>></td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
 
             first polynomial is greater than the second polynomial.</td>
 
             first polynomial is greater than the second polynomial.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> le</td><td>&nbsp;</td><td><=</td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
+
         <td> le</td><td><=</td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
 
             first polynomial is less equal the second polynomial.</td>
 
             first polynomial is less equal the second polynomial.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> lt</td><td>&nbsp;</td><td><</td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
+
         <td> lt</td><td><</td><td> Compares two polynomials accordingto the given term ordering. Returns 1 if
 
             first polynomial is less than the second polynomial.</td>
 
             first polynomial is less than the second polynomial.</td>
 
       </tr>
 
       </tr>
 
       <tr>  
 
       <tr>  
         <td> minus</td><td>&nbsp;</td><td>-</td><td> Subtract one polynomial from another.</td>
+
         <td> minus</td><td>-</td><td> Subtract one polynomial from another.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> mpower</td><td>&nbsp;</td><td>^</td><td> Returns the i-th power of a polynomial.</td>
+
         <td> mpower</td><td>^</td><td> Returns the i-th power of a polynomial.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> mtimes</td><td>&nbsp;</td><td>*</td><td> Multiplies two polynomials.</td>
+
         <td> mtimes</td><td>*</td><td> Multiplies two polynomials.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> ne</td><td>&nbsp;</td><td>~=</td><td> returns NOT eq.</td>
+
         <td> ne</td><td>~=</td><td> returns NOT eq.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> plus</td><td>&nbsp;</td><td>+</td><td> Adds two polynomials.</td>
+
         <td> plus</td><td>+</td><td> Adds two polynomials.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> subsasgn</td><td>&nbsp;</td><td>()</td><td> Writes a polynomial to the (i,j) coordinate of a CoCoAPoly array.</td>
+
         <td> subsasgn</td><td>()</td><td> Writes a polynomial to the (i,j) coordinate of a CoCoAPoly array.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> subsref</td><td>&nbsp;</td><td>()</td><td> Returns the (i,j) element of a CoCoAPoly array, {i,j} returns  
+
         <td> subsref</td><td>()</td><td> Returns the (i,j) element of a CoCoAPoly array, {i,j} returns  
 
             the element as a string.</td>
 
             the element as a string.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> times</td><td>&nbsp;</td><td>.*</td><td> Multiplies arrays of polynomials elementwise. If both arrays have the same dimension than each element of poly1 is multiplied with the corresponding element in poly2. If one of the poly's is a single value, this value is multiplied to each element in the other poly. If both poly's are single values they are simply multiplied.</td>
+
         <td> times</td><td>.*</td><td> Multiplies arrays of polynomials elementwise. If both arrays have the same dimension than each element of poly1 is multiplied with the corresponding element in poly2. If one of the poly's is a single value, this value is multiplied to each element in the other poly. If both poly's are single values they are simply multiplied.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> uminus</td><td>&nbsp;</td><td>-</td><td> support for leading minus symbol.</td>
+
         <td> uminus</td><td>-</td><td> support for leading minus symbol.</td>
 
       </tr>
 
       </tr>
 
       <tr>
 
       <tr>
         <td> uplus</td><td>&nbsp;</td><td>+</td><td> support for leading plus symbol.</td>
+
         <td> uplus</td><td>+</td><td> support for leading plus symbol.</td>
 
       </tr>
 
       </tr>
 
     </table>
 
     </table>

Revision as of 16:53, 19 June 2008

Introduction

The CoCoAPoly class represents a polynomial over a given polynomial ring (See CoCoARing).

It is based on a representation of the terms by using the logarithm of the term. For example the polynomial x^2+2y+3xy+4 defined over the Ring Q[x,y] can be represented in a matrix of the following form:

coeffpower xpower y
120
201
311
400

Constructor

The constructor for a CoCoAPoly can be used in one of the three different forms:

  • CoCoAPoly('keyword1',value1,'keyword2','value2',...).

Available keywords are listed below:

KeywordDescriptionDefault
RingA CoCoARing objectQ[x[1]]
TermsA term representing matrix as described above.
Can also be the string 'One' or 'Zero'.
This will generate the constant 1 or 0 polynomial.
[0 0]

Table 1: Keywords for CoCoAPoly


  • A string can be passed as a single argument. For example: CoCoAPoly('x^2+2y'). The string must hold the following conventions:
    • Indeterminates: a-z
    • + or - seperates two terms
    • Coefficients are placed left to the indeterminate and without a '*' character. Decimal delimiter is '.'. If coefficient=1 it is not needed to be typed.
    • The ring is build upon the found indeterminates over Q with a DegRevLex ordering. If only a constant is given the constant polynomial over Q[x] is returned. To define a poly over an indeterminate which is not part of the current polynomial use coefficient = 0.


  • A real numeric value can be passed as a single argument. For example: CoCoAPoly(2). This will return a constant polynomial over Q[x[1]].

Attributes

ring A CoCoARing
terms a polynomial representing matrix as described above.

Methods

MethodOperatorDescription
display  Is used by Matlab to print a CoCoAPoly to the command window. E.g. when a command is not terminated by a ';'.
end  returns the last coloumn or row of CoCoAPoly array
eq== Compares two polynomials. Returns 1 if all attributes are equal. Of polynomials are not equal 0 is returned.
ge>= Compares two polynomials accordingto the given term ordering. Returns 1 if first polynomial is greater equal the second polynomial.
get Returns the attributes of a polynomial. Syntax: get(polyVar, 'Keyword'), where polyVar is a CoCoAPoly and 'Keyword' is one of the keywords listed in table 1. Additionaly the keyword 'String' can be used. This will return the polynomial as a string. The keyword 'Latex' will return a string using Latex syntax.
gt> Compares two polynomials accordingto the given term ordering. Returns 1 if first polynomial is greater than the second polynomial.
le<= Compares two polynomials accordingto the given term ordering. Returns 1 if first polynomial is less equal the second polynomial.
lt< Compares two polynomials accordingto the given term ordering. Returns 1 if first polynomial is less than the second polynomial.
minus- Subtract one polynomial from another.
mpower^ Returns the i-th power of a polynomial.
mtimes* Multiplies two polynomials.
ne~= returns NOT eq.
plus+ Adds two polynomials.
subsasgn() Writes a polynomial to the (i,j) coordinate of a CoCoAPoly array.
subsref() Returns the (i,j) element of a CoCoAPoly array, {i,j} returns the element as a string.
times.* Multiplies arrays of polynomials elementwise. If both arrays have the same dimension than each element of poly1 is multiplied with the corresponding element in poly2. If one of the poly's is a single value, this value is multiplied to each element in the other poly. If both poly's are single values they are simply multiplied.
uminus- support for leading minus symbol.
uplus+ support for leading plus symbol.

Examples

A collection of examples is provided in the file TestCoCoAPoly.m. This file defines the function TestCoCoAPoly which will run and display many examples. A few common examples are presented below.

  • Default polynomial: Constant 0 over Q[x[1]]

<matlab> pDefault = CoCoAPoly(); </matlab>

  • Create two polynomials over same ring

<matlab> r1 = CoCoARing('Typ','Q','Indets',{'x','y'},'Ordering','DegRevLex'); p1 = CoCoAPoly('Ring', r1, 'Terms', [1 1 2 ; 1 2 1 ; 1 1 1]); p2 = CoCoAPoly('Ring', r1, 'Terms', [1 1 2 ; 1 0 0 ; 1 0 1]); </matlab>

  • Add the two polynomials

<matlab> pAdded = p1+p2; </matlab>

  • To read the attributes of a CoCoARing use the following command (this examples reads all attributes):

<matlab> [a1,a2] = get(p1,'Ring','Terms'); </matlab>

  • Create an array of CoCoAPolys and access an element

<matlab> pArray = [p1,p2 ; p2,p1]; pElement = pArray(1,2); </matlab>

  • Passing a string to create a CoCoAPoly

<matlab> poly = CoCoAPoly('45.4x^2x-x^1y^2+0z+5'); </matlab>