Code Monkey home page Code Monkey logo

extmath's People

Contributors

adanielpincab avatar neizod avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

yerke-kz

extmath's Issues

Enchant `NumeralSystem` to accept complex system such as Roman numeral system.

so this:

NumeralSystem({ 'I':    1, 'IV':   4, 'V':   5, 'IX':   9,
                'X':   10, 'XL':  40, 'L':  50, 'XC':  90,
                'C':  100, 'CD': 400, 'D': 500, 'CM': 900,
                'M': 1000 })

will returns correct Roman numeral system.

implementation details

  • key-value of input dict may be swap.
  • parse int -> str should be very easy (due to the rule)
  • parse str -> int require lexical (regex) analysis.

Release to PyPI

Anyone interest to release this module to PyPI? I have no experience doing it.

We may also need to change the name of the project first?

  • change repo name.
  • test build on Test PyPI.
  • release to PyPI.

Enchant `InfinityList` with `.test()` and `.position()`.

.test(n) will gives True or False that indicate the list (will going to) contain the number n or not.

>>> prime.test(42)
False
>>> prime.test(281)
True

The equivalent workaround is

n in prime.under(n+1)

which is a little bit slow because it must iterate through all n below it. While

len(factorized(n)) == 1

is much faster due to factorized iterate from the 1st prime number to the prime number not larger than n**0.5 only.


.position(n) gives the output just like fibonacci[n]. They just use smarter algorithm that are not require all number below it exist. e.g.

fibonacci n = (phi**n - psi**n) / sqrt 5
    where
        phi = (1 + sqrt 5) / 2
        psi = (1 - sqrt 5) / 2

Both may force to raise NotImplementError if not such better algorithm exist.

Clean up for releasing

main

  • drop support for python2 and pypy? (so we can use the robust syntax like generators...)
  • rewrite InfiniteList by using metaclass...
  • drop monkey patching (Fraction.decimal)
  • drop duality -- it's a wired concept and hard to use!
  • make sure it pass PEP8.

chores

  • better docs.
  • update github wiki.
  • fix trailing white spaces.

Implement `sieve` for `prime`.

prime is so slow, it may comes up very fast with sieve method, init only once.

else would be rewrite entire prime list. to make it gain ability of generating prime much faster.

Rewrite factorized

factorized is an elegant function (returns list), but most of the time, we didn't need all factors, just 1st of them.

new factor should be class that return factor object, which has this properties:

  • factor(N).__iter__() returns generator that yielded all elem as same as factorized. (so we can do product(factor(N)) == N)
  • factor.(N)items() returns tuple of (prime, power).
  • factor(N).__mul__(M) gives output as same as factor(N*M), just faster because we already know that N*M is not prime.
  • factor(N).__str__() show string repr of the factor in this example form: 2**5 * 3**2 * 7**1 * ...

New class: NumericBase

NumericBase returns numericbase object, which work this way:

>>> mybase = NumericBase('01234567')
>>> mybase.int('1342')
738
>>> mybase.str(738)
'1342'

fist arg get str repr of values of each symbol in base, ascending from zero to base minus one.

>>> stdb16 = NumericBase('0123456789abcdef')
>>> stdb32 = NumericBase('abcdefghijklmnopqrstuvwxyz234567')

Enhance factorized with Quadratic Sieve.

factorized function should became a class, which has some of this features:

  • factor in lazy manner (returns an iterator, or some chaining objects like linked list).
  • any number should use trial_division algorithm to factoring, until reach some point that factor using this algorithm slow.
  • put remaining number test for primality, if turns out composite, use quadratic_sieve to continue factor it.

additional function

  • legendre sumbol
  • matrix kernel function

Instance of InfinityList (prime, fibonacci) doesn't handle properly with `print` in PyPy.

In standard Python (CPython 2 or 3), doing print prime gives output of prime number from 2 up to the most recent calculate prime, with trailing ... that indicate there are much more element not yet discovered in this list.

But in PyPy, while trying to do print prime, it will going to iterate itself forever, without printing anything.

Since I'm not going to break the infinity-style's __iter__ behavior. (Plus, the standard python just run this pass). I'd recommend slicing the list before print it out. The syntax is print prime[:].

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.