I'm writing a Maple procedure and I have a line that is "if ... then ..." and I would like it to be if k is an integer (or if k^2 is a square) - how would onw say that in Maple? Thanks!
Asked
Active
Viewed 624 times
2 Answers
0
To check whether something is an integer, you can use the type command. For example,
> type( 2/3, integer );
false
> type( 3, integer );
true
To check whether an integer is a perfect square, you can use the issqr command, as in the following examples:
> issqr(16);
true
> issqr(15);
false
Thus, your if statement might (if I'm guessing your intent correctly) look something like this.
if type( k, integer ) and issqr( k ) then
DoSomething()
end if
James
- 9,272
0
There is a shorthand for type checking in an if statement:
if k::integer then
# do something
end if
To me, that is more elegant.
Carl Love
- 1,193