Defining Mutually Recursive functions in Coq This question is related to (but not the same as):

How to define a function inductively on two arguments in Coq?

In particular, I used those techniques (defining a second fixed point function) and Coq still complains.

Consider the following formalization of regular expressions.

Inductive symbol : Set := Zero | One.

Definition string := list symbol.

Fixpoint symbol_eq (a:symbol) (b:symbol) : bool :=
  match a with
    Zero =&gt;
    match b with
      Zero =&gt; true
    | One =&gt; false
    end
  | One =&gt;
    match b with
      Zero =&gt; false
    | One =&gt; true
    end
  end.


Inductive regexp : Set :=
    Symbol (s:symbol)
  | Concat (r1:regexp) (r2:regexp)
  | Union (u1:regexp) (u2:regexp)
  | Star (u1:regexp)
  .

Fixpoint rgm (r:regexp) (s:string) :=
  match r with
    Symbol ss =&gt;
      match s with
        nil =&gt; false
      | a::nil =&gt; (symbol_eq ss a)
      | a::b::tl =&gt; false
      end
   | Union r1 r2 =&gt; (orb (rgm r1 s) (rgm r2 s))
   | Concat r1 r2 =&gt;
       let fix f s1 s2 :=
         match s2 with
           nil =&gt; (andb (rgm r1 (rev s1)) (rgm r2 s2))
         | a::tl =&gt; (orb (andb (rgm r1 (rev s1)) (rgm r2 s2))
                         (f (a::s1) tl))
         end
       in (f nil s)
   | Star r1 =&gt;
       match s with
         nil =&gt; true
       | a::tl =&gt;
         let fix f s1 s2 :=
           match s2 with
             nil =&gt; (rgm r1 (rev s1))
           | a::tl =&gt; (orb (andb (rgm r1 (rev s1)) (rgm r s2))
                           (f (a::s1) tl))
           end
         in (f (a::nil) tl)
       end
  end.


Coq refuses to compile it for the following reason:

Error: Cannot guess decreasing argument of fix.


Question: how can we fix this?
As stated in Coq Reference Manual (2.3)


  in Fixpoint, the decreasing argument must be given (unless the
  function is not recursive), but it must not necessary be structurally
  decreasing.


Key word is structurally, Coq can't guess, which arguments is decreasing at each step of the recursion.

The reason for this is nicely described in Software Foundations


  Since Coq is not just a functional programming language, but also a
  consistent logic, any potentially non-terminating function needs to be
  rejected. Here is an (invalid!) Coq program showing what would go
  wrong if Coq allowed non-terminating recursive functions:

 Fixpoint loop_false (n : nat) : False := loop_false n. 

  
  That is, propositions like False would become provable (e.g. loop_false 0 would
  be a proof of False), which would be a disaster for Coq's logical
  consistency.