✅ How to group by tautology with LINQ?

IEnumerable<Row> rows =
[
new Row(null, "_or_", null, null),
new Row(null, "_or_", true, true),
new Row(null, "_or_", false, null),
new Row(true, "_or_", true, true),
new Row(true, "_or_", false, true),
new Row(false, "_or_", false, false),

new Row(null, "or", null, null),
new Row(null, "or", true, true),
new Row(null, "or", false, null),
new Row(true, "or", true, true),
new Row(true, "or", false, true),
new Row(false, "or", false, false),

new Row(null, "xor", null, null),
new Row(null, "xor", true, null),
new Row(null, "xor", false, null),
new Row(true, "xor", true, false),
new Row(true, "xor", false, true),
new Row(false, "xor", false, false),
new Row(null, "xor_", null, null),
new Row(null, "xor_", true, null),
new Row(null, "xor_", false, null),
new Row(true, "xor_", true, false),
new Row(true, "xor_", false, true),
new Row(false, "xor_", false, false)
];
IEnumerable<Row> rows =
[
new Row(null, "_or_", null, null),
new Row(null, "_or_", true, true),
new Row(null, "_or_", false, null),
new Row(true, "_or_", true, true),
new Row(true, "_or_", false, true),
new Row(false, "_or_", false, false),

new Row(null, "or", null, null),
new Row(null, "or", true, true),
new Row(null, "or", false, null),
new Row(true, "or", true, true),
new Row(true, "or", false, true),
new Row(false, "or", false, false),

new Row(null, "xor", null, null),
new Row(null, "xor", true, null),
new Row(null, "xor", false, null),
new Row(true, "xor", true, false),
new Row(true, "xor", false, true),
new Row(false, "xor", false, false),
new Row(null, "xor_", null, null),
new Row(null, "xor_", true, null),
new Row(null, "xor_", false, null),
new Row(true, "xor_", true, false),
new Row(true, "xor_", false, true),
new Row(false, "xor_", false, false)
];
2 Replies
canton7
canton710mo ago
Talk map be cheap, but I'm not sure what your question is without some explanatory text Two operators are in the same group if they produce the same output for all possible combinations of input? So, just GroupBy(row => (row.Left, row.Right, row.Result))? GroupBy returns a collection of IGrouping objects, which have a Key property (the tuple we constructed in the GroupBy call), and it implements IEnumerable letting you loop through the group's members Each of the group's members is a Row object here Easiest is just to run it in the debugger and have a poke around in the Watch window What does that output? Ah, you're not looking for operators which have the same output for all inputs You don't have a type anywhere which is "an operator, and all its combinations of inputs and outputs" You can solve it using linq for sure You need to group by an object which captures all of the combinations of input and output, and compares equal if all of those are the same Since your Row objects are sorted (for each operator), you could ignore the inputs and just look at the results (since everything's always in the same order). So two operators are in the same group of the Results of their Rows are the same in the same order (SequenceEquals) I think you need to represent a truth table for each operator Rather than bunging all of the rows for all operators together Then two operators are grouped together if their truth tables are equal, as I said Right, and now write code to compare two truth tables and see whether they're equal (That would be easier if TruthTable was its own type, but whatever) I mean, sure. That doesn't change what you need to do, though Not sure I understand the point of removing all of your messages? Just makes me look like I'm talking to myself...! But glad you (presumably?) got it working!
i like chatgpt
i like chatgptOP10mo ago
ChatGPT solved it. 🙂
Want results from more Discord servers?
Add your server