diff options
Diffstat (limited to 'Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_Support.xtend')
-rw-r--r-- | Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_Support.xtend | 148 |
1 files changed, 148 insertions, 0 deletions
diff --git a/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_Support.xtend b/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_Support.xtend new file mode 100644 index 00000000..ab92b42f --- /dev/null +++ b/Solvers/Vampire-Solver/ca.mcgill.ecse.dslreasoner.vampire.reasoner/src/ca/mcgill/ecse/dslreasoner/vampire/reasoner/builder/Logic2VampireLanguageMapper_Support.xtend | |||
@@ -0,0 +1,148 @@ | |||
1 | package ca.mcgill.ecse.dslreasoner.vampire.reasoner.builder | ||
2 | |||
3 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.QuantifiedExpression | ||
4 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Variable | ||
5 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VLSTerm | ||
6 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VLSVariable | ||
7 | import ca.mcgill.ecse.dslreasoner.vampireLanguage.VampireLanguageFactory | ||
8 | import java.util.ArrayList | ||
9 | import java.util.HashMap | ||
10 | import java.util.List | ||
11 | import java.util.Map | ||
12 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.ComplexTypeReference | ||
13 | import org.eclipse.emf.common.util.EList | ||
14 | import hu.bme.mit.inf.dslreasoner.logic.model.logiclanguage.Term | ||
15 | |||
16 | class Logic2VampireLanguageMapper_Support { | ||
17 | private val extension VampireLanguageFactory factory = VampireLanguageFactory.eINSTANCE | ||
18 | |||
19 | // ID Handler | ||
20 | def protected String toIDMultiple(String... ids) { | ||
21 | ids.map[it.split("\\s+").join("_")].join("_") | ||
22 | } | ||
23 | |||
24 | def protected String toID(String ids) { | ||
25 | ids.split("\\s+").join("_") | ||
26 | } | ||
27 | |||
28 | // Support Functions | ||
29 | // booleans | ||
30 | // AND and OR | ||
31 | def protected VLSTerm unfoldAnd(List<? extends VLSTerm> operands) { | ||
32 | if (operands.size == 1) { | ||
33 | return operands.head | ||
34 | } else if (operands.size > 1) { | ||
35 | return createVLSAnd => [ | ||
36 | left = operands.head | ||
37 | right = operands.subList(1, operands.size).unfoldAnd | ||
38 | ] | ||
39 | } else | ||
40 | throw new UnsupportedOperationException('''Logic operator with 0 operands!''') | ||
41 | } | ||
42 | |||
43 | def protected VLSTerm unfoldOr(List<? extends VLSTerm> operands) { | ||
44 | |||
45 | // if(operands.size == 0) {basically return true} | ||
46 | /*else*/ if (operands.size == 1) { | ||
47 | return operands.head | ||
48 | } else if (operands.size > 1) { | ||
49 | return createVLSOr => [ | ||
50 | left = operands.head | ||
51 | right = operands.subList(1, operands.size).unfoldOr | ||
52 | ] | ||
53 | } else | ||
54 | throw new UnsupportedOperationException('''Logic operator with 0 operands!''') // TEMP | ||
55 | } | ||
56 | |||
57 | def protected VLSTerm unfoldDistinctTerms(Logic2VampireLanguageMapper m, EList<Term> operands, | ||
58 | Logic2VampireLanguageMapperTrace trace, Map<Variable, VLSVariable> variables) { | ||
59 | if(operands.size == 1) { return m.transformTerm(operands.head,trace,variables) } | ||
60 | else if(operands.size > 1) { | ||
61 | val notEquals = new ArrayList<VLSTerm>(operands.size*operands.size/2) | ||
62 | for(i:0..<operands.size) { | ||
63 | for(j: i+1..<operands.size) { | ||
64 | notEquals+=createVLSInequality=>[ | ||
65 | it.left= m.transformTerm(operands.get(i),trace,variables) | ||
66 | it.right = m.transformTerm(operands.get(j),trace,variables) | ||
67 | ] | ||
68 | } | ||
69 | } | ||
70 | return notEquals.unfoldAnd | ||
71 | } | ||
72 | else throw new UnsupportedOperationException('''Logic operator with 0 operands!''') | ||
73 | } | ||
74 | |||
75 | // Symbolic | ||
76 | // def postprocessResultOfSymbolicReference(TypeReference type, VLSTerm term, Logic2VampireLanguageMapperTrace trace) { | ||
77 | // if(type instanceof BoolTypeReference) { | ||
78 | // return booleanToLogicValue(term ,trace) | ||
79 | // } | ||
80 | // else return term | ||
81 | // } | ||
82 | // def booleanToLogicValue(VLSTerm term, Logic2VampireLanguageMapperTrace trace) { | ||
83 | // throw new UnsupportedOperationException("TODO: auto-generated method stub") | ||
84 | // } | ||
85 | /* | ||
86 | * def protected String toID(List<String> ids) { | ||
87 | * ids.map[it.split("\\s+").join("'")].join("'") | ||
88 | * } | ||
89 | */ | ||
90 | // QUANTIFIERS + VARIABLES | ||
91 | def protected VLSTerm createUniversallyQuantifiedExpression(Logic2VampireLanguageMapper mapper, | ||
92 | QuantifiedExpression expression, Logic2VampireLanguageMapperTrace trace, Map<Variable, VLSVariable> variables) { | ||
93 | val variableMap = expression.quantifiedVariables.toInvertedMap [ v | | ||
94 | createVLSVariable => [it.name = toIDMultiple("Var", v.name)] | ||
95 | ] | ||
96 | |||
97 | val typedefs = new ArrayList<VLSTerm> | ||
98 | for (variable : expression.quantifiedVariables) { | ||
99 | val eq = createVLSFunction => [ | ||
100 | it.constant = toIDMultiple("type", (variable.range as ComplexTypeReference).referred.name) | ||
101 | it.terms += createVLSVariable => [ | ||
102 | it.name = toIDMultiple("Var", variable.name) | ||
103 | ] | ||
104 | |||
105 | ] | ||
106 | typedefs.add(eq) | ||
107 | } | ||
108 | |||
109 | |||
110 | createVLSUniversalQuantifier => [ | ||
111 | it.variables += variableMap.values | ||
112 | it.operand = createVLSImplies => [ | ||
113 | it.left = unfoldAnd(typedefs) | ||
114 | it.right = mapper.transformTerm(expression.expression, trace, variables.withAddition(variableMap)) | ||
115 | ] | ||
116 | ] | ||
117 | } | ||
118 | |||
119 | def protected VLSTerm createExistentiallyQuantifiedExpression(Logic2VampireLanguageMapper mapper, | ||
120 | QuantifiedExpression expression, Logic2VampireLanguageMapperTrace trace, Map<Variable, VLSVariable> variables) { | ||
121 | val variableMap = expression.quantifiedVariables.toInvertedMap [ v | | ||
122 | createVLSVariable => [it.name = toIDMultiple("Var", v.name)] | ||
123 | ] | ||
124 | |||
125 | val typedefs = new ArrayList<VLSTerm> | ||
126 | for (variable : expression.quantifiedVariables) { | ||
127 | val eq = createVLSFunction => [ | ||
128 | it.constant = toIDMultiple("type", (variable.range as ComplexTypeReference).referred.name) | ||
129 | it.terms += createVLSVariable => [ | ||
130 | it.name = toIDMultiple("Var", variable.name) | ||
131 | ] | ||
132 | ] | ||
133 | typedefs.add(eq) | ||
134 | } | ||
135 | |||
136 | typedefs.add(mapper.transformTerm(expression.expression, trace, variables.withAddition(variableMap))) | ||
137 | createVLSExistentialQuantifier => [ | ||
138 | it.variables += variableMap.values | ||
139 | it.operand = unfoldAnd(typedefs) | ||
140 | |||
141 | ] | ||
142 | } | ||
143 | |||
144 | def protected withAddition(Map<Variable, VLSVariable> map1, Map<Variable, VLSVariable> map2) { | ||
145 | new HashMap(map1) => [putAll(map2)] | ||
146 | } | ||
147 | |||
148 | } | ||