Mingjian's Blog

You are just a hardcore character of the life game. Keep upgrading and don't die.

0%

由于一个工作需要把大量的vbscript脚本转换成python脚本, 需要学习一下python的ast模块, 本文是一些干货的笔记. 由于当前最新的python 3.8的官方文档过于简略, 主要参考和翻译绿树蛇的文档和python3.10pre的文档.

AST是Abstract Syntax Trees的缩写, 中文是抽象语法树.

AST和code的转换

python代码有三个分身,

  1. 以unicode字符串存在的源代码. 人类可读写, python解释器不可读.
  2. 以AST对象存在的抽象语法树. 人类可读写, 但很难读懂原来的语义, 用来显示python语义元素之间的关系. 是从源代码翻译成目标代码的中间产品.
  3. 以code object存在的可执行的目标代码. python解释器可读, 人类不可读.
阅读全文 »

\(\def\tauequ{\mathbin{\vDash\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\Dashv{\mathbin{\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\DEF{\sf{D\scriptsize EF}.\quad}\) \(\def\DEFi{\sf{D\scriptsize EF}^*.\quad}\) \(\def\DEFn{\sf{D\scriptsize EF}_*.\quad}\) \(\def\DEFin{\sf{D\scriptsize EF}^*_*.\quad}\) \(\def\llbracket{\unicode{x27E6}}\) \(\def\rrbracket{\unicode{x27E7}}\) \(\def\PROOF{\sf{P\scriptsize ROOF}.\quad}\)

点击这里进入AMIL目录

Problem 1

Show that (a) \(\Gamma;\alpha\vDash\varphi\) iff \(\Gamma\vDash(\alpha\rightarrow\varphi)\); and (b) \(\varphi\tauequ\psi\) iff \(\vDash(\varphi\leftrightarrow\psi)\).

\(\PROOF\)

阅读全文 »

\(\def\PROOF{\sf{P\scriptsize ROOF}.\quad}\)

点击这里进入AMIL目录

Problem 2

Show that no one of the following sentences is logically implied by the other two. (This is done by giving a structure in which the sentence in question is false, while the other two are true.)

  1. \(\forall{x}\forall{y}\forall{z}(Pxy\rightarrow Pyz\rightarrow Pxz).\) Recall that by our convention \(\alpha\rightarrow\beta\rightarrow\gamma\) is \(\alpha\rightarrow(\beta\rightarrow\gamma).\)
  2. \(\forall{x}\forall{y}(Pxy\rightarrow Pyx\rightarrow x=y).\)
  3. \(\forall{x}\exists{y}Pxy\rightarrow\exists{y}\forall{x}Pxy.\)
阅读全文 »

\(\def\tauequ{\mathbin{\vDash\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\Dashv{\mathbin{\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\DEF{\sf{D\scriptsize EF}.\quad}\) \(\def\DEFi{\sf{D\scriptsize EF}^*.\quad}\) \(\def\DEFn{\sf{D\scriptsize EF}_*.\quad}\) \(\def\DEFin{\sf{D\scriptsize EF}^*_*.\quad}\) \(\def\llbracket{\unicode{x27E6}}\) \(\def\rrbracket{\unicode{x27E7}}\) \(\def\PROOF{\sf{P\scriptsize ROOF}.\quad}\)

这是一个关于数理逻辑的读书笔记或者学习总结, 书名是A Mathematical Introduction to Logic, 作者Herbert B. Enderton, University of California

本文是Chapter 2, Section 2.2, 点击这里进入AMIL目录

阅读全文 »

\(\def\tauequ{\mathbin{\vDash\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\Dashv{\mathbin{\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\DEF{\sf{D\scriptsize EF}.\quad}\) \(\def\DEFi{\sf{D\scriptsize EF}^*.\quad}\) \(\def\DEFn{\sf{D\scriptsize EF}_*.\quad}\) \(\def\DEFin{\sf{D\scriptsize EF}^*_*.\quad}\) \(\def\llbracket{\unicode{x27E6}}\) \(\def\rrbracket{\unicode{x27E7}}\) \(\def\PROOF{\sf{P\scriptsize ROOF}.\quad}\)

这是一个关于数理逻辑的读书笔记或者学习总结, 书名是A Mathematical Introduction to Logic, 作者Herbert B. Enderton, University of California

本文是Chapter 2, Section 2.1 点击这里进入AMIL目录

阅读全文 »

\(\def\tauequ{\mathbin{\vDash\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\Dashv{\mathbin{\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\DEF{\sf{D\scriptsize EF}.\quad}\) \(\def\DEFi{\sf{D\scriptsize EF}^*.\quad}\) \(\def\DEFn{\sf{D\scriptsize EF}_*.\quad}\) \(\def\DEFin{\sf{D\scriptsize EF}^*_*.\quad}\)

这是一个关于数理逻辑的读书笔记或者学习总结, 书名是A Mathematical Introduction to Logic, 作者Herbert B. Enderton, University of California

本文是Chapter 1, Section 1.7, 点击这里进入AMIL目录

阅读全文 »

\(\def\tauequ{\mathbin{\vDash\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\Dashv{\mathbin{\style{display: inline-block; transform: scaleX(-1)}{\vDash}}}\) \(\def\DEF{\sf{D\scriptsize EF}.\quad}\) \(\def\DEFi{\sf{D\scriptsize EF}^*.\quad}\) \(\def\DEFn{\sf{D\scriptsize EF}_*.\quad}\) \(\def\DEFin{\sf{D\scriptsize EF}^*_*.\quad}\)

这是一个关于数理逻辑的读书笔记或者学习总结, 书名是A Mathematical Introduction to Logic, 作者Herbert B. Enderton, University of California

本文是Chapter 1, Section 1.1, 1.2, 点击这里进入AMIL目录

阅读全文 »