cella-lang 0.1.202610301840 → 0.1.202610312349
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGES.md +18 -0
- package/README.md +3 -1
- package/cella-dap.mjs +16 -0
- package/cella-host.d.ts +23 -0
- package/cella_bg.wasm +0 -0
- package/corpus.json +497 -2
- package/modules/algebra.cell +0 -0
- package/modules/array.cell +0 -0
- package/modules/decidable.cell +0 -0
- package/modules/fin.cell +0 -0
- package/modules/function.cell +0 -0
- package/modules/functor.cell +0 -0
- package/modules/index.json +27 -26
- package/modules/int.cell +0 -0
- package/modules/intlinarith.cell +0 -0
- package/modules/intomega.cell +0 -0
- package/modules/intring.cell +0 -0
- package/modules/json.cell +0 -0
- package/modules/linarith.cell +0 -0
- package/modules/linsys.cell +0 -0
- package/modules/list.cell +0 -0
- package/modules/map.cell +0 -0
- package/modules/meta.cell +0 -0
- package/modules/monad.cell +0 -0
- package/modules/omega.cell +0 -0
- package/modules/ord.cell +0 -0
- package/modules/ordering.cell +0 -0
- package/modules/ordering.relations.cell +0 -0
- package/modules/polyrith.cell +0 -0
- package/modules/ring.cell +0 -0
- package/modules/tree.cell +0 -0
- package/modules/vector.cell +0 -0
- package/modules/winding.cell +0 -0
- package/package.json +4 -4
- package/stdlib.cell +0 -0
package/CHANGES.md
CHANGED
|
@@ -8,6 +8,10 @@
|
|
|
8
8
|
- 新匯出 `lsp_message(json) -> json 陣列`:Language Server Protocol 在瀏覽器裡(一則訊息進、要送出的訊息出:回應與 `textDocument/publishDiagnostics`)。和原生的 `cella lsp` 是同一份協定層;先載入標準庫快照與文件 import 的模組包。
|
|
9
9
|
### ⚠️ 不相容
|
|
10
10
|
|
|
11
|
+
- 標準庫的 `Vec` 改成帶索引的歸納型別:`data Vec (A : Type) : Nat -> Type = vnil | vcons`(之前是「串列加長度證明」的配對)。操作都對任意元素型別、回傳 `Vec`:`head`、`tail`(只收非空的向量)、`toList`、`fromList`(長度是 `length xs`)、`map`、`replicate`、`append`(長度相加)、`zipWith`、`foldRight`、`get`(`Fin n` 索引)、`tabulate`;定理 `toListLength`、`mapToList`、`appendToList`、`fromListToList`。拿掉 `Nat` 專用的別名與轉成 `List` 再算的函式(`mapNN`、`replicateNat`、`appendNat`、`sumNat`、`prodNat`、`maxNat`、`any`、`count`、`nth`、`takeList`……):使用處改成 `v.toList` 之後用 `List` 的函式。
|
|
12
|
+
- 標準庫的 `ord` 與 `ordering` 重寫:`Ordering` 的運算進 namespace(`flipOrdering` -> `Ordering.flip`,`appendOrdering`/`thenCompare` -> `Ordering.then`(寫 `a.then b`),`eqOrdering` -> `Ordering.beq`,`isLT`…`isGE` -> `Ordering.isLT`…);各型別的比較 `cmpNat` -> `Nat.threeWay`、`compareNat` -> `Nat.threeWayStructurally`、`compareBool` -> `Bool.threeWay`、`compareString` -> `String.threeWay`(原生加速照舊)、`compareChars` -> `String.threeWayChars`(不叫 `Nat.compare`:`Nat` 與 `Bool` 的 namespace 自動打開,會讓 `Ord` 的方法 `compare` 有歧義);排序 `sort`、`sortOn`、`mergeSortBy`、`nubOrd` -> `List.sort`、`List.sortOn`、`List.sortBy`、`List.distinct`。`ordering` 只留定律(`Ordering.flipFlip`、`Nat.threeWayRefl`…);插入排序 `insertBy`/`sortBy`、`minNat`/`maxNat`/`clampNat`、`comparePairNat` 等拿掉,`Nat.ble`/`Int.ble` 的重複引理拿掉(用 `nat` 的)。比較類別 `LE`、`LessThan`、`CEq`、`DecLE`、`DecLT`、`DecCEq` 與 Nat、Int 的實例搬到新模組 `ordering.relations`(`≤`、`<` 的記號要它)。
|
|
13
|
+
- 標準庫的 `map` 改名:`Map.member` -> `Map.contains`、`Map.findWithDefault` -> `Map.getOr`、`Map.elems` -> `Map.values`、`Map.foldrWithKey` -> `Map.foldRight`;內部的建構子 `mapTip`、`mapBin` -> `mapLeaf`、`mapBranch`。`meta` 的 `evalBool`、`decideBoolProg` -> `Expr.boolValue`、`Expr.decideBool`(tactic `decideBool` 不變)。
|
|
14
|
+
- `@cella-lang/python` 的 `Random.unitAfter` 拿掉,併進 `Random.unit`(`random()` 的結果不變)。
|
|
11
15
|
- `arduino.verdictWith` 拿掉:宿主隨時間給的輸入改放在程式 JSON 裡,與 `"board"` 並列(`"inputs": [{t, key, value}]`),由 `arduino.verdict`、`arduino.types` 與除錯器的 `load` 讀;三個分支的判決入口都是 `verdict src input fuel`。除錯器的 `inputScript()` 給的就是 `"inputs"` 的內容。
|
|
12
16
|
- C 家族的文字照 UTF-8:程式 JSON 的字串字面量、`input` 與除錯時補的輸入是 Unicode 文字,程式看到的是它的 UTF-8 位元組(`"héllo"` 的 `size()` 是 6,和 clang 相同;之前是 5);判決的 `out` 與除錯器的輸出是程式寫出的位元組照 UTF-8 解回的文字,不合法的序列是 U+FFFD。只有 ASCII 的程式不受影響。
|
|
13
17
|
- C 家族改成三個套件各自的入口:`@cella-lang/c`、`@cella-lang/cpp`、`@cella-lang/arduino` 是深嵌入的三個分支(`c.verdict`、`cpp.verdict`、`arduino.verdict`,型別查詢 `*.types`、除錯器的入口各自一組),`@cella-lang/cfamily` 是它們共用的核心、沒有入口。舊的單一入口 `cfamily.verdict`、`cfamily.verdictWith`、`cfamily.types`、`cfamily.boardInfo` 與除錯器的 `cfamily.load`…拿掉:呼叫端照程式的 `lang` 與 `board` 選分支(C 是 `c`,有板子的 C++ 是 `arduino`,其餘 C++ 是 `cpp`)。有板子的判決是 `arduino.verdict src input fuel`(判決的 JSON 多了 `pins` 與 `env`;宿主的輸入放在程式 JSON 的 `"inputs"`)。
|
|
@@ -27,6 +31,20 @@
|
|
|
27
31
|
|
|
28
32
|
### 新增
|
|
29
33
|
|
|
34
|
+
- C 家族:`abort()` 與 `assert(e)`(要引入 `<assert.h>`)。程式異常結束是標準定義的結束:判決 accept,`problems` 多一筆種類 `abort`(新的種類;C++ 未接住的例外照舊是 `uncaught`)。
|
|
35
|
+
- C 家族:`exit(status)` 寫成一句時正常結束、status 是結束碼(判決的 `exit`);status 要執行時才算得出來時判 unknown(還不支援)。
|
|
36
|
+
- C 家族:`rand`、`srand`、`time`。rand 的序列照 glibc 的演算法(沒有 srand 時種子是 1:1804289383、846930886…),判決的 `assumes` 帶 `{"implementation":"glibc","choice":"rand.sequence"}`;time 讀到 0,帶 `{"implementation":"environment","choice":"time.now"}`。假設的 `implementation` 現在說出擔保者(之前沒寫時一律是 libc++)。
|
|
37
|
+
- C 家族:標準標頭的巨集常數(`eConst`,名字照原文):`<limits.h>`/`<climits>` 的全部限制(`INT_MAX`、`CHAR_BIT`、`ULONG_MAX`…,值依目標平台)、`EOF`、`RAND_MAX`、`EXIT_SUCCESS`、`EXIT_FAILURE`。引入了定義它的標頭才有值;C 沒引入時判 reject(未宣告),C++ 只引入別的標準標頭時判 unknown(標頭會不會間接引入依函式庫而定),什麼都沒引入時判 reject。
|
|
38
|
+
- 除錯器的覆蓋:C、C++、Arduino、Python 的除錯模組多一個匯出 `stopVisits : Stopping -> String`(JSON `{"<節點>": 次數}`:這一段執行進入每個帶標籤的節點幾次,和 stepIn 停下的定義相同)。`cella-lang/dap` 的工作階段在模組有這個匯出時把每一段加總,`coverage()` 回到目前為止的總計(沒有的模組回 null);一次 continue 跑到底就拿得到整支程式的覆蓋,不必一步一步數。沒跑到的節點不在裡面。`run` 回傳的停點多帶了計數,宿主仍把它當不透明的值,其他匯出照舊。
|
|
39
|
+
- C 家族的判決:`goto` 跳進巢狀區塊(`goto L; { L: ... }`,合法的 C)之前判 reject,改判 unknown(`unsupported`:模型還不執行這種跳躍);標籤不在函式裡照舊 reject,理由改成「goto to a label that is not in the function」。
|
|
40
|
+
- C 家族的判決理由:類別或結構的物件轉成整數或浮點數(`std::string s; int x = s;`)的理由改成「incompatible types: no conversion from std::string to integer」,之前誤寫成「pointer to integer」。判決與標註的節點不變。
|
|
41
|
+
- 瀏覽器的 `run`:用到自己宣告的型別(`data`、record)並對它 `match` 的程式不再卡住(之前印出 `expected a closed Nat, got "Neutral"`);`run` 與檢查、編譯用同一個模組名。
|
|
42
|
+
- 錯誤訊息:名字遮蔽了同名的建構子時(`namespace Shape` 裡定義了 `Shape.circle`,再寫 `circle 3`),型別不合的錯誤多一條附註,說出名字解析到哪個定義、遮蔽了哪個建構子。
|
|
43
|
+
- `cella-lang/host` 附上型別宣告(`cella-host.d.ts`:`loadLibrary` 與它回傳的 `call`、`str`、`nat`、`toStr`、`toNat`、`tag`)。
|
|
44
|
+
- C++ 的判決:模型還沒有的標準函式,寫成不帶 `std::` 的名字(`srand`,或經 `using namespace std` 的 `sort`)也判 unknown(`unsupported`),不再判「未宣告」。宣告的節點標籤和變數標籤相同時,串列初始化不再把變數判成未初始化。
|
|
45
|
+
- C 家族的語法樹多一個型別 `tAuto`(`{"k":"tAuto"}`,C++ 的 `auto`):宣告的型別從初始值推導,照範本引數的推導(`auto` 去掉參考與頂層的 const;`auto &` 寫成 `tRef tAuto`、`const auto &` 寫成 `tRef (tConst tAuto)`,`sForRange` 的 `auto &` 照舊用 byRef)。範圍 for 的 `auto` 從 `*begin` 推導。沒有初始值、或用大括號初始化的 `auto` 判拒絕。
|
|
46
|
+
- `@cella-lang/cpp` 的函式庫多了 `std::pair`、`make_pair`、`less`、`greater`、`sort`、`lower_bound`、`upper_bound`、`push_heap`/`pop_heap`/`make_heap`/`sort_heap`、`queue`、`priority_queue`、`stack`、`set`、`map`(照 libc++ 18 的行為)。`sort` 的判決附上假設 `sort.order`(相等而不同的元素排出來的順序照 libc++)。預設比較子的 `lower_bound`/`upper_bound` 在範圍沒有依值分割時判 `ubLib`;空的容器取元素(`front`、`top`、`pop`,vector 的 `front`、`back`)判 `ubBounds`。
|
|
47
|
+
- C 家族的判決多一個問題種類 `ubOverlap`(reject):指定的值讀自和目的地部分重疊的物件(C11 6.5.16.1p3、C++17 [expr.ass]p8),例如聯合裡位移不同的兩個同型結構互相指定。
|
|
30
48
|
- C 家族的判決多兩個問題種類:`ubAlign`(C:轉換出的指標沒有對齊於指向的型別,C11 6.3.2.3p7,reject)與 `ubAlignUnknown`(unknown:C++ 的同一件事,結果是未指定的指標值,[expr.static.cast]p13;或對不對齊要看實作把物件放在哪裡,例如宣告的 `char` 陣列轉成 `int *`)。之前這些程式判 accept(malloc 的位元組 1 轉成 `int *` 再寫)或 unknown「pointer conversions are not supported」(`float *` 直接轉成 `int *`)。
|
|
31
49
|
- C 家族的指標轉換:物件指標之間直接轉換(`(int *)&f`)和經 `void *` 的相同,之前判 unknown;`signed char` 以 `%hhd` 讀放得進的值不再誤判成未定義行為。
|
|
32
50
|
- 除錯器(C 與 C++)只停在程式寫的節點:虛擬函式的分派、隱含的建構子與指定、建構子裡設定動態型別這些產生的程式碼不再停。
|
package/README.md
CHANGED
|
@@ -139,6 +139,7 @@ def stopOut (s : cpp.Stopping) : String := cpp.stopOut s
|
|
|
139
139
|
def stopErr (s : cpp.Stopping) : String := cpp.stopErr s
|
|
140
140
|
def stopDetail (s : cpp.Stopping) : String := cpp.stopDetail s
|
|
141
141
|
def divergences (s : cpp.Stopping) : String := cpp.divergences s
|
|
142
|
+
def stopVisits (s : cpp.Stopping) : String := cpp.stopVisits s
|
|
142
143
|
def feed (text : String) (x : cpp.Session) : cpp.Session := cpp.feed text x
|
|
143
144
|
def globals (x : cpp.Session) : String := cpp.globals x
|
|
144
145
|
def frames (at : String) (x : cpp.Session) : String := cpp.frames at x
|
|
@@ -152,7 +153,7 @@ import { compile_wasm_library } from 'cella-lang';
|
|
|
152
153
|
import { createSession, DAP_EXPORTS } from 'cella-lang/dap';
|
|
153
154
|
|
|
154
155
|
// after loadPackage('cpp'); `load` takes the place of `init`
|
|
155
|
-
const exportsList = DAP_EXPORTS.map((e) => (e === 'init' ? 'load' : e)).concat(['divergences']);
|
|
156
|
+
const exportsList = DAP_EXPORTS.map((e) => (e === 'init' ? 'load' : e)).concat(['divergences', 'stopVisits']);
|
|
156
157
|
const bytes = compile_wasm_library(debuggerSource, exportsList.join(',')); // throws a JSON string on errors
|
|
157
158
|
const session = await createSession(bytes, { program: programJson });
|
|
158
159
|
session.onEvent((event, body) => { /* 'stopped' | 'output' | 'terminated' | 'exited' | 'divergence' */ });
|
|
@@ -162,6 +163,7 @@ session.stackTrace(); // [{id, fn, nodeId}], innermost
|
|
|
162
163
|
session.variables(0); // [{id, name, type, value, declNode}] of frame 0; 'globals' for globals
|
|
163
164
|
session.setVariable(0, 's', '100'); // frame, the variable's id (as variables() gives it), text
|
|
164
165
|
await session.stepIn(); // also next(), stepOut(), continue(), pause(), terminate()
|
|
166
|
+
session.coverage(); // {"<node id>": times entered} so far, as stepIn counts them (with stopVisits)
|
|
165
167
|
await session.supplyInput('3\n'); // after a stop with reason 'awaiting-input'; closeInput() for the end of input
|
|
166
168
|
session.readEnv(); // the board's hardware (pins, servos, LCD, clock); null without a board
|
|
167
169
|
session.setInput('analog:A0', '512'); // a board's input changed while paused, from the next read on
|
package/cella-dap.mjs
CHANGED
|
@@ -9,6 +9,8 @@
|
|
|
9
9
|
// `setInput` 可用;再匯出 `clockMs : Conf -> Nat`(模擬時鐘)時,`inputScript()` 把改過的輸入寫成依時間的輸入腳本。
|
|
10
10
|
// 另外匯出 `divergences : Stop -> String`(JSON 陣列,每筆 {kind, at, clause, reason}:標準與實作分歧、照實作繼續的地方)時,
|
|
11
11
|
// 新記下的一筆送一個 `divergence` 事件(不中斷執行),`exited` 的 body 帶完整的 `divergences`。
|
|
12
|
+
// 另外匯出 `stopVisits : Stop -> String`(JSON {"<節點>": 次數}:這一段執行進入每個帶標籤的節點幾次,和 stepIn 停下的定義相同)時,
|
|
13
|
+
// 工作階段把每一段加總,`coverage()` 回到目前為止的總計(沒有這個匯出的模組回 null);沒跑到的節點不在裡面。
|
|
12
14
|
// 程式以資料傳入的模組(只編譯一次,例如 C/C++ 的深嵌入)匯出 `load : String -> Conf` 取代 `init`:
|
|
13
15
|
// `createSession(bytes, { program })` 把程式(JSON 文字)交給 `load`。程式沒通過檢查時停在 `rejected`
|
|
14
16
|
// (`stopDetail` 是 {kind: "reject", at, why}),用到還不支援的構造時停在 `unsupported`({kind: "unsupported", at, why}),
|
|
@@ -55,6 +57,19 @@ export class CellaDebugSession {
|
|
|
55
57
|
this.stops = 0; // 停下的次數(紀錄用:輸入與環境的改動記在「第幾次停下之後」)
|
|
56
58
|
this.log = []; // 補輸入與環境輸入的紀錄:重放(之後的 stepBack)照它得到相同結果
|
|
57
59
|
this.divergences = []; // 已送出的分歧(模組匯出 divergences 時)
|
|
60
|
+
this.visits = typeof lib.exports.stopVisits === 'function' ? {} : null; // 每個節點被進入的次數(模組匯出 stopVisits 時)
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/** 到目前為止每個節點被進入的次數({"<節點>": 次數};模組沒有匯出 `stopVisits` 時是 null)。 */
|
|
64
|
+
coverage() {
|
|
65
|
+
return this.visits === null ? null : { ...this.visits };
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
// 把一段執行的計數加進總計
|
|
69
|
+
countVisits(stop) {
|
|
70
|
+
if (this.visits === null) return;
|
|
71
|
+
const counts = JSON.parse(this.lib.toStr(this.lib.call('stopVisits', stop)));
|
|
72
|
+
for (const [node, n] of Object.entries(counts)) this.visits[node] = (this.visits[node] ?? 0) + n;
|
|
58
73
|
}
|
|
59
74
|
|
|
60
75
|
/** 事件:`stopped` {reason, nodeId, detail?}、`output` {category, output}、`terminated` {}、`exited` {exitCode, divergences?}、
|
|
@@ -159,6 +174,7 @@ export class CellaDebugSession {
|
|
|
159
174
|
const bps = lib.str(this.breakpoints.join('\n'));
|
|
160
175
|
for (;;) {
|
|
161
176
|
const stop = lib.call('run', lib.nat(kind), bps, lib.nat(this.inputClosed ? 1 : 0), lib.nat(this.fuel), this.conf);
|
|
177
|
+
this.countVisits(stop);
|
|
162
178
|
this.flushOutput(stop);
|
|
163
179
|
this.flushDivergences(stop);
|
|
164
180
|
const tag = Number(lib.toNat(lib.call('stopKind', stop)));
|
package/cella-host.d.ts
ADDED
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/** A value of the library module: opaque (a WasmGC reference), only passed back to its exported functions. */
|
|
2
|
+
export type CellaValue = unknown;
|
|
3
|
+
|
|
4
|
+
/** A library-mode module (`cella compile --target wasm --export a,b`), loaded for calling its exports one at a time. */
|
|
5
|
+
export interface CellaLibrary {
|
|
6
|
+
/** The module's raw exports. */
|
|
7
|
+
readonly exports: WebAssembly.Exports;
|
|
8
|
+
/** Calls an exported Cella function; its arguments and its result are opaque values. */
|
|
9
|
+
call(name: string, ...args: CellaValue[]): CellaValue;
|
|
10
|
+
/** A JS string as a Cella `String`. */
|
|
11
|
+
str(s: string): CellaValue;
|
|
12
|
+
/** A JS integer as a Cella `Nat`. */
|
|
13
|
+
nat(n: number | bigint): CellaValue;
|
|
14
|
+
/** A Cella `String` as a JS string. */
|
|
15
|
+
toStr(v: CellaValue): string;
|
|
16
|
+
/** A Cella `Nat` as a BigInt. */
|
|
17
|
+
toNat(v: CellaValue): bigint;
|
|
18
|
+
/** The constructor index of a data value, in declaration order (`Bool`: true 0, false 1). */
|
|
19
|
+
tag(v: CellaValue): number;
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
/** Loads a library-mode module from its bytes. */
|
|
23
|
+
export function loadLibrary(bytes: BufferSource): Promise<CellaLibrary>;
|
package/cella_bg.wasm
CHANGED
|
Binary file
|
package/corpus.json
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
{
|
|
2
|
-
"semanticsHash": "
|
|
2
|
+
"semanticsHash": "42f803337cd7935c",
|
|
3
3
|
"entries": [
|
|
4
4
|
{
|
|
5
5
|
"name": "standalone:prelude",
|
|
@@ -382,6 +382,502 @@
|
|
|
382
382
|
]
|
|
383
383
|
}
|
|
384
384
|
},
|
|
385
|
+
{
|
|
386
|
+
"name": "ex:Hello, World! (en)",
|
|
387
|
+
"mode": "preloaded",
|
|
388
|
+
"modules": [],
|
|
389
|
+
"code": "-- A first program: press Run to print a line\ndef main : IO Unit := putStr \"Hello, World!\"\n",
|
|
390
|
+
"expected": {
|
|
391
|
+
"verdict": "accept",
|
|
392
|
+
"defs": [
|
|
393
|
+
"main"
|
|
394
|
+
],
|
|
395
|
+
"unknown": [],
|
|
396
|
+
"assumptions": [
|
|
397
|
+
"not_rechecked_by_kernel:"
|
|
398
|
+
]
|
|
399
|
+
}
|
|
400
|
+
},
|
|
401
|
+
{
|
|
402
|
+
"name": "ex:Hello, World! (zh-TW)",
|
|
403
|
+
"mode": "preloaded",
|
|
404
|
+
"modules": [],
|
|
405
|
+
"code": "-- 第一個程式:按「執行」,印出一行字\ndef main : IO Unit := putStr \"Hello, World!\"\n",
|
|
406
|
+
"expected": {
|
|
407
|
+
"verdict": "accept",
|
|
408
|
+
"defs": [
|
|
409
|
+
"main"
|
|
410
|
+
],
|
|
411
|
+
"unknown": [],
|
|
412
|
+
"assumptions": [
|
|
413
|
+
"not_rechecked_by_kernel:"
|
|
414
|
+
]
|
|
415
|
+
}
|
|
416
|
+
},
|
|
417
|
+
{
|
|
418
|
+
"name": "ex:For mathematicians: Gauss's sum (en)",
|
|
419
|
+
"mode": "preloaded",
|
|
420
|
+
"modules": [
|
|
421
|
+
"nat",
|
|
422
|
+
"ring"
|
|
423
|
+
],
|
|
424
|
+
"code": "-- 1 + 2 + … + n: the same function runs, and is proved.\nimport ring\n\ndef sum (n : Nat) : Nat := match n with\n | zero => zero\n | succ k => add (sum k) (succ k)\n\n-- Run: compute 1 + 2 + … + 100\ndef main : IO Unit := putNat (sum 100)\n\n-- Check: Gauss's formula holds for every n\n-- (1 + … + n) + (1 + … + n) = n × (n + 1)\ntheorem gauss (n : Nat) : add (sum n) (sum n) = mul n (succ n) := by {\n induction n with\n | zero => exact refl\n | succ k ih =>\n rewrite (regroup (sum k) k);\n rewrite ih;\n exact (finish k)\n}\n\n-- Two algebra steps, proved by ring (sum k is an unknown to it)\ntheorem regroup (s : Nat) (k : Nat) : add (add s (succ k)) (add s (succ k)) = add (add s s) (add (succ k) (succ k)) := by { ring }\ntheorem finish (k : Nat) : add (mul k (succ k)) (add (succ k) (succ k)) = mul (succ k) (succ (succ k)) := by { ring }\n",
|
|
425
|
+
"expected": {
|
|
426
|
+
"verdict": "accept",
|
|
427
|
+
"defs": [
|
|
428
|
+
"finish",
|
|
429
|
+
"gauss",
|
|
430
|
+
"main",
|
|
431
|
+
"regroup",
|
|
432
|
+
"sum"
|
|
433
|
+
],
|
|
434
|
+
"unknown": [],
|
|
435
|
+
"assumptions": [
|
|
436
|
+
"not_rechecked_by_kernel:",
|
|
437
|
+
"termination_by_elaborator:Nat.add",
|
|
438
|
+
"termination_by_elaborator:Nat.addAssoc",
|
|
439
|
+
"termination_by_elaborator:Nat.addComm",
|
|
440
|
+
"termination_by_elaborator:Nat.addSuccR",
|
|
441
|
+
"termination_by_elaborator:Nat.addZeroR",
|
|
442
|
+
"termination_by_elaborator:Nat.mul",
|
|
443
|
+
"termination_by_elaborator:Nat.mulAssoc",
|
|
444
|
+
"termination_by_elaborator:Nat.mulComm",
|
|
445
|
+
"termination_by_elaborator:Nat.mulDistribL",
|
|
446
|
+
"termination_by_elaborator:Nat.mulOneR",
|
|
447
|
+
"termination_by_elaborator:Nat.mulSuccR",
|
|
448
|
+
"termination_by_elaborator:Nat.mulZeroR",
|
|
449
|
+
"termination_by_elaborator:main.gauss",
|
|
450
|
+
"termination_by_elaborator:main.sum",
|
|
451
|
+
"termination_by_elaborator:monoEval",
|
|
452
|
+
"termination_by_elaborator:monoIns",
|
|
453
|
+
"termination_by_elaborator:monoInsSound",
|
|
454
|
+
"termination_by_elaborator:monoLe",
|
|
455
|
+
"termination_by_elaborator:monoMul",
|
|
456
|
+
"termination_by_elaborator:monoMulSound",
|
|
457
|
+
"termination_by_elaborator:polyAdd",
|
|
458
|
+
"termination_by_elaborator:polyAddSound",
|
|
459
|
+
"termination_by_elaborator:polyEval",
|
|
460
|
+
"termination_by_elaborator:polyIns",
|
|
461
|
+
"termination_by_elaborator:polyInsSound",
|
|
462
|
+
"termination_by_elaborator:polyMul",
|
|
463
|
+
"termination_by_elaborator:polyMulSound",
|
|
464
|
+
"termination_by_elaborator:polyNum",
|
|
465
|
+
"termination_by_elaborator:polyNumSound",
|
|
466
|
+
"termination_by_elaborator:polyScale",
|
|
467
|
+
"termination_by_elaborator:polyScaleSound",
|
|
468
|
+
"termination_by_elaborator:ringEval",
|
|
469
|
+
"termination_by_elaborator:ringLeN",
|
|
470
|
+
"termination_by_elaborator:ringNorm",
|
|
471
|
+
"termination_by_elaborator:ringNormSound",
|
|
472
|
+
"termination_by_elaborator:ringNth"
|
|
473
|
+
]
|
|
474
|
+
}
|
|
475
|
+
},
|
|
476
|
+
{
|
|
477
|
+
"name": "ex:For mathematicians: Gauss's sum (zh-TW)",
|
|
478
|
+
"mode": "preloaded",
|
|
479
|
+
"modules": [
|
|
480
|
+
"nat",
|
|
481
|
+
"ring"
|
|
482
|
+
],
|
|
483
|
+
"code": "-- 1 + 2 + … + n:同一個函式,可以執行,也可以證明。\nimport ring\n\ndef sum (n : Nat) : Nat := match n with\n | zero => zero\n | succ k => add (sum k) (succ k)\n\n-- 按「執行」:算出 1 + 2 + … + 100\ndef main : IO Unit := putNat (sum 100)\n\n-- 按「檢查」:高斯的公式對每一個 n 都成立\n-- (1 + … + n) + (1 + … + n) = n × (n + 1)\ntheorem gauss (n : Nat) : add (sum n) (sum n) = mul n (succ n) := by {\n induction n with\n | zero => exact refl\n | succ k ih =>\n rewrite (regroup (sum k) k);\n rewrite ih;\n exact (finish k)\n}\n\n-- 兩個代數步驟,ring 自動證明(把 sum k 當成一個未知數)\ntheorem regroup (s : Nat) (k : Nat) : add (add s (succ k)) (add s (succ k)) = add (add s s) (add (succ k) (succ k)) := by { ring }\ntheorem finish (k : Nat) : add (mul k (succ k)) (add (succ k) (succ k)) = mul (succ k) (succ (succ k)) := by { ring }\n",
|
|
484
|
+
"expected": {
|
|
485
|
+
"verdict": "accept",
|
|
486
|
+
"defs": [
|
|
487
|
+
"finish",
|
|
488
|
+
"gauss",
|
|
489
|
+
"main",
|
|
490
|
+
"regroup",
|
|
491
|
+
"sum"
|
|
492
|
+
],
|
|
493
|
+
"unknown": [],
|
|
494
|
+
"assumptions": [
|
|
495
|
+
"not_rechecked_by_kernel:",
|
|
496
|
+
"termination_by_elaborator:Nat.add",
|
|
497
|
+
"termination_by_elaborator:Nat.addAssoc",
|
|
498
|
+
"termination_by_elaborator:Nat.addComm",
|
|
499
|
+
"termination_by_elaborator:Nat.addSuccR",
|
|
500
|
+
"termination_by_elaborator:Nat.addZeroR",
|
|
501
|
+
"termination_by_elaborator:Nat.mul",
|
|
502
|
+
"termination_by_elaborator:Nat.mulAssoc",
|
|
503
|
+
"termination_by_elaborator:Nat.mulComm",
|
|
504
|
+
"termination_by_elaborator:Nat.mulDistribL",
|
|
505
|
+
"termination_by_elaborator:Nat.mulOneR",
|
|
506
|
+
"termination_by_elaborator:Nat.mulSuccR",
|
|
507
|
+
"termination_by_elaborator:Nat.mulZeroR",
|
|
508
|
+
"termination_by_elaborator:main.gauss",
|
|
509
|
+
"termination_by_elaborator:main.sum",
|
|
510
|
+
"termination_by_elaborator:monoEval",
|
|
511
|
+
"termination_by_elaborator:monoIns",
|
|
512
|
+
"termination_by_elaborator:monoInsSound",
|
|
513
|
+
"termination_by_elaborator:monoLe",
|
|
514
|
+
"termination_by_elaborator:monoMul",
|
|
515
|
+
"termination_by_elaborator:monoMulSound",
|
|
516
|
+
"termination_by_elaborator:polyAdd",
|
|
517
|
+
"termination_by_elaborator:polyAddSound",
|
|
518
|
+
"termination_by_elaborator:polyEval",
|
|
519
|
+
"termination_by_elaborator:polyIns",
|
|
520
|
+
"termination_by_elaborator:polyInsSound",
|
|
521
|
+
"termination_by_elaborator:polyMul",
|
|
522
|
+
"termination_by_elaborator:polyMulSound",
|
|
523
|
+
"termination_by_elaborator:polyNum",
|
|
524
|
+
"termination_by_elaborator:polyNumSound",
|
|
525
|
+
"termination_by_elaborator:polyScale",
|
|
526
|
+
"termination_by_elaborator:polyScaleSound",
|
|
527
|
+
"termination_by_elaborator:ringEval",
|
|
528
|
+
"termination_by_elaborator:ringLeN",
|
|
529
|
+
"termination_by_elaborator:ringNorm",
|
|
530
|
+
"termination_by_elaborator:ringNormSound",
|
|
531
|
+
"termination_by_elaborator:ringNth"
|
|
532
|
+
]
|
|
533
|
+
}
|
|
534
|
+
},
|
|
535
|
+
{
|
|
536
|
+
"name": "ex:For programmers: run it, prove it (en)",
|
|
537
|
+
"mode": "preloaded",
|
|
538
|
+
"modules": [],
|
|
539
|
+
"code": "-- Reverse a list: reverse the rest, then put the first one at the end\ndef rev (xs : List Nat) : List Nat := match xs with\n | nil => nil\n | cons x rest => append (rev rest) [x]\n\n-- Run: imperative-style code (do, let, let mut, if else)\ndef main : IO Unit := do\n let xs := [3, 1, 4, 1, 5]\n let total := xs.sum\n let mut size := \"small\"\n if Nat.ble 10 total then\n size := \"big\"\n else\n size := \"small\"\n putStr f\"reversed: {rev xs}\"\n putStr f\"total: {total} ({size})\"\n\n-- Check: reversing twice gives back the list -- for every list, not just the one above\ntheorem revRev (xs : List Nat) : rev (rev xs) = xs := match xs with\n | nil => refl\n | cons x rest => (revSnoc (rev rest) x).trans ((revRev rest).cong (cons x))\n\n-- The lemma it uses: putting y at the end and reversing puts y in front of the reversal\ntheorem revSnoc (xs : List Nat) (y : Nat) : rev (append xs [y]) = cons y (rev xs) := match xs with\n | nil => refl\n | cons x rest => (revSnoc rest y).cong (fun (l : List Nat) => append l [x])\n",
|
|
540
|
+
"expected": {
|
|
541
|
+
"verdict": "accept",
|
|
542
|
+
"defs": [
|
|
543
|
+
"main",
|
|
544
|
+
"rev",
|
|
545
|
+
"revRev",
|
|
546
|
+
"revSnoc"
|
|
547
|
+
],
|
|
548
|
+
"unknown": [],
|
|
549
|
+
"assumptions": [
|
|
550
|
+
"not_rechecked_by_kernel:",
|
|
551
|
+
"termination_by_elaborator:List.append",
|
|
552
|
+
"termination_by_elaborator:main.rev",
|
|
553
|
+
"termination_by_elaborator:main.revRev",
|
|
554
|
+
"termination_by_elaborator:main.revSnoc"
|
|
555
|
+
]
|
|
556
|
+
}
|
|
557
|
+
},
|
|
558
|
+
{
|
|
559
|
+
"name": "ex:For programmers: run it, prove it (zh-TW)",
|
|
560
|
+
"mode": "preloaded",
|
|
561
|
+
"modules": [],
|
|
562
|
+
"code": "-- 反轉一個串列:先反轉剩下的,再把第一個接到最後\ndef rev (xs : List Nat) : List Nat := match xs with\n | nil => nil\n | cons x rest => append (rev rest) [x]\n\n-- 按「執行」:命令式的寫法(do、let、let mut、if else)\ndef main : IO Unit := do\n let xs := [3, 1, 4, 1, 5]\n let total := xs.sum\n let mut size := \"small\"\n if Nat.ble 10 total then\n size := \"big\"\n else\n size := \"small\"\n putStr f\"reversed: {rev xs}\"\n putStr f\"total: {total} ({size})\"\n\n-- 按「檢查」:反轉兩次會回到原本的串列——對每一個串列都成立,不只是上面那一個\ntheorem revRev (xs : List Nat) : rev (rev xs) = xs := match xs with\n | nil => refl\n | cons x rest => (revSnoc (rev rest) x).trans ((revRev rest).cong (cons x))\n\n-- 用到的引理:把 y 接到最後再反轉,等於把 y 放到反轉的最前面\ntheorem revSnoc (xs : List Nat) (y : Nat) : rev (append xs [y]) = cons y (rev xs) := match xs with\n | nil => refl\n | cons x rest => (revSnoc rest y).cong (fun (l : List Nat) => append l [x])\n",
|
|
563
|
+
"expected": {
|
|
564
|
+
"verdict": "accept",
|
|
565
|
+
"defs": [
|
|
566
|
+
"main",
|
|
567
|
+
"rev",
|
|
568
|
+
"revRev",
|
|
569
|
+
"revSnoc"
|
|
570
|
+
],
|
|
571
|
+
"unknown": [],
|
|
572
|
+
"assumptions": [
|
|
573
|
+
"not_rechecked_by_kernel:",
|
|
574
|
+
"termination_by_elaborator:List.append",
|
|
575
|
+
"termination_by_elaborator:main.rev",
|
|
576
|
+
"termination_by_elaborator:main.revRev",
|
|
577
|
+
"termination_by_elaborator:main.revSnoc"
|
|
578
|
+
]
|
|
579
|
+
}
|
|
580
|
+
},
|
|
581
|
+
{
|
|
582
|
+
"name": "ex:The length is in the type (en)",
|
|
583
|
+
"mode": "preloaded",
|
|
584
|
+
"modules": [],
|
|
585
|
+
"code": "-- The length is in the type: Vec n is a list of exactly n numbers\ndata Vec : Nat -> Type = vnil : Vec zero | vcons : {n : Nat} -> Nat -> Vec n -> Vec (succ n)\n\n-- Only a non-empty vector has a first element: the type says Vec (succ n), so an empty one cannot be passed in; no check at run time\ndef first {n : Nat} (v : Vec (succ n)) : Nat := match v with\n | vcons x rest => x\n\n-- Joining two vectors adds the lengths -- the checker makes sure of it\ndef join {m : Nat} {n : Nat} (a : Vec m) (b : Vec n) : Vec (add m n) := match a with\n | vnil => b\n | vcons x rest => vcons x (join rest b)\n\ndef scores : Vec 3 := vcons 90 (vcons 75 (vcons 82 vnil))\n\ndef main : IO Unit := putNat (first (join scores scores))\n\n-- Uncomment the line below: taking the first of an empty vector is rejected when checking\n-- def oops : Nat := first vnil\n",
|
|
586
|
+
"expected": {
|
|
587
|
+
"verdict": "accept",
|
|
588
|
+
"defs": [
|
|
589
|
+
"Vec",
|
|
590
|
+
"first",
|
|
591
|
+
"join",
|
|
592
|
+
"main",
|
|
593
|
+
"scores"
|
|
594
|
+
],
|
|
595
|
+
"unknown": [],
|
|
596
|
+
"assumptions": [
|
|
597
|
+
"not_rechecked_by_kernel:",
|
|
598
|
+
"termination_by_elaborator:Nat.add",
|
|
599
|
+
"termination_by_elaborator:main.join"
|
|
600
|
+
]
|
|
601
|
+
}
|
|
602
|
+
},
|
|
603
|
+
{
|
|
604
|
+
"name": "ex:The length is in the type (zh-TW)",
|
|
605
|
+
"mode": "preloaded",
|
|
606
|
+
"modules": [],
|
|
607
|
+
"code": "-- 型別裡帶著長度:Vec n 是剛好 n 個數的串列\ndata Vec : Nat -> Type = vnil : Vec zero | vcons : {n : Nat} -> Nat -> Vec n -> Vec (succ n)\n\n-- 只能對非空的向量取第一個:型別寫的是 Vec (succ n),空的根本傳不進來,不用執行期的檢查\ndef first {n : Nat} (v : Vec (succ n)) : Nat := match v with\n | vcons x rest => x\n\n-- 接起兩個向量,長度相加——長度對不對由檢查器保證\ndef join {m : Nat} {n : Nat} (a : Vec m) (b : Vec n) : Vec (add m n) := match a with\n | vnil => b\n | vcons x rest => vcons x (join rest b)\n\ndef scores : Vec 3 := vcons 90 (vcons 75 (vcons 82 vnil))\n\ndef main : IO Unit := putNat (first (join scores scores))\n\n-- 把下面這行的註解拿掉:對空向量取第一個,檢查時就被擋下\n-- def oops : Nat := first vnil\n",
|
|
608
|
+
"expected": {
|
|
609
|
+
"verdict": "accept",
|
|
610
|
+
"defs": [
|
|
611
|
+
"Vec",
|
|
612
|
+
"first",
|
|
613
|
+
"join",
|
|
614
|
+
"main",
|
|
615
|
+
"scores"
|
|
616
|
+
],
|
|
617
|
+
"unknown": [],
|
|
618
|
+
"assumptions": [
|
|
619
|
+
"not_rechecked_by_kernel:",
|
|
620
|
+
"termination_by_elaborator:Nat.add",
|
|
621
|
+
"termination_by_elaborator:main.join"
|
|
622
|
+
]
|
|
623
|
+
}
|
|
624
|
+
},
|
|
625
|
+
{
|
|
626
|
+
"name": "ex:Check it before it is finished (holes) (en)",
|
|
627
|
+
"mode": "preloaded",
|
|
628
|
+
"modules": [],
|
|
629
|
+
"code": "-- A program can be checked before it is finished: ?rest is a hole. The verdict is Unknown (not an error), and it says what type the hole needs\ndef area (w : Nat) (h : Nat) : Nat := mul w ?rest\n",
|
|
630
|
+
"expected": {
|
|
631
|
+
"verdict": "unknown",
|
|
632
|
+
"defs": [
|
|
633
|
+
"area"
|
|
634
|
+
],
|
|
635
|
+
"unknown": [
|
|
636
|
+
"main.area:hole"
|
|
637
|
+
],
|
|
638
|
+
"assumptions": [
|
|
639
|
+
"termination_by_elaborator:Nat.mul"
|
|
640
|
+
]
|
|
641
|
+
}
|
|
642
|
+
},
|
|
643
|
+
{
|
|
644
|
+
"name": "ex:Check it before it is finished (holes) (zh-TW)",
|
|
645
|
+
"mode": "preloaded",
|
|
646
|
+
"modules": [],
|
|
647
|
+
"code": "-- 程式還沒寫完也能檢查:?rest 是一個洞。判決是 Unknown(不是錯),並說出洞要填什麼型別\ndef area (w : Nat) (h : Nat) : Nat := mul w ?rest\n",
|
|
648
|
+
"expected": {
|
|
649
|
+
"verdict": "unknown",
|
|
650
|
+
"defs": [
|
|
651
|
+
"area"
|
|
652
|
+
],
|
|
653
|
+
"unknown": [
|
|
654
|
+
"main.area:hole"
|
|
655
|
+
],
|
|
656
|
+
"assumptions": [
|
|
657
|
+
"termination_by_elaborator:Nat.mul"
|
|
658
|
+
]
|
|
659
|
+
}
|
|
660
|
+
},
|
|
661
|
+
{
|
|
662
|
+
"name": "ex:Where the mistake is (en)",
|
|
663
|
+
"mode": "preloaded",
|
|
664
|
+
"modules": [],
|
|
665
|
+
"code": "-- A mistake is pointed out: where it is, the rule it breaks, the type expected\ndef answer : Nat := \"forty-two\"\n",
|
|
666
|
+
"expected": {
|
|
667
|
+
"verdict": "reject",
|
|
668
|
+
"defs": [],
|
|
669
|
+
"unknown": [],
|
|
670
|
+
"assumptions": []
|
|
671
|
+
}
|
|
672
|
+
},
|
|
673
|
+
{
|
|
674
|
+
"name": "ex:Where the mistake is (zh-TW)",
|
|
675
|
+
"mode": "preloaded",
|
|
676
|
+
"modules": [],
|
|
677
|
+
"code": "-- 寫錯的地方會被指出來:位置、違反的規則、期待的型別\ndef answer : Nat := \"forty-two\"\n",
|
|
678
|
+
"expected": {
|
|
679
|
+
"verdict": "reject",
|
|
680
|
+
"defs": [],
|
|
681
|
+
"unknown": [],
|
|
682
|
+
"assumptions": []
|
|
683
|
+
}
|
|
684
|
+
},
|
|
685
|
+
{
|
|
686
|
+
"name": "ex:Assumptions are listed (en)",
|
|
687
|
+
"mode": "preloaded",
|
|
688
|
+
"modules": [],
|
|
689
|
+
"code": "-- What is not proved is said: a postulate is an assumption. A proof that uses it is still accepted, but the verdict lists the assumption it rests on\npostulate excludedMiddle (p : Type) : Either p (p -> Empty)\ndef decide (p : Type) : Either p (p -> Empty) := excludedMiddle p\n",
|
|
690
|
+
"expected": {
|
|
691
|
+
"verdict": "accept",
|
|
692
|
+
"defs": [
|
|
693
|
+
"decide",
|
|
694
|
+
"excludedMiddle"
|
|
695
|
+
],
|
|
696
|
+
"unknown": [],
|
|
697
|
+
"assumptions": [
|
|
698
|
+
"postulate:main.excludedMiddle"
|
|
699
|
+
]
|
|
700
|
+
}
|
|
701
|
+
},
|
|
702
|
+
{
|
|
703
|
+
"name": "ex:Assumptions are listed (zh-TW)",
|
|
704
|
+
"mode": "preloaded",
|
|
705
|
+
"modules": [],
|
|
706
|
+
"code": "-- 沒證的事要明說:postulate 是一個假設。用到它的證明照樣接受,但判決會列出它依賴這個假設\npostulate excludedMiddle (p : Type) : Either p (p -> Empty)\ndef decide (p : Type) : Either p (p -> Empty) := excludedMiddle p\n",
|
|
707
|
+
"expected": {
|
|
708
|
+
"verdict": "accept",
|
|
709
|
+
"defs": [
|
|
710
|
+
"decide",
|
|
711
|
+
"excludedMiddle"
|
|
712
|
+
],
|
|
713
|
+
"unknown": [],
|
|
714
|
+
"assumptions": [
|
|
715
|
+
"postulate:main.excludedMiddle"
|
|
716
|
+
]
|
|
717
|
+
}
|
|
718
|
+
},
|
|
719
|
+
{
|
|
720
|
+
"name": "ex:Leave the algebra to ring (en)",
|
|
721
|
+
"mode": "preloaded",
|
|
722
|
+
"modules": [
|
|
723
|
+
"nat",
|
|
724
|
+
"ring"
|
|
725
|
+
],
|
|
726
|
+
"code": "import ring\n-- Leave the algebra to a decision procedure: ring proves polynomial identities (it expands and collects; the kernel rechecks the proof)\ntheorem square (a : Nat) (b : Nat) : mul (add a b) (add a b) = add (add (mul a a) (add (mul a b) (mul a b))) (mul b b) := by { ring }\ntheorem cube (a : Nat) (b : Nat) : mul (add a b) (mul (add a b) (add a b)) = add (mul a (mul a a)) (add (mul 3 (mul (mul a a) b)) (add (mul 3 (mul a (mul b b))) (mul b (mul b b)))) := by { ring }\n",
|
|
727
|
+
"expected": {
|
|
728
|
+
"verdict": "accept",
|
|
729
|
+
"defs": [
|
|
730
|
+
"cube",
|
|
731
|
+
"square"
|
|
732
|
+
],
|
|
733
|
+
"unknown": [],
|
|
734
|
+
"assumptions": [
|
|
735
|
+
"termination_by_elaborator:Nat.add",
|
|
736
|
+
"termination_by_elaborator:Nat.addAssoc",
|
|
737
|
+
"termination_by_elaborator:Nat.addComm",
|
|
738
|
+
"termination_by_elaborator:Nat.addSuccR",
|
|
739
|
+
"termination_by_elaborator:Nat.addZeroR",
|
|
740
|
+
"termination_by_elaborator:Nat.mul",
|
|
741
|
+
"termination_by_elaborator:Nat.mulAssoc",
|
|
742
|
+
"termination_by_elaborator:Nat.mulComm",
|
|
743
|
+
"termination_by_elaborator:Nat.mulDistribL",
|
|
744
|
+
"termination_by_elaborator:Nat.mulOneR",
|
|
745
|
+
"termination_by_elaborator:Nat.mulSuccR",
|
|
746
|
+
"termination_by_elaborator:Nat.mulZeroR",
|
|
747
|
+
"termination_by_elaborator:monoEval",
|
|
748
|
+
"termination_by_elaborator:monoIns",
|
|
749
|
+
"termination_by_elaborator:monoInsSound",
|
|
750
|
+
"termination_by_elaborator:monoLe",
|
|
751
|
+
"termination_by_elaborator:monoMul",
|
|
752
|
+
"termination_by_elaborator:monoMulSound",
|
|
753
|
+
"termination_by_elaborator:polyAdd",
|
|
754
|
+
"termination_by_elaborator:polyAddSound",
|
|
755
|
+
"termination_by_elaborator:polyEval",
|
|
756
|
+
"termination_by_elaborator:polyIns",
|
|
757
|
+
"termination_by_elaborator:polyInsSound",
|
|
758
|
+
"termination_by_elaborator:polyMul",
|
|
759
|
+
"termination_by_elaborator:polyMulSound",
|
|
760
|
+
"termination_by_elaborator:polyNum",
|
|
761
|
+
"termination_by_elaborator:polyNumSound",
|
|
762
|
+
"termination_by_elaborator:polyScale",
|
|
763
|
+
"termination_by_elaborator:polyScaleSound",
|
|
764
|
+
"termination_by_elaborator:ringEval",
|
|
765
|
+
"termination_by_elaborator:ringLeN",
|
|
766
|
+
"termination_by_elaborator:ringNorm",
|
|
767
|
+
"termination_by_elaborator:ringNormSound",
|
|
768
|
+
"termination_by_elaborator:ringNth"
|
|
769
|
+
]
|
|
770
|
+
}
|
|
771
|
+
},
|
|
772
|
+
{
|
|
773
|
+
"name": "ex:Leave the algebra to ring (zh-TW)",
|
|
774
|
+
"mode": "preloaded",
|
|
775
|
+
"modules": [
|
|
776
|
+
"nat",
|
|
777
|
+
"ring"
|
|
778
|
+
],
|
|
779
|
+
"code": "import ring\n-- 代數交給決策程序:ring 證明多項式恆等式(展開、整理都由它做,證明由 kernel 重驗)\ntheorem square (a : Nat) (b : Nat) : mul (add a b) (add a b) = add (add (mul a a) (add (mul a b) (mul a b))) (mul b b) := by { ring }\ntheorem cube (a : Nat) (b : Nat) : mul (add a b) (mul (add a b) (add a b)) = add (mul a (mul a a)) (add (mul 3 (mul (mul a a) b)) (add (mul 3 (mul a (mul b b))) (mul b (mul b b)))) := by { ring }\n",
|
|
780
|
+
"expected": {
|
|
781
|
+
"verdict": "accept",
|
|
782
|
+
"defs": [
|
|
783
|
+
"cube",
|
|
784
|
+
"square"
|
|
785
|
+
],
|
|
786
|
+
"unknown": [],
|
|
787
|
+
"assumptions": [
|
|
788
|
+
"termination_by_elaborator:Nat.add",
|
|
789
|
+
"termination_by_elaborator:Nat.addAssoc",
|
|
790
|
+
"termination_by_elaborator:Nat.addComm",
|
|
791
|
+
"termination_by_elaborator:Nat.addSuccR",
|
|
792
|
+
"termination_by_elaborator:Nat.addZeroR",
|
|
793
|
+
"termination_by_elaborator:Nat.mul",
|
|
794
|
+
"termination_by_elaborator:Nat.mulAssoc",
|
|
795
|
+
"termination_by_elaborator:Nat.mulComm",
|
|
796
|
+
"termination_by_elaborator:Nat.mulDistribL",
|
|
797
|
+
"termination_by_elaborator:Nat.mulOneR",
|
|
798
|
+
"termination_by_elaborator:Nat.mulSuccR",
|
|
799
|
+
"termination_by_elaborator:Nat.mulZeroR",
|
|
800
|
+
"termination_by_elaborator:monoEval",
|
|
801
|
+
"termination_by_elaborator:monoIns",
|
|
802
|
+
"termination_by_elaborator:monoInsSound",
|
|
803
|
+
"termination_by_elaborator:monoLe",
|
|
804
|
+
"termination_by_elaborator:monoMul",
|
|
805
|
+
"termination_by_elaborator:monoMulSound",
|
|
806
|
+
"termination_by_elaborator:polyAdd",
|
|
807
|
+
"termination_by_elaborator:polyAddSound",
|
|
808
|
+
"termination_by_elaborator:polyEval",
|
|
809
|
+
"termination_by_elaborator:polyIns",
|
|
810
|
+
"termination_by_elaborator:polyInsSound",
|
|
811
|
+
"termination_by_elaborator:polyMul",
|
|
812
|
+
"termination_by_elaborator:polyMulSound",
|
|
813
|
+
"termination_by_elaborator:polyNum",
|
|
814
|
+
"termination_by_elaborator:polyNumSound",
|
|
815
|
+
"termination_by_elaborator:polyScale",
|
|
816
|
+
"termination_by_elaborator:polyScaleSound",
|
|
817
|
+
"termination_by_elaborator:ringEval",
|
|
818
|
+
"termination_by_elaborator:ringLeN",
|
|
819
|
+
"termination_by_elaborator:ringNorm",
|
|
820
|
+
"termination_by_elaborator:ringNormSound",
|
|
821
|
+
"termination_by_elaborator:ringNth"
|
|
822
|
+
]
|
|
823
|
+
}
|
|
824
|
+
},
|
|
825
|
+
{
|
|
826
|
+
"name": "ex:do in Option (en)",
|
|
827
|
+
"mode": "preloaded",
|
|
828
|
+
"modules": [],
|
|
829
|
+
"code": "-- do is not only for IO: in Option, if any step fails (none), the whole chain is none, with no checks at every step\ndef divide (a : Nat) (b : Nat) : Option Nat := if Nat.beq b 0 then none else some (Nat.div a b)\n\ndef average (total : Nat) (count : Nat) (scale : Nat) : Option Nat := do\n mean <- divide total count\n scaled <- divide (mul mean 100) scale\n pure scaled\n\ndef show (r : Option Nat) : String := match r with\n | some v => f\"{v}\"\n | none => \"none\"\n\ndef main : IO Unit := do\n putStr (show (average 90 3 10))\n putStr (show (average 90 0 10))\n",
|
|
830
|
+
"expected": {
|
|
831
|
+
"verdict": "accept",
|
|
832
|
+
"defs": [
|
|
833
|
+
"average",
|
|
834
|
+
"divide",
|
|
835
|
+
"main",
|
|
836
|
+
"show"
|
|
837
|
+
],
|
|
838
|
+
"unknown": [],
|
|
839
|
+
"assumptions": [
|
|
840
|
+
"not_rechecked_by_kernel:",
|
|
841
|
+
"termination_by_elaborator:List.append",
|
|
842
|
+
"termination_by_elaborator:List.nth",
|
|
843
|
+
"termination_by_elaborator:Nat.beq",
|
|
844
|
+
"termination_by_elaborator:Nat.blt",
|
|
845
|
+
"termination_by_elaborator:Nat.divAuxFuel",
|
|
846
|
+
"termination_by_elaborator:Nat.modAuxFuel",
|
|
847
|
+
"termination_by_elaborator:Nat.mul",
|
|
848
|
+
"termination_by_elaborator:Nat.sub",
|
|
849
|
+
"termination_by_elaborator:natDigits",
|
|
850
|
+
"termination_by_elaborator:strConcat"
|
|
851
|
+
]
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
{
|
|
855
|
+
"name": "ex:do in Option (zh-TW)",
|
|
856
|
+
"mode": "preloaded",
|
|
857
|
+
"modules": [],
|
|
858
|
+
"code": "-- do 不只用在 IO:在 Option 裡,任何一步失敗(none),整串就是 none,不用一層層檢查\ndef divide (a : Nat) (b : Nat) : Option Nat := if Nat.beq b 0 then none else some (Nat.div a b)\n\ndef average (total : Nat) (count : Nat) (scale : Nat) : Option Nat := do\n mean <- divide total count\n scaled <- divide (mul mean 100) scale\n pure scaled\n\ndef show (r : Option Nat) : String := match r with\n | some v => f\"{v}\"\n | none => \"none\"\n\ndef main : IO Unit := do\n putStr (show (average 90 3 10))\n putStr (show (average 90 0 10))\n",
|
|
859
|
+
"expected": {
|
|
860
|
+
"verdict": "accept",
|
|
861
|
+
"defs": [
|
|
862
|
+
"average",
|
|
863
|
+
"divide",
|
|
864
|
+
"main",
|
|
865
|
+
"show"
|
|
866
|
+
],
|
|
867
|
+
"unknown": [],
|
|
868
|
+
"assumptions": [
|
|
869
|
+
"not_rechecked_by_kernel:",
|
|
870
|
+
"termination_by_elaborator:List.nth",
|
|
871
|
+
"termination_by_elaborator:Nat.beq",
|
|
872
|
+
"termination_by_elaborator:Nat.divAuxFuel",
|
|
873
|
+
"termination_by_elaborator:Nat.modAuxFuel",
|
|
874
|
+
"termination_by_elaborator:Nat.mul",
|
|
875
|
+
"termination_by_elaborator:Nat.sub",
|
|
876
|
+
"termination_by_elaborator:natDigits",
|
|
877
|
+
"termination_by_elaborator:strConcat"
|
|
878
|
+
]
|
|
879
|
+
}
|
|
880
|
+
},
|
|
385
881
|
{
|
|
386
882
|
"name": "route-a.json:a1",
|
|
387
883
|
"mode": "preloaded",
|
|
@@ -1398,7 +1894,6 @@
|
|
|
1398
1894
|
],
|
|
1399
1895
|
"unknown": [],
|
|
1400
1896
|
"assumptions": [
|
|
1401
|
-
"termination_by_elaborator:List.append",
|
|
1402
1897
|
"termination_by_elaborator:Nat.add"
|
|
1403
1898
|
]
|
|
1404
1899
|
}
|
package/modules/algebra.cell
CHANGED
|
Binary file
|
package/modules/array.cell
CHANGED
|
Binary file
|
package/modules/decidable.cell
CHANGED
|
Binary file
|
package/modules/fin.cell
CHANGED
|
Binary file
|
package/modules/function.cell
CHANGED
|
Binary file
|
package/modules/functor.cell
CHANGED
|
Binary file
|
package/modules/index.json
CHANGED
|
@@ -1,36 +1,37 @@
|
|
|
1
1
|
{
|
|
2
|
-
"source_hash": "
|
|
2
|
+
"source_hash": "b8199dc4cc0b2dbd0e3f66612bc84cd57334f6824c13c3f9d68ab735b2f7b0d3",
|
|
3
3
|
"modules": {
|
|
4
|
-
"algebra": {"deps": ["int", "nat", "ring", "algebra"], "bytes":
|
|
5
|
-
"array": {"deps": ["nat", "list", "array"], "bytes":
|
|
6
|
-
"decidable": {"deps": ["decidable"], "bytes":
|
|
4
|
+
"algebra": {"deps": ["int", "nat", "ring", "algebra"], "bytes": 115317},
|
|
5
|
+
"array": {"deps": ["nat", "list", "array"], "bytes": 91215},
|
|
6
|
+
"decidable": {"deps": ["decidable"], "bytes": 81880},
|
|
7
7
|
"either": {"deps": ["either"], "bytes": 50001},
|
|
8
|
-
"fin": {"deps": ["fin"], "bytes":
|
|
9
|
-
"function": {"deps": ["function"], "bytes":
|
|
10
|
-
"functor": {"deps": ["functor"], "bytes":
|
|
11
|
-
"int": {"deps": ["int"], "bytes":
|
|
12
|
-
"intlinarith": {"deps": ["nat", "ring", "int", "intring", "linarith", "intlinarith"], "bytes":
|
|
13
|
-
"intomega": {"deps": ["nat", "ring", "linarith", "omega", "int", "intring", "intlinarith", "intomega"], "bytes":
|
|
14
|
-
"intring": {"deps": ["nat", "ring", "int", "intring"], "bytes":
|
|
15
|
-
"json": {"deps": ["int", "json"], "bytes":
|
|
16
|
-
"linarith": {"deps": ["nat", "ring", "linarith"], "bytes":
|
|
17
|
-
"linsys": {"deps": ["nat", "ring", "int", "intring", "linsys"], "bytes":
|
|
18
|
-
"list": {"deps": ["list"], "bytes":
|
|
19
|
-
"map": {"deps": ["ord", "map"], "bytes":
|
|
20
|
-
"meta": {"deps": ["option", "meta"], "bytes":
|
|
21
|
-
"monad": {"deps": ["functor", "monad"], "bytes":
|
|
8
|
+
"fin": {"deps": ["fin"], "bytes": 44972},
|
|
9
|
+
"function": {"deps": ["function"], "bytes": 76092},
|
|
10
|
+
"functor": {"deps": ["functor"], "bytes": 60334},
|
|
11
|
+
"int": {"deps": ["int"], "bytes": 90934},
|
|
12
|
+
"intlinarith": {"deps": ["nat", "ring", "int", "intring", "linarith", "intlinarith"], "bytes": 90285},
|
|
13
|
+
"intomega": {"deps": ["nat", "ring", "linarith", "omega", "int", "intring", "intlinarith", "intomega"], "bytes": 77761},
|
|
14
|
+
"intring": {"deps": ["nat", "ring", "int", "intring"], "bytes": 75813},
|
|
15
|
+
"json": {"deps": ["int", "json"], "bytes": 75106},
|
|
16
|
+
"linarith": {"deps": ["nat", "ring", "linarith"], "bytes": 61917},
|
|
17
|
+
"linsys": {"deps": ["nat", "ring", "int", "intring", "linsys"], "bytes": 84130},
|
|
18
|
+
"list": {"deps": ["list"], "bytes": 102919},
|
|
19
|
+
"map": {"deps": ["ord", "map"], "bytes": 43359},
|
|
20
|
+
"meta": {"deps": ["option", "meta"], "bytes": 56109},
|
|
21
|
+
"monad": {"deps": ["functor", "monad"], "bytes": 64066},
|
|
22
22
|
"nat": {"deps": ["nat"], "bytes": 74234},
|
|
23
|
-
"omega": {"deps": ["nat", "ring", "linarith", "omega"], "bytes":
|
|
23
|
+
"omega": {"deps": ["nat", "ring", "linarith", "omega"], "bytes": 57608},
|
|
24
24
|
"option": {"deps": ["option"], "bytes": 64335},
|
|
25
|
-
"ord": {"deps": ["ord"], "bytes":
|
|
26
|
-
"ordering": {"deps": ["ord", "
|
|
27
|
-
"
|
|
25
|
+
"ord": {"deps": ["ord"], "bytes": 35783},
|
|
26
|
+
"ordering": {"deps": ["ord", "ordering"], "bytes": 39508},
|
|
27
|
+
"ordering.relations": {"deps": ["int", "ordering.relations"], "bytes": 98888},
|
|
28
|
+
"polyrith": {"deps": ["nat", "ring", "int", "intring", "linarith", "intlinarith", "polyrith"], "bytes": 74152},
|
|
28
29
|
"prod": {"deps": ["prod"], "bytes": 76120},
|
|
29
|
-
"ring": {"deps": ["nat", "ring"], "bytes":
|
|
30
|
+
"ring": {"deps": ["nat", "ring"], "bytes": 53702},
|
|
30
31
|
"sigma": {"deps": ["sigma"], "bytes": 66048},
|
|
31
|
-
"tree": {"deps": ["tree"], "bytes":
|
|
32
|
+
"tree": {"deps": ["tree"], "bytes": 52945},
|
|
32
33
|
"unit": {"deps": ["unit"], "bytes": 63055},
|
|
33
|
-
"vector": {"deps": ["fin", "vector"], "bytes":
|
|
34
|
-
"winding": {"deps": ["int", "decidable", "winding"], "bytes":
|
|
34
|
+
"vector": {"deps": ["fin", "vector"], "bytes": 43900},
|
|
35
|
+
"winding": {"deps": ["int", "decidable", "winding"], "bytes": 92894}
|
|
35
36
|
}
|
|
36
37
|
}
|
package/modules/int.cell
CHANGED
|
Binary file
|
package/modules/intlinarith.cell
CHANGED
|
Binary file
|
package/modules/intomega.cell
CHANGED
|
Binary file
|
package/modules/intring.cell
CHANGED
|
Binary file
|
package/modules/json.cell
CHANGED
|
Binary file
|
package/modules/linarith.cell
CHANGED
|
Binary file
|
package/modules/linsys.cell
CHANGED
|
Binary file
|
package/modules/list.cell
CHANGED
|
Binary file
|
package/modules/map.cell
CHANGED
|
Binary file
|
package/modules/meta.cell
CHANGED
|
Binary file
|
package/modules/monad.cell
CHANGED
|
Binary file
|
package/modules/omega.cell
CHANGED
|
Binary file
|
package/modules/ord.cell
CHANGED
|
Binary file
|
package/modules/ordering.cell
CHANGED
|
Binary file
|
|
Binary file
|
package/modules/polyrith.cell
CHANGED
|
Binary file
|
package/modules/ring.cell
CHANGED
|
Binary file
|
package/modules/tree.cell
CHANGED
|
Binary file
|
package/modules/vector.cell
CHANGED
|
Binary file
|
package/modules/winding.cell
CHANGED
|
Binary file
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cella-lang",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.202610312349",
|
|
4
4
|
"description": "The Cella proof checker (cubical type theory with QTT) compiled to WebAssembly — browsers and Node.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "cella.js",
|
|
@@ -8,17 +8,17 @@
|
|
|
8
8
|
"exports": {
|
|
9
9
|
".": { "types": "./cella.d.ts", "default": "./cella.js" },
|
|
10
10
|
"./assets": "./assets.js",
|
|
11
|
-
"./host": "./cella-host.mjs",
|
|
11
|
+
"./host": { "types": "./cella-host.d.ts", "default": "./cella-host.mjs" },
|
|
12
12
|
"./dap": "./cella-dap.mjs",
|
|
13
13
|
"./corpus.json": "./corpus.json",
|
|
14
14
|
"./package.json": "./package.json"
|
|
15
15
|
},
|
|
16
16
|
"files": ["cella.js", "cella_bg.wasm", "cella.d.ts", "cella_bg.wasm.d.ts",
|
|
17
|
-
"stdlib.cell", "modules/", "assets.js", "cella-host.mjs", "cella-dap.mjs", "corpus.json", "README.md", "CHANGES.md", "LICENSE", "NOTICE"],
|
|
17
|
+
"stdlib.cell", "modules/", "assets.js", "cella-host.mjs", "cella-host.d.ts", "cella-dap.mjs", "corpus.json", "README.md", "CHANGES.md", "LICENSE", "NOTICE"],
|
|
18
18
|
"keywords": ["cella", "proof", "type-theory", "cubical", "wasm", "theorem-prover"],
|
|
19
19
|
"homepage": "https://cella-lang.org/",
|
|
20
20
|
"license": "Apache-2.0",
|
|
21
21
|
"author": "SungYu Chang",
|
|
22
22
|
"engines": { "node": ">=18" },
|
|
23
|
-
"cella": { "checkerHash": "
|
|
23
|
+
"cella": { "checkerHash": "586b0f744f1cee8a", "semanticsHash": "42f803337cd7935c", "filesHash": "496013be36c2cc51", "commit": "617b2e335bed66747688ce927550496ac0759225" }
|
|
24
24
|
}
|
package/stdlib.cell
CHANGED
|
Binary file
|