2

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 ?

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
Asdf
  • 300
  • 2
  • 9

1 Answers1

2

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.

Robert Dodier
  • 16,905
  • 2
  • 31
  • 48
  • Do you have any idea what "charfun" stands for? This is useful but I'll have a hard time memorising it, a good mnemonic would be appreciated. – Rolazaro Azeveires Jul 16 '18 at 20:41
  • 1
    "charfun" = "characteristic function", which is confusing because "characteristic function" also means the Fourier transform of a probability density (and maybe other things). The function which is 1 on some set and 0 otherwise is also called an "indicator function". – Robert Dodier Jul 16 '18 at 23:54
  • Yes, indicator would probably be better, characteristic is used in too many contexts to be useful by itself. Well... maybe I'll memorise after this conversation. :-) Thank you. – Rolazaro Azeveires Jul 17 '18 at 00:31
  • Great! Thank you so much! That's what I was looking for. It appears, engineering way of telling things is very different than pro-mathematician way, so all the keywords for google were wrong :) – Asdf Jul 24 '18 at 00:00