---
# System prepended metadata

title: Lab 4

---

# Lab 4

## Problem 1


### Part 1

```racket
(define list-length
  (lambda (l)
    (match l
      ['() 0]
      [(cons _ tail) (+ 1 (list-length tail))])))

    (list-length '(21 7 4)) ≡ 3
    (list-length '(21 7 4))
--> (match '(21 7 4) ...)
--> (+ 1 (list-length tail))
--> (+ 1 (list-length '(7 4)))
--> (+ 1 (match '(7 4) ...))
--> (+ 1 (+ 1 (list-length '(4))))
--> (+ 1 (+ 1 (match '(4) ...)))
--> (+ 1 (+ 1 (+ 1 (list-length '()))))
--> (+ 1 (+ 1 (+ 1 (match '()))))
--> (+ 1 (+ 1 (+ 1 0)))
--> (+ 1 (+ 1 1))
--> (+ 1 2)
--> 3
```

### Part 2

**Claim**: `(list-length '(21 7 4)) ≡ 3`.

_Proof_.
The left-hand side of the equivalence evaluates as shown above:

$3 \equiv 3$
>Thus, (list-length '(21 7 4)) ≡ 3.
□

## Problem 2

**Claim**: `(list-replicate "!" 3) ≡ '("!" "!" "!")`

_Proof_.
The left-hand side of the equivalence evaluates as follows:

```racket
    (list-replicate "!" 3)
--> (cons "!" (list-replicate "!" (- 3 1)))
--> (cons "!" (cons "!" (list-replicate "!" (- 2 1))))
--> (cons "!" (cons "!" (cons "!" (list-replicate "!" (- 1 1)))))
--> (cons "!" (cons "!" (cons "!" '())))
--> '("!" "!" "!")


```

□


**Claim**: `((list-length (list-append '(1 2) '(3 4 5))) ≡ (+ (list-length '(1 2)) (list-length '(3 4 5)))`

_Proof_.
The left-hand side of the equivalence evaluates as follows:



```racket

    ((list-length (list-append '(1 2) '(3 4 5)))
--> (list-length '(1 2 3 4 5))
--> 5

    (+ (list-length '(1 2)) (list-length '(3 4 5)))
--> (+ 2 (list-length '(3 4 5)))
--> (+ 2 3)
--> 5

5 ≡ 5

```

□

