Qbasicnews.com

Full Version: article on "exotic" logic optimization...
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Pages: 1 2
For the spaces try putting it inside a code block. Like this:


Code:
Make my spaces stay O great code block! ;)
                       Does this really stay?
      Oh yes!
Quote:(exotic since almost no one uses these)
Code:
2) Use of XOR

XOR is called "exclusive OR" because one OR the other must be true, AND both cannot be true or false at the same time:

"IF A = 99 OR B = 3 THEN IF A <> B THEN..." is equivalent to
"IF A = 99 XOR B = 3 THEN..."
AGA,
The idea of expalining these "exotic" functions is a good one. However, before you put all this in the FAQ, I looked at the section on XOR, and there are some problems:

a) Your statement that they cannot be true or false at the same time, somhow doesn't sound quite right, though technically correct. I would consider re-phrasing it.

b) I compiled and did a quick test of your example and it does not work for different values of A and B. For example: if A=99 and B=1, both expressions give the same results. But if A=99 and B=3, then you get different results. If A=99 and B=99 you also get different results.

c) I suggest you provide other, more binary, examples of the XOR, in addition to your compound "if" example.

In your section on the use of NOT, I would mention that the NOT performs the 1's complement on the argument, which you could explain as it inverts all the bits.
*****
Ok, thanks. The XOR problem was there because I didn't treat A and B as numbers but as T/F values in that part. Can't add another one though, as my head is already prepped to explode. Smile

Rephrased and added info on 1's complement..
Y'know, I never knew there is an EQV and IMP operators. Thanks!!!

And yes, try to "short-circuit your IF's

IF a then
if B then
if c then
end if
end if
End if
Speaking of IMP, that one's tricky... I changed it.. think I got it right this time.
Ok, I put it in http://faq.qbasicnews.com/?blast=LogicOptimize

I used lots of evil tricks..
A nice addition to the FAQ.

I see how to short-circuit AND, but how do you short circuit OR? Don't you need both conditionals in the first line?
No.

You can do several things.

1) You can duplicate the result for both statements.
2) You can use GOTO for both statements to goto the result. If one is true, you go to the result and you don't need to check the other statement.
3) You can do the same thing as (2), rewriting the code internally in the compiler, which is what QB *should* do.
very nice, taught me some new stuff Big Grin
now make a "Differences between WHILE...WEND, DO...LOOP UNTIL, and IF NOT A THEN GOTO TOP" one
Pages: 1 2