0

I just heard something very insteresting but cannot find any ressources.
The story is that when faced with an algorithmic problem that requiered multiple ifs, one student of a friend did answer with a mathematic one liner.

Now I already knew that you could do anyting with math but I want to be able to do it.
From what I know it might be possible to do a loop given the shape of those function, but conditions?

Does someone know how to resolve something like:

IF boolean
  THEN expression
  ELSE expression2

in math terms (without Bool algebra)?

Best regards,

Sarfraz

4

3 回答 3

2

假设boolean是 0 或 1,并且表达式是数学的:

expr = boolean * expression + (1-boolean) * expression2
于 2013-04-17T13:03:31.183 回答
1

假设布尔值为 0 或 1:

result = boolean*expression+(1-boolean)*expression2
于 2013-04-17T13:03:05.220 回答
1

你指的是多路复用器吗?

如果布尔值为 S,表达式为 A,表达式 2 为 B,则结果 Z 的公式为

Z = (A * S) + (B * ^S)

于 2013-04-17T13:13:14.817 回答