Debian Codegraph @

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

raw
1 ; EXPECT: feasible
2 ; COMMAND-LINE: --sygus-out=status --lang=sygus2 --no-check-synth-sol
3
4 (set-logic ALL)
5
6 ; The environment datatypes
7 (declare-datatype NVars ((x) (y)))
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 (Sub (subL Aexp) (subR Aexp))
40 )
41 )
42
43 ; Function to evaluate arithmetic expressions
44 (define-fun-rec evalA ((env Env) (a Aexp)) Int
45 (ite (is-Val a)
46 (val a)
47 (envSelect (name a) env)
48 ))
49
50 ; Syntax for boolean expressions
51 (declare-datatype Bexp
52 (
53 (GTH (geqL Aexp) (geqR Aexp))
54 )
55 )
56
57 ; Function to evaluate boolean expressions
58 (define-fun-rec evalB ((env Env) (b Bexp)) Bool
59 (> (evalA env (geqL b)) (evalA env (geqR b)))
60 )
61
62 ; Syntax for commands
63 (declare-datatype Com
64 (
65 (Assign (lhs NVars) (rhs Aexp))
66 (While (wCond Bexp) (wCom Com))
67 )
68 )
69
70 ; Function to evaluate statements
71 (define-fun-rec evalC ((env Env) (c Com)) Env
72 (ite (is-Assign c)
73 (envStore (lhs c) (evalA env (rhs c)) env)
74 (ite (evalB env (wCond c)) (evalC (evalC env (wCom c)) c) env)
75 )
76 )
77
78 (synth-fun prog () Com
79 ((C1 Com) (C2 Com) (VX NVars) (A1 Aexp) (A2 Aexp) (B Bexp) (I Int))
80 (
81 (C1 Com ((While B C2)))
82 (C2 Com ((Assign VX A2)))
83 (VX NVars (x))
84 (A1 Aexp ((Var VX)))
85 (A2 Aexp ((Val I)))
86 (B Bexp ((GTH A2 A1)))
87 (I Int (2))
88 )
89 )
90
91 (constraint (= (evalC (cons (build x 0) nil) prog) (cons (build x 2) nil)))
92
93 (check-synth)