converting logical true/false to numeric 1/0?

410 views Asked by At

In most languages I can either directly multiply logical truth on some numeric value, or at least there are simple function for converting type Boolean to some specific type, like int, or double. Normally, it is easy because "true" or "false" is just an alias to numeric 1 or 0.

But not in Maxima.

And I can not find any embedded function for converting logical values to numeric either. Is there any?

How can I do a conditional masking of the function, for instance?

F(x,param):=condition(x,param)*f(x), where condition returns logical values, like (x>param)->true/false ?

1

There are 1 answers

4
Robert Dodier On BEST ANSWER

You can write (if x > param then 1 else 0)*f(x) for example.

You can also write charfun(x > param)*f(x). See ? charfun.