-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersquestionFurther information is requestedFurther information is requested
Description
Implement AND / OR logic per Rule Group type, starting with all/any rule group Gates.
Initial gates to implement (key in yml -> logic table)
all-> AND logicany-> OR logicnall-> Not AND / NAND logicnany-> Not OR / NOR logic
Other derived gates to consider such as XOR & XNOR.
- Note: Analogy/Description to work against:
- OR (
any) = "At least one is true" - XOR (
xany) = "One or the other, but not both" / one condition out of several isexclusivematch. - XNOR (
xnany) = "They agree" / can deduce from all conditions not matching that the current case must be true.
- OR (
Further reading / refresher on Truth Tables:
- https://www.geeksforgeeks.org/electronics-engineering/truth-table/
- https://mechtrician.com/logic-gates-or-and-not-nor-nand-xor-xnor-truth-table/
Java to represent truth table
- Note: This is based on two inputs or rules only (A : B)
import java.util.Arrays;
public class TruthTables {
// Logical operations
private static boolean AND(boolean a, boolean b) {
return a && b;
}
private static boolean OR(boolean a, boolean b) {
return a || b;
}
private static boolean XOR(boolean a, boolean b) {
return a ^ b;
}
private static boolean XAND(boolean a, boolean b) {
// XAND is essentially AND, but labeled differently
return a && b;
}
private static boolean NAND(boolean a, boolean b) {
return !(a && b);
}
private static boolean XNAND(boolean a, boolean b) {
// Same as NAND, but labeled differently
return !(a && b);
}
private static boolean NOR(boolean a, boolean b) {
return !(a || b);
}
private static boolean XNOR(boolean a, boolean b) {
return !(a ^ b); // true if both are equal
}
// Print truth table for selected gates
private static void printTruthTable() {
boolean[] values = {false, true};
// Header
System.out.printf("%-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s%n",
"A", "B", "AND", "XAND", "OR", "XOR", "XNOR", "NAND", "XNAND", "NOR");
// Rows
for (boolean a : values) {
for (boolean b : values) {
System.out.printf("%-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s %-5s%n",
a, b,
AND(a, b),
XAND(a, b),
OR(a, b),
XOR(a, b),
XNOR(a, b),
NAND(a, b),
XNAND(a, b),
NOR(a, b)
);
}
}
}
public static void main(String[] args) {
printTruthTable();
}
}1. Boolean Functions:
- Each logic gate is implemented as a separate method for clarity.
2. XAND & XNAND:
- XAND is just AND but labeled differently.
- XNAND is just NAND but labeled differently.This is useful if you want them explicitly in the table.
3. XNOR
- Implemented as !(a ^ b) — true when both inputs are the same.
4. Output Formatting:
- Uses printf with fixed-width columns for a clean table.
Sample Output:
A B AND XAND OR XOR XNOR NAND XNAND NOR
false false false false false false true true true true
false true false false true true false true true false
true false false false true true false true true false
true true true true true false true false false false
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or requestgood first issueGood for newcomersGood for newcomersquestionFurther information is requestedFurther information is requested