|
3.5.1 General command syntax
In SINGULAR a command is either a declaration, an assignment, a
call to a function without return value, or a print command. The general
form of a command is described in the following subsections.
Declaration
- type name
= expression ;
declares a variable with the given name of the given type and assigns
the expression as initial value to it. Expression is an expression of
the specified type or one that can be converted to that type.
See Type conversion and casting.
- type name_list
= expression_list ;
declares variables with the given names and assigns successively each
expression of expression_list to the corresponding name of
name_list. Both lists must be of the same length. Each expression in
expression_list is an expression of the specified type or one that can
be converted to that type. See Type conversion and casting.
- type name
;
declares a variable with the given name of the given type and assigns
the default value of the specific type to it.
See Names, for more information on declarations. See Data types,
for a description of all data types known to SINGULAR.
| ring r; // the default ring
poly f,g = x^2+y^3,xy+z2; // the polynomials f=x^2+y^3 and g=x*y+z^2
ideal I = f,g; // the ideal generated by f and g
matrix m[3][3]; // a 3 x 3 zero matrix
int i=2; // the integer i=2
|
Assignment
-
name
= expression ;
assigns expression to name.
-
name_list
= expression_list ;
assigns successively each expression of expression_list to the
corresponding name of name_list. Both lists must be of the same
length. This is not a simultaneous assignment. Thus, f, g = g, f; does
not swap the values of f and g , but rather assigns
g to both f and g .
A type conversion of the type of expression to the type of
name must be possible. See Type conversion and casting.
An assignment itself does not yield a value. Hence, compound assignments
like i = j = k; are not allowed and result in an error.
| f = x^2 + y^2 ; // overrides the old value of f
I = jacob(f);
f,g = I[1],x^2+y^2 ; // overrides the old values of f and g
|
Function without return value
-
function_name [
( argument_list ) ] ;
calls function function_name with arguments argument_list.
The function may have output (not to be confused with a return value of
type string). See Functions. Functions without a return value are
specified there to have a return type 'none'.
Some of these functions have to be called without parentheses, e.g.,
help , LIB .
| ring r;
ideal i=x2+y2,x;
i=std(i);
degree(i); // degree has no return value but prints output
==> // dimension (proj.) = 0
==> // degree (proj.) = 2
|
Print command
-
expression
;
prints the value of an expression, for example, of a variable.
Use the function print (or the procedure show from inout.lib)
to get a pretty output of various data
types, e.g., matrix or intmat. See print.
| int i=2;
i;
==> 2
intmat m[2][2]=1,7,10,0;
print(m);
==> 1 7
==> 10 0
|
|