QB64.org Forum

Active Forums => Programs => Topic started by: TempodiBasic on July 25, 2021, 05:03:21 pm

Title: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: TempodiBasic on July 25, 2021, 05:03:21 pm
Hi QB64 community
Hi QB64 guys and gals
It comes back: IMP the logical illogical Operator

Here a four demonstrations to IMPlement  the IMPly operator of logic functions.

How I have learnt from many ways, there is poor use of IMP in the code.
Why? It isn't IMPossible that its logic is a bit cryptic or uncommon.  It is IMPossible to use a linear process of evaluation to have an efficient IMP use. So here it follows a program that let you try and test 4 IMProbable FUNCTIONS that say you if a value is out of a range and  in the range of the 2 value passed, the lowest and the uppest of the give values.
The FUNCTIONS are build with the goal of using IMP to demonstrate how a logical expression can be changed in another using different logic operators.
The table of truth of IMP is this following
A     B      A IMP B    =      (( NOT A)    OR B)
T     T            T                     F             T
F     T            T                     T             T
F     F            T                     T             T
T     F            F                     F             F

in another IMP thread   Luke said IMP is equal to  NOT a  OR B
I thanks all you QB64 coders with your tips, informations, point of views, comments to let me enlarge my knowledge and learn more to code...
here the demo
press the yellow character to activate the correlate FUNCTION, press Escape to quit
the output shows the value tested and their graphic placement on the row 1-80 of SCREEN 0
Code: QB64: [Select]
  1. 'IMP demo in multiple cases
  2. _Title "IMProbable Demonstrations of the IMPossible Logic Operator named IMP..."
  3. 'demo  OutOfRange  InTheRange Lowest Uppest
  4.     n$ = UCase$(InKey$)
  5.     If n$ = Chr$(27) Then End
  6.     If n$ <> "" And InStr("OILU", n$) Then
  7.         Cls
  8.         For a = 1 To 10
  9.             b = Int(Rnd * 40) + 1
  10.             c = Int(Rnd * 30) + 2 + b
  11.             d = Int(Rnd * 79) + 1
  12.             Locate (a - 1) * 2 + 1, 1
  13.             Print b; "  "; c; "  "; d; "  ";
  14.             If n$ = "O" Then If outheRange(b, c, d) Then Print "out of range "; ' Else Print "in the range ";
  15.             If n$ = "I" Then If intheRange(b, c, d) = -1 Then Print "In the range<---";
  16.             If n$ = "L" Then If Lowest(b, c, d) Then Print "lowest  is "; d
  17.             If n$ = "U" Then If Uppest(b, c, d) Then Print "Uppest  is "; d
  18.             ' graphic rappresentation
  19.             Color 2, 0: Locate (a - 1) * 2 + 2, b: Print ">";: Locate , c: Print "<";: Color 14, 0: Locate , d: Print "O";: Color 7, 0
  20.         Next a
  21.     End If
  22.     Locate 23, 1: Print " Outherange Intherange Lowest Uppest, Escape to quit"
  23.     Color 14, 0: Locate 23, 2: Print "O";: Locate 23, 13: Print "I";: Locate 23, 24: Print "L";: Locate 23, 31: Print "U";: Color 7, 0
  24.     _Limit 10
  25.  
  26.  
  27. ' SUB and FUNCTION area  / area delle SUB e delle FUNCTION
  28. Function outheRange (min As Integer, max As Integer, value As Integer)
  29.     outheRange = 0
  30.     outheRange = (min <= value Imp value >= max)
  31.  
  32. Function intheRange (min As Integer, max As Integer, value As Integer)
  33.     intheRange = 0
  34.     intheRange = (value <= max) Imp (value <= min)
  35.     intheRange = Not intheRange
  36.  
  37. Function Lowest (a1%, a2%, T%)
  38.     'NOT a OR b
  39.     '3 8 1 -> F imp F = T
  40.     '3 8 4 -> T imp F = F  no lowest
  41.     '5 3 2 -> F imp T = T
  42.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  43.     If a1% > a2% Then Swap a1%, a2%
  44.     Lowest = a1% < T% Imp a1% > a2%
  45.  
  46. Function Uppest (a1%, a2%, T%)
  47.     'NOT a OR b
  48.     '3 8 9 -> F imp T = T
  49.     '3 2 6 -> F imp F = T
  50.     '5 6 2 -> T imp T = T  -->bug  that it solves ordering a1% vs a2%
  51.     '6 4 2 -> T imp F = F no uppest
  52.     If a1% < a2% Then Swap a1%, a2%
  53.     Uppest = a1% > T% Imp a1% < a2%
  54.  
Thanks to try, welcome feedbacks



Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: bplus on July 26, 2021, 08:03:06 am
TempodiBasic function:
Code: QB64: [Select]
  1. Function Lowest (a1%, a2%, T%)
  2.     'NOT a OR b
  3.     '3 8 1 -> F imp F = T
  4.     '3 8 4 -> T imp F = F  no lowest
  5.     '5 3 2 -> F imp T = T
  6.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  7.     If a1% > a2% Then Swap a1%, a2%
  8.     Lowest = a1% < T% Imp a1% > a2%
  9.  

Bad idea to swap a1% and a2% specially when there is no need:
If a1% < a2% then lowest% = a1% else lowest% = a2%
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: bplus on July 26, 2021, 08:17:26 am
@TempodiBasic

I tested your intheRange function and found inconsistency:
Code: QB64: [Select]
  1. 'IMP demo in multiple cases
  2. _Title "IMProbable Demonstrations of the IMPossible Logic Operator named IMP..."
  3. 'demo  OutOfRange  InTheRange Lowest Uppest
  4. Dim As Integer rLow, rHigh, test
  5. rLow = -5: rHigh = 5
  6.     Input "Enter number to test in range -5 to 5 (use 0 (in Range) to quit) "; test
  7.     If intheRange(rLow, rHigh, test) Then Print "In the range -5 to 5." Else Print "Not in the range -5 to 5."
  8. Loop Until test = 0
  9.  
  10. ' SUB and FUNCTION area  / area delle SUB e delle FUNCTION
  11. Function outheRange (min As Integer, max As Integer, value As Integer)
  12.     outheRange = 0
  13.     outheRange = (min <= value Imp value >= max)
  14.  
  15. Function intheRange (min As Integer, max As Integer, value As Integer)
  16.     intheRange = 0
  17.     intheRange = (value <= max) Imp (value <= min)
  18.     intheRange = Not intheRange
  19.  
  20. Function Lowest (a1%, a2%, T%)
  21.     'NOT a OR b
  22.     '3 8 1 -> F imp F = T
  23.     '3 8 4 -> T imp F = F  no lowest
  24.     '5 3 2 -> F imp T = T
  25.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  26.     If a1% > a2% Then Swap a1%, a2%
  27.     Lowest = a1% < T% Imp a1% > a2%
  28.  
  29. Function Uppest (a1%, a2%, T%)
  30.     'NOT a OR b
  31.     '3 8 9 -> F imp T = T
  32.     '3 2 6 -> F imp F = T
  33.     '5 6 2 -> T imp T = T  -->bug  that it solves ordering a1% vs a2%
  34.     '6 4 2 -> T imp F = F no uppest
  35.     If a1% < a2% Then Swap a1%, a2%
  36.     Uppest = a1% > T% Imp a1% < a2%
  37.  
  38.  
  39.  

If 5 is in the range then -5 should be also.

Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: TempodiBasic on July 26, 2021, 12:56:20 pm
Hi Bplus
Thanks for you feedbacks!

1.
about bad swap in lowest...
Code: QB64: [Select]
  1. 'NOT a OR b
  2.     '3 8 1 -> F imp F = T
  3.     '3 8 4 -> T imp F = F  no lowest
  4.     '5 3 2 -> F imp T = T
  5.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  6.     IF a1% > a2% THEN SWAP a1%, a2%
  7.     Lowest = a1% < T% IMP a1% > a2%

I want to stress the Illogical Logical table of IMP with this comment left in the function
Quote
'6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
in this example test, the function returns a wrong result returning True (as IMP table shows)
So I agree with you that it is LOGICAL that if T > a1  AND a1>a2 why should we swap these last two?
But wait a moment  the expression is T>a1 IMP a1>a2 ! That is the point.
The swap brings the evaluation to the 2 first rows where the function Lowest returns the right value True/False.

And dear friend I agree with you that it is not so elegant as a single row of evaluation statement but it works.
PS: now you get why this is an IMProbable Demonstrations of the IMPossible Logic Operator named IMP  ;)


2.
using negative numbers in the range...
I must admit that this point of view is interesting and I must declare that originally the function has been built thinking to a position in the Right Upper sector of a Cartesian plan with the two dimensions X and Y from 0 to + infinite.
Maybe that this choice has been made because it is naturally thinking of a position as something that exists. But using a different cohordinates system a negative value is possible.
Well I'll use your feedback to expand (if it will be possible) the functions to the whole gamma of cohordinates of Cartesian bidimensional plan.

Thanks again
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: Dimster on July 26, 2021, 02:01:53 pm
I love this topic Tempodi .

The statement " intheRange = (value <= max) Imp (value <= min) "  ...which shows up as line 38 for me....How does the ... IMP (value <= min) .....actually work correctly. The implied should be the value can be equal to min but not a value less than min. A value less than min should not be intheRange. If our range is  10 to 20 and the value is 9, that 9 would be less than the min of 10. ??? so what am I missing in this Logical Operator???

Thanks very much for tackling it. I have had no confidence in the results I'm getting but it seems like it should be a useful tool with logic applications.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: TempodiBasic on July 26, 2021, 07:39:39 pm
Hi DImster
thanks for feedback and ideas to talk about.

Quote
I love this topic Tempodi
My pleasure to get the interest of QB64 coders.


Quote
The implied should be the value can be equal to min but not a value less than min. A value less than min should not be intheRange. If our range is  10 to 20 and the value is 9, that 9 would be less than the min of 10. ??? so what am I missing in this Logical Operator???

At the starting time, also I was thinking about IMP as the word imply but this is wrong and it brings us in the wrong direction. We use in human language this word with the meaning IF...THEN... while IMP seems to be a mathematical  imply that formally has as name Material Implication or Material Conditional.
read here if you want to get more deep informations  https://en.wikipedia.org/wiki/Material_conditional (https://en.wikipedia.org/wiki/Material_conditional)
So it seems that we must think about IMP as we think about + of the sum with its feature. It is an operator that gives False only if the first condition is True and the second condition is False. This is the path to set the right conditions in the two branches of IMP and to get back the desired result.

Well the function has the goal to return True (-1/ NOT 0) if the third parameter is between the first and the second parameters.
let's test the expression   
Code: QB64: [Select]
  1.  intheRange = 0  '<---- this is the default result (False/ No)
  2.     intheRange = (value <= max) IMP (value <= min)   '<-- this is the expression that using IMP answer to the question " Is value between min and max?
  3.     intheRange = NOT intheRange' <-- really the above expression calculates the OutOfRange so we must NOT the result

Min  Max  Value    (value <= max) IMP (value <= min)            (NOT    (value<=max))  OR  (value <=min)
 10   20      9        (9<=20)   IMP  (9<=10)                              (NOT     (9<=20))        OR    (9<= 10)
                               True   IMP    True   -------> True                (NOT   True)       OR  (True)  ------> True
 10  20     21         21 <= 20  IMP  21<= 10                               NOT (21<=20)   OR (21<= 10)
                                  False  IMP   False  ---> True                     NOT False OR False ------> True
 10  20     11         11<= 20  IMP 11<=10                                NOT(11<=20)  OR (11<=10)
                                  True  IMP    False ---> False                     NOT True OR  False  -----> False

changing the > with < and viceversa we get the one shot InTheRange
Min  Max  Value    (value >= max) IMP (value >= min)            (NOT    (value>=max))  OR  (value >=min)
 10   20      9        (9>=20)   IMP  (9>=10)                              (NOT     (9>=20))        OR    (9>= 10)
                               False   IMP    False   -------> True                (NOT   False)       OR  (False)  ------> True
 10  20     21         21 >= 20  IMP  21>= 10                               NOT (21>=20)   OR (21>= 10)
                                  True  IMP   True  ---> True                     NOT True OR True ------> True
 10  20     11         11>= 20  IMP 11>=10                                NOT(11>=20)  OR (11>=10)
                                False    IMP   True ---> True                     NOT False OR  True  -----> True
So the code of the FUNCTION InTheRange will be
Code: QB64: [Select]
  1.  intheRange = 0  '<---- this is the default result (False/ No)
  2.     intheRange = (value >= max) IMP (value >= min)   '<-- this is the expression that using IMP answer to the question " Is value between min and max?

And with this last sentence I feel to have finished to share my new knowledge about IMP.

PS Thank you, I have got a new InTheRange in oneshot!
Now I'll try to give an universal wellworking also with negative numbers. Next time.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: Dimster on July 27, 2021, 10:34:36 am
Quote
At the starting time, also I was thinking about IMP as the word imply but this is wrong and it brings us in the wrong direction. We use in human language this word with the meaning IF...THEN... while IMP seems to be a mathematical  imply that formally has as name Material Implication or Material Conditional.

All the other logical operators (And, Or, Xor, Eqv) seem to be Basic logic.

IMP is false if its first operand is true and the second is false. Otherwise IMP is true.. My parents always said 2 wrongs do not make a right but it would appear with this Material Implicator , 2 wrongs do imply a right ( if First Operand is False and second operand is False then result is True). Two wrongs making a right.

Thanks again, I'll smoke a little more marijuana and a bottle of whiskey and I know I'll understand it perfectly.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: SMcNeill on July 27, 2021, 06:10:06 pm
IMP is a NOT A OR B evaluation.

If you’re NOT sick, OR if you’re a woman, then you get a discount on health insurance, which breaks down to:

SICK, WOMAN = DISCOUNT
YES, YES = TRUE (you’re a woman)
NO, YES = TRUE (you’re a woman)
NO, NO = FALSE (you’re sick and not a woman)
YES, NO = TRUE (you’re not sick)

SICK IMP WOMAN = DISCOUNT
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: TempodiBasic on July 28, 2021, 05:40:36 am
Hi Qb64 boys and Girls

I come back on topic...

@SMcNeill  Great Steve, an example enlighting and very practical!

@Dimster
Yes it is not under common sense that two lies brings to a truth! But also in common speaking IMP is there:
1 -You are a good guy  = You aren't a bad guy   
2 - this sentence isn't false = this sentence is true
3 - the shirt is clean = the shirt is not dirty
As human we use a not strictly binary system of values, so until the reference system is with only two choices we feel IMP  as normal and right (see sentence 2), while we use a reference system with more than two options we feel that IMP is not so accurate (see sentence 1 and 3) because we cut out a choice but there are more than one alternative.
you aren't a bad guy = you are normal guy  or you are a good guy or....what other meaning you can add?

@bplus
Thanks for feedback... I was searching far far away the solution! But with your test you have already suggested  me also the solution!
Yes deleting an = the function gets accuracy again
Here the code with testing:
Code: QB64: [Select]
  1. 'IMP demo in multiple cases
  2. _Title "IMProbable Demonstrations of the IMPossible Logic Operator named IMP..."
  3. 'demo  OutOfRange  InTheRange Lowest Uppest
  4. Dim As Integer rLow, rHigh, test
  5. rLow = -5: rHigh = 5
  6.     Input "Enter number to test in range -5 to 5 (use 100 (in Range) to quit) "; test
  7.     If intheRange(rLow, rHigh, test) Then Print "In the range -5 to 5." Else Print "Not in the range -5 to 5."
  8. Loop Until test = 100
  9.  
  10. ' SUB and FUNCTION area  / area delle SUB e delle FUNCTION
  11. Function outheRange (min As Integer, max As Integer, value As Integer)
  12.     outheRange = 0
  13.     outheRange = (min <= value Imp value >= max)
  14.  
  15. Function intheRange (min As Integer, max As Integer, value As Integer)
  16.     intheRange = 0
  17.     intheRange = (value <= max) Imp (value < min)
  18.     intheRange = Not intheRange
  19.  
  20. Function Lowest (a1%, a2%, T%)
  21.     'NOT a OR b
  22.     '3 8 1 -> F imp F = T
  23.     '3 8 4 -> T imp F = F  no lowest
  24.     '5 3 2 -> F imp T = T
  25.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  26.     If a1% > a2% Then Swap a1%, a2%
  27.     Lowest = a1% < T% Imp a1% > a2%
  28.  
  29. Function Uppest (a1%, a2%, T%)
  30.     'NOT a OR b
  31.     '3 8 9 -> F imp T = T
  32.     '3 2 6 -> F imp F = T
  33.     '5 6 2 -> T imp T = T  -->bug  that it solves ordering a1% vs a2%
  34.     '6 4 2 -> T imp F = F no uppest
  35.     If a1% < a2% Then Swap a1%, a2%
  36.     Uppest = a1% > T% Imp a1% < a2%
  37.  

@TempodiBasic
please don't run to make mistakes
this code is buggy for now no oneshot InTheRange !
Quote
intheRange = 0  '<---- this is the default result (False/ No)
    intheRange = (value >= max) IMP (value >= min)   '<-- this is the expression that using IMP answer to the question " Is value between min and max?



Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: bplus on July 28, 2021, 09:29:05 am
@TempodiBasic

I think I will take a range check on IMP.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: Dimster on July 28, 2021, 10:33:19 am
So if I'm understanding this correctly. Tempodi's assertion that we can't interpret IMP as meaning Imply in the traditional sense, and applying Steve's example:

The convention of A IMP B, where A = Sick and B =Woman can be rewritten as     ((Sick)*-1) OR Woman = Discount.
The convention therefore should be thought more as (A*-1) or B IMP  D

In effect the Left side of the IMP statement sets up exclusionary value(s) and the Right side of the IMP statement provides more exclusionary values to consider. They are really not implying each other but rather building up exclusionary values. And test is to see if D falls within those exclusionary values. 

The way the convention of A IMP B is written had me thinking the A in fact did imply B and as a result we came up with D. So Sick IMPLIED Woman and therefore it effects the Discount. In my mind I could see a Health Plan only for Women and if a woman was sick when applying for the plan then if effected the Discount but Steve's example makes so much more sense because it would include both males and females.

Lord, don't you love the logic of people v's machines?

Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: bplus on July 28, 2021, 10:53:13 am
I think AND and OR and NOT work in conventional sense but IMP is purely for bit math users.

Implies, logically to me, usually means if A is element or subset of B then A has all the characteristics that identify an element or subset as B. eg if A is a man then A is a human, if C is a women then C is a human.


Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: Dimster on July 28, 2021, 11:24:32 am
So b+ , the A IMP B are not providing a different set of values but the B would be a value(s) held within the A ? So the A could be a range and the B a specific value? Or even vice versa, the A carrying a specific value and the B the range containing the A? That concept would bring back that idea that IMP does mean Imply. If the range is 10 to 20 then it certainly does imply 12 but not 9.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: bplus on July 28, 2021, 11:39:15 am
Yeah I think Basic's IMP exists only to round out a set of bit manipulations you can do with 0's and 1's or True and False values there may be some esoteric need for it. You certainly don't need it for range determination.

IF x > high_range OR x < low_range THEN PRINT x ;" is out of range"

What could be simpler to understand for range?
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: SMcNeill on July 28, 2021, 04:59:48 pm
IMP is a NOT A OR B evaluation.

If you’re NOT sick, OR if you’re a woman, then you get a discount on health insurance, which breaks down to:

SICK, WOMAN = DISCOUNT
YES, YES = TRUE (you’re a woman)
NO, YES = TRUE (you’re a woman)
NO, NO = FALSE (you’re sick and not a woman)
YES, NO = TRUE (you’re not sick)

SICK IMP WOMAN = DISCOUNT

Actually, I wrote that wrong.  :P

SICK, WOMAN = DISCOUNT
YES, YES = TRUE (you’re a woman)
NO, YES = TRUE (you’re a woman)
NO, NO = TRUE (you’re not sick)
YES, NO = FALSE (you’re sick and not a woman)

See if that doesn’t look a little more like the logic chart Tempodi shared:

The table of truth of IMP is this following
A     B      A IMP B
T     T            T             
F     T            T                   
F     F            T                 
T     F            F             

Why I reversed my bottom two lines, I have no clue, but when I looked back over them, they were swapped.  :P

IMP is one of those operators which I’ve never personally needed.  Honestly, I’d rather write this:

DISCOUNT = (NOT SICK) OR WOMAN

than:

DISCOUNT = SICK IMP WOMAN

They’re the same thing, and IMP might save a few microprocesses, but I find the first much more readable and able to be understood for my personal code and use.

Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: SMcNeill on July 28, 2021, 05:24:00 pm
Another way to break down the logic of IMP is to remember with A IMP B:

Your result is *always* going to have all the bits of B set…

For example, let’s assume A and B are both _UNSIGNED _BYTEs.

Now if B =3, the result of A IMP B will be = ??????11, depending on A to fill in the ?
And if B = 5, the result of A IMP B will be = ?????1?1, depending on A to fill in the ?

*Whatever* the final result is, it’s going to have every bit set that B already has set.



And, with that half of the process solved, it’s *also* going to set any bits that A *DOES NOT* have set.

A = 2.  B = 3.

In binary, those are:
A = 00000010
B = 00000011

A IMP B is solved by first setting all the bits in the answer to match B:   ??????11
Then we toggle all the bits in A: 11111101.
And we set the ones that are on, for our answer: 11111111

2 IMP 3 = 255



(NOT A) OR B

That’s the breakdown of what IMP is doing.

(NOT A) says the result is going to have all the bits set that A does NOT have.
OR B says our result is *also* going to have all the bits set that B does.

A IMP B = (NOT A) OR B

Really, that’s all there is to it.  It’s convoluted, and not really something I think most folks ever really need, but that’s all the does in a nutshell.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: TempodiBasic on July 29, 2021, 07:48:53 am
Last news on IMP
1. It is supported until VB6 but it was dismissed in VB.NET  for the equivalence to NOT(A) OR B !
2. It is useful if you must make a choice in which the determinant element is the second... in fact IMP gives False only if the second element is False and the first element is True....
here an example in VB6 to make a quick choice in a  cascade IF (use Google for get the text but code seems readable)
https://masterdrive.it/visual-basic-6-17/lha-visto-loperatore-logico-imp-41456/ (https://masterdrive.it/visual-basic-6-17/lha-visto-loperatore-logico-imp-41456/)

In sum IMP is there and can be used! Let think about it like it would be the equivalent of  SQR or LOG operation versus +-*/. It is not so times used but it can be more useful in specific setting or with specific research to use it.
Code: QB64: [Select]
  1. IMPuse IMP IMPoperator
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: Dimster on July 29, 2021, 10:21:26 am
What an education this tread has been for me. And I have to say that I feel for Fabel Schoolboy. He shared his discovery on IMP but seems the criticism was taken so personally. I guess this is one of the things I like about the comments many of the coders on this site take. Even though we may use the words "I, You, me etc" those words which are a personal reference to yourself, invariably should trigger a personal reply and that's when we run into those scenarios where we have to defend ourselves, sometimes heatedly. But you guys, for the most part, keep your responses directed to the code and not the person. Your criticism of the code is much more helpful from a learning perspective, and I for one appreciate that very much.

I don't think the logical operator IMP has ever had as strong a light shined on it. Maybe this tread could be referenced in a Best Practice or Learning Section. You guys rock.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: OldMoses on July 29, 2021, 07:09:51 pm
I can't say I've gotten any ideas on how/where/when to use IMP, as NOT A OR B seems more intuitive, but I did rather enjoy Steve's sick woman example...;)
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: SMcNeill on July 29, 2021, 07:54:57 pm
I can't say I've gotten any ideas on how/where/when to use IMP, as NOT A OR B seems more intuitive, but I did rather enjoy Steve's sick woman example...;)

Honestly, I doubt I’d even do (NOT A) OR B  very often.  I’m much more comfortable, and likely to use, something like:

Healthy = NOT Sick
Discount = Healthy OR Woman

Even though the above is two lines, *anyone* should be able to just glance at those and understand what they’re doing and what the intended result of them should be, quite easily.

Whereas you’re going to need a comment or two, or a very experienced programmer, to instantly know the IMP method:

Discount = Sick IMP Woman



The *only* time I’d be likely to worry with IMP, is if my boss said, “We’re having a competition for a $1,000 bonus this Xmas, and it’ll go to whoever writes a program to calculate discounts the fastest!”  In this very specific case, saving that singular math operation for speed over readability would probably be necessary.

Any other time though?  Readability and ease of maintenance for the source code, trumps saving one math process, all the rest of the time.
Title: Re: IMProbable Demonstrations of the IMPossible Logic Operator named IMP...
Post by: TempodiBasic on August 03, 2021, 07:29:01 am
Hi QB64 boys and girls
here the final cut of my little IMPossible IMPortant library with 4 general purpouse functions:

-OutheRange: it returns if a value is out of a range
(Thanks to Bplus for feedback and showing a point of weakness of previous formula)

-IntheRange: it returns if a value is in a range

-Lower: it returns if the third value is the lowest among 3 passed

-Uppest: it returns if the third values is the uppest among 3 passed

They works also with negative numbers.
They can be easily modified to work with different kinds of numer data redifining the type of parameters and of the function.

Code: QB64: [Select]
  1. 'IMP demo in multiple cases
  2. _Title "IMProbable Demonstrations of the IMPossible Logic Operator named IMP..."
  3.  
  4. Dim As Integer rLow, rHigh, test
  5. rLow = -5: rHigh = 5
  6. Print "Min   Max   Value   Intherange OutheRange Lowest Uppest"
  7. For test = -6 To 6
  8.     Print rLow; "   "; rHigh; "    "; test; "     "; intheRange(rLow, rHigh, test); "        "; outheRange(rLow, rHigh, test); "        "; Lowest(rLow, rHigh, test); "       "; Uppest(rLow, rHigh, test)
  9.     Swap rLow, rHigh
  10.     ' ------- output debugging STEP BY STEP -------------
  11.     'Print "TEST ="; test
  12.     'Print "Min "; rLow; "  Value "; test; "  Max "; rHigh
  13.     'Print "In the range -5 to 5.";: Print intheRange(rLow, rHigh, test)
  14.     'Print "Not in the range -5 to 5.";: Print outheRange(rLow, rHigh, test)
  15.     'Print "It is the lowest";: Print Lowest(rLow, rHigh, test)
  16.     'Print "It is the uppest";: Print Uppest(rLow, rHigh, test)
  17.     'Print " Press a key to continue..."
  18.     'Sleep: Cls
  19.     '-----------------------------------------------------
  20. '------------------------------------------------------------------------
  21. ' SUB and FUNCTION area  / area delle SUB e delle FUNCTION
  22. Function outheRange (Min As Integer, Max As Integer, Value As Integer)
  23.     '3 8 1 -> F imp F = T
  24.     '3 8 4 -> T imp F = F  no OUTHERANGE
  25.     '3 8 9 -> T imp T = T
  26.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  27.     If Min > Max Then Swap Min, Max
  28.     outheRange = 0
  29.     outheRange = (Min <= Value) Imp (Value > Max)
  30.  
  31. Function intheRange (Min As Integer, Max As Integer, Value As Integer)
  32.     '3 8 1 -> F imp F = T -->NOT()--> F
  33.     '3 8 4 -> T imp F = F -->NOT() -->T   INTHERANGE
  34.     '3 8 9 -> T imp T = T -->NOT() --> F
  35.     If Min > Max Then Swap Min, Max
  36.     intheRange = 0
  37.     intheRange = Not ((Min <= Value) Imp (Value > Max))
  38.  
  39. Function Lowest (a1%, a2%, T%)
  40.     'NOT a OR b
  41.     '3 8 1 -> F imp F = T
  42.     '3 8 4 -> T imp F = F  no lowest
  43.     '5 3 2 -> F imp T = T
  44.     '6 4 9 -> T imp T = T  --> bug that it solves ordering a1% vs a2%
  45.     If a1% > a2% Then Swap a1%, a2%
  46.     Lowest = a1% < T% Imp a1% > a2%
  47.  
  48. Function Uppest (a1%, a2%, T%)
  49.     'NOT a OR b
  50.     '3 8 9 -> F imp T = T
  51.     '3 2 6 -> F imp F = T
  52.     '5 6 2 -> T imp T = T  -->bug  that it solves ordering a1% vs a2%
  53.     '6 4 2 -> T imp F = F no uppest
  54.     If a1% < a2% Then Swap a1%, a2%
  55.     Uppest = a1% > T% Imp a1% < a2%
  56.  

So you can IMProve your experience of IMP with these blackbox functions.

PS don't read this thread if you are not interesting to IMP, why do you waste your time?