neizod / extmath Goto Github PK
View Code? Open in Web Editor NEWCollections of useful tools in mathematics.
License: MIT License
Collections of useful tools in mathematics.
License: MIT License
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
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?
.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.
InfiniteList
by using metaclass...Fraction.decimal
)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.
patial_orginname
instead of just partial
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 * ...
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')
1st of all, if merge fail, just migrate fibonacci.position
to fibonacci.__call__
to provide fibonacci(n)
syntax style.
since there are 2 difference algorithm, doing exactly same task (w/ time difference depend on test case). this should be merge into 1-obvious way: the __getitem__
.
for speed efficiency.
factorized
function should became a class, which has some of this features:
trial_division
algorithm to factoring, until reach some point that factor using this algorithm slow.quadratic_sieve
to continue factor it.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[:]
.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.