我读到一个类型的归纳原理只是一个关于命题P
的定理。所以我基于右(或反向)列表构造函数为List
构造了一个归纳原理。
Definition rcons {X:Type} (l:list X) (x:X) : list X :=
l ++ x::nil.
归纳原则本身是:
Definition true_for_nil {X:Type}(P:list X -> Prop) : Prop :=
P nil.
Definition true_for_list {X:Type} (P:list X -> Prop) : Prop :=
forall xs, P xs.
Definition preserved_by_rcons {X:Type} (P: list X -> Prop): Prop :=
forall xs' x, P xs' -> P (rcons xs' x).
Theorem list_ind_rcons:
forall {X:Type} (P:list X -> Prop),
true_for_nil P ->
preserved_by_rcons P ->
true_for_list P.
Proof. Admitted.
但是现在,我在使用这个定理时遇到了麻烦。我不知道如何调用它来达到与induction
策略相同的效果。
例如,我尝试过:
Theorem rev_app_dist: forall {X} (l1 l2:list X), rev (l1 ++ l2) = rev l2 ++ rev l1.
Proof. intros X l1 l2.
induction l2 using list_ind_rcons.
但在最后一行,我得到了:
Error: Cannot recognize an induction scheme.
定义和应用list_ind_rcons
等自定义归纳原则的正确步骤是什么?
由于
答案 0 :(得分:4)
你所做的大部分都是正确的。问题是,由于中间定义,Coq很难认识到你所写的是归纳原理。例如,这可以正常工作:
Theorem list_ind_rcons:
forall {X:Type} (P:list X -> Prop),
P nil ->
(forall x l, P l -> P (rcons l x)) ->
forall l, P l.
Proof. Admitted.
Theorem rev_app_dist: forall {X} (l1 l2:list X), rev (l1 ++ l2) = rev l2 ++ rev l1.
Proof. intros X l1 l2.
induction l2 using @list_ind_rcons.
我不知道Coq是否能够自动展开中间定义应该被认为是错误,但至少有一个解决方法。
答案 1 :(得分:1)
如果想要保留中间定义,那么可以使用 DT <- dbReadTable(my_db, "hist")
ui <- fluidPage(
sidebarPanel(
numericInput("num", label = h3("select to see age increase above ", inputId = 'Value', min = 0),),
mainPanel(
dataTableOutput('Filter')),
)
)
server <- function(input, output,session){
output$Filter <- renderDataTable(
datatable(
DT %>% filter(( <= )), ### need help here
caption = 'Growth of Age Greater then User Input',
selection="single", escape=FALSE,
options = list(
lengthMenu = list(c(5, 15, -1), c('5', '15', 'All')),
pageLength = 10,
#remove the search bar in the list
sDom = '<"top">lrt<"bottom">ip'
)
),
server = TRUE
)
}
shinyApp( ui = ui, server = server)
机制,如下所示:
Section
Coq替换定义,Require Import Coq.Lists.List. Import ListNotations.
Definition rcons {X:Type} (l:list X) (x:X) : list X :=
l ++ [x].
Section custom_induction_principle.
Variable X : Type.
Variable P : list X -> Prop.
Hypothesis true_for_nil : P nil.
Hypothesis true_for_list : forall xs, P xs.
Hypothesis preserved_by_rcons : forall xs' x, P xs' -> P (rcons xs' x).
Fixpoint list_ind_rcons (xs : list X) : P xs. Admitted.
End custom_induction_principle.
具有所需类型,list_ind_rcons
有效:
induction ... using ...
顺便说一句,这种归纳原理存在于标准库(List
模块)中:
Theorem rev_app_dist: forall {X} (l1 l2:list X),
rev (l1 ++ l2) = rev l2 ++ rev l1.
Proof. intros X l1 l2.
induction l2 using list_ind_rcons.
Abort.