How to forbid simpl tactic to unfold arithmetic expressions?

前端 未结 2 1710
灰色年华
灰色年华 2021-01-12 03:16

The simpl tactic unfolds expressions like 2 + a to \"match trees\" which doesn\'t seem simple at all. For example:



        
相关标签:
2条回答
  • 2021-01-12 03:46

    You can tweak how the simpl tactic behaves so you get less matches.

    Require Import Coq.ZArith.ZArith.
    
    Goal forall i:Z, ((fun x => (x + i)%Z) 3%Z = (i + 3)%Z).
    Arguments Z.add x y : simpl nomatch.
    simpl.
    

    Read more about it here.

    Otherwise you can use other tactics that allow you to choose how to reduce. cbn beta, for example.

    0 讨论(0)
  • 2021-01-12 04:11

    You can control definition unfolding with the Transparent and Opaque commands. In your example, you should be able to say something like

    Opaque Z.add.
    simpl.
    Transparent Z.add.
    

    Alternatively, the Arguments command can be used to instruct the simpl tactic to avoid simplifying terms in certain contexts. E.g.

    Arguments Z.add _ _ : simpl nomatch.
    

    does the trick for me in your case. What this particular variant does is to avoid simplifying a term when a big, ugly match would appear in head position after doing so (what you saw in your example). There are other variants too, however.

    Finally, just for completeness, the Ssreflect library provides nice infrastructure for making certain definitions opaque locally. So you could say something like

    rewrite (lock Z.add) /= -lock.
    

    meaning "lock Z.add, so that it won't simplify, then simplify the remaining of the expression (the /= switch), then unlock the definition again (-lock)".

    0 讨论(0)
提交回复
热议问题