experience report smuggling a little bit of coq inside a
play

Experience Report: Smuggling a Little Bit of Coq Inside a CAD - PowerPoint PPT Presentation

Experience Report: Smuggling a Little Bit of Coq Inside a CAD Development Context Dimitur Krustev IGE+XAO Balkan 6 July 2020 / Coq Workshop 2020 Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 1 / 13 Outline


  1. Experience Report: Smuggling a Little Bit of Coq Inside a CAD Development Context Dimitur Krustev IGE+XAO Balkan 6 July 2020 / Coq Workshop 2020 Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 1 / 13

  2. Outline Introduction 1 When We Use Coq 2 Example: A* Search How We Use Coq 3 Why We Use Coq 4 Conclusions 5 Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 2 / 13

  3. Introduction Introduction IGE+XAO – a company working on electrical CAD software for almost 35 years a part of Schneider Electric since 2018 Quality assurance based on a combination of widely used standard techniques However, we found formal verification using Coq useful in certain specific circumstances why when how Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 3 / 13

  4. Introduction Company – Products IGE+XAO – focus on electrical CAD systems, since 1986 Solutions for several domains Transport equipment manufacturing (Aircraft, Trains, Ships, Automotive) system design of electrical installation cable harness routing cable harness manufacturing . . . Equipment, Machinery, Plant Automation schematic editors 3D Electrical Panel Design . . . Construction Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 4 / 13

  5. Introduction Company – Products IGE+XAO – focus on electrical CAD systems, since 1986 Solutions for several domains Transport equipment manufacturing (Aircraft, Trains, Ships, Automotive) system design of electrical installation cable harness routing cable harness manufacturing . . . Equipment, Machinery, Plant Automation schematic editors 3D Electrical Panel Design . . . Construction Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 4 / 13

  6. Introduction Company – Products IGE+XAO – focus on electrical CAD systems, since 1986 Solutions for several domains Transport equipment manufacturing (Aircraft, Trains, Ships, Automotive) system design of electrical installation cable harness routing cable harness manufacturing . . . Equipment, Machinery, Plant Automation schematic editors 3D Electrical Panel Design . . . Construction Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 4 / 13

  7. Introduction Company – Organization R&D departments in several countries France, Poland, Bulgaria, Denmark, Tunisia Technologies used in recent years majority of code still in C++ new projects based on .NET – mostly C# more recently, F# also used in .NET projects QA – standard methods, expected to give best cost/quality ratio unit/automated/manual tests code reviews code linters F# in our technology stack faster to prototype domain-specific algorithms immutable by default – easier to write correct parallel code luckily, OCaml code extracted by Coq mostly usable as F# code Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 5 / 13

  8. When We Use Coq When We Use Coq Tricky generic algorithms – not in standard libraries – with disproportionately high impact on final quality Stable specification, easy to formalize Rare small examples in Coq (apply "patches" to electrical Business Logic design documents) Domain-specific Best Area for Coq: Algorithms ● graph algorithms (A* search, length-preserving tree layout, B&B TSP, ...) Generic ● data structures (union-find, priority Standard Algorithms & Libraries queues, ...) Data ● PL-related (a single exception) Structures Research work, not directly related to our production, is not discussed here Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 6 / 13

  9. When We Use Coq Example: A* Search Example: A* Search – Context 0016 40RT1;J2;HP 1 00074 DR24 10 9 00064 DR24 Context: a tool for 11 00084 DR24 TT0003-TB0020 0161 22 automatically 0158 22 23 0150RD 21 0148RD 15 0149RD 22 TT0003-TB0011 3 00083 DR24 drawing wiring 1 00063 DR24 2 3 DR24 2 TT0003-TB0020 0007 15 00081 DR24 13 00061 DR24 4 1 DR24 14 TT0003-TB0020 diagrams 17 0125RD 19 0134 DR22 5 00062 DR24 7 00082 DR24 3 00072 DR24 6 5 0017 TT0003-TB0020 40RT1 40RT1;J2;HP 0020 We needed a customized version of A* Search in order to find wire routes during diagram generation to have more generic API (e.g. arbitrary edge weights) to fine-tune performance (e.g. LIFO tie-breaking) ⇒ an in-house implementation Subtle correctness arguments Key infrastructure for the whole product ⇒ We chose verification in Coq as main QA approach Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 7 / 13

  10. When We Use Coq Example: A* Search Example: A* Search – Specification ✞ ☎ Fixpoint CorrectRouteHelper ( start : Node ) ( endNode : Node ) ( w : Weight ) ( path : list Node ) : Prop := match path with | nil => start = endNode ∧ w = weightZero | node :: path => ∃ w ’, In ( endNode , w ’) ( neighbors node ) ∧ ∃ w ’’, CorrectRouteHelper start node w ’’ path ∧ w = weightAdd w ’’ w ’ end . Definition CorrectRoute ( start : Node ) ( route : Node · Weight · list Node ) : Prop := let ’( endNode , w , path ) := route in isGoalNode endNode = true ∧ NoDup ( endNode :: path ) ∧ CorrectRouteHelper start endNode w path . Theorem Astar_CorrectRoute : ∀ start route , Astar start = Some route → CorrectRoute start route . ✝ ✆ Relatively simple and not expected to change in the future Trade-off: only check result route correctness, not optimality Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 8 / 13

  11. When We Use Coq Example: A* Search Example: A* Search – Evaluation Time spent on A* Search verification ( ∼ 40h) only slightly longer that what would be needed to create initial implementation in F# with enough unit tests A* in Coq → A* in F# ⊂ Wiring Diagram Generator (WDG) ⊂ Electrical Diagram Visualizer (EDV) Top-level product extensively tested during 2 years: Language Lines of code Issues Impl. Proofs Cmts. Issues A* Coq 173 203 29 0 A* (extracted) F# 39 - - 0 WDG C# + F# 108K - - 400+ EDV C# + TypeScript - - - 800+ Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 9 / 13

  12. How We Use Coq How We Use Coq Main goal: keep cost/quality ratio competitive with respect to other QA methods Avoid using tools/libraries not coming with the standard Coq installation Use built-in extraction to produce executable code major enabler: we already use a language – F# – which is (mostly) compatible with Coq extraction functional programming techniques already used in production – mostly because they make parallel programming easier Code verified in Coq typically tiny in size and stable over time ⇒ so far, we can avoid Coq integration in automatic build process; integrating extracted code manually instead Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 10 / 13

  13. How We Use Coq Extraction: Technical Issues F# is compatible with OCaml core, but some features in extracted code are problematic F# module system very limited ⇒ avoid using modules no higher-kinded types ⇒ manual tweaking and/or some workarounds in Coq: ✞ ☎ Record FinSetOps ( A : Set ) := { FinSet : Set ; empty : FinSet ; add : ∀ ( A_dec : ∀ x y : A , { x = y } + { x <> y }), A → FinSet → FinSet ; contains : ∀ ( A_dec : ∀ x y : A , { x = y } + { x <> y }), A → FinSet → bool ; ... }. Variable fsOps : FinSetOps Node . ✝ ✆ higher-kinded type “hidden” in extracted code: ✞ ☎ . . . l e t closedSet ’ = fsOps . add node_dec node closedSet . . . ✝ ✆ Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 11 / 13

  14. Why We Use Coq Why We Use Coq The use of Coq – for certain use cases – provides tangible net benefits in the long term 1 short-term extra investment – need to spend time in doing proofs short-term result – a 100% guarantee that the specification is respected (typically impossible with other QA methods) long-term gains – no need to repeatedly deal with bugs, which inevitably appear regularly in tricky unverified code typically far outweigh the short-term investment required Due to the nature of our products, use of formal verification can bring sufficient benefits only in a small number of situations, but the impact on quality is disproportionately high 1 assuming availability of competent Coq users Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 12 / 13

  15. Conclusions Conclusions Using Coq to formally verify selected parts of the code can be highly beneficial – in certain use cases – even for standard off-the-shelf software Dimitur Krustev (IGE+XAO Balkan) Smuggling a Little Bit of Coq Coq Workshop 2020 13 / 13

Download Presentation
Download Policy: The content available on the website is offered to you 'AS IS' for your personal information and use only. It cannot be commercialized, licensed, or distributed on other websites without prior consent from the author. To download a presentation, simply click this link. If you encounter any difficulties during the download process, it's possible that the publisher has removed the file from their server.

Recommend


More recommend