Skip to content

Commit 0d1aff1

Browse files
committed
Replace the min-cost stuff with a simple multiplication by 100
1 parent a6fd8c8 commit 0d1aff1

File tree

1 file changed

+13
-31
lines changed

1 file changed

+13
-31
lines changed

src/core/egglog-herbie.rkt

Lines changed: 13 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -209,8 +209,10 @@
209209
(batchref-idx (batch-push! batch term))))
210210
(batchref batch idx))
211211

212-
(define (normalize-cost c min-cost)
213-
(exact-round (* (/ c min-cost) 100)))
212+
;; Egglog requires integer costs, but Herbie uses floating-point costs.
213+
;; Scale by 1000 to convert Herbie's float costs to Egglog's integer costs.
214+
(define (normalize-cost c)
215+
(exact-round (* c 1000)))
214216

215217
(define (prelude curr-program #:mixed-egraph? [mixed-egraph? #t])
216218
(define pform (*active-platform*))
@@ -220,30 +222,12 @@
220222

221223
(egglog-program-add! spec-egraph curr-program)
222224

223-
;;; To add support for floating point cost (which egglog does not support), compute
224-
;;; the minimum by accumulating all raw costs and normalize them
225-
(define raw-costs '())
226-
227-
;; Add raw num-typed-nodes and var-typed-nodes costs
228-
(for ([repr (in-list (all-repr-names))])
229-
(set! raw-costs (cons (platform-repr-cost pform (get-representation repr)) raw-costs)))
230-
231-
;; Add raw platform-impl-nodes
232-
(for ([impl (in-list (platform-impls pform))])
233-
(set! raw-costs (cons (impl-info impl 'cost) raw-costs)))
234-
235-
(define nonzero-costs (filter (negate zero?) raw-costs))
236-
(define min-cost
237-
(if (empty? nonzero-costs)
238-
1
239-
(apply min nonzero-costs)))
240-
241225
(define typed-graph
242226
`(datatype MTy
243-
,@(num-typed-nodes pform min-cost)
244-
,@(var-typed-nodes pform min-cost)
227+
,@(num-typed-nodes pform)
228+
,@(var-typed-nodes pform)
245229
(Approx M MTy)
246-
,@(platform-impl-nodes pform min-cost)))
230+
,@(platform-impl-nodes pform)))
247231
(egglog-program-add! typed-graph curr-program)
248232

249233
(egglog-program-add! `(constructor do-lower (M String) MTy :unextractable) curr-program)
@@ -358,7 +342,7 @@
358342
`(,(serialize-op sound-op) ,@(make-list arity 'M) M :cost 4294967295)
359343
`(,(serialize-op unsound-op) ,@(make-list arity 'M) :cost 4294967295)))))
360344

361-
(define (platform-impl-nodes pform min-cost)
345+
(define (platform-impl-nodes pform)
362346
(for/list ([impl (in-list (platform-impls pform))])
363347
(define arity (length (impl-info impl 'itype)))
364348
(define typed-name (string->symbol (string-append (symbol->string (serialize-impl impl)) "Ty")))
@@ -367,28 +351,26 @@
367351
`(,typed-name ,@(for/list ([i (in-range arity)])
368352
'MTy)
369353
:cost
370-
,(normalize-cost (impl-info impl 'cost) min-cost))))
354+
,(normalize-cost (impl-info impl 'cost)))))
371355

372356
(define (typed-num-id repr-name)
373357
(string->symbol (string-append "Num" (symbol->string repr-name))))
374358

375359
(define (typed-var-id repr-name)
376360
(string->symbol (string-append "Var" (symbol->string repr-name))))
377361

378-
(define (num-typed-nodes pform min-cost)
362+
(define (num-typed-nodes pform)
379363
(for/list ([repr (in-list (all-repr-names))]
380364
#:when (not (eq? repr 'bool)))
381365
`(,(typed-num-id repr) BigRat
382366
:cost
383-
,(normalize-cost (platform-repr-cost pform (get-representation repr))
384-
min-cost))))
367+
,(normalize-cost (platform-repr-cost pform (get-representation repr))))))
385368

386-
(define (var-typed-nodes pform min-cost)
369+
(define (var-typed-nodes pform)
387370
(for/list ([repr (in-list (all-repr-names))])
388371
`(,(typed-var-id repr) String
389372
:cost
390-
,(normalize-cost (platform-repr-cost pform (get-representation repr))
391-
min-cost))))
373+
,(normalize-cost (platform-repr-cost pform (get-representation repr))))))
392374

393375
(define (num-lowering-rules)
394376
(for/list ([repr (in-list (all-repr-names))]

0 commit comments

Comments
 (0)