Skip to content

Commit ceff165

Browse files
committed
simplify example for Feedback.with_traces in docfile
1 parent 31242d6 commit ceff165

File tree

2 files changed

+23
-78
lines changed

2 files changed

+23
-78
lines changed

help/Docfiles/Feedback.with_traces.md

Lines changed: 16 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ Feedback.with_traces : (string * int) list -> ('a -> 'b) -> 'a -> 'b
88

99
Invoke a function with specified levels for traces.
1010

11-
The `with_traces` function is used to set values for a collection of
11+
The `with_traces` function is used to set values of a collection of
1212
tracing variables for the duration of one top-level function call.
1313

1414
In a state where trace variables designated by `nm_1,...,nm_k` have
@@ -30,67 +30,28 @@ if the function invocation fails.
3030

3131
### Example
3232

33-
In the following we make a recursive definition, temporarily setting
34-
some traces so that aspects of the internal workings of the definition
35-
mechanism are printed out. First we find the present values of the
36-
trace variables:
37-
33+
First we define a convenience function.
3834
``` hol4
39-
> map current_trace
40-
["Definition.TC extraction",
41-
"Definition.termination candidates"];
42-
val it = [0, 0]: int list (* default values *)
35+
> fun pr_thm th = (print_thm th; print "\n");
36+
val pr_thm = fn: thm -> unit
4337
```
44-
Now we make the definition while locally setting the trace values:
45-
``` hol4
46-
> with_traces [("Definition.TC extraction", 3),
47-
("Definition.termination candidates",2)]
48-
Define
49-
`fact n = if n = 0 then 1 else n * fact (n-1)`;
50-
51-
# # # #
52-
------------------------
53-
TC extraction on clause:
54-
55-
fact n = if n = 0 then 1 else n * RESTRICT fact R n (n − 1)
56-
57-
Extracting from:
58-
59-
n = 0
60-
61-
push_context:
62-
n = 0
6338

64-
Extracting from:
39+
Now we examine a theorem with and without traces set to local values.
6540

66-
1
67-
68-
push_context:
69-
n ≠ 0
70-
71-
Extracting from:
72-
73-
n * RESTRICT fact R n (n − 1)
74-
75-
TC Capture:
76-
[n ≠ 0, n ≠ 0 ⇒ R (n − 1) n] ⊢ RESTRICT fact R n (n − 1) = fact (n − 1)
41+
``` hol4
42+
> map current_trace ["assumptions", "types"] ;
43+
val it = [0, 0]: int list
7744
78-
Termination conditions: 1
79-
Candidate termination relations generated: 2
80-
Termination proof successful with candidate 1:
81-
inv_image $< (λx. x)
45+
> pr_thm EQ_SYM_EQ;
46+
⊢ ∀x y. x = y ⇔ y = x
47+
val it = (): unit
8248
83-
Equations stored under "fact_def".
84-
Induction stored under "fact_ind".
85-
val it = ⊢ ∀n. fact n = if n = 0 then 1 else n * fact (n − 1): thm
86-
```
49+
> with_traces [("assumptions",1), ("types",1)] pr_thm EQ_SYM_EQ;
50+
[] ⊢ ∀(x :α) (y :α). x = y ⇔ y = x
51+
val it = (): unit
8752
88-
And the trace values have been restored:
89-
``` hol4
90-
> map current_trace
91-
["Definition.TC extraction",
92-
"Definition.termination candidates"]
93-
val it = [0, 0]: int list (* back to default values *)
53+
> map current_trace ["assumptions", "types"] ;
54+
val it = [0, 0]: int list
9455
```
9556

9657
### See also

src/prekernel/Feedback.sml

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -420,40 +420,24 @@ fun current_trace nm =
420420
| NONE => registered_err "current_trace" nm
421421

422422
fun with_traces flags f x =
423-
let fun update_flag (nm,new) =
423+
let fun update_flag (nm,j) =
424424
case find_record nm
425425
of NONE => registered_err "with_traces" nm
426-
| SOME (recd as {value, maximum, ...}) =>
427-
let val orig = trfp_get value
428-
fun reset_value() = trfp_set value orig
429-
in bound_check "with_traces" nm maximum new;
430-
trfp_set value new;
426+
| SOME {value, maximum, ...} =>
427+
let val i = trfp_get value
428+
fun reset_value() = trfp_set value i
429+
in bound_check "with_traces" nm maximum j;
430+
trfp_set value j;
431431
reset_value end
432432
val reset_fns = map update_flag flags
433433
fun reset_flags() = List.app (fn f => f()) reset_fns
434434
val y = f x handle e => (reset_flags(); Portable.reraise e)
435435
in
436-
reset_flags(); y
436+
reset_flags(); y
437437
end
438438

439439
fun trace flag = with_traces [flag]
440440

441-
(*
442-
fun trace (nm, i) f x =
443-
case find_record nm of
444-
NONE => registered_err "trace" nm
445-
| SOME {value, maximum, ...} =>
446-
(bound_check "trace" nm maximum i
447-
; let
448-
val init = trfp_get value
449-
val _ = trfp_set value i
450-
val y = f x handle e => (trfp_set value init; Portable.reraise e)
451-
val _ = trfp_set value init
452-
in
453-
y
454-
end)
455-
*)
456-
457441
val () = register_btrace ("assumptions", Globals.show_assums)
458442
val () = register_btrace ("numeral types", Globals.show_numeral_types)
459443

0 commit comments

Comments
 (0)