Sujet : Re: help with a logic algorithm
De : thiago.adams (at) *nospam* gmail.com (Thiago Adams)
Groupes : comp.lang.cDate : 03. Apr 2024, 13:32:12
Autres entêtes
Organisation : A noiseless patient Spider
Message-ID : <31b9ca44-7c8e-43f2-afce-ee1adca1cc0b@gmail.com>
References : 1 2
User-Agent : Mozilla Thunderbird
On 03/04/2024 08:33, Anton Shepelev wrote:
Thiago Adams:
I need an algorithm that finds the possible states of
variables used in "ifs"
The industrial approach (e.g. from digital circuitry) is to
convert the expression into a minimal sum of truth
constituents. There are several algorithms to do so
efficiently, i.e. to find the minimal coverage of the truth
table by truth constituents. The only ones I know are by a
Russian author published in a Russian book by logic, so I
cannot provide a useful reference.
A family of appraches is based on the Karnaugh map:
https://en.wikipedia.org/wiki/Karnaugh_map
If you expressions are simple, however, a direct enumaration
of 2^n combinations could work.
I think the number of variables will be small.
if (a) ...
if (a && b) ...
if (a || b) etc..
But even if I have let's say 10 variables, then 2^10 = 1024 still something fast to do.