This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; 'in returns seq | |
; 'lte returns (reduce join seq) | |
; 'in? filters by pattern | |
; 'lte? tests value by lattice ordering | |
; 'is? matches by pattern (non-monotonic) | |
; path membership | |
(d/deduct in :path [a c] | |
in? :edge [?a ?b] | |
in? :path [?b ?c]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;Support for simple constraints on lvars during unification was added in 76fd4d7c: | |
;; | |
;; https://github.com/clojure/core.logic/commit/76fd4d7c155161d74ad5cd8d87955148eece1fe0 | |
;; | |
;;but these constraints apply to a single lvar only. | |
;;The unifier could support more general constraints if it accepted an explicit predicate function. | |
;;For instance, given this `data-numeric?` predicate and `spec` data: | |
(defn data-numeric? [data dimension] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
--- src/clj/cljs/analyzer.clj 2012-11-17 01:01:55.712323358 -0500 | |
+++ src/cljs/cljs/analyzer.cljs 2012-11-17 11:51:47.030558150 -0500 | |
@@ -6,14 +6,23 @@ | |
; the terms of this license. | |
; You must not remove this notice, or any other, from this software. | |
-(set! *warn-on-reflection* true) | |
+;; (set! *warn-on-reflection* true) | |
(ns cljs.analyzer |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
;;I'd like to use core.logic to rewrite "colloquial" plot specifications into full, correct specs from which the C2PO compiler can generate graphics. | |
;;A full C2PO plot spec looks like: | |
{:data [...] ;;A seq of maps | |
:group :identity | |
:stat :identity | |
:mapping {} ;;A map from a geom's aesthetic to a key in the data maps, e.g., {:x :weight, :y :miles-per-gallon} | |
:geom :point | |
:scales {} ;;A map of aesthetic keywords to scales, e.g., {:x :linear} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defrel person id) | |
(defrel task id start end duration) | |
(facts person [['A] ['B]]) | |
(facts task [[1 0 10 5] | |
[2 0 10 9] | |
[3 0 11 3]]) | |
(defne personso [q] | |
([()]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#lang racket | |
;; 0CFA in the AAM style on some hairy Church numeral churning | |
;; + compilation phase | |
;; + lazy non-determinism | |
;; + specialized step & iterator 0m34.248s vs 0m16.339s | |
;; + compute store ∆s 0m16.339s vs 0m1.065s (!!!) | |
;; An Exp is one of: |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
% Two dices are thrown and the results added up. | |
% We sample when the sum is conditioned on the first dice landing on 2. | |
output(S) :- | |
randvar(a, dice(X), X), | |
dice(Y), | |
S is X + Y. | |
dice(X) :- | |
X is random(6) + 1. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Memoization is fundamentally a top-down computation and dynamic | |
programming is fundamentally bottom-up. In memoization, we observe | |
that a computational *tree* can actually be represented as a | |
computational *DAG* (the single most underrated data structure in | |
computer science); we then use a black-box to turn the tree into a | |
DAG. But it allows the top-down description of the problem to remain | |
unchanged. | |
In dynamic programming, we make the same observation, but construct | |
the DAG from the bottom-up. That means we have to rewrite the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
; y has upper bound x, z has upper bound (Seqable y) | |
typed.core=> (ann foo (All [x [y :< x] [z :< (Seqable y)]] | |
[x y z -> Any])) | |
[typed.core/foo (All [x [y :< x] [z :< (clojure.lang.Seqable y)]] (Fn [x y z -> Any]))] | |
typed.core=> (declare foo) | |
#'typed.core/foo | |
;cf = check-form | |
typed.core=> (cf (foo 2 2 [2])) | |
Any |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defne all-distinctfd [l] | |
([()]) | |
([[h . t]] | |
(distinctfd h) | |
(all-distinctfd t))) | |
(run 1 [q] | |
(fresh [a1 a2 a3 a4 | |
b1 b2 b3 b4 | |
c1 c2 c3 c4 |