Top
Back: 3.5.4 Objects
Forward: 3.5.6 Flow control
FastBack: 3. General concepts
FastForward: 4. Data types
Up: 3.5 The SINGULAR language
Top: Singular 2-0-4 Manual
Contents: Table of Contents
Index: F. Index
About: About This Document

3.5.5 Type conversion and casting

Type conversion

Assignments convert the type of the right-hand side to the type of the left-hand side of the assignment, if possible. Operators and functions which require certain types of operands can also implicitly convert the type of an expression. It is, for example, possible to multiply a polynomial by an integer because the integer is automatically converted to a polynomial. Type conversions do not act transitively. Possible conversions are:

  1.intideal
  2.polyideal
  3.intvecintmat
  4.intintvec
  5.intintmat
  6.stringlink
  7.resolutionlist
  8.idealmatrix
  9.intmatrix
  10.intmatmatrix
  11.intvecmatrix
  12.modulematrix
  13.numbermatrix
  14.polymatrix
  15.vectormatrix
  16.idealmodule
  17.matrixmodule
  18.vectormodule
  19.intnumber
  20.intpoly
  21.numberpoly
  22.stringproc
  23.listresolution
  24.intvector (i → i*gen(1))
  25.polyvector (p → p*gen(1))

Type casting

An expression can be casted to another type by using a type cast expression:
type ( expression ).

Possible type casts are:

 tofrom
 idealexpression lists of int, number, poly
 idealint, matrix, module, number, poly, vector
 intnumber, poly
 intvecexpression lists of int, intmat
 intmatintvec (see intmat type cast)
 listexpression lists of any type
 matrixmodule, ideal, vector, matrix.
There are two forms to convert something to a matrix: if matrix( expression ) is used then the size of the matrix is determined by the size of expression.
But matrix( expression , m , n ) may also be used - the result is a $ m \times n $ matrix (see matrix type cast)
 moduleexpression lists of int, number, poly, vector
 moduleideal, matrix, vector
 numberpoly
 polyint, number
 stringany type (see string type cast)

Example:

 
  ring r=0,x,(c,dp);
  number(3x);
→ 0
  number(poly(3));
→ 3
  ideal i=1,2,3,4,5,6;
  print(matrix(i));
→ 1,2,3,4,5,6
  print(matrix(i,3,2));
→ 1,2,
→ 3,4,
→ 5,6 
  vector v=[1,2];
  print(matrix(v));
→ 1,
→ 2 
  module(matrix(i,3,2));
→ _[1]=[1,3,5]
→ _[2]=[2,4,6]

Top Back: 3.5.4 Objects Forward: 3.5.6 Flow control FastBack: 3. General concepts FastForward: 4. Data types Up: 3.5 The SINGULAR language Top: Singular 2-0-4 Manual Contents: Table of Contents Index: F. Index About: About This Document
            User manual for Singular version 2-0-4, October 2002, generated by texi2html.