Formal Verification of Transcompiled Mobile Applications Using First-Order Logic
Abstract
1. Introduction
- Introduces a new framework that translates high-level transcompiled source and target codes as FOL representation, which ensures logical representation of the code.
- Applies Z3-based equivalence checking using manually encoded FOL representations of Swift and Java code.
- Automates the FOL generation process using ANTLR to enable scalable semantic verification.
- Defines an interpretable metric based on shared axioms to assess semantic preservation across translations.
- Validates the approach through a Swift-to-Java case study, showing improved semantic accuracy over BLEU-style metrics.
2. Related Works
3. Methodology
3.1. Framework Overview
3.2. Equivalence Checking Using Z3
3.2.1. Expressiveness of FOL in Code Verification
- Static Code Structures: Variables, methods, classes, loops with fixed bounds, and simple conditional statements.
- Deterministic Control Flow: Constructs such as if-else statements, for-loops, and bounded while-loops can be accurately captured within FOL expressions.
- Function and Method Calls: Provided that functions or methods have well-defined inputs and outputs, FOL can effectively model their behavior.
3.2.2. Code Conversion to First-Order Logic (FOL)
- Identification of Code Elements: The very first step in translating the source and target codes into predicate logic or FOL is to recognize the various elements inside the code, including the classes, methods, attributes, and control structures. For example, the Swift code in Table 1 contains a single class, two attributes (“x and y”), and a constructor that begins with the keyword “init” to initialize the attributes. Additionally, the class contains a method called myFunction, which has a condition that checks whether “x is greater than y,” or vice versa. This condition prints from zero to the more minor attribute minus one if the attribute is true.
- Defining Logical Statements: The next step is to convert the identified code elements into first-order logic. All statements are converted into predicates using logical statements that represent the code’s conditions and transformations. FOL expressions are used to describe every class, method, loop, and condition. Consider a class named MyClass, for instance, which contains a method, attributes, and both Java and Swift code. This class can be translated into first-order logic as follows:Class Instantiation and Attributes:Method Definition:Method Behavior:Since we have converted the code into first-order logic, we can use the Z3 tool to determine whether the source and target codes are equivalent.This detailed conversion process ensures that the logical representations are precise and accurately reflect the original code’s behavior.
3.2.3. Equivalence Checking Using Z3 Solver
- Adding FOL to the Z3 solver: Both the source code (Swift) and the target code (Java) FOL expressions are loaded into the solver.
- Adding the Constraints: The constraints are added using the add function, which specifies the items that need to be checked.
- Solver Execution: The solver checks whether the added constraints have been satisfied. If the solver finds that the constraints have been satisfied, it confirms the equivalence of the source and target codes; if the constraints have not been satisfied, it identifies that the two codes are not equivalent.
3.2.4. Observed Challenges and Limitations of Using Z3
- A Lack of Semantic Completeness: The simplified Z3 example shown in Figure 3 does not encode certain essential semantic aspects such as program state evolutions, next-state transitions, control-flow behaviors, or variable-store updates. The example does not represent the full program semantics; therefore, it is used only as an illustration of solver interaction.
- Manual and Solver-Dependent Workflow: Both the source and target programs had to be manually rewritten as logical formulas and submitted into the solver. This process is time-consuming, difficult, and prone to human error, as each new program requires that the logical formulas be reconstructed from scratch.
- No Direct Link to Programming Languages: Although Z3 can check for satisfiability, it cannot parse or interpret Swift or Java syntax. All language constructs must be expressed manually in FOL, preventing the automatic extraction of semantics and hindering the scalability of this approach.
- Limited Support for Cross-Language Mapping: Z3 provides no built-in mechanism for aligning the structural components of programs that are written in different languages. Establishing a correspondence between constructs (e.g., loops, conditionals, and method bodies) is difficult without an automated parsing layer.
3.3. Formal Semantics Mapping of Swift and Java Constructs
Illustrative Mapping Example
i = 0
i(0) = i
(i(n) < 10 → Print(i(n)) ∧ i(n+1) = i(n) + 1)
- i = 0This initializes the loop counter i to zero, just like int i = 0 in Java or the implicit counter in Swift’s for i in 0..<10.
- (0) = iThis states that the value of i at the initial step (n = 0) is i. This serves as the base case scenario for the logical sequence.
- (...)This universal quantifier means that the following logical expression must hold for all the steps n in the Loop. It also abstracts the repetition aspect of the Loop.
- i(n) < 10This condition checks whether the current value of i at step n is less than 10, similar to the loop condition in both Swift (0..<10) and Java (while(i < 10)).
- → (Implication)This symbol, read as “implies,” means that if the loop condition i(n) < 10 holds at step n, then the following two actions must occur.
- Print(i(n))This indicates that the current value of i is printed at step n. It abstracts the output command from both languages (print(i) in Swift and System.out.println(i) in Java).
- ∧ (Logical AND)This symbol connects multiple logical statements. In this case, it ensures that both the print operation and the increment step happen together whenever the condition is true.
- i(n + 1) = i(n) + 1This equation represents the increment logic. It states that the value of i at the next step (n+1) is one more than its value at the current step n, mimicking the i++ behavior in Java SE 22 version and the implicit increment in Swift’s 5.1 for loop.
3.4. Automated Equivalence Checking Using ANTLR
3.5. Experimental Setup
- RQ1: How accurate is ANTLR-based automated formal verification in ensuring semantic equivalence between original Swift and trans-compiled Java code?
- RQ2: What efficiency advantages does ANTLR-based verification have over the earlier Z3-based manual verification approach?
3.5.1. Evaluation Metric
3.5.2. Efficiency and Automation Comparison
- FOL conversion effort: The amount of manual effort required to represent program logic in FOL.
- Time required per application: The average duration needed to verify each sample program.
- Error-proneness due to manual input: The likelihood of initiating mistakes when encoding the logic manually using the Z3-based approach.
- Ability to handle complex loop constructs: The system’s capability of managing nested loops and control flow variations.
- Ease of integration with the transcompiler: How seamlessly the verification method can be integrated into the overall transcompilation pipeline.
3.5.3. Code Samples
- Bubble Sort Algorithm: A basic sorting algorithm is used to sort an array of integers.
- Linked List Implementation: A data structure consisting of nodes, where each node contains data and references the next node.
- Stack: A data structure that follows the Last In, First Out (LIFO) principle.
- A Simple Banking Application: A basic application with account management features.
- Binary Search Tree: A tree data structure, where each node has at most two children, referred to as the left and right children.
- Static and dynamic control flow.
- Function and method calls.
- Recursive and iterative patterns.
- Simple to moderately complex applications.
Tools Used:
- Z3 SMT Solver: Used for equivalence checking by analyzing the logical expressions derived from the source and target codes.
- ANTLR: Used for parsing the source and target codes and generating structured syntax trees for equivalence checking.
- Languages: The source code was written in Swift, while the target code was transcompiled to Java.
4. Experiments and Results
4.1. Syntactic vs. Semantic Evaluation—BLEU vs. Equivalence Accuracy
4.2. Efficiency Comparison—Z3 vs. ANTLR
5. Conclusions and Future Work
5.1. Scope and Limitations
5.2. Future Work
- Expanding Beyond FOL: In an upcoming study, we aim to explore higher-order and temporal logics to model dynamic constructs and richer language features that extend beyond the figures expressible in FOL.
- Cross-Language Generalization: Applying the framework to additional language pairs (e.g., Python –Swift and Kotlin–JavaScript) will help validate its extensibility and reveal new grammar-mapping challenges in heterogeneous programming environments.
- Runtime Semantics Integration: Combining static, logic-based verification with runtime behavior analysis may provide a comprehensive view of semantic correctness across different execution contexts.
Author Contributions
Funding
Data Availability Statement
Acknowledgments
Conflicts of Interest
Appendix A. Formal Semantics Mapping of Swift and Java Constructs
| Construct | Swift Example | Java Example | FOL Representation | Semantics Captured |
|---|---|---|---|---|
| Variable Declaration/Assignment | var x: Int = 5 | int x = 5; | Int(x) value(x) = 5 | Type assertion and initial value binding. |
| Array Declaration | var a = [1,2,3] | int[] a = {1,2,3}; | Array(Int(a)) = {1,2,3} | Element type and initialization. |
| Conditional (if/else) | if x > y { print(x) } else { print(y) } | if(x > y) System.out.println(x); else System.out.println(y); | (x > y → Print(x)) (¬(x > y) → Print(y)) | Branch behavior and output action. |
| Loop (for/while) | for i in 0..<n { sum += i } | while(i<n) { sum+=i; i++; } | k < n ( i(k) < n → sum(k+1) = sum(k) + i(k) ) | Iterative state transition under loop condition. |
| Function Definition | func add(a: Int, b: Int) -> Int { return a+b } | int add(int a,int b){return a+b;} | add(a,b) = a + b | Input–output behavior abstraction. |
| Class Definition | class MyClass { var x: Int } | class MyClass { int x; } | Class(MyClass) obj ( x(obj):Int ) | Object instantiation and type membership. |
| Method Invocation | obj.myFunc() | obj.myFunc(); | Call(obj,myFunc) → Effect(obj) | Object-bound behavior. |
| State Update | x += 1 | x = x + 1; | x’ = x + 1 | Next-state semantics for mutation. |
References
- Biørn-Hansen, A.; Grønli, T.M.; Majchrzak, T.A.; Kaindl, H.; Ghinea, G. The Use of Cross-Platform Frameworks for Google Play Store Apps. In Proceedings of the 55th Hawaii International Conference on System Sciences, Virtual, 4–7 January 2022. [Google Scholar] [CrossRef]
- Mahmoud, A.T.; Radwan, M.B.; Soliman, A.M.; Yousef, A.H.; Zayed, H.H.; Medhat, W. Trans-Compiler-Based Conversion from Cross-Platform Applications to Native Applications. Ann. Emerg. Technol. Comput. 2024, 8, 1. [Google Scholar] [CrossRef]
- Mahmoud, A.T.; Muhammad, A.A.; Yousef, A.H.; Zayed, H.H.; Medhat, W.; Selim, S. Industrial Practitioner Perspective of Mobile Applications Programming Languages and Systems. Int. J. Adv. Comput. Sci. Appl. 2023, 14, 275–285. [Google Scholar] [CrossRef]
- Muhammad, A.A.; Soliman, A.; Zayed, H.; Yousef, A.H.; Selim, S. Automated library mapping approach based on cross-platform for mobile development programming languages. Softw. Pract. Exp. 2024, 54, 683–703. [Google Scholar] [CrossRef]
- Barakat, R.; Radwan, M.B.A.; Medhat, W.M.; Yousef, A.H. Trans-Compiler-Based Database Code Conversion Model for Native Platforms and Languages. In Proceedings od the 11th International Conference, MEDI 2022, Cairo, Egypt, 21–24 November, 2022; Lecture Notes in Computer Science (Including Subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics); Springer: Berlin/Heidelberg, Germany, 2023; Volume 13761, pp. 162–175. [Google Scholar] [CrossRef]
- Muhammad, A.A.; Mahmoud, A.T.; Elkalyouby, S.S.; Hamza, R.B.; Yousef, A.H. Trans-Compiler based Mobile Applications code converter: Swift to java. In Proceedings of the 2020 2nd Novel Intelligent and Leading Emerging Sciences Conference (NILES), Giza, Egypt, 24–26 October 2020; pp. 247–252. [Google Scholar]
- Muhammad, A.A.; Soliman, A.M.; Selim, S.; Yousef, A.H. Generic Library Mapping Approach for Trans-Compilation. In Proceedings of the 2021 International Mobile, Intelligent, and Ubiquitous Computing Conference, MIUCC 2021, Cairo, Egypt, 26–27 May 2021; pp. 62–68. [Google Scholar] [CrossRef]
- El-Kaliouby, S.S.; Selim, S.; Yousef, A.H. Native Mobile Applications UI Code Conversion. In Proceedings of the 2021 16th International Conference on Computer Engineering and Systems, ICCES 2021, Cairo, Egypt, 15–16 December 2021. [Google Scholar] [CrossRef]
- Salama, D.; Hamza, R.; Kamel, M.; Muhammad, A.; Yousef, A. TCAIOSC: Trans-Compiler Based Android to iOS Converter. In Proceedings of the International Conference on Advanced Intelligent Systems and Informatics, Cairo, Egypt, 26–28 October, 2020; 1058. [Google Scholar] [CrossRef]
- Hamza, R.B.; Salama, D.I.; Kamel, M.I.; Yousef, A.H. TCAIOSC: Application Code Conversion. In Proceedings of the NILES 2019—Novel Intelligent and Leading Emerging Sciences Conference, Giza, Egypt, 28–30 October 2019; pp. 230–234. [Google Scholar] [CrossRef]
- Mahmoud, A.T.; Mohammed, A.A.; Ayman, M.; Medhat, W.; Selim, S.; Zayed, H.; Yousef, A.H.; Elaraby, N. Formal Verification of Code Conversion: A Comprehensive Survey. Technologies 2024, 12, 244. [Google Scholar] [CrossRef]
- Papineni, K.; Roukos, S.; Ward, T.; Zhu, W.J. BLEU: A method for automatic evaluation of machine translation. In Proceedings of the 40th Annual Meeting of the Association for Computational Linguistics, Toulouse, France, 6–11 July 2001; pp. 311–318. [Google Scholar] [CrossRef]
- Ren, S.; Guo, D.; Lu, S.; Zhou, L.; Liu, S.; Tang, D.; Sundaresan, N.; Zhou, M.; Blanco, A.; Ma, S. CodeBLEU: A Method for Automatic Evaluation of Code Synthesis. arXiv 2020, arXiv:cs.SE/2009.10297. [Google Scholar] [CrossRef]
- Qi, M.; Huang, Y.; Wang, M.; Yao, Y.; Liu, Z.; Gu, B.; Clement, C.; Sundaresan, N. SUT: Active Defects Probing for Transcompiler Models. In Proceedings of the 2023 Conference on Empirical Methods in Natural Language Processing, Singapore, 6–10 December 2023; Bouamor, H., Pino, J., Bali, K., Eds.; Association for Computational Linguistics: Singapore, 2023; pp. 14024–14034. [Google Scholar] [CrossRef]
- Evtikhiev, M.; Bogomolov, E.; Sokolov, Y.; Bryksin, T. Out of the BLEU: How should we assess quality of the Code Generation models? J. Syst. Softw. 2023, 203, 111741. [Google Scholar] [CrossRef]
- Ou, G.; Liu, M.; Chen, Y.; Du, X.; Wang, S.; Zhang, Z.; Peng, X.; Zheng, Z. Enhancing LLM-based Code Translation in Repository Context via Triple Knowledge-Augmented. arXiv 2025, arXiv:cs.SE/2503.18305. [Google Scholar] [CrossRef]
- Kroening, D.; Tautschnig, M. CBMC: The C Bounded Model Checker. 2020. Available online: https://github.com/diffblue/cbmc (accessed on 30 April 2025).
- Cordeiro, L.C.; Kesseli, P.; Kroening, D.; Schrammel, P.; Trtík, M. JBMC: A Bounded Model Checking Tool for Verifying Java Bytecode. In *International Conference on Computer Aided Verification* (CAV 2018); Springer: Cham, Switzerland, 2018; pp. 58–67. Available online: https://link.springer.com/chapter/10.1007/978-3-319-96145-3_3 (accessed on 30 April 2025).
- Cordeiro, L.; Kroening, D.; Schrammel, P. JBMC: Bounded Model Checking for Java Bytecode. In Proceedings of the Tools and Algorithms for the Construction and Analysis of Systems, Prague, Czech Republic, 6–11 April 2019; Beyer, D., Huisman, M., Kordon, F., Steffen, B., Eds.; Springer: Cham, Switzerland, 2019; pp. 219–223. [Google Scholar]
- Sampath, P.; Rajeev, A.; Ramesh, S. Translation Validation for Stateflow to C. In Proceedings of the 51st Annual Design Automation Conference, San Francisco, CA, USA, 1–5 June 2014. [Google Scholar] [CrossRef]
- Beyer, D.; Strejček, J. Improvements in Software Verification and Witness Validation: SV-COMP 2025. In Proceedings of the Tools and Algorithms for the Construction and Analysis of Systems (TACAS 2025), Hamilton, ON, Canada, 3–8 May 2025; Lecture Notes in Computer Science; Springer: Berlin/Heidelberg, Germany, 2025; Volume 15698. [Google Scholar]
- Leroy, X. Formal verification of a realistic compiler. Commun. ACM 2009, 52, 107–115. [Google Scholar] [CrossRef]
- Mahmoud, A.T.; Medhat, W.; Selim, S.; Zayed, H.; Yousef, A.H.; Elaraby, N. TC-Verifier: Trans-Compiler-Based Code Translator Verifier with Model-Checking. Appl. Syst. Innov. 2025, 8, 60. [Google Scholar] [CrossRef]
- De Moura, L.; Bjørner, N. Z3: An efficient SMT solver. In Proceedings of the 2008 Tools and Algorithms for Construction and Analysis of Systems, Budapest, Hungary, 29 March–6 April 2008; Springer: Berlin/Heidelberg, Germany, 2008; pp. 337–340. [Google Scholar]
- Terence, P. The Definitive ANTLR 4 Reference, 1st ed.; The Pragmatic Bookshelf: Flower Mound, TX, USA, 2013; pp. 1–328. [Google Scholar]
- Ramos, D.A.; Engler, D.R. Practical, low-effort equivalence verification of real code. In Proceedings of the International Conference on Computer Aided Verification, Snowbird, UT, USA, 14–20 July 2011; Lecture Notes in Computer Science (Including Subseries Lecture Notes in Artificial Intelligence and Lecture Notes in Bioinformatics); Springer: Berlin/Heidelberg, Germany, 2011; Volume 6806, pp. 669–685. [Google Scholar] [CrossRef]
- Wu, W.; Siegel, S. F Verifying Functional Equivalence of Programs with CIVL. In Proceedings of the International Conference for High Performance Computing, Networking, Storage and Analysis (SC17), Denver, CO, USA, 12–17 November 2017. [Google Scholar]
- Gupta, S.; Saxena, A.; Mahajan, A.; Bansal, S. Effective Use of SMT Solvers for Program Equivalence Checking Through Invariant-Sketching and Query-Decomposition. In Proceedings of the Theory and Applications of Satisfiability Testing—SAT 2018, Oxford, UK, 9–12 July 2018; Beyersdorff, O., Wintersteiger, C.M., Eds.; Springer: Cham, Switzerland, 2018; pp. 365–382. [Google Scholar]
- Jakobs, M. PEQcheck: Localized and Context-aware Checking of Functional Equivalence (Technical Report). arXiv 2021, arXiv:2101.09042. [Google Scholar] [CrossRef]
- Jakobs, M.C.; Wiesner, M. PEQtest: Testing Functional Equivalence. In Proceedings of the Fundamental Approaches to Software Engineering, Munich, Germany, 2–7 April 2022; Johnsen, E.B., Wimmer, M., Eds.; Spinger: Cham, Switzerland, 2022; pp. 184–204. [Google Scholar]
- Lopes, N.P.; Lee, J.; Hur, C.K.; Liu, Z.; Regehr, J. Alive2: Bounded translation validation for LLVM. In Proceedings of the 42nd ACM SIGPLAN International Conference on Programming Language Design and Implementation, Virtual, 20–25 June 2021; pp. 65–79. [Google Scholar] [CrossRef]
- Lin, F. Translating classes to first-order logic: An example. In Proceedings of the 21st Workshop on Formal Techniques for Java-Like Programs, FTfJP 2019—Co-located with ECOOP 2019, London, UK, 15 July 2019; pp. 1–3. [Google Scholar] [CrossRef]




| Swift Code | Java Code |
|---|---|
| class MyClass { | public class MyClass { |
| var x: Int | private int x; |
| var y: Int | private int y; |
| init(x: Int, y: Int) { | public MyClass(int x, int y) { |
| self.x = x | this.x = x; |
| self.y = y | this.y = y; |
| } | } |
| func myFunction() { | public void myFunction() { |
| if x < y { | if (x < y) { |
| for i in 0..<x { | for (int i = 0; i < x; i++) { |
| print("Value of i: (i)") | System.out.println("Value of i: " + i); |
| } | } |
| } else { | } else { |
| for i in 0..<y { | for (int i = 0; i < y; i++) { |
| print("Value of i: (i)") | System.out.println("Value of i: " + i); |
| } | } |
| } | } |
| } | } |
| } | } |
| Swift Code Using for Loop | Java Code Using while Loop |
|---|---|
| for i in 0...<10 { | int i = 0; |
| print(i) | while (i < 10) { |
| } | System.out.println(i); |
| i++; | |
| } |
| Code Sample | BLEU Score | Equivalence Accuracy |
|---|---|---|
| Old Phone App | 92.5% | 81% |
| Make a Call | 100% | 76% |
| Smart Calculator | 93% | 100% |
| Teaching Assistant | 90% | 62% |
| Match Game Show Score | 95% | 81% |
| Bubble Sort Algorithm | 70% | 100% |
| Linked List Implementation | 31% | 86% |
| Stack | 25% | 90% |
| Simple Banking Application | 20% | 91% |
| Binary Search Tree | 28% | 94% |
| Average | 64.45% | 86.1% |
| Criterion | Z3-Based Verification | ANTLR-Based Verification |
|---|---|---|
| FOL Conversion Effort | Manual, labor-intensive | Automated via grammar-based parsing |
| Time per Application | 1–2 h | <1 min |
| Runtime (per execution) | 10 s–1 day (stochastic) | 1–2 s (stable) |
| Error-Prone | High (human input) | Low |
| Scalability | Low | High |
| Loop/Nested Loop Handling | Often unscalable | Efficient |
| Integration with Transcompiler | External | Fully integrated |
Disclaimer/Publisher’s Note: The statements, opinions and data contained in all publications are solely those of the individual author(s) and contributor(s) and not of MDPI and/or the editor(s). MDPI and/or the editor(s) disclaim responsibility for any injury to people or property resulting from any ideas, methods, instructions or products referred to in the content. |
© 2025 by the authors. Licensee MDPI, Basel, Switzerland. This article is an open access article distributed under the terms and conditions of the Creative Commons Attribution (CC BY) license (https://creativecommons.org/licenses/by/4.0/).
Share and Cite
Muhammad, A.A.; Ayman, M.; Elhossany, S.A.; Medhat, W.; Selim, S.; Zayed, H.; Yousef, A.H.; Jantsch, A.; Elaraby, N. Formal Verification of Transcompiled Mobile Applications Using First-Order Logic. Technologies 2025, 13, 580. https://doi.org/10.3390/technologies13120580
Muhammad AA, Ayman M, Elhossany SA, Medhat W, Selim S, Zayed H, Yousef AH, Jantsch A, Elaraby N. Formal Verification of Transcompiled Mobile Applications Using First-Order Logic. Technologies. 2025; 13(12):580. https://doi.org/10.3390/technologies13120580
Chicago/Turabian StyleMuhammad, Ahmad Ahmad, Mahitap Ayman, Samer A. Elhossany, Walaa Medhat, Sahar Selim, Hala Zayed, Ahmed H. Yousef, Axel Jantsch, and Nahla Elaraby. 2025. "Formal Verification of Transcompiled Mobile Applications Using First-Order Logic" Technologies 13, no. 12: 580. https://doi.org/10.3390/technologies13120580
APA StyleMuhammad, A. A., Ayman, M., Elhossany, S. A., Medhat, W., Selim, S., Zayed, H., Yousef, A. H., Jantsch, A., & Elaraby, N. (2025). Formal Verification of Transcompiled Mobile Applications Using First-Order Logic. Technologies, 13(12), 580. https://doi.org/10.3390/technologies13120580

