❔ Implicate without condition
Hey, I need to multiple bools to imply a bool. If I'm not wrong, in logic it would look like this:
bool1 ^ bool2 => bool3
. However I couldn't find out how to do that in C# without using conditions (like bool bool3 = bool2 && bool1
). I hope someone can help me :))45 Replies
I'm not sure what you're asking I'm afraid
its basically if bool1 is true and bool2 is true, then bool3 also has to be true
So
bool3 = bool1 && bool2
?yes basically
So... What's the question?
Without doing it as something that would fit in an if condition
it could also be done with other variable types. For example:
when x > 3 then y has to be < 10
is this some kind of constraint solving problem?
what problem are you actually trying to solve
yes, you could call it that
I got the following truth-table:
The colors are 4 different bools
A is true when (bool1 true, bool2 true);
B is true when (bool2 false, bool4 true);
C is true when (bool1 false, bool2 true, bool4 true) or when (bool1 true, bool2 false, bool3 true, bool4 false) or when (bool1 false, bool2 false, bool3 false, bool4 false)
D is true when(bool1 false, bool2 true, bool4 false) or when (bool1 true, bool2 false, bool3 false, bool4 false)
idk how to read that diagram
I think your image cuts off the important labelling around that table
Is that a K-Map?
do you understand german?
because the rest is written in german
I understand it better than silence, sure
asis is A, Belas is B, Cedis is C, Drudis is D
manuseln, knelt haben, löpsen, nopeln are the different input bools. I'll just call them B1, B2, B3, B4
below are the different cases to check (1-7)
Right, think I follow that
So, again, what's the problem exactly?
that im not allowed to use conditions like in an if, while etc
i mean, you could use bitwise logic which isn't conditional
it's practically the same effect though
Or just
bool1 && bool2
?
No ifs or whilesdepends if the short circuiting behavior is considered some kind of condition
would be counted as a condition
if a logical AND is a condition i'm not sure where to go from there
Would it? Why? Are you sure?
yeah i'm confused
sorry, I messed up 2 words
because that's a literal translation of a boolean algebra
^
I meant branches
bool1 && bool2
won't branch. If you want to make that really clear, use bool1 & bool2
expression1 && expression2
will branch because of short-circuiting. But that's optimized away if the RHS is just a bool with no side-effectsso
bool3 = bool1 & bool2
isn't counted as a branch?where is the branch?
there aren't 2 code paths there
That won't branch.
(Well,
&&
doesn't even branch there. But &
will compile to the same)if bool1 and bool2 are both true, bool3 would be true
if however bool1 is true and bool2 is false, then bool3 would be false
so wouldn't that make it 2 paths, since it's 2 different results?
no
there is one path, which is calculate
bool1 && bool2
as shown by the JIT disassembly in canton's linkok, good to know
just like how multiplying 2 numbers is only one path
there aren't infinite branches, it's just an operation
Thanks for the help!
Is it it also possible to output, wether A,B,C or D is true, without using a branch?
A | B | C | D?
Thanks
It's kind of confusing me, what is counted as a branch and what isn't
A branch is a jump instruction
"If condition, then jump to this other bit of code"
Thank you, you really helped me!
Was this issue resolved? If so, run
/close
- otherwise I will mark this as stale and this post will be archived until there is new activity.