Top
Back: Objects
Forward: Flow control
FastBack: Implemented algorithms
FastForward: Input and output
Up: The SINGULAR language
Top: Singular Manual
Contents: Table of Contents
Index: 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. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26. 27. 28. 29.
intvec ==> intmat
poly ==> ideal
bigint ==> ideal
int ==> ideal
intmat ==> matrix
ideal ==> matrix
module ==> matrix
number ==> matrix
poly ==> matrix
vector ==> matrix
bigint ==> matrix
int ==> matrix
intvec ==> matrix
ideal ==> module
matrix ==> module
vector ==> module
bigint ==> number
int ==> number
number ==> poly
bigint ==> poly
int ==> poly
list ==> resolution
poly ==> vector (p ==> p*gen(1))
bigint ==> vector
int ==> vector (i ==> i*gen(1))
int ==> bigint
int ==> intvec
string ==> link
resolution ==> list

Type casting

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

Possible type casts are:

to from
bigint expression int, number, poly
ideal expression lists of int, number, poly
ideal int, matrix, module, number, poly, vector
int number, poly
intvec expression lists of int, intmat
intmat intvec (see intmat type cast)
list expression lists of any type
matrix module, 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)
module expression lists of int, number, poly, vector
module ideal, matrix, vector
number poly
poly int, number
ring list (the inverse of ringlist)
string any 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]
  // generators are columns of a matrix


Top Back: Objects Forward: Flow control FastBack: Implemented algorithms FastForward: Input and output Up: The SINGULAR language Top: Singular Manual Contents: Table of Contents Index: Index About: About this document
            User manual for Singular version 4.3.1, 2022, generated by texi2html.