Library Coq.omega.PreOmega
zify: the Z-ification tactic
I) translation of Z.max, Z.min, Z.abs, Z.sgn into recognized equations
Ltac zify_unop_core t thm a :=
pose proof (
thm a);
let z :=
fresh "z"
in set (
z:=
t a)
in *;
clearbody z.
Ltac zify_unop_var_or_term t thm a :=
let za :=
fresh "z"
in
(
rename a into za;
rename za into a;
zify_unop_core t thm a) ||
(
remember a as za;
zify_unop_core t thm za).
Ltac zify_unop t thm a :=
let isz :=
isZcst a in
match isz with
|
true =>
let u :=
eval compute in (
t a)
in
change (
t a)
with u in *
|
_ =>
zify_unop_var_or_term t thm a
end.
Ltac zify_unop_nored t thm a :=
let isz :=
isZcst a in
match isz with
|
true =>
zify_unop_core t thm a
|
_ =>
zify_unop_var_or_term t thm a
end.
Ltac zify_binop t thm a b:=
let isza :=
isZcst a in
match isza with
|
true =>
zify_unop (
t a) (
thm a)
b
|
_ =>
let za :=
fresh "z"
in
(
rename a into za;
rename za into a;
zify_unop_nored (
t a) (
thm a)
b) ||
(
remember a as za;
match goal with
|
H :
za = b |-
_ =>
zify_unop_nored (
t za) (
thm za)
za
|
_ =>
zify_unop_nored (
t za) (
thm za)
b
end)
end.
Ltac zify_op_1 :=
match goal with
| |-
context [
Z.max ?
a ?
b ] =>
zify_binop Z.max Z.max_spec a b
|
H :
context [
Z.max ?
a ?
b ] |-
_ =>
zify_binop Z.max Z.max_spec a b
| |-
context [
Z.min ?
a ?
b ] =>
zify_binop Z.min Z.min_spec a b
|
H :
context [
Z.min ?
a ?
b ] |-
_ =>
zify_binop Z.min Z.min_spec a b
| |-
context [
Z.sgn ?
a ] =>
zify_unop Z.sgn Z.sgn_spec a
|
H :
context [
Z.sgn ?
a ] |-
_ =>
zify_unop Z.sgn Z.sgn_spec a
| |-
context [
Z.abs ?
a ] =>
zify_unop Z.abs Z.abs_spec a
|
H :
context [
Z.abs ?
a ] |-
_ =>
zify_unop Z.abs Z.abs_spec a
end.
Ltac zify_op :=
repeat zify_op_1.
II) Conversion from nat to Z
The complete Z-ification tactic
Ltac zify := repeat (zify_nat; zify_positive; zify_N); zify_op.