<commit_before>open Type

exception Break
exception Found

(*
  Checks if a function commutes with permutation.
  f(i(a)) = i(f(a)).
*)
let check_unary iso u1 u2 =
  let l = Array.length iso in
  Util.for_all (fun i -> iso.(u1.(i)) = u2.(iso.(i))) 0 (l-1)

(*
  Checks if binary operation is multiplicative.
*)
let check_binary iso b1 b2 =
  let l = Array.length iso in
  Util.for_all2 (fun i j -> iso.(b1.(i).(j)) = b2.(iso.(i)).(iso.(j))) 0 (l-1) 0 (l-1)


let are_iso {th_const=const_op; th_unary=unary_op; th_binary=binary_op}
            {alg_size=n1; alg_const=c1; alg_unary=u1; alg_binary=b1}
            {alg_size=n2; alg_const=c2; alg_unary=u2; alg_binary=b2} =
  if n1 <> n2 then false
  else
    let n = n1 in
    let used = Array.make n false in
    let iso = Array.make n (-1) in
    (* Handle constants *)
    Util.array_iter2 (fun i j -> used.(j) <- true ; iso.(i) <- j) c1 c2 ;

    (*
       Generate actions from unary and binary operations analogous to generation
       of actions from axioms. Axioms here are implicit from the definition of isomorphism
      IMPORTANT: actions_from_unary and actions_from_binary assume that algebras
      are "synced".
    *)
    let actions_from_unary arr1 arr2 =
      let stack = Stack.create () in
      let f i =
        if iso.(arr1.(i)) = -1 then
          begin
            if used.(arr2.(iso.(i))) then
              false
            else
              begin
                iso.(arr1.(i)) <- arr2.(iso.(i)) ;
                used.(arr2.(iso.(i))) <- true ;
                Stack.push i stack ; true
              end
          end
        else if iso.(arr1.(i)) <> arr2.(iso.(i)) then
          false
        else true in
      let undo i =
        while not (Stack.is_empty stack) && Stack.top stack = i do<commit_msg>Cosmetic change.<commit_after>open Type

exception Break
exception Found

(*
  Checks if a function commutes with permutation.
  f(i(a)) = i(f(a)).
*)
let check_unary iso u1 u2 =
  let l = Array.length iso in
  Util.for_all (fun i -> iso.(u1.(i)) = u2.(iso.(i))) 0 (l-1)

(*
  Checks if binary operation is multiplicative.
*)
let check_binary iso b1 b2 =
  let l = Array.length iso in
  Util.for_all2 (fun i j -> iso.(b1.(i).(j)) = b2.(iso.(i)).(iso.(j))) 0 (l-1) 0 (l-1)


let are_iso {th_const=const_op; th_unary=unary_op; th_binary=binary_op}
            {alg_size=n1; alg_const=c1; alg_unary=u1; alg_binary=b1}
            {alg_size=n2; alg_const=c2; alg_unary=u2; alg_binary=b2} =
  if n1 <> n2 then false
  else
    let n = n1 in
    let used = Array.make n false in
    let iso = Array.make n (-1) in
    (* Handle constants *)
    Util.array_iter2 (fun i j -> used.(j) <- true ; iso.(i) <- j) c1 c2 ;

    (*
       Generate actions from unary and binary operations analogous to generation
       of actions from axioms. Axioms here are implicit from the definition of isomorphism
      IMPORTANT: actions_from_unary and actions_from_binary assume that algebras
      are "synced".
    *)
    let actions_from_unary arr1 arr2 =
      let stack = Stack.create () in
      let f i =
        if iso.(arr1.(i)) = -1 then
          begin
            if used.(arr2.(iso.(i))) then
              false
            else
              begin
                iso.(arr1.(i)) <- arr2.(iso.(i)) ;
                used.(arr2.(iso.(i))) <- true ;
                Stack.push i stack ; true
              end
          end
        else not (iso.(arr1.(i)) <> arr2.(iso.(i))) in
      let undo i =
        while not (Stack.is_empty stack) && Stack.top stack = i do
{'fraction_non_alphanumeric': 0.12687199773947444, 'fraction_numerical': 0.022605255721955354, 'mean_word_length': 2.070251517779705, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1380849', 'n_tokens_mistral': 1274, 'n_tokens_neox': 1204, 'n_words': 374}