Sujet : Re: help with a logic algorithm
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 03. Apr 2024, 01:09:00
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <2d1a0694-c700-47e9-b5f7-2136431e14e4@gmail.com>
References : 1 2
User-Agent : Mozilla Thunderbird
Em 4/2/2024 6:23 PM, Scott Lurndal escreveu:
Thiago Adams <thiago.adams@gmail.com> writes:
I need an algorithm that finds the possible states of variables used in
"ifs"
>
for instance, I need to find out possible states:
>
if (a && b){
>
// 'a' is true
// 'b' is true
>
}
else
{
// 'a' maybe be true or false
// 'b' maybe be true or false
}
>
Create truth tables. Optionally use deMorgans
laws to simplify.
https://en.wikipedia.org/wiki/Boolean_algebra
https://en.wikipedia.org/wiki/De_Morgan%27s_laws
This truth table is kind of "brutal force" isn't it?
But this gave me an idea.
I can make a expression tree.
Visiting the tree I will find a variable that I don't know if it is true or false.
Then I continue the evaluation considering this variable is true.
Then I continue the evaluation (from the point we did a branch) considering it is false.
At the end of evaluation I have the final result of the expression true and false I can merge all possible combinations for true and false.
I will try..