Coq中的递归函数
我想写一个函数Coq中的递归函数,coq,Coq,我想写一个函数 Inductive my_type := | Type_pol : Z -> my_type | Type_matrix : Z -> my_type. Inductive redPair := | RedPair_interpretation : my_type -> redPair. Inductive orderingProof := | OrderingProof_redPair : redPair -> orderingProof.
Inductive my_type :=
| Type_pol : Z -> my_type
| Type_matrix : Z -> my_type.
Inductive redPair :=
| RedPair_interpretation : my_type -> redPair.
Inductive orderingProof :=
| OrderingProof_redPair : redPair -> orderingProof.
Inductive trsTerminationProof :=
| TrsTerminationProof_ruleRemoval :
orderingProof -> trsTerminationProof -> trsTerminationProof.
我想编写一个函数return\u trsTermProof
,该函数不仅在参数d
的情况下有效,而且在有t:trsTerminationProof
的情况下也有效
Definition return_mytype (t : my_type) : option nat :=
match t with
| Type_pol _ => None
| Type_matrix i => Some (Z.to_nat i)
end.
Definition return_redPair (r : redPair ) : option nat :=
match r with
| RedPair_interpretation mty => return_mytype mty
end.
Definition return_orderProof (d : orderingProof) : option nat :=
match d with
| OrderingProof_redPair r => return_redPair r
end.
Definition return_trsTermProof (t : trsTerminationProof) : option nat :=
match t with
| TrsTerminationProof_ruleRemoval d _t => return_orderProof d
end.
如果
return\u orderProof d
返回none
,您的意思是要返回return\u trsTermProof t
Fixpoint return_trsTermProof (t : trsTerminationProof) : option nat :=
match t with
| TrsTerminationProof_ruleRemoval d t =>
(* I don't know how can I take the function (return_orderProof d) *) ...
return_trsTermProof t
end.
如果您的归纳集没有更多的构造函数,您也可以这样定义它:
Fixpoint return_trsTermProof (t : trsTerminationProof) : option nat :=
match t with
| TrsTerminationProof_ruleRemoval d t_ =>
match return_orderProof d with
| None => return_trsTermProof t_
| Some n => Some n
end
end.
我有一个例子,当有'Some n'返回'Some n',然后继续使用参数't:trsTerminationProof'。我如何分析这个例子?
Fixpoint return_trsTermProof (t : trsTerminationProof) : option nat :=
match t with
| TrsTerminationProof_ruleRemoval (OrderingProof_redPair (RedPair_interpretation (Type_pol z))) t_ => return_trsTermProof t_
| TrsTerminationProof_ruleRemoval (OrderingProof_redPair (RedPair_interpretation (Type_matrix z))) t_ => Some (Z.to_nat z)
end.