Debian Codegraph @

test/regress/cli/regress1/sygus/rec-fun-while-1.sy

raw
1 ; EXPECT: feasible
2 ; COMMAND-LINE: --sygus-out=status --lang=sygus2 --no-check-synth-sol -q
3
4 (set-logic ALL)
5
6 ; The environment datatypes
7 (declare-datatype NVars ((x)))
8
9 (declare-datatype Pair ((build (first NVars) (second Int))))
10
11 (declare-datatype Env ((cons (head Pair) (tail Env)) (nil)))
12
13 (define-fun-rec envStore ((var NVars) (value Int) (env Env)) Env
14 (ite (is-nil env)
15 (cons (build var value) env)
16 (ite (= var (first (head env)))
17 (cons (build var value) (tail env))
18 (cons (head env) (envStore var value (tail env)))
19 )
20 )
21 )
22
23 (define-fun-rec envSelect ((var NVars) (env Env)) Int
24 (ite (is-nil env)
25 0
26 (ite (= var (first (head env)))
27 (second (head env))
28 (envSelect var (tail env))
29 )
30 )
31 )
32
33 ; Syntax for arithmetic expressions
34 (declare-datatype Aexp
35 (
36 (Val (val Int))
37 (Var (name NVars))
38 (Add (addL Aexp) (addR Aexp))
39 )
40 )
41
42 ; Function to evaluate arithmetic expressions
43 (define-fun-rec evalA ((env Env) (a Aexp)) Int
44 (ite (is-Val a)
45 (val a)
46 (envSelect (name a) env)
47 ))
48
49 ; Syntax for boolean expressions
50 (declare-datatype Bexp
51 (
52 (LT (ltL Aexp) (ltR Aexp))
53 )
54 )
55
56 ; Function to evaluate boolean expressions
57 (define-fun-rec evalB ((env Env) (b Bexp)) Bool
58 (< (evalA env (ltL b)) (evalA env (ltR b)))
59 )
60
61 ; Syntax for commands
62 (declare-datatype Com
63 (
64 (Assign (lhs NVars) (rhs Aexp))
65 (While (wCond Bexp) (wCom Com))
66 )
67 )
68
69 ; Function to evaluate statements
70 (define-fun-rec evalC ((env Env) (c Com)) Env
71 (ite (is-Assign c)
72 (envStore (lhs c) (evalA env (rhs c)) env)
73 (ite (evalB env (wCond c)) (evalC (evalC env (wCom c)) c) env)
74 )
75 )
76
77 (synth-fun prog () Com
78 ((C1 Com) (C2 Com) (VX NVars) (A1 Aexp) (A2 Aexp) (B Bexp) (I Int))
79 (
80 (C1 Com ((While B C2)))
81 (C2 Com ((Assign VX A2)))
82 (VX NVars (x))
83 (A1 Aexp ((Var VX)))
84 (A2 Aexp ((Val I)))
85 (B Bexp ((LT A1 A2)))
86 (I Int (0 1 (+ I I)))
87 )
88 )
89
90 (constraint (= (evalC (cons (build x 0) nil) prog) (cons (build x 2) nil)))
91
92 (check-synth)