Coverage report: /home/runner/work/geb/geb/src/specs/bitc.lisp
Kind | Covered | All | % |
expression | 12 | 44 | 27.3 |
branch | 0 | 0 | nil |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
(in-package #:geb.bitc.spec)
4
`(or compose fork parallel swap one zero ident drop branch))
6
(defclass <bitc> (geb.mixins:direct-pointwise-mixin cat-morph) ())
8
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
9
;; Constructor Morphisms for Bits (Objects are just natural numbers)
10
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
12
(defclass compose (<bitc>)
16
(mcadr :initarg :mcadr
19
(:documentation "composes the MCAR and the MCADR"))
21
(defclass fork (<bitc>)
25
(:documentation "Copies the MCAR of length n onto length 2*n by copying its
28
(defclass parallel (<bitc>)
32
(mcadr :initarg :mcadr
41
constructs a [PARALLEL][class] term where the [MCAR] is `x` and the
48
-------------------------------
49
(parallel x y) : a + c → b + d
52
then the [PARALLEL][class] will return a function from a and c to b
53
and d where the [MCAR] and [MCADR] run on subvectors of the input."))
55
(defclass swap (<bitc>)
59
(mcadr :initarg :mcadr
68
binds the [MCAR] to n and [MCADR] to m, where if the input
69
vector is of length `n + m`, then it swaps the bits, algebraically we
73
(swap n m) : #*b₁...bₙbₙ₊₁...bₙ₊ₘ → #*bₙ₊₁...bₘ₊ₙb₁...bₙ
76
(defclass one (<bitc>)
79
"[ONE][class] represents the map from 0 onto 1 producing a vector
82
(defclass zero (<bitc>)
85
"[ZERO] map from 0 onto 1 producing a vector with only 0 in
88
(defclass ident (<bitc>)
93
"[IDENT] represents the identity"))
95
(defclass drop (<bitc>)
100
"[DROP] represents the unique morphism from n to 0."))
102
(defclass branch (<bitc>)
103
((mcar :initarg :mcar
106
(mcadr :initarg :mcadr
115
constructs a [BRANCH][class] term where the [MCAR] is `x` and the
122
-------------------------------
123
(branch x y) : 1+a → b
126
then the [BRANCH] will return a function on the type `1 + a`, where the
127
1 represents a bit to branch on. If the first bit is `0`, then the
128
[MCAR] is ran, however if the bit is `1`, then the [MCADR] is ran."))
130
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
132
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
134
(defmacro make-multi (constructor)
135
`(defun ,constructor (mcar mcadr &rest args)
136
,(format nil "Creates a multiway constructor for [~A]" constructor)
137
(reduce (lambda (x y)
138
(make-instance ',constructor :mcar x :mcadr y))
139
(list* mcar mcadr args)
142
(make-multi parallel)
147
(make-instance 'fork :mcar mcar))
149
(defun swap (mcar mcadr)
151
(make-instance 'swap :mcar mcar :mcadr mcadr))
154
(make-instance 'one))
157
(make-instance 'zero))
161
(make-instance 'ident :mcar mcar))
165
(make-instance 'drop :mcar mcar))
167
(defun branch (mcar mcadr)
168
"branch with ARG1 or ARG2"
169
(make-instance 'branch :mcar mcar :mcadr mcadr))
171
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
173
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
175
;; Ι don't do multi way pattern matching yet :(
176
(make-pattern compose mcar mcadr)
177
(make-pattern fork mcar)
178
(make-pattern parallel mcar mcadr)
179
(make-pattern swap mcar mcadr)
180
(make-pattern ident mcar)
181
(make-pattern drop mcar)
182
(make-pattern branch mcar mcadr)