Created
August 22, 2024 02:58
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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:
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:
Thus,
$$2.\ P_{xor}(s0, s1) = P(P_{or}(s0, s1) - P_{and}(s0, s1)) \neq P_{or}(s0, s1)$$
Axioms:
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$ .