Skip to content

Instantly share code, notes, and snippets.

@pavly-gerges
Created August 22, 2024 02:58
Show Gist options
  • Save pavly-gerges/741bb8c5947f67235e87226d99663e57 to your computer and use it in GitHub Desktop.
Save pavly-gerges/741bb8c5947f67235e87226d99663e57 to your computer and use it in GitHub Desktop.
A function that operates on a list of propositions and returns a predicate of their XORing operation using the primitive AND and OR.
#include <electrostatic/algorithm/arithmos/algebra/switching.h>
#include <stdlib.h>
uint8_t switching_xor(SWITCHING_TYPE **inputs, SWITCHING_TYPE *output){
if (inputs == NULL || output == NULL) {
return 1;
}
for (int i = 0; inputs[i] != NULL; i++) {
SWITCHING_TYPE prop0 = *output;
SWITCHING_TYPE prop1 = *(inputs[i]);
// XOR Propositional operation break-down
*output = ((!prop0) & prop1) | (prop0 & (!prop1));
//
// Example:
// 0 ^ 1 ^ 1 = 0
// -- break down --
// 1. [(!(0) & 1) | (0 & !(1)] = 1
// 2. [!(1) & 1) | (1 & !(1)] = 0
//
// XOR Function: Tests whether 2 binary sets are mutually exclusive
// return 1 if the predicate holds, 0 otherwise.
//
// Note: If the negation of set A can intersect with set B OR the negation
// of set B can intersect with set A; then, both sets are mutually exclusive.
//
// Note: This operates ONLY on binary sets (a set composed of only 0 or 1).
//
}
return 0;
}
@pavly-gerges
Copy link
Author

pavly-gerges commented Aug 22, 2024

Formal language formulation:

Prologue:

Let, S be an infinite set; such that $s_{n} \in S$; where $n$ is the set index. It then follows that, if for instance, two sets $s_{0}$ and $s_{1}$ are mutually exclusive or disjoint sets, then the following holds:

  • The predicate function $P_{xor}(s0, s1)$ yields a result that is congruent with the predicate function $P_{or}(s0, s1)$.
  • The predicate function $P_{xor}(s0, s1)$ yields a result that is also congruent with the predicate function $P(P_{or}(s0, s1) - P_{and}(s0, s1))$, since $P_{and}(s0, s1) = \phi$.

Thus,
$$1.\ P_{xor}(s0, s1) = P(P_{or}(s0, s1) - P_{and}(s0, s1)) = P(P_{or}(s0, s1) - \phi) = P_{or}(s0, s1)$$

However, if for another instance, two sets $s_{2}$ and $s_{3}$ are not mutually exclusive, then the following holds:

  • The predicate function $P_{xor}(s0, s1)$ yields a result that is congruent with the predicate function $P(P_{or}(s0, s1) - P_{and}(s0, s1))$.
  • The predicate function $P_{xor}(s0, s1)$ yields a result that is not congruent with the predicate function $P_{or}(s0, s1)$.

Thus,
$$2.\ P_{xor}(s0, s1) = P(P_{or}(s0, s1) - P_{and}(s0, s1)) \neq P_{or}(s0, s1)$$

Axioms:

$$ S = [s | s \in S] $$

$$ P_{xor}(v0, v1) = ((\neg v0) \land v1) \vee (v0 \land (\neg v1)) $$

$$ P_{mutex}(v0, v1) = \forall S \ \exists s0, s1 \ [s0, s1] \in S \ \iff [P_{xor}(s0, s1) \equiv P_{or}(s0, s1)]$$

Hence, if the 2 sets are mutually exclusive; then XORing them will yield the same value as ORing them. However, if they are not mutually exclusive, then XORing them won't yield the same value as ORing them, it will fallback to the original $P(P_{or}(s0, s1) - P_{and}(s0, s1))$ value; such that $P_{and}(s0, s1)) \neq \phi$.

So, in simple words, two sets $v0$ and $v1$ are said to be mutually exclusive if and only if $[P_{xor}(s0, s1) \equiv P_{or}(s0, s1)]$; such that $P_{and}(s0, s1)) = \phi$.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment