Edit logicOperator="XOR"

Imported from previous forum

… with 2 or more operands.

XOR is interpreted as “Odd” function. It is “True” IIF odd number of operands are true. Is that correct for ATDL?

This is why I am asking, I received an ATDL file with a definition like this:

<val:StrategyEdit errorMessage=“Please specify one type of Premium or Discount”>
<val:Edit logicOperator=“XOR”>
<val:Edit field=“AbsPremium” operator=“EX”/>
<val:Edit field=“PctPremium” operator=“EX”/>
<val:Edit field=“PctDiscount” operator=“EX”/>
</val:Edit>
</val:StrategyEdit>

How would you interpret this? Using “Odd” XOR definition the validation is passed when all 3 are set.

Sergey,

I am not sure about the validation expression with respect to the exclusive OR. From what I remember from school, XOR expressions return true if exactly one of two related expressions returns true (but never when both are true or both are false).

I believe it may not even be necessary if your ATDL file had specified the related strategy parameter in a different manner, like the following example:





That way, the user has no choice but to pick one of the choices. Validation can then be performed based on some other parameter, like disabling this drop down if no “price” has been entered, or making mandatory, etc.

–ws

… with 2 or more operands.

XOR is interpreted as “Odd” function. It is “True” IIF odd number of
operands are true. Is that correct for ATDL?

This is why I am asking, I received an ATDL file with a definition
like this:

<val:StrategyEdit errorMessage=“Please specify one type of Premium or
Discount”> <val:Edit logicOperator=“XOR”> <val:Edit field=“AbsPremium”
operator=“EX”/> <val:Edit field=“PctPremium” operator=“EX”/> <val:Edit
field=“PctDiscount” operator=“EX”/> </val:Edit> </val:StrategyEdit>

How would you interpret this? Using “Odd” XOR definition the validation
is passed when all 3 are set.

When we “upgraded” the rules technology for both VALIDATION and FLOW areas of FIXatdl we were really most interested in adding NOT AND. NOT OR was then likely added “to match” – however its likely of little “real world” use.

NOT AND however really opens up some exceptionally interesting capabilities in VALIDATION and FLOW rules processing. See the quote below from WikiPedia and know that is exactly what we intended to build in to FIXatdl v1.1 This capability is not to be underestimated!

“The NAND gate has the property of functional completeness. That is, any other logic function (AND, OR, etc.) can be implemented using only NAND gates. An entire processor can be created using NAND gates alone.”

According to the FIXatdl-1.1 spec:
"… the logical operators, AND and OR, can have more than two operands. Furthermore, they both perform short-circuit evaluation of their operands. That being the case, it is important that XML parsing or binding libraries maintain the order of the elements as they appear; otherwise unexpected results may occur."

But what abuot XOR? The spec doesn;t say anything about it.

SO here is my interpetation…
All logical operators are binary. However, there is an exception for AND and OR, which can have more than two operands (this was stricly for convenience since most programming languages allow for this). XOR must have two and only two operands. The operator, NOT, must have exactly one operand.

I realize that we can get a creative and let XOR have multiple interpretations (one and only one from a set, two and only two from a set, three but not more than four, etc.), but that’s the programmers job, or in this case the FIXatdl author’s job.

So I think you’ll need to re-write the to something like this:
















-Greg

Thank you, everyone, for your opinions. I agree that the safest approach is to ask the client to refactor atdl file. That’s what I am going to do.

However, just a small comment on …

All logical operators are binary…

Yes, it is true that all logical operators (AND, OR, XOR) can be considered as binary. But, for example, in Java and C# we can write an expression:
boolean result1 = true ^ true ^ true ^ true; (result1 = false - even number of true arguments)
boolean result2 = true ^ true ^ false ^ true; (result2 = true - odd number of true arguments)
boolean result3 = true ^ false ^ false ^ true; (result2 = false - even number of true arguments)
no matter what is your expression interpretation rules are:

  • like that: true ^ (true ^ (true ^ true))
  • or like that: (((true ^ true) ^ true) ^ true)
    result going to be the same because the XOR operator in those languages is associative. I believe it is associative in many other languages too.
    The same in logic gates, you can cascade two-input XOR gates into a multi-inputs XOR gate.
    Therefore, generally speaking, I would not limit XOR operator in ATDL to two operand I would rather make it clearer in the spec that XOR is associative, which means
    (A XOR B) XOR C = A XOR (B XOR C) = A XOR B XOR C
    to avoid interpretations.

[ original email was from John Shields - john.shields@nomura.com ]

Being the guilty party of the original template, I support the “one and only one” interpretation of XOR. This is by far the more common use case in algo trading–i.e. often you have a list of “mutually exclusive parameters” where the user can only “pick one”.

Would very much support including this in the Errata of ATDL, as Edits (including those with logicOperator=“XOR”) in FIXatdl 1.1 can have multiple child elements, and there’s not much real-world use here for the “odd number must be true” interpretation that purist digital designers would have…

atdl4j (atdl4j.org) has a nice recursive short-circuit implementation of the LogicOperator’s including the “one and only one” version of XOR.

According to the FIXatdl-1.1 spec: “… the logical operators, AND and
OR, can have more than two operands. Furthermore, they both perform short-
circuit evaluation of their operands. That being the case, it is
important that XML parsing or binding libraries maintain the order of
the elements as they appear; otherwise unexpected results may occur.”

But what abuot XOR? The spec doesn;t say anything about it.

SO here is my interpetation… All logical operators are binary.
However, there is an exception for AND and OR, which can have more than
two operands (this was stricly for convenience since most programming
languages allow for this). XOR must have two and only two operands. The
operator, NOT, must have exactly one operand.

I realize that we can get a creative and let XOR have multiple
interpretations (one and only one from a set, two and only two from a
set, three but not more than four, etc.), but that’s the programmers
job, or in this case the FIXatdl author’s job.

So I think you’ll need to re-write the to something like this:


-Greg