The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

Decision::Table::Rule

Decision::Table::Rule::Indexed

Rules and Boolean algebra

Rules are mathematically treatable with boolean algebra. As Decision::Table's can represent almost any logic, it is often interesting to understand what it encodes. For example if you see it as a neural network, you can train/cross/manipulate/optimize it. Because i partly translated the following texts from german books i preseved the original quotes within [DE ...].

Following basic arithmetics seems to be important in this context.

 - are two rules the same (=)      [DE ob die Regeln gleich sind (=)]
 - rule greater than another (>)   [DE ob eine Regel größer ist als die andere (>)]
 - rule less than another (<)      [DE ob eine Regel kleiner ist als die andere (<)]
 - do two rules cross (x)          [DE ob sich die beiden Regeln überkreuzen (x)]
                                   [DE ob die beiden Regeln sich gegenseitig ausschließen (x)]

Axiom: redundance [DE überflüssige Regeln]

One or two rules are redundant if both rules are in their action part identical.

[DE Ein von zwei Regeln ist überflüssig, wenn die beiden Regeln im Aktionsteil identisch sind.]

Axiom: contradiction [DE Widerspruch]

An error exists if two identical rules have contradictionary action parts.

[DE Ein Fehler liegt vor, wenn zwei gleiche Regeln entgegengesetzte Aktionen enthalten.]

Axiom: inclusion [DE Eine Regeln enthält die andere]

Rule1 includes rule2, if rule 1 always gets assigned when rule 2 is assigned.

[DE Die Regel 1 enthält die Regel 2, wenn die Regel 1 immer dann zutrifft, wenn auch die Regel 2 zutrifft.]

Axiom: crossing [DE Zwei Regeln überkreuzen sich]

Rule1 and rule2 cross, if rule1 and rule2 can be assigned simultaneously.

[DE Die Regel 1 und 2 überkreuzen sich, wenn Regel 1 und Regel 2 gleichzeitig eintreten können.]

OPTIMIZATION

The "OR"-scenario

Multiple conditions lead to the same action-combination. These conditions may be optimized as follows:

[DE Mehrer Bedinungen münden in die gleiche Decision::Table::Actions-kombination. Diese Bedingungen können wie folgt abgekürzt werden:]

Original

        if( ... )
        {
                ...
        }
        elsif( A and B )
        {
                Decision::Table::ActionA
        }
        elsif( C and D )
        {
                Decision::Table::ActionA
        }

is verbose from of

        if( (A and B) OR (C and D) )
        {
                Decision::Table::ActionA
        }

[DE MUENALAN: Eigentlich gilt ja "Ein von zwei Regeln ist überflüssig, wenn diebeiden Regeln im Aktionsteil identisch sind.". Ob dieses wirklich stimmt ?]

List of actions with identical actions [DE Aktionenslisten mit identischen Aktionen]

Two list of actions partially overlap by some actions.

[DE Falls zwei Aktionenslisten identische Aktionen enhalten, können für diese optimierte "if"-verschachtelungen aufgebaut werden:]

Example:

        rules =>
        {
                [ 1, 0, 1 ] => [ 0 ],
                [ 1, 1, 1 ] => [ 0, 1 ],
        }

The original

                if( [ 1, 0, 1 ] )
                {
                        [ 0 ]
                }
                elsif( [ 1, 1, 1 ] )
                {
                        [ 0, 1 ]
                }

is optimizable to

                if( [ 1, X, 1 ] )
                {
                        [ 0 ]

                        if( [ X, 1, X ] )
                        {
                                [ 1 ],
                        }
                }

Note: Decision::Table::Action [0] BEFORE of second "if". Otherwise the logic is not equivalent.

[DE MUENALAN Diese gilt aber (glaube ich) nur wenn sie in der gleichen Reihenfolge stehen].

Example

        rules =>
        {
                [ 1, 0, 1 ] => [ 0 ],
                [ 1, 1, 1 ] => [ 1, 0 ],
        }

is optimizable to

        if( [ 1, X, 1 ] )
        {
                if( [ X, 1, X ] )
                {
                        [ 1 ],
                }

                [ 0 ]
        }

Note: Decision::Table::Action [0] !AFTER! the second if. Otherwise the logic is not equivalent.

Author

Murat Ueanlan <muenalan@cpan.org>

1 POD Error

The following errors were encountered while parsing the POD:

Around line 151:

Non-ASCII character seen before =encoding in 'größer'. Assuming CP1252