Isabelle 为什么我的simproc没有按规定的模式激活?

Isabelle 为什么我的simproc没有按规定的模式激活?,isabelle,Isabelle,我正在为正弦简化编写simproc。下面是将sin(x+8pi+pi/2)重写为cos(x)的示例: 到目前为止,一切正常,但一旦我设置了simproc: simproc_setup sine1 ("sin (x + 8 * pi + pi / 2)") = ‹K rewrite_sine› (* this should be handled by sine1 only, but is not *) lemma "sin (x + 8 * pi + pi / 2) = cos(x)" ap

我正在为正弦简化编写simproc。下面是将sin(x+8pi+pi/2)重写为cos(x)的示例:

到目前为止,一切正常,但一旦我设置了simproc:

simproc_setup sine1 ("sin (x + 8 * pi + pi / 2)") = ‹K rewrite_sine›

(* this should be handled by sine1 only, but is not *)
lemma "sin (x + 8 * pi + pi / 2) = cos(x)"
  apply simp
  sorry

(* this should be handled by sine1 only, but is not *)
lemma "sin(x+8*pi+pi/2) = cos(x)"
  apply(tactic ‹simp_tac (put_simpset HOL_basic_ss @{context} addsimprocs [@{simproc sine1}]) 1›)
  sorry

我发现,即使使用基本的simpset,它也不是真正适用的。在第一个示例中,您的simproc没有被调用,因为simproc(如果我没记错的话)只有在用尽所有“正常”重写之后才被调用,并且您的目标立即被重写为
sin(17*pi/2+x)=cos x
。因为您的simproc不再符合该目标,所以不会调用它

在第二个示例中,调用了simproc(您可以通过在
let
块中插入例如
val_=@{print}“foo”
来验证这一点),并且它确实生成了重写规则。不幸的是,这个重写规则仍然有前提条件
8≡ 2*real\u of_int 4
,这是使用非常基本的简化设置无法解决的问题,因此无法应用规则

您可以使用simplifier跟踪来了解那里发生了什么:

lemma "sin(x+8*pi+pi/2) = cos(x)"
  using [[simp_trace, simp_trace_depth_limit = 100]]
  apply(tactic ‹simp_tac (put_simpset HOL_basic_ss @{context} addsimprocs [@{simproc sine1}]) 1›)
输出:

[0]Adding simplification procedure "Scratch.sine1" for
sin (?x + 8 * pi + pi / 2) 
[0]Adding simplification procedure "Scratch.sine1" for
sin (?x + 8 * pi + pi / 2) 
[1]SIMPLIFIER INVOKED ON THE FOLLOWING TERM:
sin (x + 8 * pi + pi / 2) = cos x 
[1]Procedure "Scratch.sine1" produced rewrite rule:
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[1]Applying instance of rewrite rule
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[1]Trying to rewrite:
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[2]SIMPLIFIER INVOKED ON THE FOLLOWING TERM:
8 ≡ 2 * real_of_int 4 
[1]FAILED
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[1]IGNORED result of simproc "Scratch.sine1" -- does not match
sin (x + 8 * pi + pi / 2)
如果添加规则
2*real\u/int 4≡ 8
对于您的simpset,它可以按预期工作

[0]Adding simplification procedure "Scratch.sine1" for
sin (?x + 8 * pi + pi / 2) 
[0]Adding simplification procedure "Scratch.sine1" for
sin (?x + 8 * pi + pi / 2) 
[1]SIMPLIFIER INVOKED ON THE FOLLOWING TERM:
sin (x + 8 * pi + pi / 2) = cos x 
[1]Procedure "Scratch.sine1" produced rewrite rule:
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[1]Applying instance of rewrite rule
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[1]Trying to rewrite:
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[2]SIMPLIFIER INVOKED ON THE FOLLOWING TERM:
8 ≡ 2 * real_of_int 4 
[1]FAILED
8 ≡ 2 * real_of_int 4 ⟹
sin (x + 8 * pi + pi / 2) ≡ cos x 
[1]IGNORED result of simproc "Scratch.sine1" -- does not match
sin (x + 8 * pi + pi / 2)