%mathpiper,def="LogicCombine"

/* LogicCombine is responsible for scanning a list of lists, which represent
   a form (p1  Or  p2  Or  ...)  And  (q1  Or  q2  Or  ...)  And ... by scanning the lists
   for combinations x Or Y  And   Not x Or Z <-- Y Or Z . If Y Or Z is empty then this clause
   is false, and thus the entire proposition is false.
*/
LogicCombine(_list) <--
[
  Local(i, j);
  For(Bind(i,1), i<=Length(list), Bind(i,AddN(i,1)))
  [
    //Echo({"list[", i, "/", Length(list), "]: ", list[i], Nl()});

    For(j := 1, (j<=Length(list[i])), j++)
    [
      Local(tocombine, n, k);
      Bind(n, list[i][j]);

      {tocombine, k} := LogicFindWith(list, i, n);// search forward for n, tocombine is the list we
                                                  // will combine the current one with
      If(tocombine != -1,
      [
        Local(combination);
        Check(k != -1, "Math", "k is -1");

        Bind(combination, LogicRemoveTautologies(Concat(list[i], list[tocombine])));
        If(combination = {},                      // the combined clause is false, so the whole thing is false
          [Bind(list, {{}}); Bind(i, Length(list)+1);], [/*Bind(i, 0);*/]);
      ]);
    ];
  ];
  list;
];

%/mathpiper