The short answer
The default way is to use abbreviation
. This introduces a purely syntactical abbreviation that will be expanded during parsing. If the a
and b
in your case are fixed terms like 1+2
and 3+4
, you can simply do this:
abbreviation "X ≡ (1 + 2) + (3 + 4)"
and then write X + c
, X - c
, X - e - a
. Note also that abbreviations are folded back before printing, i.e. (1 + 2) + (3 + 4) + 5
will be printed as X + 5
. If you don't want this, you can use abbreviation (input)
instead.
Also note that 5 + (1 + 2) + (3 + 4)
will not be printed as 5 + X
and is not syntactically the same as 5 + X
because addition associates to the left: 5 + (1 + 2) + (3 + 4)
is (5 + (1 + 2)) + (3 + 4)
, whereas 5 + X
is 5 + ((1 + 2) + (3 + 4))
.
You can also use definition
; this introduces a new constant called X
. You can unfold the definition using the theorem X_def
. But from your question, I gather that you don't want that.
What about variables?
It is not entirely clear from your question, but I guess your situation is something like this:
lemma foo: "P (a + b + c)"
(* some proof *)
lemma bar: "P (a + b - c)"
(* some proof *)
In that case, you cannot use an abbreviation as above, since a
and b
are variables and you cannot have free variables on the right-hand side of an abbreviation (or a definition). You can, however, locally fix the variables in an anonymous context:
context
fixes a b :: "'a :: ring_1" (* change this type if necessary *)
begin
abbreviation "X ≡ a + b"
lemma foo: "P (X + 3)"
(* some proof *)
lemma bar: "P (X - 3)"
(* some proof *)
end
The lemmas foo
and bar
are then exported with the fixed free variables a
and b
generalised to schematic variables in the usual fashion. However, thm foo
will be printed as ?P (X (X ?a ?b) 3)
, which is a bit strange, and, in fact, any occurrence of +
will be printed that way, so doing abbreviation (input)
is a good idea in any case.
A note on hygiene
Polluting the global namespace with a name as general as this is typically considered bad style. An alternative using a local definition would be this:
context
fixes a b :: "'a :: ring_1"
fixes X defines X_def[simp]: "X ≡ a + b"
begin
lemma foo: "P (X + 3)"
sorry
lemma bar: "P (X - 3)"
sorry
end
Here, X
is not merely a syntactical abbreviation, but a new constant whose definition must be unfolded. However, by declaring the definition a simp
rule, this unfolding will be done automatically. It will, however, not be re-folded automatically, so you will never see X
in the output after using the simplifier on it.
Upon exiting the context, the definition will be unfolded everywhere and disappears, giving you the lemmas you want.