A couple years ago, I tried to wrap my poor little non-developer head around how to use this, because I have a handful of things going on medically that seem (to me) to be connected, but I can't manage to get any doctors to care enough to help me figure out, but I was hopelessly out of my depth.
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.
It's surprisingly reassuring to realize it wasn't actually my fault that I couldn't figure it out. Thanks for explaining! I'll look into Translator and see if I can get anywhere that way.
Alas, you'd still need the knowledge graphs. I hope the licensing issues for at least some of the KGs will be resolved soon. It's a tricky issue. Even some of the ontologies and controlled vocabularies in biomedicine can't be released publicly due to copyright restrictions (for example, full SemMedDB uses UMLS which uses SNOMED).
thank you for posting this... and this is a common enough pattern (looking up previous HN threads on the same or related article) that I wonder if it's worthwhile to automate this.
"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.-
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.
I wrote some FoxPro thing for a long-distance reselling operation circa 1994. It had to handle agent commissions on a multi-level scheme and whatnot, import call detail records from telco equipment and such.
This gives me an idea. I'm going to create a super complex and unintuitive programming language where the only error message you get is "no", and call it miniKaren. :-P
I have a feature request for the https://minikanren.org/ website: just one prominent block of example code on that homepage (as early as possible) would be REALLY useful for helping understand at a glance what kind of language this is.
I even clicked through quite a few of those prominent early links and didn't find a code example!
On top of that: some examples of the kinds of problems miniKanren can solve, based on real world examples rather than purely abstract concepts (e.g. "given a set of available air flights with origins, destinations, and prices, find me the cheapest way to get from Seattle to London")
Is that even possible for something like this? You've got a pretty long list of implementations, each having its own language specific syntax, e.g. https://github.com/pythological/kanren for one python version - and there are several Python versions linked on the homepage.
Hey! Thanks for all of the work you do. I love reading your stuff.
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:
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.
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.
Hi! Sorry to be late to the party. I don't really understand how relational programming relates to discrete optimization and constraint programming.
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.
I'm interested in a miniKanren port, or something like it, to TXR Lisp. I would possibly make it a part of the standard library of the language, so programs could rely on it just being there.
A while back I was trying to understand the guts of miniKanren. I Did a careful reading of the paper and wrote up my notes along with the code here: https://codeberg.org/ashton314/microKanren
Hope that helps someone. :) It’s a fantastic little gem of a program.
Implementing and using a miniKanren was fun and enlightening. And it helped me appreciate how incredibly optimized and fast SWI-Prolog is for relational/logical programming. If someone knows of a miniKanren/language combination that outperforms SWI-Prolog and has good developer ergonomics for relational/logical programming, I’d love to hear about it.
IIRC SWI-Prolog can be embedded in Python if that's your thing. Interfacing with Scryer Prolog might be require a bit more but ought to be doable, and if they haven't surpassed SWI in some performance metrics yet I'd be surprised.
I'm kind of a lisper but I find it easier to get things done in a proper Prolog than the kanrens.
It hasn't been merged into the main branch yet, but you can embed Scryer in Python now[1], and it's quite enjoyable. I've also embedded in Java, Clojure, and elisp[2] :)
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.
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.
> if they haven't surpassed SWI in some performance metrics yet I'd be surprised
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-...
For folks that want to engage / learn more, there's been an annual miniKanren workshop and also a monthly miniKanren hangout online. Interested folk should totally come to either both!
I haven't held any hangouts online for years, although I'd consider restarting them if there is interest.
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!
I think there'll be all manner of constraint and constraint-logic programming approaches that'd be amenable. I wish I had a great answer for you as "the best".
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.
Like most things in programming, there is no "only way" to solve something, and certainly no one language (or DSL) to solve anything. You could solve it programmatically in C writing your own backtracker or state enumerator and a validation function for the rules (or block of code if you are like an old coworker that liked 10k SLOC C functions).
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.
The paper on microKanren [1] is imho the most approachable piece outside the "reasoned schemer" [2]. The thesis on which it is based is also interesting but is a thicker beast. Looking at stuff from the clojure world (clojure.core.logic and this talk [3]) is also interesting imho, especially from a dev perspective. From this point of view I found this talk [4] to be especially enlightening in how to build a database / query engine and concrete applications of MiniKanren / datalog.
If you are struggling to learn the language, you may have better luck learning Prolog first. So you don't deal with the added complexity of it being embedded in a completely unrelated language.
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.
The main problem is likely that many programmers aren’t familiar with Scheme, or any kind of Lisp. So the material is presented in the context of a host language that itself requires substantial effort to really get used to.
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.
One of the hopes is that you can drop in your favorite host language's syntax and get a working implementation. What's your usual language stack these days?
I think the initial surface look makes scheme give a bit of an 'oh crap' response. But since minikanren is actually a small program and scheme doesn't really have syntax the language should be less of a problem than initial concerns might make one think. Grokking the actual logic in any language is going to be the bigger challenge. I guess I am trying to encourage just rolling with lisp if you can, but I totally get the initial reactions toward scheme though.
That's somewhat comforting! But on the other hand, it means also that some of the folk who would be perfectly able to understand the big idea are getting gatekept by just the look of the parentheses, even though host's concrete syntax is of little importance. Which is a darn shame.
Yes, I agree, and understand the point better. Totally a great thing if this can be made accessible to a wider audience and not expect them to do all the work to grok it, especially if there are easy/easier ways to bring it to a wider audience. The parentheses don't usually remain a problem after the initial bump, I had the same issue when I started clojure but after a short while it doesn't continue to be jarring. I think after about 90 minutes it just started to be "natural" perhaps that the wrong word, it was just something that was like ok after a bit and didn't notice too much.
Thanks Will! I think it was the microkanren paper (it's a few years ago now so i'm not 100% sure but seeing it seems familiar). I think I will try the tutorial and see if it helps make it 'click'.
I found sokuza-kanren [0] to be a wonderful introduction. It starts with the absolute basics and builds into a minimal logic system through a series of well-documented steps.
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.
One of the things miniKanren has going for it is that tons of folk have built little embedded implementations in the whatever your favorite host language is. For instance, here's https://web.archive.org/web/20211205175513id_/https://erik-j... a walkthrough of how you'd implement the basics in Python. Comes with an explanation.
I looked at the tutorial and choked at the first step.
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?
Thanks for the follow-ups but my comment wasn't really asking what unify and associate mean, I'm questioning the redundant complexity in what is supposed to be the introductory tutorial to the language.
From the submitted page, "The core language, using Scheme as the host language, is described in this short, interactive tutorial."
I think these are great points. Everything should be smooth as butter for an interested reader, and the tutorial should be so approachable and such a page-turner that the curious are hooked on page one and can't put it down.
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.
Unification in the context of logic programming is basically like "use these questions and solve for all the unknowns" in algebra, except it's done with logical statements instead of algebraic equations. Searching for something like "unification prolog" (Prolog being the most well-known logic programming language) will probably give helpful material.
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.
They are commutative. As to whether unification and association are the same thing... yes, kinda. Unifying two terms kinda means associating them with each other in a database. Though I will say that it would have been better to say 'unifies x and z, as well as y and 3'.
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.
Not sure if you heard, but recently more net neutrality rules were struck down and that is expected to continue -- so ISPs (who have already done this) are allowed to inject / replace ads with their own ads, as an example. (https://thenextweb.com/news/comcast-continues-to-inject-its-... was the first article I hit in the googles)
I believe I'm being served tampered content every single time I access HTTP, so the last time that happened coincides with the last time I used a HTTP URL.
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.
I just mostly mourn all the caching and sharing potential along the way gone in the world where everyone totally needs a private secure tunnel to the very server containing most mundane, public and irrelevant information.
> 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.
bit of a trap question - clearly it doesn't need to, plenty of people accessed it in this thread fine and it works. even if it didn't, and there was a prevalent internet standard mandating it these days, you could just handwave it away, claiming that people don't need to respect standards or something.
"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.
> 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.
Haha my dyslexic ass read the title as “MiniKaren”… I was half-expecting to see some miniaturized version of someone complaining at a grocery store or something
The risk is that HTTPS is something you have to manage. Either your hosting provider auto-renews certs for you (which might cost) or you set up your own automation (which can fail, and I've seen enough properties with expired LE-issued certs to know that email reminders can be missed and certbot is not a silver bullet). That said, usually an expired cert fails open, ie users can still visit your website if they accept the scary "this is unsafe" warning. This is not an option if your website uses HSTS or is on a TLD with implicit HSTS (eg .dev), but in that case you're opting in to the responsibility of renewing your certs reliably.
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).
If you use HTTP you can have middlemen hijacking your content or inserting malicious things and nobody would know. There's all kinds of weird actors out there.
The important thing is to realize how much programming has been wasted solving problems that can be easily expressed as logic programming and/or integer programming. If you need to solve logic and combinatorial based problems, learning these techniques will save you hundreds of hours.
Sounds interesting. Could you give a specific example?
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 have a vague recollection about that kind of a declarative UI framework, but I can't remember a single detail. But it's definitely an interesting idea and I know there are other folk out there also interested in your idea.
I have a hunch this might be about the difference between "programming" and "coding". Web stuff, Hardware, and other things that don't get to just communicate with other programmers or programmers have a tendency of piling layers upon layers with custom glue and pipes everywhere.
Request: I'd love to learn more logic programming, SAT solvers, and equation solvers, but in a language I'm familiar with. Maybe python? But where to start?
I played with some Scala mini Karen implementations before, but the ones I tried were all half-baked or non-working.
The chapters on both constraint solvers and logic programming are pretty short overviews, we're talking less than 15 pages. I wouldn't recommend it if that's what you're specifically interested in.
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.
Even if you don't care about privacy, every single page using bare HTTP can have HTML or JS injected into it by a third-party.
Certain ISPs, hotels and airlines do it to their clients, and the script kiddies messing around the poorly firewalled subnet of their college's AP do it too.
It would prevent one’s ISP from injecting advertisements in the HTML as has happened commonly in the past with US ISPs. I presume that has mostly fallen out of practice but one could well blame that on the near-ubiquity of HTTPS.
The name pre-dates the Karen stereotype, but IMO the naming clash is beneficial. I won't be surprised if miniKanren implementation for some new language is actually called Karen.
IIRC, Dan told me that a million years ago, when they were choosing a name for the Kanren sourceforge repo, they had to use a name with a word that was sufficiently prominent on the internet. Kanren worked because there were enough hits for KanREN.
I don't care about something I don't and didn't care, neither have time for. I've only visited submitted page to check if it's original title is indeed "What Is miniKanren" (doubting it) and _it isn't_ - what for that.. bait ? - nothing I wanted to know about and nothing interesting there - I guess - as I read only the first sentence of this unplanned interruption:
"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.)
"What is miniKanren?" it's NOT a title of that page.
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).
[0] https://www.janestreet.com/tech-talks/algorithm-for-precisio...