DeathKing / Learning-SICP

MIT视频公开课《计算机程序的构造和解释》中文化项目及课程学习资料搜集。
https://learningsicp.github.io
10.95k stars 1.54k forks source link

《Lec4b:通用运算符》课程答疑 #103

Closed asukaminato0721 closed 2 years ago

asukaminato0721 commented 4 years ago

不是问题。

见到这个 http://www.eigenmath.org/eigenmath.c

C 实现的 CAS

编译得到的 exe 我放下面了。

eigenmath.zip

在源代码里面有

// MAXBLOCKS * BLOCKSIZE * sizeof (struct atom) = 600,000,000 bytes

// Symbolic expressions are built by linking structs of type "atom".
//
// For example, the expression "a b + c" is built like this:
//
//  _______      _______                                _______      _______
// |CONS   |    |CONS   |                              |CONS   |    |SYM    |
// |car cdr|--->|car cdr|----------------------------->|car cdr|--->|"nil"  |
// |_|_____|    |_|_____|                              |_|_____|    |_______|
//   |            |                                      |
//   |            |                                     _v_____
//   |            |                                    |SYM    |
//   |            |                                    |"c"    |
//   |            |                                    |_______|
//   |            |
//  _v_____      _v_____      _______      _______      _______
// |SYM    |    |CONS   |    |CONS   |    |CONS   |    |SYM    |
// |"add"  |    |car cdr|--->|car cdr|--->|car cdr|--->|"nil"  |
// |_______|    |_|_____|    |_|_____|    |_|_____|    |_______|
//                |            |            |
//               _v_____      _v_____      _v_____
//              |SYM    |    |SYM    |    |SYM    |
//              |"mul"  |    |"a"    |    |"b"    |
//              |_______|    |_______|    |_______|

所以这个系统实际上是用了视频里构建 CAS 的理论?算是意外收获😂。

至少能从高观点来看这个作品了,不指望能看懂。

DeathKing commented 4 years ago

Lisp 最早就是用来做符号演算的,推荐可以看下 Maxima(http://maxima.sourceforge.net/),前身是 Macsyma。

无论是何种CAS系统,都需要对表达式做 Parse 形成 AST。只是说使用 Lisp 中的S-表达式最为方便而已。