Skip to content

Instantly share code, notes, and snippets.

View swannodette's full-sized avatar

David Nolen swannodette

View GitHub Profile
; '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])
@swannodette
swannodette / gist:4120545
Created November 20, 2012 19:46 — forked from lynaghk/gist:4116442
Possible syntaxes for flexible unifier w/ multi-lvar constraints
;;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]
--- 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
@swannodette
swannodette / gist:4004143
Created November 2, 2012 20:32 — forked from lynaghk/1-rewrite_usage.clj
Questions about fancy map rewriting via core.logic
;;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}
}
(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]
([()])
@swannodette
swannodette / delta-0cfa.rkt
Created October 6, 2012 15:35 — forked from dvanhorn/delta-0cfa.rkt
Store delta 0CFA
#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:
@swannodette
swannodette / cond.pl
Created October 5, 2012 23:47 — forked from Pet3ris/cond.pl
rejection sampling conditioner in prolog
% 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.
@swannodette
swannodette / memo-dyn.txt
Created August 24, 2012 17:55 — forked from dvanhorn/memo-dyn.txt
Memoization vs dynamic programming
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
@swannodette
swannodette / fbound.clj
Created August 10, 2012 13:55 — forked from frenchy64/fbound.clj
F-bounded Polymorphism in Typed Clojure
; 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
@swannodette
swannodette / sud4-ckanren.clj
Created July 27, 2012 19:41 — forked from martintrojer/sud4-ckanren.clj
Sudoku core.logic
(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