Automated Software Engineering

, Volume 26, Issue 3, pp 653–704 | Cite as

Automatic B-model repair using model checking and machine learning

  • Cheng-Hao CaiEmail author
  • Jing Sun
  • Gillian Dobbie


The B-method, which provides automated verification for the design of software systems, still requires users to manually repair faulty models. This paper proposes B-repair, an approach that supports automated repair of faulty models written in the B formal specification language. After discovering a fault in a model using the B-method, B-repair is able to suggest possible repairs for the fault, estimate the quality of suggested repairs and use a suitable repair to revise the model. The suggestion of repairs is produced using the Isolation method, which suggests changing the pre-conditions of operations, and the Revision method, which suggests changing the post-conditions of operations. The estimation of repair quality makes use of machine learning techniques that can learn the features of state transitions. After estimating the quality of suggested repairs, the repairs are ranked, and a best repair is selected according to the result of ranking and is used to revise the model. This approach has been evaluated using a set of finite state machines seeded with faults and a case study. The evaluation has revealed that B-repair is able to repair a large number of faults, including invariant violations, assertion violations and deadlock states, and gain high accuracies of repair. Using the combination of model checking and machine learning-guided techniques, B-repair saves development time by finding and repairing faults automatically during design.


Model repair B-method Model checking Formal verification Machine learning 



We would like to thank the anonymous reviewers, whose valuable comments have contributed to the clarification of many ideas presented in the paper.


  1. Abreu, R., Zoeteweij, P., Golsteijn, R., van Gemund, A.J.C.: A practical evaluation of spectrum-based fault localization. J. Syst. Softw. 82(11), 1780–1792 (2009)Google Scholar
  2. Abrial, J.: The B-book—Assigning Programs to Meanings. Cambridge University Press, Cambridge (2005)zbMATHGoogle Scholar
  3. Abrial, J., Butler, M.J., Hallerstede, S., Hoang, T.S., Mehta, F., Voisin, L.: Rodin: an open toolset for modelling and reasoning in Event-B. Int. J. Softw. Tools Technol. Transfer 12(6), 447–466 (2010)Google Scholar
  4. Alrajeh, D., Craven, R.: Automated error-detection and repair for compositional software specifications. In: 12th International Conference Software Engineering and Formal Methods, SEFM 2014, Grenoble, France, September 1–5, 2014. Proceedings, pp. 111–127 (2014)Google Scholar
  5. Baader, F., Nipkow, T.: Term Rewriting and All That. Cambridge University Press, Cambridge (1998)zbMATHGoogle Scholar
  6. Babin, G., Ameur, Y.A., Singh, N.K., Pantel, M.: A system substitution mechanism for hybrid systems in Event-B. In: Proceedings 18th International Conference on Formal Engineering Methods Formal Methods and Software Engineering, ICFEM 2016, Tokyo, Japan, November 14–18, 2016, pp. 106–121 (2016)Google Scholar
  7. Bagaria, J.: Set theory. In: Zalta, E.N. (ed.) The Stanford Encyclopedia of Philosophy, winter 2017 edn. Stanford University, Stanford (2017)Google Scholar
  8. Barbosa, H., Déharbe, D.: Formal verification of PLC programs using the B method. In: Abstract State Machines, Alloy, B, VDM, and Z—Proceedings Third International Conference, ABZ 2012, Pisa, Italy, June 18–21, 2012, pp. 353–356 (2012)Google Scholar
  9. Behm, P., Benoit, P., Faivre, A., Meynadier, J.: Météor: A successful application of B in a large project. In: FM’99 - Formal Methods, World Congress on Formal Methods in the Development of Computing Systems, Toulouse, France, September 20–24, 1999, Proceedings, Volume I, pp. 369–387 (1999)Google Scholar
  10. Benaïssa, N., Bonvoisin, D., Feliachi, A., Ordioni, J.: The PERF approach for formal verification. In: Reliability, Safety, and Security of Railway Systems. Modelling, Analysis, Verification, and Certification—First International Conference, RSSRail 2016, Paris, France, June 28-30, 2016, Proceedings, pp. 203–214 (2016)Google Scholar
  11. Bottou, L.: Stochastic gradient descent tricks. In: Montavon, G. (ed.) Neural Networks: Tricks of the Trade, 2nd edn, pp. 421–436. Springer, Berlin (2012)Google Scholar
  12. Boulanger, J.L., Aljer, A., Mariano, G.: Formalization of digital circuits using the b method. WIT Trans. Built Environ. (2002)
  13. Breiman, L., Friedman, J.H., Olshen, R.A., Stone, C.J.: Classification and Regression Trees. Routledge, Wadsworth (1984)zbMATHGoogle Scholar
  14. Burch, J.R., Clarke, E.M., McMillan, K.L., Dill, D.L., Hwang, L.J.: Symbolic model checking: 10–20 states and beyond. Inf. Comput. 98(2), 142–170 (1992)MathSciNetzbMATHGoogle Scholar
  15. Cai, C., Sun, J., Dobbie, G.: B-repair: Repairing B-models using machine learning. In: 23rd International Conference on Engineering of Complex Computer Systems, ICECCS 2018, Melbourne, Australia, December 12–14, 2018, pp. 31–40 (2018)Google Scholar
  16. Cimatti, A., Clarke, E.M., Giunchiglia, F., Roveri, M.: NUSMV: A new symbolic model verifier. In: 11th International Conference Computer Aided Verification, CAV ’99, Trento, Italy, July 6-10, 1999, Proceedings, pp. 495–499 (1999)Google Scholar
  17. Clarke, E.M., Emerson, E.A.: Design and synthesis of synchronization skeletons using branching-time temporal logic. In: Logics of Programs, Workshop, Yorktown Heights, New York, USA, May 1981, pp. 52–71 (1981)Google Scholar
  18. Cox, D.R.: The regression analysis of binary sequences. J. R. Stat. Soc. Ser. B (Methodol.) 20, 215–242 (1958)MathSciNetzbMATHGoogle Scholar
  19. D’Silva, V., Kroening, D., Weissenbacher, G.: A survey of automated techniques for formal software verification. IEEE Trans. CAD Integrated Circuits Syst. 27(7), 1165–1178 (2008)Google Scholar
  20. Fadil, H., Koning, J.: A formal approach to model multiagent interactions using the B formal method. In: Advanced Distributed Systems: 5th International School and Symposium, ISSADS 2005, Guadalajara, Mexico, January 24–28, 2005, Revised Selected Papers, pp. 516–528 (2005)Google Scholar
  21. Gazzola, L., Micucci, D., Mariani, L.: Automatic software repair: a survey. IEEE Trans. Softw. Eng. 45(1), 34–67 (2019)Google Scholar
  22. Glorot, X., Bordes, A., Bengio, Y.: Deep sparse rectifier neural networks. In: Proceedings of the Fourteenth International Conference on Artificial Intelligence and Statistics, AISTATS 2011, Fort Lauderdale, USA, April 11-13, 2011, pp. 315–323 (2011)Google Scholar
  23. Gopinath, D., Malik, M.Z., Khurshid, S.: Specification-based program repair using SAT. In: 17th International Conference, TACAS 2011, Held as Part of the Joint European Conferences on Theory and Practice of Software Tools and Algorithms for the Construction and Analysis of Systems, ETAPS 2011, Saarbrücken, Germany, March 26–April 3, 2011. Proceedings, pp. 173–188 (2011)Google Scholar
  24. Harel, D., Katz, G., Marron, A., Weiss, G.: Non-intrusive repair of safety and liveness violations in reactive programs. Trans. Comput. Collective Intell. 16, 1–33 (2014)Google Scholar
  25. He, K., Zhang, X., Ren, S., Sun, J.: Deep residual learning for image recognition. In: 2016 IEEE Conference on Computer Vision and Pattern Recognition, CVPR 2016, Las Vegas, NV, USA, June 27–30, 2016, pp. 770–778 (2016)Google Scholar
  26. Ho, T.K.: Random decision forests. In: Third International Conference on Document Analysis and Recognition, ICDAR 1995, August 14–15, 1995, Montreal, Canada. Volume I, pp. 278–282 (1995)Google Scholar
  27. Hoffmann, S., Haugou, G., Gabriele, S., Burdy, L.: The b-method for the construction of microkernel-based systems. In: B 2007: Formal Specification and Development in B, 7th International Conference of B Users, Besançon, France, January 17–19, 2007, Proceedings, pp. 257–259 (2007)Google Scholar
  28. Huth, M., Ryan, M.D.: Logic in Computer Science—Modelling and Reasoning About Systems, 2nd edn. Cambridge University Press, Cambridge (2004)zbMATHGoogle Scholar
  29. Jha, S., Gulwani, S., Seshia, S.A., Tiwari, A.: Oracle-guided component-based program synthesis. In: Proceedings of the 32nd ACM/IEEE International Conference on Software Engineering—Volume 1, ICSE 2010, Cape Town, South Africa, 1-8 May 2010, pp. 215–224 (2010)Google Scholar
  30. Ke, Y., Stolee, K.T., Le Goues, C., Brun, Y.: Repairing programs with semantic code search (T). In: 30th IEEE/ACM International Conference on Automated Software Engineering, ASE 2015, Lincoln, NE, USA, November 9-13, 2015, pp. 295–306 (2015)Google Scholar
  31. Krings, S., Leuschel, M.: SMT solvers for validation of B and Event-B models. In: Integrated Formal Methods—12th International Conference, IFM 2016, Reykjavik, Iceland, June 1-5, 2016, Proceedings, pp. 361–375 (2016)Google Scholar
  32. Kurt, I., Ture, M., Kurum, A.T.: Comparing performances of logistic regression, classification and regression tree, and neural networks for predicting coronary artery disease. Expert Syst. Appl. 34(1), 366–374 (2008)Google Scholar
  33. Le, X.D., Chu, D., Lo, D., Le Goues, C., Visser, W.: S3: syntax- and semantic-guided repair synthesis via programming by examples. In: Proceedings of the 2017 11th Joint Meeting on Foundations of Software Engineering, ESEC/FSE 2017, Paderborn, Germany, September 4–8, 2017, pp. 593–604 (2017)Google Scholar
  34. Le, X.D., Le, Q.L., Lo, D., Le Goues, C.: Enhancing automated program repair with deductive verification. In: 2016 IEEE International Conference on Software Maintenance and Evolution, ICSME 2016, Raleigh, NC, USA, October 2–7, 2016, pp. 428–432 (2016a)Google Scholar
  35. Le, X.D., Lo, D., Le Goues, C.: History driven program repair. In: IEEE 23rd International Conference on Software Analysis, Evolution, and Reengineering, SANER 2016, Suita, Osaka, Japan, March 14–18, 2016—Volume 1, pp. 213–224 (2016b)Google Scholar
  36. Le Goues, C., Forrest, S., Weimer, W.: Current challenges in automatic software repair. Software Qual. J. 21(3), 421–443 (2013)Google Scholar
  37. Le Goues, C., Nguyen, T., Forrest, S., Weimer, W.: Genprog: a generic method for automatic software repair. IEEE Trans. Softw. Eng. 38(1), 54–72 (2012)Google Scholar
  38. Leuschel, M., Butler, M.J.: ProB: an automated analysis toolset for the B method. Int. J. Softw. Tools Technol. Transfer 10(2), 185–203 (2008)Google Scholar
  39. Leuschel, M., Cansell, D., Butler, M.J.: Validating and animating higher-order recursive functions in B. In: Rigorous Methods for Software Construction and Analysis, Essays Dedicated to Egon Börger on the Occasion of His 60th Birthday, pp. 78–92 (2009)Google Scholar
  40. Loh, W.: Classification and regression trees. Wiley Interdisc. Rew. Data Min. Knowl. Discov. 1(1), 14–23 (2011)Google Scholar
  41. Nipkow, T., Paulson, L.C., Wenzel, M.: Isabelle/HOL—A Proof Assistant for Higher-Order Logic. Lecture Notes in Computer Science, vol. 2283. Springer, Berlin (2002)zbMATHGoogle Scholar
  42. Pnueli, A.: The temporal logic of programs. In: 18th Annual Symposium on Foundations of Computer Science, Providence, Rhode Island, USA, 31 October–1 November 1977, pp. 46–57 (1977)Google Scholar
  43. Schmidt, J., Krings, S., Leuschel, M.: Interactive model repair by synthesis. In: Abstract State Machines, Alloy, B, TLA, VDM, and Z—5th International Conference, ABZ 2016, Linz, Austria, May 23–27, 2016, Proceedings, pp. 303–307 (2016)Google Scholar
  44. Schmidt, J., Krings, S., Leuschel, M.: Repair and generation of formal models using synthesis. In: Integrated Formal Methods—14th International Conference, IFM 2018, Maynooth, Ireland, September 5–7, 2018, Proceedings, pp. 346–366 (2018)Google Scholar
  45. Siekmann, J.H.: Unification theory. J. Symb. Comput. 7(3/4), 207–274 (1989)MathSciNetzbMATHGoogle Scholar
  46. Turian, J.P., Ratinov, L., Bengio, Y.: Word representations: a simple and general method for semi-supervised learning. In: ACL 2010, Proceedings of the 48th Annual Meeting of the Association for Computational Linguistics, July 11–16, 2010, Uppsala, Sweden, pp. 384–394 (2010)Google Scholar
  47. Wen, M., Chen, J., Wu, R., Hao, D., Cheung, S.: Context-aware patch generation for better automated program repair. In: Proceedings of the 40th International Conference on Software Engineering, ICSE 2018, Gothenburg, Sweden, May 27–June 03, 2018, pp. 1–11 (2018)Google Scholar
  48. Wilkerson, J.L., Tauritz, D.R.: Coevolutionary automated software correction. In: Genetic and Evolutionary Computation Conference, GECCO 2010, Proceedings, Portland, Oregon, USA, July 7–11, 2010, pp. 1391–1392 (2010)Google Scholar
  49. Yang, G., Khurshid, S., Kim, M.: Specification-based test repair using a lightweight formal method. In: FM 2012: Formal Methods—18th International Symposium, Paris, France, August 27–31, 2012. Proceedings, pp. 455–470 (2012)Google Scholar

Copyright information

© Springer Science+Business Media, LLC, part of Springer Nature 2019

Authors and Affiliations

  1. 1.School of Computer ScienceUniversity of AucklandAucklandNew Zealand

Personalised recommendations