#header-inner {background-position: right !important; width: 100% !important;}

8/1/14

Logical Operators.

Wording.

Logical operator wording is such:

A - word A, might be true or false.
B - word B, might be true or false.

not - logical negation.
and - logical conjunction.
or - logical alternative.
xor - logical exclusive alternative.
=> - logical implication. can be written as IMP.
<= - logical implication in reverse direction. can be written as IREV.
<=> - logical operator 'if and only if', also can be written as IFF, XNOR or often as ==.
nand - logical operator 'not and'.


Boolean Algebra basics.

Boolean Algebra basics using logical operators, A, and B:

A B not A A and B A or B A xor B A imp B A irev B A iff B A nand B
true true false true true false true true true false
true false false false true true false true false true
false true true false true true true false false true
false false true false false false true true true true


for example if we have: A is true, B is false, then we can say that alternative (A or B) evaluates to truth, thus has truth value. we can also say that this alternative is true.


Boolean Expressions.

Boolean expressions are equations that use words, parentheses & logical operators, equations that evaluate to boolean value.

for example: (A imp B) would be a boolean expression, a function whose value depends on values of words from set: { A, B } which can have boolean values contained in a Boolean Value Set: { true, false }.

for example: ((A or B) iff C) would be a boolean expression, a function whose value depends on values of words from set: { A, B, C } which can have boolean values contained in a Boolean Value Set: { true, false }.


'iff' differs from '==' operator with type safety. 'iff' accepts only boolean values, where '==' might also compare integers, for example. '==' might compare boolean values as well, but not only. both can be used with expressions that evaluate to boolean values.


De Morgan's Laws.

In boolean algebra De Morgan's laws are a pair of transformation rules that are both valid rules of inference. The rules allow the expression of conjunctions and alternatives purely in terms of each other via negation, with use of parentheses for operator priority.

1. 'A and B' is the same as 'not ( (not A) or (not B) )'
2. 'A or B' is the same as 'not ( (not A) and (not B) )'

De Morgan's Laws are also used in Set Theory, perhaps elsewhere as well.


See also: Conditional Instruction & Expressions.

7 comments:

  1. i think that 'Ola AH' Programming Language should have all of these logical operators as part of their sematics & syntax.

    ReplyDelete
  2. example of a conditional instruction using boolean expression with these symbols would be written as:

    if ( A iff (((not B) and C) irev D) ) { }

    ReplyDelete
  3. i'd call this approach 'rich logical syntax', which while unneccessary - as every logical expression can be written using parentheses, negation, conjunction, alternative, and logical words - might prove useful for many.

    ReplyDelete
  4. - why 'rich logical syntax'?
    - because of AH part of language's name. either as AH Mantra which enriches speech (judging from my experience), or as Anti-Hack which is targetted for experts - this makes sense in my opinion... perhaps in 'basic mode' unneeded logical operators will be excluded from syntax.

    ReplyDelete
  5. to be precise, we do not need even conjunction if we have parentheses, negation and alternative, in theory... De Morgan's Laws state that.

    but we still use conjunction for convenience.

    ReplyDelete
  6. another, less complex & strange conditional instruction using richer but still simple boolean operator syntax would be:

    if (A imp B) { doSomething() }

    semantics of this piece of code would be:

    'if A implies B then do something'.

    or more formally:

    if implication: (A => B) evaluates to 'truth' value, then execute doSomething() instruction.

    ReplyDelete
  7. little of the art, it's symbolics, perhaps?

    http://fav.me/d8vao1f .

    ReplyDelete