Search code examples
coqssreflect

how to simplify basic arithmetic in more complex goals


Here's a minimal example of my problem

Lemma arith: forall T (G: seq T), (size G + 1 + 1).+1 = (size G + 3).

I would like to be able to reduce this to forall T (G: seq T), (size G + 2).+1 = (size G + 3).

by the simplest possible means. Trying simpl or auto immediately does nothing.

If I rewrite with associativity first, that is,

intros. rewrite - addnA. simpl. auto.,

simpl and auto still do nothing. I am left with a goal of

(size G + (1 + 1)).+1 = size G + 3

I guess the .+1 is "in the way" of simpl and auto working on the (1+1) somehow. It seems like I must first remove the .+1 before I can simplify the 1+1.

However, in my actual proof, there is a lot more stuff than the .+1 "in the way" and I would really like to simplify my copious amount of +1s first. As a hack, I'm using 'replace' on individual occurrences but this feels very clumsy (and there are a lot of different arithmetic expressions to replace). Is there any better way to do this?

I am using the ssrnat library.

Thanks.


Solution

  • Coq has a ring and ring_simplify tactic for this kind of work. Sorry for my ssreflect ignorant intros, but this works:

    From mathcomp Require Import all_ssreflect.
    
    Lemma arith: forall T (G: seq T), (size G + 1 + 1).+1 = (size G + 3).
    Proof.
      intros.
      ring.
    Qed.
    

    There is also a field and field_simplify. For inequalities there are lia and lra, but I am not sure if these work in mathcomp - for lia you might need this (https://github.com/math-comp/mczify) but it might be integrated meanwhile.