File: fty-pseudo-terms.lisp

package info (click to toggle)
acl2 8.5dfsg-5
  • links: PTS
  • area: main
  • in suites: bookworm
  • size: 991,452 kB
  • sloc: lisp: 15,567,759; javascript: 22,820; cpp: 13,929; ansic: 12,092; perl: 7,150; java: 4,405; xml: 3,884; makefile: 3,507; sh: 3,187; ruby: 2,633; ml: 763; python: 746; yacc: 723; awk: 295; csh: 186; php: 171; lex: 154; tcl: 49; asm: 23; haskell: 17
file content (607 lines) | stat: -rw-r--r-- 22,856 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
; C Library
;
; Copyright (C) 2021 Kestrel Institute (http://www.kestrel.edu)
; Copyright (C) 2021 Kestrel Technology LLC (http://kestreltechnology.com)
;
; License: A 3-clause BSD license. See the LICENSE file distributed with ACL2.
;
; Author: Alessandro Coglio (coglio@kestrel.edu)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(in-package "C")

(include-book "clause-processors/pseudo-term-fty" :dir :system)
(include-book "kestrel/fty/symbol-pseudoterm-alist" :dir :system)
(include-book "kestrel/std/system/check-and-call" :dir :system)
(include-book "kestrel/std/system/check-fn-call" :dir :system)
(include-book "kestrel/std/system/fsublis-var" :dir :system)
(include-book "kestrel/std/system/check-if-call" :dir :system)
(include-book "kestrel/std/system/check-lambda-call" :dir :system)
(include-book "kestrel/std/system/check-list-call" :dir :system)
(include-book "kestrel/std/system/check-mbt-call" :dir :system)
(include-book "kestrel/std/system/check-mbt-dollar-call" :dir :system)
(include-book "kestrel/std/system/check-mv-let-call" :dir :system)
(include-book "kestrel/std/system/check-not-call" :dir :system)
(include-book "kestrel/std/system/check-or-call" :dir :system)
(include-book "std/util/defrule" :dir :system)
(include-book "xdoc/defxdoc-plus" :dir :system)

(local (include-book "std/typed-lists/pseudo-term-listp" :dir :system))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(defxdoc+ fty-pseudo-term-utilities
  :parents (atc-implementation)
  :short "FTY utilities for pseudo-terms."
  :long
  (xdoc::topstring
   (xdoc::p
    "Many system utilities, e.g. built-in and in "
    (xdoc::seetopic "acl2::std/system" "Std/system")
    ", are written using the built-in ACL2 term API.
     When using these system utilities
     in code that uses the "
    (xdoc::seetopic "acl2::pseudo-term-fty" "FTY term API")
    ", there may be a slight ``mismatch'',
     e.g. in the way the two APIs fix non-terms,
     or in the fact that, for termination,
     the ACL2 API is based on @(tsee acl2-count)
     while the FTY API is based on @(tsee pseudo-term-count).")
   (xdoc::p
    "The mismatch can be bridged by introducing
     simple wrappers of those system utilities
     that fix the term (in the FTY way) and then call the utilities.
     Here we provide a number of such wrappers,
     which should be eventually moved to a more central place.")
   (xdoc::p
    "The wrappers are accompanied by theorems
     leveraged from the wrapped utilities.
     This way the wrappers can be left disabled in code that uses them.")
   (xdoc::p
    "The @(tsee acl2-count) vs. @(tsee pseudo-term-count) issue
     requires a bit more work.
     Suppose we have a utility that returns results
     that are @(tsee acl2-count)-smaller than its arguments
     (under suitable conditions).
     In order to prove that the wrapper returns results
     that are @(tsee pseudo-term-count)-smaller than its arguments,
     we cannot leverage the theorems about @(tsee acl2-count).
     Instead, we need to enable the utilities to prove the theorems,
     and we also need to enable some FTY pseudo-term operations,
     because we need to break the FTY pseudo-term abstraction:
     we use this approach to prove theorems
     about the original utilities and @(tsee pseudo-term-count)
     under @(tsee pseudo-termp) assumptions,
     from which then the desired theorems about the wrappers readily follow.
     The theorems about the original utilities and @(tsee pseudo-term-count)
     are useful to prove the analogous theorems of utilities that call them."))
  :order-subtopics t
  :default-parent t)

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-fn-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (fn symbolp)
               (args pseudo-term-listp))
  :short "FTY version of @(tsee check-fn-call)."
  (check-fn-call (pseudo-term-fix term))
  ///

  (more-returns
   (args true-listp :rule-classes :type-prescription))

  (defret fty-check-fn-call-not-quote
    (not (equal fn 'quote)))

  (defrule pseudo-term-list-count-of-check-fn-call.args
    (implies (pseudo-termp term)
             (b* (((mv yes/no & args) (check-fn-call term)))
               (implies yes/no
                        (< (pseudo-term-list-count args)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-fn-call
             pseudo-term-kind
             pseudo-term-call->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-list-count-of-fty-check-fn-call.args
    (implies yes/no
             (< (pseudo-term-list-count args)
                (pseudo-term-count term)))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-if-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (test pseudo-termp)
               (then pseudo-termp)
               (else pseudo-termp))
  :short "FTY version of @(tsee check-if-call)."
  (check-if-call (pseudo-term-fix term))
  ///

  (defrule pseudo-term-count-of-check-if-call.test
    (implies (pseudo-termp term)
             (b* (((mv yes/no test & &) (check-if-call term)))
               (implies yes/no
                        (< (pseudo-term-count test)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-if-call
             pseudo-term-kind
             pseudo-term-call->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-count-of-fty-check-if-call.test
    (implies yes/no
             (< (pseudo-term-count test)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-count-of-check-if-call.then
    (implies (pseudo-termp term)
             (b* (((mv yes/no & then &) (check-if-call term)))
               (implies yes/no
                        (< (pseudo-term-count then)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-if-call
             pseudo-term-kind
             pseudo-term-call->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-count-of-fty-check-if-call.then
    (implies yes/no
             (< (pseudo-term-count then)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-count-of-check-if-call.else
    (implies (pseudo-termp term)
             (b* (((mv yes/no & & else) (check-if-call term)))
               (implies yes/no
                        (< (pseudo-term-count else)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-if-call
             pseudo-term-kind
             pseudo-term-call->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-count-of-fty-check-if-call.else
    (implies yes/no
             (< (pseudo-term-count else)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-count-of-check-if-call
    (implies (pseudo-termp term)
             (b* (((mv yes/no test then else) (check-if-call term)))
               (implies yes/no
                        (< (+ (pseudo-term-count test)
                              (pseudo-term-count then)
                              (pseudo-term-count else))
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-if-call
             pseudo-term-kind
             pseudo-term-call->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-count-of-fty-check-if-call
    (implies yes/no
             (< (+ (pseudo-term-count test)
                   (pseudo-term-count then)
                   (pseudo-term-count else))
                (pseudo-term-count term)))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-lambda-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (formals symbol-listp)
               (body pseudo-termp)
               (args pseudo-term-listp))
  :short "FTY version of @(tsee check-lambda-call)."
  (check-lambda-call (pseudo-term-fix term))
  ///

  (defret len-of-fty-check-lambda-calls.formals-is-args
    (equal (len formals)
           (len args))
    :hints (("Goal"
             :expand ((pseudo-term-fix term))
             :in-theory (enable check-lambda-call))))

  (defret len-of-fty-check-lambda-calls.args-is-formals
    (equal (len args)
           (len formals))
    :hints (("Goal" :use len-of-fty-check-lambda-calls.formals-is-args)))

  (in-theory (disable len-of-fty-check-lambda-calls.formals-is-args
                      len-of-fty-check-lambda-calls.args-is-formals))

  (theory-invariant (incompatible
                     (:rewrite fty-len-of-check-lambda-calls.formals-is-args)
                     (:rewrite fty-len-of-check-lambda-calls.args-is-formals)))

  (more-returns
   (formals true-listp :rule-classes :type-prescription)
   (args true-listp :rule-classes :type-prescription))

  (defrule pseudo-term-count-of-check-lambda-call.body
    (implies (pseudo-termp term)
             (b* (((mv yes/no & body &) (check-lambda-call term)))
               (implies yes/no
                        (< (pseudo-term-count body)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-lambda-call
             pseudo-term-kind
             pseudo-term-lambda->body)
    :expand (pseudo-term-count term))

  (defret pseudo-term-count-of-fty-check-lambda-call.body
    (implies yes/no
             (< (pseudo-term-count body)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-list-count-of-check-lambda-call.args
    (implies (pseudo-termp term)
             (b* (((mv yes/no & & args) (check-lambda-call term)))
               (implies yes/no
                        (< (pseudo-term-list-count args)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-lambda-call
             pseudo-term-kind
             pseudo-term-lambda->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-list-count-of-fty-check-lambda-call.args
    (implies yes/no
             (< (pseudo-term-list-count args)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-count-of-check-lambda-call
    (implies (pseudo-termp term)
             (b* (((mv yes/no & body args) (check-lambda-call term)))
               (implies yes/no
                        (< (+ (pseudo-term-count body)
                              (pseudo-term-list-count args))
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-lambda-call
             pseudo-term-count
             pseudo-term-list-count
             pseudo-term-kind
             pseudo-term-lambda->body
             pseudo-term-call->args))

  (defret pseudo-term-count-of-fty-check-lambda-call
    (implies yes/no
             (< (+ (pseudo-term-count body)
                   (pseudo-term-list-count args))
                (pseudo-term-count term)))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-remove-equal-formals-actuals ((formals symbol-listp)
                                          (actuals pseudo-term-listp))
  :guard (= (len formals) (len actuals))
  :returns (mv (new-formals symbol-listp :hyp (symbol-listp formals))
               (new-actuals pseudo-term-listp))
  :short "FTY version of @(tsee remove-equal-formals-actuals)."
  (remove-equal-formals-actuals formals
                                (pseudo-term-list-fix actuals))
  ///

  (more-returns
   (new-formals true-listp :rule-classes :type-prescription)
   (new-actuals true-listp :rule-classes :type-prescription))

  (defret len-of-fty-remove-equal-formals-actuals.new-formals-is-new-actuals
    (equal (len new-formals)
           (len new-actuals))
    :hints
    (("Goal" :in-theory (enable remove-equal-formals-actuals
                                acl2::remove-equal-formals-actuals-same-len))))

  (defret len-of-fty-remove-equal-formals-actuals.new-actuals-is-new-formals
    (equal (len new-actuals)
           (len new-formals))
    :hints
    (("Goal"
      :use len-of-fty-remove-equal-formals-actuals.new-formals-is-new-actuals)))

  (in-theory
   (disable len-of-fty-remove-equal-formals-actuals.new-formals-is-new-actuals
            len-of-fty-remove-equal-formals-actuals.new-actuals-is-new-formals))

  (theory-invariant
   (incompatible
    (:rewrite
     len-of-fty-remove-equal-formals-actuals.new-formals-is-new-actuals)
    (:rewrite
     len-of-fty-remove-equal-formals-actuals.new-actuals-is-new-formals)))

  (defrule pseudo-term-list-count-of-remove-equal-formals-actuals
    (b* (((mv & new-actuals) (remove-equal-formals-actuals formals actuals)))
      (implies (pseudo-term-listp actuals)
               (<= (pseudo-term-list-count new-actuals)
                   (pseudo-term-list-count actuals))))
    :rule-classes :linear
    :enable (remove-equal-formals-actuals
             pseudo-term-list-count))

  (defret pseudo-term-list-count-of-fty-remove-equal-formals-actuals
    (<= (pseudo-term-list-count new-actuals)
        (pseudo-term-list-count actuals))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-not-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (arg pseudo-termp))
  :short "FTY version of @(tsee check-not-call)."
  (check-not-call (pseudo-term-fix term))
  ///

  (defrule pseudo-term-count-of-check-not-call.arg
    (implies (pseudo-termp term)
             (b* (((mv yes/no arg) (check-not-call term)))
               (implies yes/no
                        (< (pseudo-term-count arg)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-not-call
             pseudo-term-kind
             pseudo-term-call->args)
    :expand (pseudo-term-count term))

  (defret pseudo-term-count-of-fty-check-not-call.arg
    (implies yes/no
             (< (pseudo-term-count arg)
                (pseudo-term-count term)))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-and-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (left pseudo-termp)
               (right pseudo-termp))
  :short "FTY version of @(tsee check-and-call)."
  (check-and-call (pseudo-term-fix term))
  ///

  (defrule pseudo-term-count-of-check-and-call.left
    (implies (pseudo-termp term)
             (b* (((mv yes/no left &) (check-and-call term)))
               (implies yes/no
                        (< (pseudo-term-count left)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable check-and-call)

  (defrule pseudo-term-count-of-check-and-call.right
    (implies (pseudo-termp term)
             (b* (((mv yes/no & right) (check-and-call term)))
               (implies yes/no
                        (< (pseudo-term-count right)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable check-and-call)

  (defret pseudo-term-count-of-fty-check-and-call.left
    (implies yes/no
             (< (pseudo-term-count left)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defret pseudo-term-count-of-fty-check-and-call.right
    (implies yes/no
             (< (pseudo-term-count right)
                (pseudo-term-count term)))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-or-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (left pseudo-termp)
               (right pseudo-termp))
  :short "FTY version of @(tsee check-or-call)."
  (check-or-call (pseudo-term-fix term))
  ///

  (defrule pseudo-term-count-of-check-or-call.left
    (implies (pseudo-termp term)
             (b* (((mv yes/no left &) (check-or-call term)))
               (implies yes/no
                        (< (pseudo-term-count left)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable check-or-call)

  (defrule pseudo-term-count-of-check-or-call.right
    (implies (pseudo-termp term)
             (b* (((mv yes/no & right) (check-or-call term)))
               (implies yes/no
                        (< (pseudo-term-count right)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable check-or-call)

  (defret pseudo-term-count-of-fty-check-or-call.left
    (implies yes/no
             (< (pseudo-term-count left)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defret pseudo-term-count-of-fty-check-or-call.right
    (implies yes/no
             (< (pseudo-term-count right)
                (pseudo-term-count term)))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-mv-let-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (mv-var symbolp)
               (vars symbol-listp)
               (indices nat-listp)
               (hides boolean-listp)
               (mv-term pseudo-termp)
               (body-term pseudo-termp))
  :short "FTY version of @(tsee check-mv-let-call)."
  (check-mv-let-call (pseudo-term-fix term))
  ///

  (defret len-of-fty-check-mv-let-call.indices/vars
    (implies yes/no
             (equal (len indices)
                    (len vars)))
    :hyp :guard
    :hints (("Goal"
             :in-theory (enable acl2::len-of-check-mv-let-call.indices/vars))))

  (defret len-of-fty-check-mv-let-call.hides/vars
    (implies yes/no
             (equal (len hides)
                    (len vars)))
    :hyp :guard
    :hints (("Goal"
             :in-theory (enable acl2::len-of-check-mv-let-call.hides/vars))))

  (in-theory (disable len-of-fty-check-mv-let-call.indices/vars
                      len-of-fty-check-mv-let-call.indices/vars))

  (defrule pseudo-term-count-of-check-mv-let-call.mv-term
    (implies (pseudo-termp term)
             (b* (((mv yes/no & & & & mv-term &) (check-mv-let-call term)))
               (implies yes/no
                        (< (pseudo-term-count mv-term)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-mv-let-call
             pseudo-term-kind)
    :prep-lemmas
    ((defrule lemma
       (implies (and (pseudo-termp term)
                     (not (pseudo-term-case term :quote)))
                (<= (pseudo-term-list-count (cdr term))
                    (pseudo-term-count term)))
       :rule-classes :linear
       :expand (pseudo-term-count term)
       :enable (pseudo-term-call->args
                pseudo-term-kind))))

  (defret pseudo-term-count-of-fty-check-mv-let-call.mv-term
    (implies yes/no
             (< (pseudo-term-count mv-term)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-count-of-check-mv-let-call.body-term
    (implies (pseudo-termp term)
             (b* (((mv yes/no & & & & & body-term) (check-mv-let-call term)))
               (implies yes/no
                        (< (pseudo-term-count body-term)
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable check-mv-let-call
    :prep-lemmas
    ((defrule lemma
       (implies (and (pseudo-termp term)
                     (consp (car term)))
                (< (pseudo-term-count (caddr (car term)))
                   (pseudo-term-count term)))
       :rule-classes :linear
       :expand (pseudo-term-count term)
       :enable (pseudo-term-lambda->body
                pseudo-term-kind))))

  (defret pseudo-term-count-of-fty-check-mv-let-call.body-term
    (implies yes/no
             (< (pseudo-term-count body-term)
                (pseudo-term-count term)))
    :rule-classes :linear)

  (defrule pseudo-term-count-of-check-mv-let-call
    (implies (pseudo-termp term)
             (b* (((mv yes/no & & & & mv-term body-term)
                   (check-mv-let-call term)))
               (implies yes/no
                        (< (+ (pseudo-term-count mv-term)
                              (pseudo-term-count body-term))
                           (pseudo-term-count term)))))
    :rule-classes :linear
    :enable (check-mv-let-call
             pseudo-term-kind
             pseudo-term-lambda->body
             pseudo-term-call->args
             pseudo-term-count
             pseudo-term-list-count))

  (defret pseudo-term-count-if-fty-check-mv-let-call
    (implies yes/no
             (b* (((mv yes/no & & & & mv-term body-term)
                   (fty-check-mv-let-call term)))
               (implies yes/no
                        (< (+ (pseudo-term-count mv-term)
                              (pseudo-term-count body-term))
                           (pseudo-term-count term)))))
    :rule-classes :linear))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-check-list-call ((term pseudo-termp))
  :returns (mv (yes/no booleanp)
               (elements pseudo-term-listp))
  :short "FTY version of @(tsee check-list-call)."
  (check-list-call (pseudo-term-fix term))
  ///

  (more-returns
   (elements true-listp :rule-classes :type-prescription)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-fsublis-var ((subst symbol-pseudoterm-alistp) (term pseudo-termp))
  :returns (new-term pseudo-termp)
  :short "FTY version of @(tsee fsublis-var)."
  (fsublis-var (symbol-pseudoterm-alist-fix subst)
               (pseudo-term-fix term))
  :prepwork
  ((defrulel lemma
     (implies (and (symbol-pseudoterm-alistp alist)
                   (pseudo-termp term))
              (pseudo-termp (fsublis-var alist term)))
     :enable acl2::symbol-pseudoterm-alistp-alt-def)))

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(define fty-fsublis-var-lst ((subst symbol-pseudoterm-alistp)
                             (terms pseudo-term-listp))
  :returns (new-terms pseudo-term-listp)
  :short "FTY version of @(tsee fsublis-var-lst)."
  (fsublis-var-lst (symbol-pseudoterm-alist-fix subst)
                   (pseudo-term-list-fix terms))

  :prepwork
  ((defrulel lemma
     (implies (and (symbol-pseudoterm-alistp subst)
                   (pseudo-term-listp terms))
              (pseudo-term-listp (fsublis-var-lst subst terms)))
     :enable acl2::symbol-pseudoterm-alistp-alt-def)))