What Is miniKanren?
minikanren.org
minikanren.org
[0] https://www.janestreet.com/tech-talks/algorithm-for-precisio...
"It will demonstrate progress to date, including the now-routine use of relational programming in miniKanren to identify personalized treatments for patients with some of the rarest and most challenging diseases in the world."
... wherefrom I cannot help but be amazed at how personalization through data optimization apparently actually helps solve such things and can be an approach.-
Normally I can at least figure out how to use something, even if I don't understand how it works under the hood, but with this, I couldn't even figure out the next step.
mediKanren's source code is under MIT license, and is on GitHub. Alas, the knowledge graphs we use for mediKanren aren't produced by us, and often have very complex licenses (one KG might include knowledge from 80 or 100 databases, each with a different license). As a result, we can't just release the KGs that are needed to actually use mediKanren. Also, creating high-quality queries that take into account all the nuances and quirks of the KGs is tricky, and changes as the KGs and the Biolink standard evolve. As a result, mediKanren requires some expertise to use effectively, along with access to the KGs.
An application that uses mediKanren as a back-end (along with other reasoners) is the NIH NCATS Biomedical Data Translator:
Please keep in mind that both Translator and mediKanren are designed for researchers and for biomedical research, not for patient care or treatment recommendations.
[0] https://bertrand.might.net/articles/algorithm-for-precision-...
The Algorithm for Precision Medicine, talk by Matthew Might [video] - https://news.ycombinator.com/item?id=37814662 - Oct 2023 (14 comments)
The Algorithm for Precision Medicine - https://news.ycombinator.com/item?id=29483549 - Dec 2021 (1 comment)
This brought back shades of 20 years ago to me. I went back to school to add a credential after my name to make myself employable. My experience running the back office for a long-distance reseller (FoxPro 2.6 database: application support, running customer service, billing, reporting, and being the networking yeoman) didn't look impressive on my resume without some additional alphabet soup.
This was my programming languages -- interpreters class. Dr Daniel Friedman ran a teach-along that culminated in implementing miniKanren in scheme. First day of class, the front row was empty. I was ten years older than every other student in the room (with the exception of Will Byrd). I sheepishly shrugged and took one of the offered seats in the row. For the next hour, the sheer force of scheme being written on the whiteboard blew my mind open. That continued for 16 weeks, three days a week. I highly recommend the experience.
I (probably) still have a pre-press copy of The Reasoned Schemer in a box in my attic. It was one of the goodies handed out on the last day of class.
You know. "Consent" is everything these days.- :)
PS. Preferably in written form ...
Lately, I've been playing a lot with the code from Neural Guided Constraint Logic Programming for Program Synthesis [1]. I want to apply it to searching for neural network architectures. Something like:
(define-relation (layero layer in out) ;; [2]
(conde
((== layer `(Linear ,in ,out)))
((== layer `(Relu ,in ,out))
(== in out))
((fresh (percent)
(== layer `(Dropout ,in ,out ,percent))
(== in out)
(countero percent)
(<o '(1) percent)
(<o percent '(0 0 1 0 0 1 1))))))
And a `layerso` that is just a sequence of `layers`. And then use some metric that captures how effective the training run was and use that metric for teaching the search network.I'm sure there's better ways to do it than the way I'm going about it. But it's a fun way to learn a bunch of cool new stuff.
Thanks for getting me started down this path!
[1] https://arxiv.org/abs/1809.02840
[2] https://github.com/eihli/reason/blob/523920773b7040325c8098a...
I even clicked through quite a few of those prominent early links and didn't find a code example!
We are working on a new version of the website, with HTTPS, and with better examples and a better layout.
I love your blog posts on LLMs, BTW! We've been experimenting with combining LLMs and miniKanren in various ways.
miniKanren was my introduction to relational programming (SQL aside!), and I had hours of trying to wrap my head around the Reasoned Schemer.
Were you aware a miniKanren-inspired language was the foundation of a large chunk of Amazon's retail data aggregation stack? I'm no longer there, but it might be one of the larger deployments out there. We spent many many hours trying to figure out the best way to run the relational engine at scale and with acceptable performance.
I did several MOOCs on discrete optimization and I understand how a constraint solver works, and how local search works, for example. I also understand how a SAT solver works.
I just do not understand what logic/relational programming does. Is that a constraint solver solving just one kind of constraint, ie logic equations, a bit like a SAT solver?
[Edit] on my side I was really impressed by a paper using Minikanren to generate an algorithm, a sorting function if I remember well. It was about 8 years ago. Tried to fully understand the paper but gave up at some point.
Hope that helps someone. :) It’s a fantastic little gem of a program.
Don’t forget: https://aphyr.com/posts/354-unifying-the-technical-interview
Differences Between miniKanren and Prolog - https://news.ycombinator.com/item?id=39088018 - Jan 2024 (29 comments)
William Byrd on logic and relational programming, miniKanren (2014) - https://news.ycombinator.com/item?id=27359963 - June 2021 (28 comments)
Making a “MiniKanren” using Z3Py - https://news.ycombinator.com/item?id=27247386 - May 2021 (5 comments)
MiniKanren as a Tool for Symbolic Computation in Python - https://news.ycombinator.com/item?id=24828498 - Oct 2020 (1 comment)
UKanren in J: Embedding in an Array Language with Rank-Polymorphic Unification [pdf] - https://news.ycombinator.com/item?id=24298292 - Aug 2020 (1 comment)
Minikanren – An embedded DSL for logic programming - https://news.ycombinator.com/item?id=18698718 - Dec 2018 (44 comments)
Reazon – miniKanren for Emacs - https://news.ycombinator.com/item?id=17947087 - Sept 2018 (21 comments)
MiniKanren – An embedded DSL for logic programming - https://news.ycombinator.com/item?id=8395079 - Oct 2014 (22 comments)
Relational Programming in miniKanren - https://news.ycombinator.com/item?id=4734592 - Nov 2012 (1 comment)
I'm kind of a lisper but I find it easier to get things done in a proper Prolog than the kanrens.
The Clojure one is bundled up into a library called libscryer-clj, which I haven't released yet, but it operates the same way as libpython-clj[3], libjulia-clj[4], and libapl-clj[5].
As an aside, Scryer is hella ergonomic. clpz+reif is an amazing and amazingly powerful combination, and Scryer's DCG philsophy over double quoted strings is chefs kiss -- it really delivers on the original mission of Prolog. Ediprolog[6] is a fantastic REPL for Emacs.
And honestly if you haven't seen Marcus Triska's work[7], by God you are missing out on one of the true joys of life.
[1]: https://github.com/jjtolton/scryer-prolog/blob/ISSUE-2464/sc...
[2]: https://github.com/mthom/scryer-prolog/discussions/2687
[3]: https://github.com/clj-python/libpython-clj
[4]: https://github.com/cnuernber/libjulia-clj
[5]: https://github.com/jjtolton/libapl-clj
Yeah, I really like Scryer, it's been my goto Prolog for quite some time.
You wouldn't know a way to get it working under Termux on Android? I tried to build it a while back but got inscrutable compiler errors and didn't follow through. Maybe building Trealla would be easier, since it's implemented in C.
I'm also enjoying http://tau-prolog.org/.
I've never tried compiling on rust before but open an issue or a discussion on the Scryer board and maybe we can figure it out!
I was/am also anticipating performance gains from Scryer. Which is why I made a point to request up to date Scryer benchmarks in the SWI forums. Still, for free/open Prolog, SWI-Prolog is hard to beat: https://swi-prolog.discourse.group/t/porting-the-swi-prolog-...
[0] https://en.wikipedia.org/wiki/Flix_(programming_language)
http://minikanren.org/#hangouts
Is there more information somewhere?
We do have a monthly call of miniKanren/OCanren researchers from around the world, where someone presents on their research. If you are interested, please send me an email!
See also: µKanren (http://webyrd.net/scheme-2013/papers/HemannMuKanren2013.pdf) and various ports like CL (https://github.com/rgc69/si-kanren) or Clojure (https://github.com/clojure/core.logic)
https://io.livecode.ch/learn/gregr/icfp2017-artifact-auas7pp
When I was in university, the usual Prolog example was solving a game of Cluedo.
But I'd expect many solver languages to be able to make it easier, like Prolog, datalog, mercury.
[0] http://cse.unl.edu/~choueiry/Documents/Hybrid-Prosser.pdf
IMO, these "zebra puzzle"/"einstein puzzle" style problems are like a "hello world" for many related techniques. What's more, there are many languages that combine several of these techniques together so that you can easily pick and choose where appropriate.
If you were just wanting to compare against another related style, answer-set programming is one thing that comes to mind.
miniKanren, Prolog, and others let you write the rules more concisely (almost always) and clearly (most of the time, not everyone will write clear code and clarity is subjective) than that, though.
I'd be happy to try to explain anything you found confusing.
Perhaps this online tutorial would be a helpful start:
Personally, while I did some Lisp back in university and was reasonably conversant in it at the time, nowadays whenever something nontrivial is presented in Lisp, it’s just too much mental overhead to get back into it, in addition to trying to understand the thing that is being presented.
Terminology like “logic variable” also needs to be explained, if you want to address an audience that isn’t already familiar with logic programming.
And remember this language for when, after you know Prolog, you start to see how it applies nicely to parts of everything you write, but it completely unsuitable for solving the entirety of almost any problem.
[1] https://github.com/jasonhemann/microKanren
[2] https://mitpress.mit.edu/books/reasoned-schemer-second-editi...
[3] https://www.youtube.com/watch?v=irjP8BO1B8Y&ab_channel=Cloju...
[4] https://www.youtube.com/watch?v=y1bVJOAfhKY&t=10s&ab_channel...
First it says "== unifies two terms". Then the first example says "(== x z) (== 3 y)" associates x with z and y with 3. Are "unify" and "associate" the same thing? Why use different words? Why does the association reverse for x and z vs 3 and y? Is it commutative?
For example you could start with two facts like "Fedora is red." and "Cat is green." Then if you ask the system "X is red." it'll tell you "X = fedora". If you ask it to list all the solutions of "X and Y are not the same color." it'll list "X = fedora, Y = cat" and "X = cat, Y = fedora". This process of binding variables to values (or other variables during simplification) is unification.
(== x x) = x for all x
It is commutative: (== x y) = (== y x) for all x and y
It is idempotent: (== x (== x y)) = (== x y) for all x and y
And it is associative: (== x (== y z)) = (== (== x y) z)
It's not transitive, e.g. if we unify pairs (using made up syntax [a, b]) then (== [x, 1] [2, y]) = [2, 1]
(== [2, y] [z, 3]) = [2, 3]
(== [x, 1] [z, 3]) does not unify (since 1 does not unify with 3)From the submitted page, "The core language, using Scheme as the host language, is described in this short, interactive tutorial."
Really---anything short of that is sub-optimal performance. I think some of it comes from new eyes reading and pointing out room for improvement. The other half is someone having the time to figure out the fix and implement it.
I think python is the most common and simple language with majority of devs would understand for concepts learning, but it is likely too slow for practical applications.
We had built an iPhone app that retrieved HTML pages from a server, but then scanned for extra metadata that was embedded in HTML comments for things like what navigation options should be displayed to accompany that page.
We got a bug report from a user that the app broke when they used it on the free WiFi on the London Underground.
It turned out there was some weird proxy running on that WiFi network that stripped HTML comments and injected extra tracking code into pages!
Switching to https fixed the bug. I haven't shipped anything that uses plaintext HTTP since then.
Here are two hurdles:
1. Can you prove me wrong?
2. Next, given 1, can you rationally justify not rolling out HTTPS everywhere.
In other words, is it actually a valid argument that "often, nothing bad happens when you use HTTP, so it is okay".
Tampering of content has nothing to do with your privacy; it's a security matter. A nefarious man-in-the-middle could insert content which attacks your browser or redirects it to a malicious site, etc.
That attacker could be on a network close to you, or a network close to the site. It's not a matter of trusting or not trusting the original site that serves the HTTP.
Therefore it doesn't matter that you're just accessing the site as an anonymous visitor without an authenticated account, just viewing public content.
Curious, why that doesn't happen when I access https://verybadguy.tld/this_page_absolutely_doesnt_have_harm... for the first time? Isn't it the browser's job to handle harmful content?
"why do you expect it to?" i think would have been lot less of a trick question, and that's simple: it's trivial to set up and offers security benefits people - i think reasonably - take for granted these days.
I want to try miniKanren in my favourite game engine Godot Engine, how would I embed it?
The typical options are c++ and porting python to gdscript, but wanted to ask.
It walks you through implementing microkanren in Ruby. You might find it easier to implement all of that in gdscript.
> The six simple building blocks: variables, states, and the four kinds of goal — make two values equal, provide local variables to an existing goal, pursue two existing goals separately, and pursue two existing goals together.
> The only data structure is a pair. We can create lists using pairs.
I'll play with it more.
I have a port of https://github.com/dananau/GTPyhop and planner systems feel related to relation programming
Of course, agree, it's totally needed for anything with a login or downloads etc, but serious question, what's the risk/benefit tradeoff here?
We're working on it! Should have a new version of the site up within a few days.
Thanks!
The benefit is that you can be sure that nothing modifies the traffic between your server and the client, so the client sees your content without any modification.
The counter-points to the benefit are that a) the traffic can still be *blocked* by any party in the middle (eg a state-level firewall), b) that traffic can absolutely be modified if the client has accepted an alternative CA for whatever reason (legal, corporate, etc) and that CA is used to MITM the connection to your server, and c) you as a website operator don't necessarily care about the MITM situation of every client's network (ie them having a MITM is their problem, not yours).
There's another benefit that browsers restrict some JS API to only run on https pages, which matters if you wanted to use those API. https://developer.mozilla.org/en-US/docs/Web/Security/Secure...
Say, in a SaaS web app that provides a comments widget (a Disqus clone), what behavior (user facing or behind the scenes) would be a good candidate to implement with logic/integer programming?
- I want window of these size, with such controls
- when this button is clicked, text from this control appears in that DB column
and system figures out all details making it cross platform, fault tollerant, etc if all infra is coded on that platform
I can see miniKanren (or some other logic programming language) being helpful in the realm of authorization.
I played with some Scala mini Karen implementations before, but the ones I tried were all half-baked or non-working.
For SAT/SMT in Python, I've heard this book is pretty good: https://theory.stanford.edu/~nikolaj/programmingz3.html. Google OR-tools has a Python frontend and they have interactive tutorials (https://developers.google.com/optimization/examples). I don't know about logic programming in Python. Note that while there's some overlap between logic programming and constraint solving ([1] [2]), the communities are pretty independent from each other. Different histories, tools, techniques, etc.
"miniKanren is a family of Domain Specific Languages for logic programming", whatever..
- shall the title of this submission better be it ?? - with respect and to not waste people's time and efforts (now just forgetting that few minutes of my life to write about it.. but not others forced labour to explain it - when there is no title: Ask HN, what's that ?).
(The Algorithm for Precision Medicine would catch my interest, wouldn't read it today.)
It's a first line that happen to be there, of quite a lot. The one only short explanation what it is that was there, I've cited in the parent.
The title of a submission shall not be edited - right ? - but here, it's obviously hallucinated (there is no title). And I seem to be downvoted by bots with context buffer size of 1 line and a submitter ? who did read no more - but who exploited me and others instead - all paid in reverse.
Dang: title of this submission breaks HN guidelines (and I'm dovnvoted for being exploited and saying it, there shall be a warning - but it's up side down, not for me only - coltea .., - or leave: * suck karma exploiting others, my no thanks, sorry).