diff options
Diffstat (limited to 'Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_RelationMapper.xtend')
-rw-r--r-- | Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_RelationMapper.xtend | 183 |
1 files changed, 183 insertions, 0 deletions
diff --git a/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_RelationMapper.xtend b/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_RelationMapper.xtend new file mode 100644 index 00000000..60653a42 --- /dev/null +++ b/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_RelationMapper.xtend | |||
@@ -0,0 +1,183 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDeclaration | ||
5 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.RelationDefinition | ||
6 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable | ||
7 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VLSFunction | ||
8 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VLSTerm | ||
9 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VLSVariable | ||
10 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VampireLanguageFactory | ||
11 | import java.util.ArrayList | ||
12 | import java.util.HashMap | ||
13 | import java.util.List | ||
14 | import java.util.Map | ||
15 | |||
16 | import static extension hu.bme.mit.inf.dslreasoner.util.CollectionsUtil.* | ||
17 | |||
18 | class Logic2VampireLanguageMapper_RelationMapper { | ||
19 | private val extension VampireLanguageFactory factory = VampireLanguageFactory.eINSTANCE | ||
20 | private val Logic2VampireLanguageMapper_Support support = new Logic2VampireLanguageMapper_Support | ||
21 | val Logic2VampireLanguageMapper base | ||
22 | |||
23 | public new(Logic2VampireLanguageMapper base) { | ||
24 | this.base = base | ||
25 | } | ||
26 | |||
27 | def dispatch public void transformRelation(RelationDefinition r, Logic2VampireLanguageMapperTrace trace) { | ||
28 | |||
29 | // 1. store all variables in support wrt their name | ||
30 | // 1.1 if variable has type, creating list of type declarations | ||
31 | val Map<Variable, VLSVariable> relationVar2VLS = new HashMap | ||
32 | val Map<Variable, VLSFunction> relationVar2TypeDecComply = new HashMap | ||
33 | val Map<Variable, VLSFunction> relationVar2TypeDecRes = new HashMap | ||
34 | val typedefs = new ArrayList<VLSTerm> | ||
35 | for (variable : r.variables) { | ||
36 | val v = createVLSVariable => [ | ||
37 | it.name = support.toIDMultiple("Var", variable.name) | ||
38 | ] | ||
39 | relationVar2VLS.put(variable, v) | ||
40 | |||
41 | val varTypeComply = createVLSFunction => [ | ||
42 | it.constant = support.toIDMultiple("type", (variable.range as ComplexTypeReference).referred.name) | ||
43 | it.terms += createVLSVariable => [ | ||
44 | it.name = support.toIDMultiple("Var", variable.name) | ||
45 | ] | ||
46 | ] | ||
47 | relationVar2TypeDecComply.put(variable, varTypeComply) | ||
48 | |||
49 | val varTypeRes = createVLSFunction => [ | ||
50 | it.constant = support.toIDMultiple("type", (variable.range as ComplexTypeReference).referred.name) | ||
51 | it.terms += createVLSVariable => [ | ||
52 | it.name = support.toIDMultiple("Var", variable.name) | ||
53 | ] | ||
54 | ] | ||
55 | relationVar2TypeDecRes.put(variable, varTypeRes) | ||
56 | } | ||
57 | |||
58 | val comply = createVLSFofFormula => [ | ||
59 | it.name = support.toIDMultiple("compliance", r.name) | ||
60 | it.fofRole = "axiom" | ||
61 | it.fofFormula = createVLSUniversalQuantifier => [ | ||
62 | for (variable : r.variables) { | ||
63 | val v = createVLSVariable => [ | ||
64 | it.name = variable.lookup(relationVar2VLS).name | ||
65 | ] | ||
66 | it.variables += v | ||
67 | |||
68 | } | ||
69 | it.operand = createVLSImplies => [ | ||
70 | it.left = createVLSFunction => [ | ||
71 | it.constant = support.toIDMultiple("rel", r.name) | ||
72 | for (variable : r.variables) { | ||
73 | val v = createVLSVariable => [ | ||
74 | it.name = variable.lookup(relationVar2VLS).name | ||
75 | ] | ||
76 | it.terms += v | ||
77 | } | ||
78 | ] | ||
79 | it.right = support.unfoldAnd(new ArrayList<VLSTerm>(relationVar2TypeDecComply.values)) | ||
80 | ] | ||
81 | ] | ||
82 | ] | ||
83 | |||
84 | val res = createVLSFofFormula => [ | ||
85 | it.name = support.toIDMultiple("relation", r.name) | ||
86 | it.fofRole = "axiom" | ||
87 | it.fofFormula = createVLSUniversalQuantifier => [ | ||
88 | for (variable : r.variables) { | ||
89 | val v = createVLSVariable => [ | ||
90 | it.name = variable.lookup(relationVar2VLS).name | ||
91 | ] | ||
92 | it.variables += v | ||
93 | |||
94 | } | ||
95 | it.operand = createVLSImplies => [ | ||
96 | it.left = support.unfoldAnd(new ArrayList<VLSTerm>(relationVar2TypeDecRes.values)) | ||
97 | it.right = createVLSEquivalent => [ | ||
98 | it.left = createVLSFunction => [ | ||
99 | it.constant = support.toIDMultiple("rel", r.name) | ||
100 | for (variable : r.variables) { | ||
101 | val v = createVLSVariable => [ | ||
102 | it.name = variable.lookup(relationVar2VLS).name | ||
103 | ] | ||
104 | it.terms += v | ||
105 | |||
106 | } | ||
107 | ] | ||
108 | it.right = base.transformTerm(r.value, trace, relationVar2VLS) | ||
109 | ] | ||
110 | |||
111 | ] | ||
112 | |||
113 | ] | ||
114 | |||
115 | ] | ||
116 | |||
117 | // trace.relationDefinition2Predicate.put(r,res) | ||
118 | trace.specification.formulas += comply; | ||
119 | trace.specification.formulas += res; | ||
120 | |||
121 | } | ||
122 | |||
123 | def dispatch public void transformRelation(RelationDeclaration r, Logic2VampireLanguageMapperTrace trace) { | ||
124 | |||
125 | // 1. store all variables in support wrt their name | ||
126 | // 1.1 if variable has type, creating list of type declarations | ||
127 | val List<VLSVariable> relationVar2VLS = new ArrayList | ||
128 | val List<VLSFunction> relationVar2TypeDecComply = new ArrayList | ||
129 | val typedefs = new ArrayList<VLSTerm> | ||
130 | |||
131 | for (i : 0..<r.parameters.length) { | ||
132 | |||
133 | val v = createVLSVariable => [ | ||
134 | it.name = support.toIDMultiple("Var", i.toString) | ||
135 | ] | ||
136 | relationVar2VLS.add(v) | ||
137 | |||
138 | val varTypeComply = createVLSFunction => [ | ||
139 | it.constant = support.toIDMultiple("type", (r.parameters.get(i) as ComplexTypeReference).referred.name) | ||
140 | it.terms += createVLSVariable => [ | ||
141 | it.name = support.toIDMultiple("Var", i.toString) | ||
142 | ] | ||
143 | ] | ||
144 | relationVar2TypeDecComply.add(varTypeComply) | ||
145 | |||
146 | } | ||
147 | |||
148 | |||
149 | val comply = createVLSFofFormula => [ | ||
150 | it.name = support.toIDMultiple("compliance", r.name) | ||
151 | it.fofRole = "axiom" | ||
152 | it.fofFormula = createVLSUniversalQuantifier => [ | ||
153 | |||
154 | for (i : 0..<r.parameters.length) { | ||
155 | val v = createVLSVariable => [ | ||
156 | it.name = relationVar2VLS.get(i).name | ||
157 | ] | ||
158 | it.variables += v | ||
159 | |||
160 | } | ||
161 | |||
162 | it.operand = createVLSImplies => [ | ||
163 | it.left = createVLSFunction => [ | ||
164 | it.constant = support.toIDMultiple("rel", r.name) | ||
165 | |||
166 | for (i : 0..<r.parameters.length) { | ||
167 | val v = createVLSVariable => [ | ||
168 | it.name = relationVar2VLS.get(i).name | ||
169 | ] | ||
170 | it.terms += v | ||
171 | } | ||
172 | |||
173 | ] | ||
174 | it.right = support.unfoldAnd(relationVar2TypeDecComply) | ||
175 | ] | ||
176 | ] | ||
177 | ] | ||
178 | |||
179 | // trace.relationDefinition2Predicate.put(r,res) | ||
180 | trace.specification.formulas += comply | ||
181 | } | ||
182 | |||
183 | } | ||