Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Numerical tower #34

Open
51 of 71 tasks
jcubic opened this issue Mar 24, 2020 · 8 comments
Open
51 of 71 tasks

Numerical tower #34

jcubic opened this issue Mar 24, 2020 · 8 comments
Labels
Milestone

Comments

@jcubic
Copy link
Collaborator

jcubic commented Mar 24, 2020

TODO:

  • Complex Type
    • Complex-Float
    • Complex Integer
    • Complex Rational
      • (make-rectangular 1/2 2/4)
      • (/ 10+10i 10+2i) works in Kawa (Lips convert to Float)
      • Complex NaN e.g. +nan.0+5.0i
      • Complex Infinite e.g. 3.0+inf.0i
    • Mixed complex 1/2+0.1i (all combinations)
    • Rational Complex literal
      • inexact #i1/2+2/4i -> (exact->inexact 1/2+2/4i).
    • big num complex 10e+10i.
  • Float Type
  • Rational
  • BigInteger
  • Number literals
  • hex octal and binary and decimal literals (#b #o #x #d)
    • binary/hex/octal with complex and rational #b1/100 #b100+100i
  • big literal numbers in scientific notation should parse as big int
  • #e #i exact inexact literals that do conversion
    • #b#x #x#b replace in tokenizer (1/4 == 0.25)
    • #i#b1/100 inexact rational binary
    • big exact fractions #e1e-1000 or #e1.2e-1000
  • +nan.0 and -nan.0 return by parser
  • proper negative 0
  • Case insensitive mnemonics
  • string->number should parse all tokens #[ieoxb]
  • proper casting and all combination of operations
  • properly working string->number
  • Unit tests for operations (all types)
    • sqrt
    • abs
    • /
      • nan
      • inf
    • number->string (check if they are ok)
    • string->number
    • +
      • nan
      • inf
    • -
      • nan
      • inf
    • *
      • nan
      • inf
    • modulo integer integer (test types)
    • quotient integer integer (test types)
    • reminder int int (test types)
    • max
    • min
    • gcd integer ...
    • lcm integer ...
    • exp
    • expt
    • log
    • trigonometry
      • sin
      • cos
      • tan
      • asin
      • acos
      • atan
    • round, truncate, floor, ceiling
    • positive? / negative?
    • exact->inexact
    • inexact->exact

Bugs

@jcubic jcubic added the enhancement New feature or request label Mar 24, 2020
@jcubic jcubic changed the title Complex numbers Complex and Rational numbers Mar 28, 2020
jcubic added a commit that referenced this issue Mar 29, 2020
@jcubic jcubic changed the title Complex and Rational numbers Numeric Tower System Apr 13, 2020
@jcubic jcubic removed the resolved label Apr 13, 2020
@jcubic jcubic added this to the 1.0 milestone Apr 13, 2020
@jcubic jcubic changed the title Numeric Tower System Number Tower System Apr 13, 2020
@jcubic jcubic changed the title Number Tower System Numerical tower Apr 14, 2020
jcubic added a commit that referenced this issue Apr 17, 2020
#i and #e are just syntax extensions that map to exact->inexact and inexact->exact
jcubic added a commit that referenced this issue Apr 18, 2020
LISP not properly parses BigInt literals
It now supports bigInt hex/octal/binary literals
It now supports string->number on any radix that convert to BigInt if it's numerical value
jcubic added a commit that referenced this issue May 10, 2020
jcubic added a commit that referenced this issue May 10, 2020
jcubic added a commit that referenced this issue May 10, 2020
jcubic added a commit that referenced this issue May 10, 2020
The hack is in a form of literal parameter to Pair::toObject so you can create Object
from alist when value are LIPS types (they are not converted to JS values)
jcubic added a commit that referenced this issue May 13, 2020
so you can call #i1/2+1/2i and get 0.5+0.5i the same is the oposite
jcubic added a commit that referenced this issue May 13, 2020
return proper value for #e0.1 -> 1/10
jcubic added a commit that referenced this issue May 16, 2020
jcubic added a commit that referenced this issue May 16, 2020
jcubic added a commit that referenced this issue May 16, 2020
The parser handle those mnemonics because it would be hard to have them swapped with #[xob]
jcubic added a commit that referenced this issue May 17, 2020
sign is optional like in Kawa #i10i
fix parsing single number literals
jcubic added a commit that referenced this issue May 17, 2020
jcubic added a commit that referenced this issue May 17, 2020
it now show proper error 'Maximum BigInt size exceeded' if number is too big in Chrome
jcubic added a commit that referenced this issue May 17, 2020
jcubic added a commit that referenced this issue May 17, 2020
jcubic added a commit that referenced this issue May 21, 2020
jcubic added a commit that referenced this issue May 21, 2020
jcubic added a commit that referenced this issue Feb 26, 2021
jcubic added a commit that referenced this issue Feb 27, 2021
Fix case when calculating sub on rational and complex
Fix error messages for invalid numbers in complex op
jcubic added a commit that referenced this issue Feb 27, 2021
@jcubic
Copy link
Collaborator Author

jcubic commented Mar 1, 2021

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/

jcubic added a commit that referenced this issue Mar 4, 2021
This fixes division of complex that have +nan.0 or +inf.0 in on of the parts
divided by non complex value.
jcubic added a commit that referenced this issue Mar 4, 2021
now `(/ n)` == `(/ 1 n)`
@jcubic
Copy link
Collaborator Author

jcubic commented Mar 4, 2021

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.

jcubic added a commit that referenced this issue Apr 16, 2021
jcubic added a commit that referenced this issue Apr 16, 2021
jcubic added a commit that referenced this issue Apr 16, 2021
jcubic added a commit that referenced this issue Nov 18, 2021
Fix complex division that return non complex value
Fix division of two idenntical complex numbers
jcubic added a commit that referenced this issue Nov 18, 2021
Fix complex division that return non complex value
Fix division of two idenntical complex numbers
@jpellegrini
Copy link

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...

@jcubic
Copy link
Collaborator Author

jcubic commented Apr 13, 2023

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

jcubic added a commit that referenced this issue Apr 13, 2023
@jcubic
Copy link
Collaborator Author

jcubic commented Apr 13, 2023

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.

@jpellegrini
Copy link

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)

@jpellegrini
Copy link

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...

jcubic added a commit that referenced this issue Apr 13, 2023
jcubic added a commit that referenced this issue Apr 14, 2023
jcubic added a commit that referenced this issue Apr 14, 2023
jcubic added a commit that referenced this issue Apr 14, 2023
jcubic added a commit that referenced this issue Feb 8, 2024
jcubic added a commit that referenced this issue Feb 9, 2024
jcubic added a commit that referenced this issue Feb 11, 2024
@jcubic
Copy link
Collaborator Author

jcubic commented Feb 12, 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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants