@@ -21,7 +21,7 @@ object ProofsConverter {
21
21
* @param f formula to convert
22
22
* @return Scala code representing the formula in string format
23
23
*/
24
- private def any2code (a : K .Sequent | K .Formula | K .Term ): String = (a match
24
+ def any2code (a : K .Sequent | K .Formula | K .Term ): String = (a match
25
25
case sq : K .Sequent => asFront(sq)
26
26
case form : K .Formula => asFront(form)
27
27
case term : K .Term => asFront(term)
@@ -109,7 +109,7 @@ object ProofsConverter {
109
109
* @param proof proof to extract formulas from
110
110
* @return set of formulas
111
111
*/
112
- private def extractFormulasFromProof (proof : K .SCProof ): Set [K .Formula ] =
112
+ def extractFormulasFromProof (proof : K .SCProof ): Set [K .Formula ] =
113
113
proof.steps.foldLeft(Set .empty[K .Formula ])((prev, next) => {
114
114
prev ++ (next match
115
115
case sp @ SCSubproof (subproof, _) => extractFormulasFromProof(subproof)
@@ -122,37 +122,40 @@ object ProofsConverter {
122
122
})
123
123
124
124
/**
125
- * Extracts all variables, functions, formula variables, predicates and connectors from a set of formulas
125
+ * Extracts all symbols: variables, functions, formula variables, predicates and connectors from a set of formulas
126
126
*
127
127
* @param formulas set of formulas to extract variables from
128
128
* @return tuple of sets of variables, functions, formula variables, predicates and connectors
129
129
*/
130
- private def extractVariables (
130
+ def extractSymbols (
131
131
formulas : Set [K .Formula ]
132
132
): (Set [K .VariableLabel ], Set [K .SchematicFunctionLabel ], Set [K .VariableFormulaLabel ], Set [K .SchematicPredicateLabel ], Set [K .SchematicConnectorLabel ]) =
133
133
def extractVariablesAux (
134
134
formula : K .Formula
135
135
): (Set [K .VariableLabel ], Set [K .SchematicFunctionLabel ], Set [K .VariableFormulaLabel ], Set [K .SchematicPredicateLabel ], Set [K .SchematicConnectorLabel ]) =
136
- var variableSet = formula.schematicTermLabels.collect { case v : K .VariableLabel => v }
137
- var functionSet = formula.schematicTermLabels.collect { case f : K .SchematicFunctionLabel => f }
138
- var formulaVariableSet = formula.schematicAtomicLabels.collect { case v : K .VariableFormulaLabel => v }
139
- var predicateSet = formula.schematicAtomicLabels.collect { case p : K .SchematicPredicateLabel => p }
140
- var connectorSet = formula.schematicConnectorLabels.collect { case c : K .SchematicConnectorLabel => c }
136
+ val variableSet = formula.schematicTermLabels.collect { case v : K .VariableLabel => v } ++ formula.freeVariables ++ formula.freeSchematicTermLabels.collect { case v : K .VariableLabel => v }
137
+ // val constantSet = formula.constantTermLabels.collect { case c: K.ConstantFunctionLabel if c.arity == 0 => c }
138
+ val functionSet = formula.schematicTermLabels.collect { case f : K .SchematicFunctionLabel => f } ++ formula.freeSchematicTermLabels.collect { case f : K .SchematicFunctionLabel => f }
139
+ // val constantFunctionSet = formula.constantTermLabels.collect { case c: K.ConstantFunctionLabel if c.arity > 0 => c }
140
+ val formulaVariableSet = formula.schematicAtomicLabels.collect { case v : K .VariableFormulaLabel => v } ++ formula.freeVariableFormulaLabels
141
+ val predicateSet = formula.schematicAtomicLabels.collect { case p : K .SchematicPredicateLabel => p }
142
+ // val constantPredicateSet = formula.constantAtomicLabels
143
+ val connectorSet = formula.schematicConnectorLabels.collect { case c : K .SchematicConnectorLabel => c }
141
144
(variableSet, functionSet, formulaVariableSet, predicateSet, connectorSet)
142
145
143
- formulas.foldLeft(
144
- (Set .empty[ K . VariableLabel ], Set .empty[ K . SchematicFunctionLabel ], Set .empty[ K . VariableFormulaLabel ], Set .empty[ K . SchematicPredicateLabel ], Set .empty[ K . SchematicConnectorLabel ])
145
- )((prev, next ) => {
146
- val (variableSet, functionSet, formulaVariableSet, predicateSet, connectorSet ) = prev
147
- val (variableSet_, functionSet_, formulaVariableSet_, predicateSet_, connectorSet_) = extractVariablesAux(next)
148
- (
149
- variableSet ++ variableSet_ ,
150
- functionSet ++ functionSet_ ,
151
- formulaVariableSet ++ formulaVariableSet_ ,
152
- predicateSet ++ predicateSet_,
153
- connectorSet ++ connectorSet_
154
- )
155
- } )
146
+ formulas.foldLeft(( Set .empty[ K . VariableLabel ], Set .empty[ K . SchematicFunctionLabel ], Set .empty[ K . VariableFormulaLabel ], Set .empty[ K . SchematicPredicateLabel ], Set .empty[ K . SchematicConnectorLabel ]))(
147
+ (prev, next) => {
148
+ val (variableSet, functionSet, formulaVariableSet, predicateSet, connectorSet ) = prev
149
+ val (variableSet_, functionSet_, formulaVariableSet_, predicateSet_, connectorSet_ ) = extractVariablesAux(next)
150
+ (
151
+ variableSet ++ variableSet_,
152
+ functionSet ++ functionSet_ ,
153
+ formulaVariableSet ++ formulaVariableSet_ ,
154
+ predicateSet ++ predicateSet_ ,
155
+ connectorSet ++ connectorSet_
156
+ )
157
+ }
158
+ )
156
159
157
160
/**
158
161
* Generates a valid Scala/Lisa code to declare variables, functions, formula variables, predicates and connectors
@@ -164,7 +167,7 @@ object ProofsConverter {
164
167
* @return Scala code representing the variables in string format
165
168
*/
166
169
private def generateVariablesCode (formulas : Set [K .Formula ], accessibility : String ): String =
167
- val (variableSet, functionSet, formulaVariableSet, predicateSet, connectorSet) = extractVariables (formulas)
170
+ val (variableSet, functionSet, formulaVariableSet, predicateSet, connectorSet) = extractSymbols (formulas)
168
171
val access = if accessibility != " " then accessibility.strip() + " " else " "
169
172
(variableSet.map(v => access + s " val ${v.id} = variable " ).toList.sorted ++
170
173
functionSet.map(f => access + s " val ${f.id} = function[ ${f.arity}] " ).toList.sorted ++
@@ -181,7 +184,7 @@ object ProofsConverter {
181
184
*
182
185
* @return Scala code representing the variables in string format
183
186
*/
184
- private def generateVariablesCode (proof : K .SCProof , accessibility : String = " private" ): String =
187
+ def generateVariablesCode (proof : K .SCProof , accessibility : String = " private" ): String =
185
188
generateVariablesCode(extractFormulasFromProof(proof), accessibility)
186
189
187
190
/**
@@ -193,7 +196,9 @@ object ProofsConverter {
193
196
* @return Scala code representing the theorem in string format
194
197
*/
195
198
private def generateTheoremCode (name : String , proof : K .SCProof ): String = {
196
- s " val $name = Theorem( \n " +
199
+ // lowercase and underscore-separated version of the theorem name
200
+ val filteredName = " [A-Za-z0-9]+" .r.findAllIn(name).mkString(" _" ).toLowerCase
201
+ s " val $filteredName = Theorem( \n " +
197
202
indent(any2code(proof.conclusion)) +
198
203
s " \n ) { \n " +
199
204
indent(scproof2code(proof)) +
0 commit comments