# -*- coding: utf-8 -*-
-"""
-Examine solution as an outline of computation.
-
-TODO: shared substructure.
-
-"""
import re
-from utils import yellow, green, cyan, red, _repr, drepr
-import debug, defn
+from collections import defaultdict
+import debug, defn
from draw_circuit import infer_edges
-from collections import defaultdict
+from utils import yellow, green, cyan, red, _repr
class trace(object):
"""
- Examine solution as an outline of computation.
+ Examine solution as an outline of computation. Essentially it computes
+ `trace` for every term in the current solution.
+
+ See `help trace` for more information on `trace`.
"""
def __init__(self, interp):
> b :- c.
> c.
-
In our solution we see that `a` is true.
> sol
The way trace lets you know that it has omitted something is with a
message `item: shared structure see above` or `item: *cycle*`.
- > trace bar(10,10)
+ > trace bar(10, 10)
bar(10,10) = 220
|
│
│ foo(X=10) = (X=10 + 1)=11.
│
+ │
└─ += 110
bar(A=10, B=10) += (A=10 * foo(B=10)=11)=110.
|
- └─ foo(10): shared structure see above
+ └─ foo(10) = 11
+ |
+ └─ continue as before (shared structure)
+
+
+ Now, let's have a look at the geometric series, `a`.
> trace a
├─ += 1
│
│ a += 1.
+ │
└─ += 1.0
a += (a=2.0 / 2)=1.0.
|
- └─ a: *cycle*
+ └─ a = 2.0
+ |
+ └─ continue as before (cyclic structure, will continue forever)
"""