GithubHelp home page GithubHelp logo

Numerical tower about lips HOT 8 OPEN

jcubic avatar jcubic commented on May 17, 2024
Numerical tower

from lips.

Comments (8)

jcubic avatar jcubic commented on May 17, 2024 1

@jpellegrini thanks I will make sure to add those to unit tests when will work on that function.

from lips.

jcubic avatar jcubic commented on May 17, 2024 1

fixed the simple case and Started adding tests for bigint + float combination, but still rational need some work:

lips> (expt 1/2 2)
1/4
lips> (expt 2 1/2)
2/1

there is a need to add different root calculations (I'm not sure if Scheme has something like this out of the box, it may be useful to expose).

And also added an exception when invoking expt on complex numbers since this will require more work, need to think how to handle trigonometry functions, that are required to calculate power operation on complex numbers.

from lips.

jcubic avatar jcubic commented on May 17, 2024

Arithmetic error:

;; Returns the arithmetic, geometric, and
;; harmonic means of a nested list of numbers
(define (means ton)
  (letrec*
     ((mean
        (lambda (f g)
          (f (/ (sum g ton) n))))
      (sum
        (lambda (g ton)
          (if (null? ton)
            (+)
            (if (number? ton)
                (g ton)
                (+ (sum g (car ton))
                   (sum g (cdr ton)))))))
      (n (sum (lambda (x) 1) ton)))
    (values (mean values values)
            (mean exp log)
            (mean / /))))

Note that evaluating (means '(3 (1 4))) returns three values: 8/3, 2.28942848510666 (approximately), and 36/19.

LIPS devel returns:

8/3
2.2894284851066633
8/3

Ref: https://small.r7rs.org/wiki/R7RSSmallErrata/

from lips.

jcubic avatar jcubic commented on May 17, 2024

Function (means '(3 (1 4))) is fixed the problem was that (/ 2) was returning 2 and it was even in doc string. According to spec it should return 1/2.

from lips.

jpellegrini avatar jpellegrini commented on May 17, 2024

Hi,
Not sure if this is supposed to be working already (I see expt is not marked in your checklist), but anyway - (expt 1.5 0) and (expt 2 3.0) return an error saying that LIPS can't convert BigInt to number...

from lips.

jpellegrini avatar jpellegrini commented on May 17, 2024

there is a need to add different root calculations (I'm not sure if Scheme has something like this out of the box, it may be useful to expose).

R7RS has only square roots... I usually do (expt x 1/n) for the n-th root.

And also added an exception when invoking expt on complex numbers since this will require more work, need to think how to handle trigonometry functions, that are required to calculate power operation on complex numbers.

Maybe (expt x y) could be implemented as (exp (* (log x) y)), if you already have log for complexes?

And (log z), with z complex, would be

REAL: (log (magnitude z))
IMAG: (angle z)

from lips.

jpellegrini avatar jpellegrini commented on May 17, 2024

Maybe (expt x y) could be implemented as (exp (* (log x) y)), if you already have log for complexes?

See PR #247

And I see you already have implemented complex log...

from lips.

jcubic avatar jcubic commented on May 17, 2024

@jpellegrini expt was fully implemented and fully tested. It will be released in the next beta version.

It matches the implementation of Kawa and doesn't have rounding errors when the power is an integer.

from lips.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.