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. int ==> ideal
 2. poly ==> ideal
 3. intvec ==> intmat
 4. int ==> intvec
 5. int ==> intmat
 6. string ==> link
 7. resolution ==> list
 8. ideal ==> matrix
 9. int ==> matrix
 10. intmat ==> matrix
 11. intvec ==> matrix
 12. module ==> matrix
 13. number ==> matrix
 14. poly ==> matrix
 15. vector ==> matrix
 16. ideal ==> module
 17. matrix ==> module
 18. vector ==> module
 19. int ==> number
 20. int ==> poly
 21. number ==> poly
 22. string ==> proc
 23. list ==> resolution
 24. int ==> vector
  (i ==> i*gen(1))
 25. poly ==> vector
  (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:

  to from
  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
  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]


<font size="-1">
&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; User manual for <a href="http://www.singular.uni-kl.de/"><i>Singular</i></a> version 2-0-4, October 2002,
generated by <a href="http://www.gnu.org/software/texinfo/"><i>texi2html</i></a>.
</font>

</body>
</html>
