Coverage report: /home/runner/work/geb/geb/src/seqn/seqn.lisp
Kind | Covered | All | % |
expression | 256 | 549 | 46.6 |
branch | 9 | 28 | 32.1 |
Key
Not instrumented
Conditionalized out
Executed
Not executed
Both branches taken
One branch taken
Neither branch taken
1
(in-package :geb.seqn.main)
3
(defun fill-in (num seq)
4
"Fills in extra inputs on the right with 0-oes"
5
(geb.utils:apply-n num (lambda (x) (append x (list 0))) seq))
8
(make-list n :initial-element 0))
10
(defun prod-list (l1 l2)
11
"Takes two lists of same length and gives pointwise product
12
where first element come from first list and second from second
15
SEQN> (prod-list (list 1 2) (list 3 4))
18
(mapcar #'list l1 l2))
20
(defun seq-max-fill (seq1 seq2)
21
"Takes two lists, makes them same length by adding 0es on the right
22
where necessary and takes their pointwise product"
23
(let ((l1 (length seq1))
26
(prod-list (fill-in (- l2 l1) seq1) seq2)
27
(prod-list seq1 (fill-in (- l1 l2) seq2)))))
30
(max (car lst) (cadr lst)))
32
(defmethod width ((obj <substobj>))
33
(typecase-of substobj obj
38
(seq-max-fill (width (mcar obj))
39
(width (mcadr obj))))))
40
(prod (append (width (mcar obj))
42
(otherwise (geb.utils:subclass-responsibility obj))))
44
(defmethod width ((obj <natobj>))
45
(typecase-of natobj obj
46
(nat-width (list (num obj)))
47
(otherwise (geb.utils:subclass-responsibility obj))))
49
(defun inj-coprod-parallel (obj copr)
50
"takes an width(A) or width(B) already transformed with a width(A+B)
51
and gives an appropriate injection of (a1,...,an) into
52
(max (a1, b1), ...., max(an, bn),...) i.e. where the maxes are being
53
taken during the width operation without filling in of the smaller object"
54
(let* ((lng (length obj))
55
(lngcoprod (1- (length copr)))
56
(dif (- lngcoprod lng))
60
(composition (drop-width (append obj (zero-list dif))
62
(inj-length-left obj (zero-list dif))))))
64
(defmethod dom ((x <seqn>))
65
"Gives the domain of a morphism in SeqN.
66
For a less formal desription consult the specs file"
68
(composition (dom (mcadr x)))
70
(parallel-seq (append (dom (mcar x)) (dom (mcadr x))))
73
(remove-right (append (mcar x) (list 0)))
74
(remove-left (cons 0 (mcar x)))
76
(inj-length-left (mcar x))
77
(inj-length-right (mcadr x))
78
(inj-size (list (mcar x)))
79
(branch-seq (cons 1 (dom (mcar x))))
82
(shift-front (mcar x))
83
(seqn-add (list (mcar x) (mcar x)))
84
(seqn-subtract (list (mcar x) (mcar x)))
85
(seqn-multiply (list (mcar x) (mcar x)))
86
(seqn-divide (list (mcar x) (mcar x)))
87
(seqn-mod (list (mcar x) (mcar x)))
89
(seqn-concat (list (mcar x) (mcadr x)))
90
(seqn-decompose (list (mcar x)))
91
(seqn-eq (list (mcar x) (mcar x)))
92
(seqn-lt (list (mcar x) (mcar x)))
93
(otherwise (geb.utils:subclass-responsibility x))))
95
(defmethod cod ((x <seqn>))
96
"Gives the codomain of a morphism in SeqN.
97
For a less formal description consult the specs file"
99
(composition (cod (mcar x)))
100
(fork-seq (append (mcar x) (mcar x)))
101
(parallel-seq (append (cod (mcar x)) (cod (mcadr x))))
104
(remove-right (mcar x))
105
(remove-left (mcar x))
106
(drop-width (mcadr x))
107
(inj-length-left (append (mcar x) (mcadr x)))
108
(inj-length-right (append (mcar x) (mcadr x)))
109
(inj-size (list (mcadr x)))
110
(branch-seq (cod (mcar x)))
113
(shift-front (let ((mcar (mcar x))
115
(append (cons (nth (1- mcadr) mcar)
116
(subseq mcar 0 (1- mcadr)))
117
(subseq mcar mcadr))))
118
(seqn-add (list (mcar x)))
119
(seqn-subtract (list (mcar x)))
120
(seqn-multiply (list (mcar x)))
121
(seqn-divide (list (mcar x)))
122
(seqn-nat (list (mcar x)))
123
(seqn-mod (list (mcar x)))
124
(seqn-concat (list (+ (mcar x) (mcadr x))))
125
(seqn-decompose (list 1 (1- (mcar x))))
128
(otherwise (geb.utils:subclass-responsibility x))))
130
(defmethod gapply ((morphism <seqn>) vector)
131
"Takes a list of vectors of natural numbers and gives out their evaluations.
132
Currently does not correspond directly to the intended semantics but
133
is capable of succesfully evaluating all compiled terms"
134
(etypecase-of seqn morphism
136
(composition (gapply (mcar morphism)
137
(gapply (mcadr morphism) vector)))
138
(parallel-seq (let ((lng (length (dom (mcar morphism)))))
139
(append (gapply (mcar morphism)
142
(gapply (mcadr morphism)
145
(fork-seq (append vector vector))
147
(remove-right (butlast vector))
148
(remove-left (cdr vector))
150
(inj-length-left (append vector
151
(make-list (length (mcadr morphism))
152
:initial-element 0)))
153
(inj-length-right (append (make-list (length (mcar morphism))
157
(branch-seq (let ((cdr (cdr vector)))
158
(if (= 0 (car vector))
159
(gapply (mcar morphism)
161
(gapply (mcadr morphism)
163
(shift-front (let ((mcadr (1- (mcadr morphism))))
164
(append (cons (nth mcadr
166
(subseq vector 0 mcadr))
167
(subseq vector (mcadr morphism)))))
170
(seqn-add (list (+ (car vector) (cadr vector))))
171
(seqn-subtract (list (- (car vector) (cadr vector))))
172
(seqn-multiply (list (* (car vector) (cadr vector))))
173
(seqn-divide (list (multiple-value-bind (q)
174
(floor (car vector) (cadr vector)) q)))
175
(seqn-mod (list (mod (car vector) (cadr vector))))
176
(seqn-nat (list (mcadr morphism)))
177
(seqn-concat (list (+ (* (expt 2 (mcadr morphism)) (car vector))
179
(seqn-decompose (let ((car (car vector))
180
(exp (expt 2 (1- (mcar morphism)))))
184
(seqn-eq (if (= (car vector) (cadr vector))
187
(seqn-lt (if (< (car vector) (cadr vector))
191
(defmethod well-defp-cat ((morph <seqn>))
192
(etypecase-of seqn morph
194
(let* ((mcar (mcar morph))
195
(mcadr (mcadr morph))
198
(if (and (well-defp-cat mcar)
199
(well-defp-cat mcadr)
203
(error "Co(Domains) do not match for ~A with domain
204
of MCAR ~A1 and codomain of MCADR ~A2."
207
(if (and (well-defp-cat (mcar morph))
208
(well-defp-cat (mcadr morph)))
210
(error "Not well-defined parallel composition ~A" morph)))
212
(let* ((mcar (mcar morph))
213
(mcadr (mcadr morph))
218
(if (and (well-defp-cat mcar)
219
(well-defp-cat mcadr)
220
(obj-equalp dom1 dom2)
221
(obj-equalp cod1 cod2))
223
(error "Not a well-defined branching ~A.
224
~A1 has dom ~a1 and cod ~a2.
225
~A2 has dom ~a3 and cod ~a4"
226
morph mcar dom1 cod1 mcadr dom2 cod2))))
228
(if (>= (length (mcar morph))
231
(error "Wrong shift-length for ~A" morph)))