Skip to content

Instantly share code, notes, and snippets.

View no-defun-allowed's full-sized avatar

Hayley Patton no-defun-allowed

View GitHub Profile
@no-defun-allowed
no-defun-allowed / nn.lisp
Created November 2, 2018 00:28
a neural network with petalisp
(ql:quickload :petalisp)
(use-package :petalisp)
(defvar x (as-matrix #2a((5.1 3.5 1.4 0.2)
(4.9 3.0 1.4 0.2)
(6.2 3.4 5.4 2.3)
(5.9 3.0 5.1 1.9))))
(defvar y (as-matrix #(0 0 1 1)))
(defvar w (as-matrix #(0.5 0.5 0.5 0.5)))
@no-defun-allowed
no-defun-allowed / oblique-strategies.el
Last active August 26, 2020 15:47
Brian Eno's Oblique Strategies cards in Emacs
(defvar *oblique-strategy-list*
'("Remove specifics and convert to ambiguities"
"Don't be frightened of cliches"
"What is the reality of the situation?"
"Are there sections? Consider transitions "
"Turn it upside down "
"Think of the radio "
"Allow an easement (an easement is the abandonment of a stricture) "
"Simple subtraction "
"Go slowly all the way round the outside "
@no-defun-allowed
no-defun-allowed / parse.lisp
Created January 4, 2019 08:04
lisp parsing lisp
(defun read-list (stream)
(if (char= (peek-char t stream) #\))
(progn
(read-char stream)
nil)
(cons (read-sexp stream)
(read-list stream))))
(defun read-atom (stream &optional (collected nil))
(let ((char (peek-char (null collected) stream nil :eof)))
@no-defun-allowed
no-defun-allowed / nn2.lisp
Created March 17, 2019 07:24
A deeper neural network using Petalisp.
(ql:quickload :petalisp.examples)
(use-package '(:petalisp :petalisp.examples.linear-algebra))
;; We use this internal function in our hack over transpose and matmul.
(import 'petalisp.examples.linear-algebra::coerce-to-matrix)
(declaim (optimize (speed 3) (safety 1) (debug 0)))
;; I use these modified function definitions to produce the ranges
;; [0, n - 1] instead of [1, n], which makes handling them aside already
;; computed arrays much easier.
(defun transpose (x)
@no-defun-allowed
no-defun-allowed / nn3.lisp
Created April 19, 2019 02:21
A half-baked neural network library using Petalisp.
(ql:quickload :petalisp.examples)
(use-package '(:petalisp :petalisp.examples.linear-algebra))
;; we use this internal function in our hack over transpose and matmul.
(import 'petalisp.examples.linear-algebra::coerce-to-matrix)
(declaim (optimize (speed 3) (safety 1) (debug 3)))
;; i use these modified function definitions to produce the ranges
;; [0, n - 1] instead of [1, n], which makes handling them aside already
;; computed arrays much easier.
(defun transpose (x)
@no-defun-allowed
no-defun-allowed / lir-generator-and-printer.lisp
Created December 29, 2019 09:30
A LIR printer and a utility function for making Cleavir HIR, MIR and LIR
(ql:quickload '(:concrete-syntax-tree :trucler-native
:cleavir2-cst-to-ast :sicl-ast-to-hir
:sicl-hir-to-mir :sicl-mir-to-lir))
(defvar *environment*)
(defvar *client*)
(defun expression-to-ir (expression &key (type :lir))
(let* ((cst (concrete-syntax-tree:cst-from-expression expression))
(ast (cleavir-cst-to-ast:cst-to-ast *client* cst *environment*))
(hir (sicl-ast-to-hir:ast-to-hir *client* ast)))
@no-defun-allowed
no-defun-allowed / fft.lisp
Created March 22, 2020 09:58
The Fast Fourier Transform in Petalisp
(use-package :petalisp)
(defun fft (x)
(let ((n (shape-size (shape x))))
(assert (= (shape-rank (shape x)) 1))
(assert (zerop (logand n (1- n))) ()
"The length is not a power of 2")
(if (<= n 1)
x
(let* ((even (fft (reshape x (~ 0 2 (1- n))
@no-defun-allowed
no-defun-allowed / regexp.hs
Last active April 22, 2020 01:36
Stupid regular expression engine in Haskell
data NFAState = Match Char NFAState |
MatchAll NFAState |
Amb NFAState NFAState | Halt
deriving Show
data Automaton = Running [Char] NFAState | Finished deriving Show
finished :: Automaton -> Bool
finished (Running _ _) = False
finished Finished = True
@no-defun-allowed
no-defun-allowed / subtypep-set-arithmetic.lisp
Last active July 11, 2020 01:28
Asking logic questions using SUBTYPEP
CL-USER> (defun true? (p)
"Is P the universal set, i.e. is our statement P true?"
(subtypep 't p))
TRUE?
CL-USER> (deftype implies (p q)
"Are all elements of P elements of Q? (This is basically SUBTYPEP again.)"
`(or (not ,p) ,q))
IMPLIES
CL-USER> (true? '(implies cons list)) ; Does CONS imply LIST?
;; Note that SUBTYPEP returns:
(ql:quickload :the-cost-of-nothing)
(in-package :cl-user)
(defun foo (x)
(declare (integer x)
(optimize (speed 3)))
(< (- (expt 2 256)) x (expt 2 256)))
(the-cost-of-nothing:bench (foo 7))
(in-package :sb-c)