let relation_to_equations (finite_domain: finite_domain) (term: term) : term list =
  match term with
    | Term.Func func ->
        (* no relation, just keep term *)
        if not (Symbol.is_fd_relation func.Term.symbol) then
          term :: []

        else begin
          match func.Term.subterms.(0) with
            | Term.Func _ ->
                (* must be flat *)
                failwith ("Finite_domain.relation_to_equation: " ^ Term.term_to_string term)
                                    
            | Term.Const symbol ->
                (* transform into equation *)
                let symbol' =
                  Symbol.get_symbol_from_fd_symbol symbol
                in
                let result =
                  func.Term.subterms.(Array.length func.Term.subterms - 1)
                in
                let function_term =
                  if Symbol.arity symbol' = 0 then
                    Term.request_const symbol'
                  else
                    let arguments =
                      Array.sub func.Term.subterms 1 (Array.length func.Term.subterms - 2)
                    in
                      Term.request_func (symbol', arguments)
                in
                  Term.request_func (Symbol.equality, [| function_term; result |]) :: []
                                    
            | Term.Var _ ->
                (* transform into all equations of that arity *)
                let function_symbols =
                  Problem.get_arity
                    (get_problem finite_domain)#getFunctionArities
                    (Symbol.arity func.Term.symbol - 2)
                in
                  List.map
                    (fun symbol ->
                      (* transform into equation *)
                      let result =
                        func.Term.subterms.(Array.length func.Term.subterms - 1)
                      in
                      let arguments =
                        Array.sub func.Term.subterms 1 (Array.length func.Term.subterms - 2)
                      in
                      let function_term =
                        Term.request_func (symbol, arguments)
                      in
                        Term.request_func (Symbol.equality, [| function_term; result |])
                    )
                    function_symbols
          end

    | _ ->
        (* no relation, just keep term *)
        term :: []