C
C#2y ago
Faceboiii

❔ 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
canton7
canton72y ago
I'm not sure what you're asking I'm afraid
Faceboiii
FaceboiiiOP2y ago
its basically if bool1 is true and bool2 is true, then bool3 also has to be true
canton7
canton72y ago
So bool3 = bool1 && bool2?
Faceboiii
FaceboiiiOP2y ago
yes basically
canton7
canton72y ago
So... What's the question?
Faceboiii
FaceboiiiOP2y ago
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
Jimmacle
Jimmacle2y ago
is this some kind of constraint solving problem? what problem are you actually trying to solve
Faceboiii
FaceboiiiOP2y ago
yes, you could call it that
Faceboiii
FaceboiiiOP2y ago
I got the following truth-table:
Faceboiii
FaceboiiiOP2y ago
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)
Jimmacle
Jimmacle2y ago
idk how to read that diagram
canton7
canton72y ago
I think your image cuts off the important labelling around that table Is that a K-Map?
Faceboiii
FaceboiiiOP2y ago
do you understand german? because the rest is written in german
canton7
canton72y ago
I understand it better than silence, sure
Faceboiii
FaceboiiiOP2y ago
Faceboiii
FaceboiiiOP2y ago
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)
canton7
canton72y ago
Right, think I follow that So, again, what's the problem exactly?
Faceboiii
FaceboiiiOP2y ago
that im not allowed to use conditions like in an if, while etc
Jimmacle
Jimmacle2y ago
i mean, you could use bitwise logic which isn't conditional it's practically the same effect though
canton7
canton72y ago
Or just bool1 && bool2? No ifs or whiles
Jimmacle
Jimmacle2y ago
depends if the short circuiting behavior is considered some kind of condition LUL
Faceboiii
FaceboiiiOP2y ago
would be counted as a condition
Jimmacle
Jimmacle2y ago
if a logical AND is a condition i'm not sure where to go from there
canton7
canton72y ago
Would it? Why? Are you sure?
Jimmacle
Jimmacle2y ago
yeah i'm confused
Faceboiii
FaceboiiiOP2y ago
sorry, I messed up 2 words
Jimmacle
Jimmacle2y ago
because that's a literal translation of a boolean algebra ^
Faceboiii
FaceboiiiOP2y ago
I meant branches
canton7
canton72y ago
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-effects
Faceboiii
FaceboiiiOP2y ago
so bool3 = bool1 & bool2 isn't counted as a branch?
Jimmacle
Jimmacle2y ago
where is the branch? there aren't 2 code paths there
canton7
canton72y ago
That won't branch.
MODiX
MODiX2y ago
canton7#1569
sharplab.io (click here)
public class C {
public bool M(bool a, bool b) {
return a && b;
}
}
public class C {
public bool M(bool a, bool b) {
return a && b;
}
}
React with ❌ to remove this embed.
canton7
canton72y ago
(Well, && doesn't even branch there. But & will compile to the same)
Faceboiii
FaceboiiiOP2y ago
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?
Jimmacle
Jimmacle2y ago
no there is one path, which is calculate bool1 && bool2 as shown by the JIT disassembly in canton's link
Faceboiii
FaceboiiiOP2y ago
ok, good to know
Jimmacle
Jimmacle2y ago
just like how multiplying 2 numbers is only one path there aren't infinite branches, it's just an operation
Faceboiii
FaceboiiiOP2y ago
Thanks for the help! Is it it also possible to output, wether A,B,C or D is true, without using a branch?
canton7
canton72y ago
A | B | C | D?
MODiX
MODiX2y ago
canton7#1569
sharplab.io (click here)
public class C {
public bool M(bool a, bool b, bool c, bool d) {
return a | b | c | d;
}
}
public class C {
public bool M(bool a, bool b, bool c, bool d) {
return a | b | c | d;
}
}
React with ❌ to remove this embed.
Faceboiii
FaceboiiiOP2y ago
Thanks It's kind of confusing me, what is counted as a branch and what isn't harold
canton7
canton72y ago
A branch is a jump instruction "If condition, then jump to this other bit of code"
Faceboiii
FaceboiiiOP2y ago
Thank you, you really helped me!
Accord
Accord2y ago
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.
Want results from more Discord servers?
Add your server