Skip to content

Commit

Permalink
Merge pull request #1129 from herbie-fp/autofix-12-1
Browse files Browse the repository at this point in the history
Automated Resyntax fixes
  • Loading branch information
pavpanchekha authored Jan 20, 2025
2 parents 42d9ae4 + 7183cd9 commit d03acf0
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 36 deletions.
60 changes: 27 additions & 33 deletions src/reports/common.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -202,7 +202,7 @@
(define fabs-impl (get-fpcore-impl 'fabs (repr->prop r) (list r)))
(define e (list fabs-impl x))
(define c (context (list x) r r))
(format "~a = ~a" x* (converter* e c))]
(list (format "~a = ~a" x* (converter* e c)))]
[(list 'negabs x)
; TODO: why are x* and x-sign unused?
(define x* (string->symbol (format "~a_m" x)))
Expand All @@ -220,7 +220,7 @@
(define vs* (context-vars ctx*))
;; We added some sign-* variables to the front of the variable
;; list in `ctx*`, we only want the originals here
(format-sort-instruction (take-right vs* (length vs)) language)]))
(list (format-sort-instruction (take-right vs* (length vs)) language))]))

(define (format-sort-instruction vs l)
(match l
Expand Down Expand Up @@ -278,37 +278,31 @@
(define out-prog* (fpcore-add-props out-prog (list ':precision output-prec)))

(define versions
(reap
[sow]
(for ([(lang record) (in-dict languages)])
(match-define (list ext converter) record)
(when (and (fpcore? out-prog*) (or (equal? ext "fpcore") (supported-by-lang? out-prog* ext)))
(define name
(if identifier
(symbol->string identifier)
"code"))
(define out (converter out-prog* name))
(define prelude-lines
(string-join
(append-map (lambda (instruction)
(let ([l (format-prelude-instruction instruction ctx ctx* lang converter)])
(if (list? l)
l
(list l))))
instructions)
(if (equal? lang "TeX") "\\\\\n" "\n")
#:after-last "\n"))
(sow (cons lang
((if (equal? lang "TeX")
(curry format "\\begin{array}{l}\n~a\\\\\n~a\\end{array}\n")
string-append)
prelude-lines
out)))))))

(define math-out
(if (dict-has-key? versions "TeX")
(let ([val (dict-ref versions "TeX")]) val)
""))
(reap [sow]
(for ([(lang record) (in-dict languages)])
(match-define (list ext converter) record)
(when (and (fpcore? out-prog*)
(or (equal? ext "fpcore") (supported-by-lang? out-prog* ext)))
(define name
(if identifier
(symbol->string identifier)
"code"))
(define out (converter out-prog* name))
(define prelude-lines
(string-join
(append-map (lambda (instruction)
(format-prelude-instruction instruction ctx ctx* lang converter))
instructions)
(if (equal? lang "TeX") "\\\\\n" "\n")
#:after-last "\n"))
(sow (cons lang
((if (equal? lang "TeX")
(curry format "\\begin{array}{l}\n~a\\\\\n~a\\end{array}\n")
string-append)
prelude-lines
out)))))))

(define math-out (dict-ref versions "TeX" ""))

(define dropdown
`(select (option "Math")
Expand Down
3 changes: 1 addition & 2 deletions src/reports/core2mathjs.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,7 @@
[*gensym-collisions* 1]
[*gensym-fix-name* fix-name])
; make compiler context
(define ctx
(ctx-update-props (make-compiler-ctx) (append '(:precision binary64 :round nearestEven))))
(define ctx (ctx-update-props (make-compiler-ctx) '(:precision binary64 :round nearestEven)))

; translate
(define p (open-output-string))
Expand Down
3 changes: 2 additions & 1 deletion src/reports/plot.rkt
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,8 @@
; (a) a power of 10 between n and (n + ε) divisions below max where ε is some tolerance, or
; (b) a value, n divisions below max
(define sub-range (round (/ (- max min) (add1 number))))
(define near (λ (x n) (and (<= x n) (<= (abs (/ (- x n) sub-range)) 0.2)))) ; <- tolerance
(define (near x n)
(and (<= x n) (<= (abs (/ (- x n) sub-range)) 0.2))) ; <- tolerance
(for/list ([itr (in-range 1 (add1 number))])
(define power10
(first-power10 (ordinal->real (clamp (- max (* (add1 itr) sub-range)) min max) repr)
Expand Down

0 comments on commit d03acf0

Please sign in to comment.