Inside a tactic block, one can use the keyword conv to enter
conversion mode. This mode allows to travel inside assumptions and
goals, even inside function abstractions and dependent arrows, to apply rewriting or
simplifying steps.
As a first example, let us prove example
(abc:Nat):a*(b*c)=a*(c*b)
(examples in this file are somewhat artificial since
other tactics could finish them immediately). The naive
first attempt is to enter tactic mode and try rw[Nat.mul_comm]. But this
transforms the goal into b*c*a=a*(c*b), after commuting the
very first multiplication appearing in the term. There are several
ways to fix this issue, and one way is to use a more precise tool:
the conversion mode. The following code block shows the current target
after each line.
The above snippet shows three navigation commands:
lhs navigates to the left-hand side of a relation (equality, in this case).
There is also a rhs to navigate to the right-hand side.
congr creates as many targets as there are (nondependent and explicit) arguments to the current head function
(here the head function is multiplication).
Once arrived at the relevant target, we can use rw as in normal
tactic mode.
The second main reason to use conversion mode is to rewrite under
binders. Suppose we want to prove example
(funx:Nat=>0+x)=(funx=>x).
The naive first attempt is to enter tactic mode and try
rw[Nat.zero_add]. But this fails with a frustrating
error: tactic 'rewrite' failed, did not find instance of the pattern
in the target expression
0 + ?n
⊢ (fun x => 0 + x) = fun x => x
The solution is:
example:(funx:Nat=>0+x)=(funx=>x):=by⊢ (funx=>0+x)=funx=>xconv=>| (funx=>0+x)=funx=>xlhs| funx=>0+xintroxx:Nat| 0+xrw[Nat.zero_add]x:Nat| x
where introx is the navigation command entering inside the fun binder.
Note that this example is somewhat artificial, one could also do:
enter [1, x, 2, y] iterate arg and intro with the given arguments.
done fail if there are unsolved goals.
trace_state display the current tactic state.
whnf put term in weak head normal form.
tactic => <tactic sequence> go back to regular tactic mode. This
is useful for discharging goals not supported by conv mode, and
applying custom congruence and extensionality lemmas.