Skip to content

Commit 97a9e9e

Browse files
committed
Bug fixes, remove expr->tex, fix bugs, fmt
1 parent 653e69f commit 97a9e9e

File tree

6 files changed

+110
-140
lines changed

6 files changed

+110
-140
lines changed

src/api/server.rkt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -478,7 +478,8 @@
478478
(match-define (alt-analysis alt test-errors) analysis)
479479
(define cost (alt-cost alt repr))
480480

481-
(define history (render-history alt pcontext (test-context test) errcache))
481+
(define history-json (render-json alt pcontext (test-context test) errcache))
482+
(define history (render-history history-json (test-context test)))
482483

483484
(define vars (test-vars test))
484485
(define splitpoints

src/reports/common.rkt

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@
3737
format-percent
3838
write-html
3939
program->fpcore
40-
program->tex
40+
fpcore->tex
4141
fpcore->string
4242
js-tex-include
4343
doc-url
@@ -159,10 +159,9 @@
159159
("Wolfram" "wl" ,core->wls)
160160
("TeX" "tex" ,(λ (c i) (core->tex c)))))
161161

162-
(define (program->tex prog ctx #:loc [loc #f])
163-
(define prog* (program->fpcore prog ctx))
164-
(if (supported-by-lang? prog* "tex")
165-
(core->tex prog* #:loc (and loc (cons 2 loc)) #:color "blue")
162+
(define (fpcore->tex fpcore #:loc [loc #f])
163+
(if (supported-by-lang? fpcore "tex")
164+
(core->tex fpcore #:loc (and loc (cons 2 loc)) #:color "blue")
166165
"ERROR"))
167166

168167
(define (render-program expr ctx #:ident [identifier #f] #:pre [precondition '(TRUE)])

src/reports/history.rkt

Lines changed: 63 additions & 94 deletions
Original file line numberDiff line numberDiff line change
@@ -58,18 +58,6 @@
5858
(define err (errors-score-masked (hash-ref errcache (alt-expr altn)) mask))
5959
(format-accuracy err repr #:unit "%"))
6060

61-
(define (expr->fpcore expr ctx #:ident [ident #f])
62-
(list 'FPCore
63-
(context-vars ctx)
64-
(let loop ([expr expr])
65-
(match expr
66-
[(? symbol?) expr]
67-
[(? number?) expr]
68-
[(? literal?) (literal-value expr)]
69-
[(approx spec impl) (loop impl)]
70-
[(hole precision spec) (loop spec)]
71-
[(list op args ...) (cons op (map loop args))]))))
72-
7361
(define (mixed->fpcore expr ctx)
7462
(define expr*
7563
(let loop ([expr expr])
@@ -122,65 +110,49 @@
122110
(make-list (pcontext-length pcontext) #f))
123111

124112
;; HTML renderer for derivations
125-
(define (render-history altn pcontext ctx errcache [mask (make-mask pcontext)])
126-
(match altn
127-
[(alt prog 'start (list) _)
128-
(define err (altn-errors altn pcontext ctx errcache mask))
113+
(define (render-history json ctx)
114+
(define err
115+
(match (hash-ref json 'error)
116+
[(? number? n) (format-accuracy n (context-repr ctx) #:unit "%")]
117+
[other other]))
118+
(define prog (read (open-input-string (hash-ref json 'program))))
119+
(match (hash-ref json 'type)
120+
["start"
129121
(list `(li (p "Initial program " (span ((class "error")) ,err))
130-
(div ((class "math")) "\\[" ,(program->tex prog ctx) "\\]")))]
122+
(div ((class "math")) "\\[" ,(fpcore->tex prog) "\\]")))]
131123

132-
[(alt prog 'add-preprocessing `(,prev) _)
133-
;; TODO message to user is? proof later
134-
`(,@(render-history prev pcontext ctx errcache mask) (li "Add Preprocessing"))]
135-
136-
[(alt _ `(regimes ,splitpoints) prevs _)
137-
(define intervals
138-
(for/list ([start-sp (cons (sp -1 -1 #f) splitpoints)]
139-
[end-sp splitpoints])
140-
(interval (sp-cidx end-sp) (sp-point start-sp) (sp-point end-sp) (sp-bexpr end-sp))))
141-
(define repr (context-repr ctx))
124+
["add-preprocessing" `(,@(render-history (hash-ref json 'prev) ctx) (li "Add Preprocessing"))]
142125

126+
["regimes"
127+
(define prevs (hash-ref json 'prevs))
143128
`((li ((class "event")) "Split input into " ,(~a (length prevs)) " regimes")
144129
(li ,@(apply append
145-
(for/list ([entry prevs]
146-
[idx (in-naturals)]
147-
[new-mask (regimes-pcontext-masks pcontext splitpoints prevs ctx)])
148-
(define mask* (map and-fn mask new-mask))
149-
(define entry-ivals
150-
(filter (λ (intrvl) (= (interval-alt-idx intrvl) idx)) intervals))
151-
(define condition
152-
(string-join (map (curryr interval->string repr) entry-ivals) " or "))
153-
`((h2 (code "if " (span ((class "condition")) ,condition)))
154-
(ol ,@(render-history entry pcontext ctx errcache mask*))))))
130+
(for/list ([entry (in-list prevs)]
131+
[condition (in-list (hash-ref json 'conditions))])
132+
`((h2 (code "if " (span ((class "condition")) ,(string-join condition " or "))))
133+
(ol ,@(render-history entry ctx))))))
155134
(li ((class "event")) "Recombined " ,(~a (length prevs)) " regimes into one program."))]
156135

157-
[(alt prog `(taylor ,loc ,pt ,var) `(,prev) _)
158-
(define core (mixed->fpcore prog ctx))
159-
`(,@(render-history prev pcontext ctx errcache mask)
160-
(li (p "Taylor expanded in " ,(~a var) " around " ,(~a pt))
161-
(div ((class "math"))
162-
"\\[\\leadsto "
163-
,(core->tex core #:loc (and loc (cons 2 loc)) #:color "blue")
164-
"\\]")))]
136+
["taylor"
137+
(define-values (prev pt var loc) (apply values (map (curry hash-ref json) '(prev pt var loc))))
138+
`(,@(render-history prev ctx)
139+
(li (p "Taylor expanded in " ,var " around " ,pt)
140+
(div ((class "math")) "\\[\\leadsto " ,(fpcore->tex prog #:loc loc) "\\]")))]
165141

166-
[(alt prog `(evaluate ,loc) `(,prev) _)
167-
(define core (mixed->fpcore prog ctx))
168-
(define err (altn-errors altn pcontext ctx errcache mask))
169-
`(,@(render-history prev pcontext ctx errcache mask)
142+
["evaluate"
143+
(define-values (prev loc) (apply values (map (curry hash-ref json) '(prev loc))))
144+
`(,@(render-history prev ctx)
170145
(li (p "Evaluated real constant" (span ((class "error")) ,err))
171-
(div ((class "math"))
172-
"\\[\\leadsto "
173-
,(core->tex core #:loc (and loc (cons 2 loc)) #:color "blue")
174-
"\\]")))]
146+
(div ((class "math")) "\\[\\leadsto " ,(fpcore->tex prog #:loc loc) "\\]")))]
175147

176-
[(alt prog `(rr ,loc ,input ,proof) `(,prev) _)
177-
(define err (altn-errors altn pcontext ctx errcache mask))
178-
`(,@(render-history prev pcontext ctx errcache mask)
179-
(li ,(if proof
180-
(render-proof (render-proof-json proof pcontext ctx errcache mask) ctx)
181-
""))
148+
["rr"
149+
(define-values (prev loc proof) (apply values (map (curry hash-ref json) '(prev loc proof))))
150+
`(,@(render-history prev ctx)
151+
(li ,(if (eq? proof (json-null))
152+
""
153+
(render-proof proof ctx)))
182154
(li (p "Applied rewrites" (span ((class "error")) ,err))
183-
(div ((class "math")) "\\[\\leadsto " ,(program->tex prog ctx #:loc loc) "\\]")))]))
155+
(div ((class "math")) "\\[\\leadsto " ,(fpcore->tex prog #:loc loc) "\\]")))]))
184156

185157
(define (errors-score-masked errs mask)
186158
(if (ormap identity mask)
@@ -191,29 +163,28 @@
191163
(errors-score errs)))
192164

193165
(define (render-proof proof-json ctx)
194-
`(div ([class "proof"])
195-
(details (summary "Step-by-step derivation")
196-
(ol ,@(for/list ([step (in-list proof-json)])
197-
(define-values (direction err loc rule prog-str)
198-
(apply values (map (curry hash-ref step)
199-
'(direction error loc rule program))))
200-
(define dir
201-
(match direction
202-
["goal" "goal"]
203-
["rtl" "right to left"]
204-
["ltr" "left to right"]))
205-
(define prog (read (open-input-string prog-str)))
206-
(if (equal? dir "goal")
207-
""
208-
`(li (p (code ([title ,dir]) ,rule)
209-
(span ([class "error"])
210-
,(if (number? err)
211-
(format-accuracy err (context-repr ctx) #:unit "%")
212-
err)))
213-
(div ((class "math"))
214-
"\\[\\leadsto "
215-
,(core->tex prog #:loc (and loc (cons 2 loc)) #:color "blue")
216-
"\\]"))))))))
166+
`(div
167+
((class "proof"))
168+
(details
169+
(summary "Step-by-step derivation")
170+
(ol ,@
171+
(for/list ([step (in-list proof-json)])
172+
(define-values (direction err loc rule prog-str)
173+
(apply values (map (curry hash-ref step) '(direction error loc rule program))))
174+
(define dir
175+
(match direction
176+
["goal" "goal"]
177+
["rtl" "right to left"]
178+
["ltr" "left to right"]))
179+
(define prog (read (open-input-string prog-str)))
180+
(if (equal? dir "goal")
181+
""
182+
`(li (p (code ([title ,dir]) ,rule)
183+
(span ((class "error"))
184+
,(if (number? err)
185+
(format-accuracy err (context-repr ctx) #:unit "%")
186+
err)))
187+
(div ((class "math")) "\\[\\leadsto " ,(fpcore->tex prog #:loc loc) "\\]"))))))))
217188

218189
(define (render-json altn pcontext ctx errcache [mask (make-list (pcontext-length pcontext) #f)])
219190
(define repr (context-repr ctx))
@@ -224,16 +195,17 @@
224195

225196
(match altn
226197
[(alt prog 'start (list) _)
227-
`#hash((program . ,(fpcore->string (expr->fpcore prog ctx))) (type . "start") (error . ,err))]
198+
`#hash((program . ,(fpcore->string (program->fpcore prog ctx))) (type . "start") (error . ,err))]
228199

229200
[(alt prog `(regimes ,splitpoints) prevs _)
230201
(define intervals
231202
(for/list ([start-sp (cons (sp -1 -1 #f) splitpoints)]
232203
[end-sp splitpoints])
233204
(interval (sp-cidx end-sp) (sp-point start-sp) (sp-point end-sp) (sp-bexpr end-sp))))
234205

235-
`#hash((program . ,(fpcore->string (expr->fpcore prog ctx)))
206+
`#hash((program . ,(fpcore->string (program->fpcore prog ctx)))
236207
(type . "regimes")
208+
(error . ,err)
237209
(conditions . ,(for/list ([entry prevs]
238210
[idx (in-naturals)])
239211
(define entry-ivals
@@ -245,7 +217,7 @@
245217
(render-json entry pcontext ctx errcache mask*))))]
246218

247219
[(alt prog `(taylor ,loc ,pt ,var) `(,prev) _)
248-
`#hash((program . ,(fpcore->string (expr->fpcore prog ctx)))
220+
`#hash((program . ,(fpcore->string (program->fpcore prog ctx)))
249221
(type . "taylor")
250222
(prev . ,(render-json prev pcontext ctx errcache mask))
251223
(pt . ,(~a pt))
@@ -254,14 +226,14 @@
254226
(error . ,err))]
255227

256228
[(alt prog `(evaluate ,loc) `(,prev) _)
257-
`#hash((program . ,(fpcore->string (expr->fpcore prog ctx)))
229+
`#hash((program . ,(fpcore->string (program->fpcore prog ctx)))
258230
(type . "evaluate")
259231
(prev . ,(render-json prev pcontext ctx errcache mask))
260232
(loc . ,loc)
261233
(error . ,err))]
262234

263235
[(alt prog `(rr ,loc ,input ,proof) `(,prev) _)
264-
`#hash((program . ,(fpcore->string (expr->fpcore prog ctx)))
236+
`#hash((program . ,(fpcore->string (program->fpcore prog ctx)))
265237
(type . "rr")
266238
(prev . ,(render-json prev pcontext ctx errcache mask))
267239
(proof . ,(if proof
@@ -271,7 +243,7 @@
271243
(error . ,err))]
272244

273245
[(alt prog 'add-preprocessing `(,prev) preprocessing)
274-
`#hash((program . ,(fpcore->string (expr->fpcore prog ctx)))
246+
`#hash((program . ,(fpcore->string (program->fpcore prog ctx)))
275247
(type . "add-preprocessing")
276248
(prev . ,(render-json prev pcontext ctx errcache mask))
277249
(error . ,err)
@@ -283,14 +255,11 @@
283255
(define-values (err fpcore)
284256
(cond
285257
[(impl-prog? expr)
286-
(values (errors-score-masked (hash-ref errcache expr) mask)
287-
(program->fpcore expr ctx))]
288-
[else
289-
(values "N/A" (mixed->fpcore expr ctx))]))
258+
(values (errors-score-masked (hash-ref errcache expr) mask) (program->fpcore expr ctx))]
259+
[else (values "N/A" (mixed->fpcore expr ctx))]))
290260

291261
`#hash((error . ,err)
292262
(program . ,(fpcore->string fpcore))
293-
294263
(direction . ,(match dir
295264
['Rewrite<= "rtl"]
296265
['Rewrite=> "ltr"]

src/reports/make-graph.rkt

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -86,10 +86,9 @@
8686
"Percentage Accurate"
8787
(format-accuracy (errors-score start-error) repr #:unit "%")
8888
(format-accuracy (errors-score end-error) repr #:unit "%")
89-
#:title
90-
(format "Minimum Accuracy: ~a → ~a"
91-
(format-accuracy (apply max (map ulps->bits start-error)) repr #:unit "%")
92-
(format-accuracy (apply max (map ulps->bits end-error)) repr #:unit "%")))
89+
#:title (format "Minimum Accuracy: ~a → ~a"
90+
(format-accuracy (apply max (map ulps->bits start-error)) repr #:unit "%")
91+
(format-accuracy (apply max (map ulps->bits end-error)) repr #:unit "%")))
9392
,(render-large "Time" (format-time time))
9493
,(render-large "Alternatives" (~a (length end-exprs)))
9594
,(if (*pareto-mode*)
@@ -175,17 +174,16 @@
175174
(define target-cost (hash-ref target 'cost))
176175
(define target-expr (read (open-input-string (hash-ref target 'expr))))
177176
(let-values ([(dropdown body) (render-program target-expr ctx #:ident identifier)])
178-
`(section
179-
([id ,(format "target~a" i)] (class "programs"))
180-
(h2 "Developer Target "
181-
,(~a i)
182-
": "
183-
(span ((class "subhead"))
184-
(data ,(format-accuracy (errors-score target-error) repr #:unit "%"))
185-
" accurate, "
186-
(data ,(~r (/ start-cost target-cost) #:precision '(= 1)) "×")
187-
" speedup")
188-
,dropdown
189-
,(render-help "report.html#target"))
190-
,body)))
177+
`(section ([id ,(format "target~a" i)] (class "programs"))
178+
(h2 "Developer Target "
179+
,(~a i)
180+
": "
181+
(span ((class "subhead"))
182+
(data ,(format-accuracy (errors-score target-error) repr #:unit "%"))
183+
" accurate, "
184+
(data ,(~r (/ start-cost target-cost) #:precision '(= 1)) "×")
185+
" speedup")
186+
,dropdown
187+
,(render-help "report.html#target"))
188+
,body)))
191189
,(render-reproduction test))))

src/reports/timeline.rkt

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -309,19 +309,19 @@
309309

310310
(define (render-phase-alts alts)
311311
`((dt "Alt Table")
312-
(dd (details
313-
(summary "Click to see full alt table")
314-
(table ((class "times"))
315-
(thead (tr (th "Status") (th "Accuracy") (th "Program")))
316-
,@(for/list ([rec (in-list alts)])
317-
(match-define (list expr status score repr-name) rec)
318-
(define repr (get-representation (read (open-input-string repr-name))))
319-
`(tr ,(match status
320-
["next" `(td (span ([title "Selected for next iteration"]) ""))]
321-
["done" `(td (span ([title "Selected in a prior iteration"]) ""))]
322-
["fresh" `(td)])
323-
(td ,(format-accuracy score repr #:unit "%") "")
324-
(td (pre ,expr)))))))))
312+
(dd (details (summary "Click to see full alt table")
313+
(table ((class "times"))
314+
(thead (tr (th "Status") (th "Accuracy") (th "Program")))
315+
,@
316+
(for/list ([rec (in-list alts)])
317+
(match-define (list expr status score repr-name) rec)
318+
(define repr (get-representation (read (open-input-string repr-name))))
319+
`(tr ,(match status
320+
["next" `(td (span ([title "Selected for next iteration"]) ""))]
321+
["done" `(td (span ([title "Selected in a prior iteration"]) ""))]
322+
["fresh" `(td)])
323+
(td ,(format-accuracy score repr #:unit "%") "")
324+
(td (pre ,expr)))))))))
325325

326326
(define (render-phase-times times)
327327
`((dt "Calls")
@@ -364,15 +364,15 @@
364364
" saved)"))))
365365

366366
(define (render-phase-branches branches)
367-
`((dt "Results")
368-
(dd (table ((class "times"))
369-
(thead (tr (th "Accuracy") (th "Segments") (th "Branch")))
370-
,@(for/list ([rec (in-list branches)])
371-
(match-define (list expr score splits repr-name) rec)
372-
(define repr (get-representation (read (open-input-string repr-name))))
373-
`(tr (td ,(format-accuracy score repr #:unit "%") "")
374-
(td ,(~a splits))
375-
(td (code ,expr))))))))
367+
`((dt "Results") (dd (table ((class "times"))
368+
(thead (tr (th "Accuracy") (th "Segments") (th "Branch")))
369+
,@(for/list ([rec (in-list branches)])
370+
(match-define (list expr score splits repr-name) rec)
371+
(define repr
372+
(get-representation (read (open-input-string repr-name))))
373+
`(tr (td ,(format-accuracy score repr #:unit "%") "")
374+
(td ,(~a splits))
375+
(td (code ,expr))))))))
376376

377377
(define (render-phase-outcomes outcomes)
378378
`((dt "Samples") (dd (table ((class "times"))

src/syntax/sugar.rkt

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -242,16 +242,19 @@
242242
(define (munge expr #:root? [root? #f])
243243
(match expr
244244
[(? literal?) (literal->fpcore expr)]
245+
[(? number?) expr]
245246
[(? symbol?) expr]
246247
[(approx _ impl) (munge impl)]
248+
[(hole _ spec) (munge spec)]
247249
[(list 'if cond ift iff) (list 'if (munge cond) (munge ift) (munge iff))]
248250
[(list (? impl-exists? impl) args ...)
249251
(define args* (map munge args))
250252
(define vars (impl-info impl 'vars))
251253
(define node (replace-vars (map cons vars args*) (impl-info impl 'fpcore)))
252254
(if root?
253255
node
254-
(push! impl node))]))
256+
(push! impl node))]
257+
[(list spec-op args ...) (list* spec-op (map munge args))]))
255258

256259
(define root (munge expr #:root? #t))
257260
(cons (list->vector (reverse instrs)) root))

0 commit comments

Comments
 (0)