前往小程序,Get更优阅读体验!
立即前往
首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >「SF-LC」1 Basics

「SF-LC」1 Basics

作者头像
零式的天空
发布于 2022-03-14 06:35:27
发布于 2022-03-14 06:35:27
40600
代码可运行
举报
文章被收录于专栏:零域Blog零域Blog
运行总次数:0
代码可运行

These series of notes combined

  • My notes on reading Software Foundation and (if any) watching on Coq intensive.
  • Gotchas from my independent studies and discussion within Prof.Fluet‘s class.

The .v code is a gorgeous example of literal programming and the compiled .html website is full-fledged. So this note is intended to be NOT self-contained and only focus on things I found essential or interesting. This note is intended to be very personal and potentially mix English with Chinese (You can Lol) So yeah. Don’t expect it to be well organized and well written. I posted it on blog mainly for my own references purpose. The quotes could either come from the book or saying from someone (even including me).

Data and Functions

Custom Notation

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Notation "x && y" := (andb x y).
Notation "x || y" := (orb x y).

can go pretty far with unicode char…

making things infix

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Notation "x + y" := (plus x y)
                      (at level 50, left associativity)
                      : nat_scope.
Notation "x - y" := (minus x y)
                      (at level 50, left associativity)
                      : nat_scope.
Notation "x * y" := (mult x y)
                      (at level 40, left associativity)
                      : nat_scope.

why 40 50? Making sure there are still rooms for priority in between…

no known PL using real number for priority though

Data Constructor with arguments

there are 2 ways to define them:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Inductive color : Type :=
  | black
  | white
  | primary (p : rgb).      (* ADT, need to name arg, useful in proof *)
  | primary : rgb -> color. (* GADT style, dependent type *)

Syntax for arguments having the same type

As a notational convenience, if two or more arguments have the same type, they can be written together

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Inductive nybble : Type :=
  | bits (b0 b1 b2 b3 : bit).
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Fixpoint mult (n m : nat)         : nat := 
Fixpoint plus (n : nat) (m : nat) : nat := 

Fixpoint and Structrual Recursion

This requirement is a fundamental feature of Coq’s design: In particular, it guarantees that every function that can be defined in Coq will terminate on all inputs.

However, Coq’s “decreasing analysis” is not very sophisticated. E.g.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Fixpoint evenb (n:nat) : bool :=
  match n with
  | O        => true
  | S O      => false
  | n        => evenb (pred (pred n))
  end.

will result in a error that basically complains “this structure is not shrinking”.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Error:
Recursive definition of evenb is ill-formed.

evenb : nat -> bool
n : nat
n0 : nat
n1 : nat

Recursive call to evenb has principal argument equal to
"Nat.pred (Nat.pred n)" instead of one of the following variables: "n0" "n1".

Recursive definition is:
"fun n : nat =>
 match n with
 | 0 => true
 | 1 => false
 | S (S _) => evenb (Nat.pred (Nat.pred n))
 end".

N.B. the n0 and n1 are sub-terms of n where n = S (S _).

So we have to make the sub-structure explicit to indicate the structure is obviously shrinking:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Fixpoint evenb (n:nat) : bool :=
  match n with
  | O        => true
  | S O      => false
  | S (S n') => evenb n'
  end.

Now Coq will know this Fixpoint is performing a structural recursion over the 1st recursion and it guarantees to be terminated since the structure is decreasing:

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
evenb is defined
evenb is recursively defined (decreasing on 1st argument)

Proof by Case Analysis

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
Theorem plus_1_neq_0_firsttry : ∀n : nat,
  (n + 1) =? 0 = false.
Proof.
  intros n.
  simpl. (* does nothing! *)
Abort.

simpl. does nothing since both + and =? have 2 cases.

so we have to destruct n as 2 cases: nullary O and unary S n'.

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
intros n. destruct n as [ (* O *) | (* S *) n'] eqn:E.
  • the intro pattern as [ |n'] name new bindings.
  • eqn:E annonate the destructed eqn (equation?) as E in the premises of proofs. It could be elided if not explicitly used, but useful to keep for the sake of documentation as well.
代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
subgoal 1

  n : nat
  E : n = 0                          (* case 1, n is [O] a.k.a. [0] *)
  ============================
  (0 + 1 =? 0) = false


subgoal 2

  n, n' : nat
  E : n = S n'                       (* case 2, n is [S n'] *)
  ============================
  (S n' + 1 =? 0) = false

If there is no need to specify any names, we could omit as clause or simply write as [|] or as []. In fact. Any as clause could be ommited and Coq will fill in random var name auto-magically.

A small caveat on intro

代码语言:javascript
代码运行次数:0
运行
AI代码解释
复制
intros x y. destruct y as [ | y ] eqn:E.

By doing this, name y is shadowed. It’d usually better to use, say y' for this purpose.

Qed

standing for Latin words “Quod Erat Demonstrandum”…meaning “that which was to be demonstrated”.

本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2021-03-28,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
暂无评论
推荐阅读
自动化篇 - 黑客们使用的自动化方案,很多人还不知道
聊到 App 端的自动化,大家能想到的可能是 Appium、UIAutomator2、Airtest 等一系列自动化框架。
吴延宝
2019/08/28
2.4K0
自动化篇 - 黑客们使用的自动化方案,很多人还不知道
利用无障碍服务(AccessibilityService)批量清理后台进程
Demo地址:https://github.com/qyxxjd/ClearProcesses
续写经典
2018/08/28
1.9K0
利用无障碍服务(AccessibilityService)批量清理后台进程
提高Android自动化测试稳定性的方法(三)
在之前的一篇文章《移动端UI自动化过程中的难点及应对策略》中,我们提到在Android自动化测试执行过程中经常会遇到一些非预期的系统弹框,我们可以通过无障碍服务来实现智能点击处理,但是通常这个服务只能手动到设置中开启,今天就跟大家分享一下如何实现一个自定义的无障碍服务以及如何自动化的开启它。
岛哥的质量效能笔记
2021/08/18
5770
提高Android自动化测试稳定性的方法(三)
妙用AccessibilityService黑科技实现微信自动加好友拉人进群聊[通俗易懂]
在上上周的周六和周日,我发了两篇利用itchat实现微信机器人的文章(Python):
全栈程序员站长
2022/09/05
3.3K0
Android辅助功能原理与基本使用详解-AccessibilityService
本文主要介绍了如何通过AccessibilityService在Android上实现类似iOS的辅助功能,包括屏幕阅读器、放大镜、文本提取、快速拨号、屏幕录制、悬浮窗口、手势识别等功能。同时,还介绍了如何自定义AccessibilityService提供个性化的辅助功能,并分享了部分实现代码和示例。
用户1155943
2018/01/04
7.1K0
Android辅助功能原理与基本使用详解-AccessibilityService
Android:AccessibilityService辅助功能基础使用(附微信抢红包教程)
辅助功能(AccessibilityService)是一个Android系统提供的一种服务,继承自Service类。AccessibilityService运行在后台,能够监听系统发出的一些事件(AccessibilityEvent),这些事件主要是UI界面一系列的状态变化,比如按钮点击、输入框内容变化、焦点变化等等,查找当前窗口的元素并能够模拟点击等事件。官方文档
Android技术干货分享
2019/08/12
6.4K0
微信小游戏 跳一跳 Android 插件分析开发测试 adb 命令
screenshot 源码:https://github.com/iOSDevLog/Jump 现在跳得准了。 测试:https://github.com/iOSDevLog/Jump/release
iOSDevLog
2018/05/17
9970
Android静默安装实现方案,仿360手机助手秒装和智能安装功能
用户1158055
2018/01/08
3.3K0
Android静默安装实现方案,仿360手机助手秒装和智能安装功能
免Root实现Apk静默安装,覆盖兼容市场主流的98%的机型
依然来首经典的歌曲,或许歌声里有你的一段往事,也许你会心痛,毕竟你入心了。好,伴随歌声继续鸡汤。
开发者技术前线
2020/11/23
2.4K0
免Root实现Apk静默安装,覆盖兼容市场主流的98%的机型
自动化篇 | 再也不用担心老人们用智能机了
由于智能机操作的复杂性,很多老年人的手机使用一段时间之后,不知不觉间,下载了一大堆垃圾软件,内存占用越来越大,机器越用越卡。
AirPython
2020/03/23
5040
自动化篇 | 再也不用担心老人们用智能机了
自动化篇 | 朋友圈被折叠?会自动化不存在的
如果你经常需要 发朋友圈,无论是哪里复制的文案,直接粘贴后到输入框发送出去,肯定会被官方 折叠 处理,因此,应用市场上出现了很多防折叠输入法 App。
AirPython
2020/03/23
4730
自动化篇 | 朋友圈被折叠?会自动化不存在的
NotificationListenerService的那些事儿
最近在公司时接到一个需求:需要实时监听设备的通知栏消息,并可以捕获到通知的内容,然后进行对应的操作。刚看到这个需求的时候,脑子里第一反应就是使用 AccessibilityService 。 AccessibilityService 支持的事件监听类型中有 TYPE_NOTIFICATION_STATE_CHANGED ,该事件类型就是用来监听通知栏消息状态改变的,众多的抢红包插件利用的就是这个原理。
俞其荣
2022/07/28
1.3K0
NotificationListenerService的那些事儿
【云+社区年度征文】探究 | 如何捕获一个 Activity页面上所有的点击行为
既然我要捕获点击事件,首先就想到的是通过事件分发机制,也就是在源头就去获取所有的触摸事件,然后对点击事件进行统计,干吧~
码上积木
2020/12/03
1.1K0
001. 顶部 Activity / TopActivity [android]
第一个应用是 Android 的取最顶部 Activity。 源码:https://github.com/iOSDevLog/1day1app 001.TopActivity.png 分析一下需求。
iOSDevLog
2018/05/17
1K0
为了保护小姐姐的眼睛,我用自动化做了一款语音机器人
最近一位小姐姐在微信上向我抱怨,说自己每天坐地铁上下班,路上会阅读一些好的文章来提升自己。
AirPython
2020/05/26
7910
为了保护小姐姐的眼睛,我用自动化做了一款语音机器人
UIAutomator2.0和AccessibilityService实现分析
UiAutomator是Android 4.1以上提供的一个UI自动化测试工具,4.3升级到了UiAutomator2.0,实现方式也从UiTestAutomationBridge变成了UiAutomation。
drunkdream
2020/01/02
3.9K4
Android Accessibility 安全性研究报告
第一章Accessibility简介 近期,360烽火实验室发现一款滥用Accessibility的木马,该木马具有浏览器地址栏劫持、搜索劫持、桌面点击劫持以及防卸载等系列恶意行为,本报告将结合我们对该木马的分析,从Accessbility的设计初衷、技术发展、滥用情况等角度研究Accessibility的安全性。 一、 设计意义 依据Android官方文档,考虑到一些用户不能很好地使用Android设备,比如由于视力、身体、年龄方面的限制,造成阅读内容、触控操作、声音信息等方面的获取困难,因此Androi
FB客服
2018/02/08
1.8K0
Android Accessibility 安全性研究报告
AccessibilityService从入门到出轨
前言 任何技术都是一把双刃剑,用的好与好不,都在于使用它的人,一念天堂,一念地狱。 AccessibilityService根据官方的介绍,是指开发者通过增加类似contentDescription的属性,从而在不修改代码的情况下,让残障人士能够获得使用体验的优化,大家可以打开AccessibilityService来试一下,点击区域,可以有语音或者触摸的提示,帮助残障人士使用App。 当然,现在AccessibilityService已经基本偏离了它设计的初衷,至少在国内是这样,越来越多的
用户1907613
2018/07/20
1.8K0
推荐阅读
相关推荐
自动化篇 - 黑客们使用的自动化方案,很多人还不知道
更多 >
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档