ajcr / molloy Goto Github PK
View Code? Open in Web Editor NEWHow many choices of 5 things from :cake::pizza::doughnut::pizza::green_apple::cake::green_apple: contain at least one slice of pizza?
License: MIT License
How many choices of 5 things from :cake::pizza::doughnut::pizza::green_apple::cake::green_apple: contain at least one slice of pizza?
License: MIT License
Currently constraint conjuncts are separated by and
, e.g. red < 5 and yellow > 7
.
It would be neater to allow this to be alternatively written as red < 5, yellow > 7
.
Currently molloy builds arrays of polynomial coefficients from constraints, and then multiplies them to get a final array whereupon the requested coefficient can be read off as the answer.
This is simple and and is quite fast, as long as the user does not ask for too large a count (say much higher than 1 million) and not too many constraints are put upon items in the possible collection (so we do not have to too much polynomial multiplication [= convolution] and flipping of ones and zeros in arrays).
However, rather than build arrays, it would be potentially much more efficient and useful to construct generating functions for each constraint, multiply them, and then grab the needed coefficient from the corresponding power series expansion of that function.
Using SymPy would make the first two steps relatively simple, but the last part is still difficult. SymPy has a built-in method for extracting the Taylor term of a function expansion, but it uses repeated differentiation and is incredibly slow for anything but tiny integers.
A more promising approach is to take the generating function, expand it into partial fractions and then recognise the coefficient formula for each one. For example, (1 - x)^-(k+1)
expands to a series where x^n
has coefficient (n+k) C n
and so this coefficient can be computed very quickly.
So in summary there are four-ish steps to making this work:
Whether this will always work, I'm not yet sure. I have made some progress, but getting the code to work reliably is a challenge - it can be hard to properly expand the function and then recognise the appropriate formula for the fraction.
In other words: support or
.
Allow constrains such as (red > 4 and yellow < 10) or (red > 4 and green < 16)
.
This type of problem can be solved using inclusion-exclusion:
S(red > 4 and yellow < 10) +
S(red > 4 and green < 16) -
S(red > 4 and yellow < 10 and green < 16)
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.