- --- In ntb-clips@yahoogroups.com, Art Kocsis <artkns@...> wrote:
>

Thanks for your explanations, Art!

> At 9/10/2013 05:11 PM, Flo wrote:

>> It has been discussed several times that NT doesn't master Boolean

>> Expressions (cf message #21773)...

> Flo, If I can jump in here.(...)

> In testing boolean expressions...

This is certainly a great help for users trying to go further into that topic.

However, I would like to get back to my question concerning the specific concept that was introduced by Wayne VanWeerthuizen (where is he?) with his abovementioned 'NoteTab Tutorial Control Structures v003.OTL'...

> Is anyone (also Wayne himself) still using such expressions and

So far, Wayne gave us the solution for only five conditions.

> could give us more examples. Regrettably, Wayne's Tutorial was

> never finished and has remained a highly instructive fragment

> only. Also, it's lacking complete working examples

Given a simple list...

A B

A B C

A C D

B

D E F

we could test Wayne's five expressions against that list with the following clip...

^!Set %Lines%=^$GetTextLineCount$

^!Set %Row%=1

^!Goto ^?{(H=5)Find lines matching...==A AND B|A OR B|A NOT B|A XOR B|NOT A}

:A AND B

:Loop_1

^!Set %A%=0; %B%=0

^!Jump ^%Row%

^!IfMatch "^.*A.*$" "^$GetLine$" ^!Set %A%=1

^!IfMatch ".*B.*$" "^$GetLine$" ^!Set %B%=1

^!If ^$Calc(MIN(^%A%;^%B%))$=1 Next Else Skip

^!Set %Hits%=^%Hits%^$GetLine$^P

^!Inc %Row%

^!If ^$GetRow$ < ^%Lines% Loop_1

^!Info [L]Expression: A AND B^P^PMatches:^P^%Hits%

^!Goto Out

:A OR B

:Loop_2

^!Set %A%=0; %B%=0

^!Jump ^%Row%

^!IfMatch "^.*A.*$" "^$GetLine$" ^!Set %A%=1

^!IfMatch ".*B.*$" "^$GetLine$" ^!Set %B%=1

^!If ^$Calc(MAX(^%A%;^%B%))$=1 Next Else Skip

^!Set %Hits%=^%Hits%^$GetLine$^P

^!Inc %Row%

^!If ^$GetRow$ < ^%Lines% Loop_2

^!Info [L]Expression: A OR B^P^PMatches:^P^%Hits%

^!Goto Out

:A NOT B

:Loop_3

^!Set %A%=0; %B%=0

^!Jump ^%Row%

^!IfMatch "^.*A.*$" "^$GetLine$" ^!Set %A%=1

^!IfMatch ".*B.*$" "^$GetLine$" ^!Set %B%=1

^!If ^$Calc(MIN(^%A%;1-^%B%))$=1 Next Else Skip

^!Set %Hits%=^%Hits%^$GetLine$^P

^!Inc %Row%

^!If ^$GetRow$ < ^%Lines% Loop_3

^!Info [L]Expression: A NOT B^P^PMatches:^P^%Hits%

^!Goto Out

:A XOR B

:Loop_4

^!Set %A%=0; %B%=0

^!Jump ^%Row%

^!IfMatch "^.*A.*$" "^$GetLine$" ^!Set %A%=1

^!IfMatch ".*B.*$" "^$GetLine$" ^!Set %B%=1

^!If ^$Calc(ABS(^%A%-^%B%))$=1 Next Else Skip

^!Set %Hits%=^%Hits%^$GetLine$^P

^!Inc %Row%

^!If ^$GetRow$ < ^%Lines% Loop_4

^!Info [L]Expression: A XOR B^P^PMatches:^P^%Hits%

^!Goto Out

:NOT A

:Loop_5

^!Set %A%=0

^!Jump ^%Row%

^!IfMatch "^.*A.*$" "^$GetLine$" ^!Set %A%=1

^!If ^$Calc(1-^%A%)$=1 Next Else Skip

^!Set %Hits%=^%Hits%^$GetLine$^P

^!Inc %Row%

^!If ^$GetRow$ < ^%Lines% Loop_5

^!Info [L]Expression: NOT A^P^PMatches:^P^%Hits%

^!Goto Out

:Out

^!ClearVariables

As far as I can see, the clip gets to correct results.

Nevertheless, for me the question remains: Is there any way to enlarge Wayne's concept to conditions like 'A AND B AND NOT (E OR D)', for example? Or is there no way to get beyond the borders of those five conditions?

Regards,

Flo

P.S. Regarding...

> Too often help is solicited and answers posted with nary a word

How right you are.... :-(

> of feedback or thanks. That is not a motivator for continuing

> to offer help.

What is obvious to some may not be to others so here are a few more of my 3 AM thoughts...

It may simplify things to break up the logical test into parts. We have already seen that the AND operation is easy to work with so it's good to convert to all ANDs if possible. So if you are testing A AND B AND C AND (D OR E OR F), you could first create a temp variable

If (D+E+F) > 0 set T=1 else set T=0. Then you can do IfTrue(A*B*C*T)

I see no need to limit things to 0 and 1 as long as you remember to use comparisons instead of IfTrue\IfFalse.. The above could also be done as If (A*B*C*(D+E+F)) > 0 then it is True.

Also, to try to avoid NOTs, you just have to plan ahead a little. Here is a very simple example.

If you wanted to accept lines with at least 2 letters and 0 digits, you could do:

If <at least 2 letters> L=1 else L=0

If <digits exist> D=1 else D=0

Then you would have to test for L AND NOT D

BUT if you think in terms of what you want to accept and do

If <at least 2 letters> L=1 else L=0

If <digits exist> D=0 else D=1

Then you would only have to test for L AND D.

Unless you have some reason for doing so, I still say it's better to do one test at a time and skip as soon as a test fails.

I'm sure you have a good grip on this now and plenty to think about.

Joy

--- In ntb-clips@yahoogroups.com, <flo.gehrke@...> wrote:

> You want to find out how to do this Wayne's way and I'm saying

Art & Joy,

> this is a big mistake except for the simplest of cases.

Many thanks again for your contributions to this topic!

Obviously, I've been on the wrong track when looking for more complex expressions based on Wayne's concept. As Art put it...

> The VanWeerthuizenian Expressions get very messy

Your alternatives will provide a helpful basis for creating better solutions in a this field.

> very, very quickly once you go beyond the trivial

> two parameter, ...

Regards,

Flo