dual pivot quicksort verification and proof using key
play

Dual Pivot Quicksort: Verification and Proof using KeY Jonas - PowerPoint PPT Presentation

Dual Pivot Quicksort: Verification and Proof using KeY Jonas Schiffl Karlsruher Institut f ur Technologie July 27th, 2016 Introduction Introduction Why verify Dual Pivot Quicksort? Introduction Why verify Dual Pivot Quicksort?


  1. Dual Pivot Quicksort: Verification and Proof using KeY Jonas Schiffl Karlsruher Institut f¨ ur Technologie July 27th, 2016

  2. Introduction

  3. Introduction Why verify Dual Pivot Quicksort?

  4. Introduction Why verify Dual Pivot Quicksort? ◮ Inspired by discovery of Timsort Bug

  5. Introduction Why verify Dual Pivot Quicksort? ◮ Inspired by discovery of Timsort Bug ◮ Widely used standard library algorithm

  6. Introduction Why verify Dual Pivot Quicksort? ◮ Inspired by discovery of Timsort Bug ◮ Widely used standard library algorithm ◮ Complex enough

  7. Introduction Why verify Dual Pivot Quicksort? ◮ Inspired by discovery of Timsort Bug ◮ Widely used standard library algorithm ◮ Complex enough ◮ Simple enough

  8. Section 1 Algorithm Description

  9. Quicksort value of element at index array index

  10. Quicksort value of element at index array index

  11. Quicksort value of element at index array index

  12. Quicksort value of element at index array index

  13. Quicksort value of element at index array index

  14. Quicksort value of element at index array index

  15. Quicksort value of element at index array index

  16. Quicksort value of element at index array index

  17. Quicksort value of element at index array index

  18. Dual Pivot Quicksort value of element at index array index

  19. Dual Pivot Quicksort value of element at index array index

  20. Dual Pivot Quicksort value of element at index array index

  21. Dual Pivot Quicksort Why use Dual Pivot Quicksort?

  22. Dual Pivot Quicksort Why use Dual Pivot Quicksort? ◮ Theory: Average number of swaps reduced by 20% (Yaroslavskiy 2009)

  23. Dual Pivot Quicksort Why use Dual Pivot Quicksort? ◮ Theory: Average number of swaps reduced by 20% (Yaroslavskiy 2009) ◮ Practice: Multi-pivot Quicksorts are more cache-efficient (Kushagra 2014)

  24. Dual Pivot Quicksort Why use Dual Pivot Quicksort? ◮ Theory: Average number of swaps reduced by 20% (Yaroslavskiy 2009) ◮ Practice: Multi-pivot Quicksorts are more cache-efficient (Kushagra 2014) ◮ Benchmarking shows it is faster

  25. Java Implementation – Choosing a Sorting Algorithm

  26. Java Implementation – Choosing a Sorting Algorithm data type? int, long, float, double byte > 285 short, char length? length? highly structured? < =29 < 47 else no length? yes > 29 > 3200 else < 47 Counting Sort Insertion Sort Quicksort Merge Sort

  27. Java Implementation – Quicksort Quicksort

  28. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements

  29. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements Sort elements in their positions

  30. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements All 5 Sort elements in their positions elements distinct?

  31. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements All 5 Sort elements in their positions elements distinct? no Single Pivot Partition

  32. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements All 5 Sort elements in their positions elements distinct? yes no Dual Pivot Partition Single Pivot Partition

  33. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements All 5 Sort elements in their positions elements distinct? yes no Dual Pivot Partition Single Pivot Partition Central part large?

  34. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements All 5 Sort elements in their positions elements distinct? yes no Dual Pivot Partition Single Pivot Partition Central yes part Pivot Values Partition large?

  35. Java Implementation – Quicksort Quicksort Select 5 evenly spaced array elements All 5 Sort elements in their positions elements distinct? yes no Dual Pivot Partition Single Pivot Partition Central yes part Pivot Values Partition large? no Recursion

  36. Java Implementation – Single Pivot Partition value of element at index array index

  37. Java Implementation – Single Pivot Partition value of element at index array index

  38. Java Implementation – Dual Pivot Partition value of element at index array index

  39. Java Implementation – Dual Pivot Partition value of element at index array index

  40. Java Implementation – Swap Pivot Values Partition value of element at index array index

  41. Java Implementation – Swap Pivot Values Partition value of element at index array index

  42. Java Implementation – Partitioning great less k

  43. Java Implementation – Partitioning great less k

  44. Java Implementation – Partitioning great less k

  45. Java Implementation – Partitioning great less k

  46. Java Implementation – Partitioning great less k

  47. Java Implementation – Partitioning great less k

  48. Java Implementation – Partitioning great less k

  49. Java Implementation – Partitioning great less k

  50. Java Implementation – Partitioning great less k

  51. Java Implementation – Partitioning great less k

  52. Java Implementation – Partitioning great less k

  53. Java Implementation – Partitioning k great less

  54. Section 2 Specification and Proof

  55. Work Flow

  56. Work Flow ◮ Encapsulating source code in its own Java class

  57. Work Flow ◮ Encapsulating source code in its own Java class ◮ Subdivision into three classes: One per partitioning style

  58. Work Flow ◮ Encapsulating source code in its own Java class ◮ Subdivision into three classes: One per partitioning style ◮ Writing specification Running KeY Adapting specification or source code

  59. General KeY Strategy

  60. General KeY Strategy ◮ Autopilot Strategy Macro

  61. General KeY Strategy ◮ Autopilot Strategy Macro ◮ If proof fails: ◮ Confirm by generating counterexample ◮ Find violated specification condition ◮ Adapt specification (or source code)

  62. General KeY Strategy ◮ Autopilot Strategy Macro ◮ If proof fails: ◮ Confirm by generating counterexample ◮ Find violated specification condition ◮ Adapt specification (or source code) ◮ If no proof is found: ◮ Increase number of steps (?) ◮ Interactive Rule Apps (Quantifier Instantiation, if-then-else-split) ◮ Heap Simplification + SMT Solver

  63. Feasibility – Problems with KeY

  64. Feasibility – Problems with KeY ◮ Computation time

  65. Feasibility – Problems with KeY ◮ Computation time ◮ Method extraction ◮ Exact Localization ◮ SMT Solver ◮ Block Contracts

  66. Feasibility – Problems with KeY ◮ Computation time ◮ Method extraction ◮ Exact Localization ◮ SMT Solver ◮ Block Contracts ◮ Error in specification or lack of resources?

  67. Feasibility – Problems with KeY ◮ Computation time ◮ Method extraction ◮ Exact Localization ◮ SMT Solver ◮ Block Contracts ◮ Error in specification or lack of resources? ◮ Localizability

  68. Feasibility – Problems with KeY ◮ Computation time ◮ Method extraction ◮ Exact Localization ◮ SMT Solver ◮ Block Contracts ◮ Error in specification or lack of resources? ◮ Localizability ◮ Stability

  69. Feasibility – Problems with KeY ◮ Computation time ◮ Method extraction ◮ Exact Localization ◮ SMT Solver ◮ Block Contracts ◮ Error in specification or lack of resources? ◮ Localizability ◮ Stability ◮ Responsiveness

  70. Violation of Single Pivot Partition Invariant

  71. Violation of Single Pivot Partition Invariant great less k

  72. Violation of Single Pivot Partition Invariant while (a[great] > pivot2) { if (great -- == k) { break outer; } } while (a[great] == pivot2) { if (great -- == k) { break outer; } } while (a[great] > pivot) { --great; } ...

  73. Violation of Single Pivot Partition Invariant less great k ... ... ... < = > = >

  74. Section 3 Conclusive Remarks

  75. Conclusive Remarks

  76. Conclusive Remarks ◮ Verifying a large, complex, real-world Java program with KeY is feasable, but not without challenges

  77. Conclusive Remarks ◮ Verifying a large, complex, real-world Java program with KeY is feasable, but not without challenges ◮ Correct sorting, but invariant is violated

  78. Conclusive Remarks ◮ Verifying a large, complex, real-world Java program with KeY is feasable, but not without challenges ◮ Correct sorting, but invariant is violated

  79. Further Work

  80. Further Work ◮ Prove permutation property

  81. Further Work ◮ Prove permutation property ◮ Prove method as-is

  82. Further Work ◮ Prove permutation property ◮ Prove method as-is ◮ Prove entire sort(int[]) method

  83. Further Work ◮ Prove permutation property ◮ Prove method as-is ◮ Prove entire sort(int[]) method ◮ Prove entire sort method

  84. Further Work ◮ Prove permutation property ◮ Prove method as-is ◮ Prove entire sort(int[]) method ◮ Prove entire sort method

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