From b62f93d2b3f74922e7fd27cb39a092f81e6785d4 Mon Sep 17 00:00:00 2001 From: Bhargav Kulkarni Date: Sun, 22 Sep 2024 16:13:03 -0600 Subject: [PATCH] fix addition --- src/core/explain.rkt | 11 ++++++++--- src/core/logspace.rkt | 15 +++++++++++++-- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/core/explain.rkt b/src/core/explain.rkt index 7be9a39cc..948d63855 100644 --- a/src/core/explain.rkt +++ b/src/core/explain.rkt @@ -20,6 +20,9 @@ (provide explain actual-errors) +(define 100.l (flonum->logfl 100.0)) +(define 32.l (flonum->logfl 32.0)) + (define *top-3* (make-parameter #f)) (define MAX-EXP 1023) @@ -165,6 +168,8 @@ (define cond-x (abs (/ xfl (+ xfl yfl)))) (define cond-y (abs (/ yfl (+ xfl yfl)))) + ;(define cond-x.l (logabs (log/ xlog (log+ xlog ylog)))) + ;(define cond-y.l (logabs (log/ ylog (log+ xlog ylog)))) (define x.eps (+ 127 (bigfloat-exponent (exacts-ref x-ex)))) (define y.eps (+ 127 (bigfloat-exponent (exacts-ref y-ex)))) @@ -546,13 +551,13 @@ (define explanations-table (for/list ([(key val) (in-dict expls->points)] #:unless (zero? (length val))) - (define expr (car key)) + (define subexpr (car key)) (define expl (cdr key)) (define err-count (length val)) (define maybe-count (length (hash-ref maybe-expls->points key '()))) - (define flow-list (make-flow-table oflow-hash uflow-hash expr expl)) + (define flow-list (make-flow-table oflow-hash uflow-hash subexpr expl)) - (list (~a (car expr)) (~a expr) (~a expl) err-count maybe-count flow-list))) + (list (~a (car subexpr)) (~a subexpr) (~a expl) err-count maybe-count flow-list))) (define sorted-explanations-table (take-top-n (sort explanations-table > #:key fourth))) diff --git a/src/core/logspace.rkt b/src/core/logspace.rkt index 37dc0d30c..f6d6807ee 100644 --- a/src/core/logspace.rkt +++ b/src/core/logspace.rkt @@ -89,8 +89,8 @@ (if (log<= A B) A B)) (define (log+ A B) - (define P (logmax A B)) - (define Q (logmin A B)) + (define P (if (log>= (logabs A) (logabs B)) A B)) + (define Q (if (log< (logabs A) (logabs B)) A B)) (match-define (logfl a sa ea) P) (match-define (logfl b sb eb) Q) (define x (- eb ea)) @@ -251,3 +251,14 @@ [(list (or 'PI.f64 'PI.f32 'E.f64 'E.f32)) (flonum->logfl ((impl-info (first expr) 'fl)))] [(list op args ...) (cons (op->logop op) (map expr->logfl args))] [sym sym])) + +(define x (flonum->logfl 2e+103)) +(define 1.l (flonum->logfl 1.0)) +(define 2.l (flonum->logfl 2.0)) + +(define x+1 (log+ x 1.l)) +(define 1/x+1 (log/ 1.l x+1)) + +(define 2/x (log/ 2.l x)) + +(define res (log- 1/x+1 2/x))