【问题标题】:How can I use type arguments in an ltac?如何在 ltac 中使用类型参数?
【发布时间】:2019-04-01 20:37:33
【问题描述】:

我正在尝试编写以下函数:

Ltac restore_dims :=
  repeat match goal with
  | [ |- context[@Mmult ?m ?n ?o ?A ?B]] => let Matrix m' n' := type of A in 
                                           let Matrix n'' o' := type of B in 
                                           replace m with m' by easy
         end.

也就是说,我想在我的 Ltac 中使用有关 A 和 B 类型的信息(它们都是具有二维参数的矩阵)。这可能吗?如果可以,怎么做?

(理想情况下,这将用m' 替换有问题的m,对于我目标中的所有矩阵产品,no 也是如此。)

【问题讨论】:

    标签: coq coq-tactic


    【解决方案1】:

    您可以对type of A 进行语法匹配以提取参数。

    Ltac restore_dims :=
      repeat match goal with
      | [ |- context[@Mmult ?m ?n ?o ?A ?B]] =>
            match type of A with
            |  Matrix ?m' ?n' => replace m with m' by easy
            end;
            match type of B with
            |  Matrix ?n'' ?o' => replace n with n'' by easy
              (* or whatever you wanted to do with n'' and o' *)
            end
      end.
    

    如果您认为 mm' 将是可转换的,而不仅仅是相等,并且您关心具有良好的证明条件,请考虑使用策略 change 而不是 replace,例如change n'' with n。这不会在证明项中添加任何内容,因此使用起来可能更容易。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-01-01
      • 2017-10-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多