diff --git a/README.md b/README.md index 5666d41a2206f5b6c6e08d513eb2c5dcc91fb40a..788e1942e10806dce55c0c6beab043f39f437b8e 100644 --- a/README.md +++ b/README.md @@ -22,22 +22,22 @@ size_categories: A benchmark for measuring how well LLMs do **program verification** — not code generation — on real, human-authored problems. -It has 233 problems. Each one comes with a correct C solution that has been given a formal +It has 242 problems. Each one comes with a correct C solution that has been given a formal spec and checked by [**QCP**](https://www.qua.codes/en/index.html). The proofs are done in one -of two backends, **Rocq** or **Lean 4**. All 233 have a Rocq version; 83 also have a Lean one. +of two backends, **Rocq** or **Lean 4**. All 242 have a Rocq version; 83 also have a Lean one. The problems are in four groups, all under `benchmarks/`, next to the build files: | group | problems | C lines | source | |---|---:|---:|---| | `benchmarks/Codeforces/` | 147 | 6,899 | competitive-programming problems, grouped into `examples_shard/` slices | -| `benchmarks/Algorithms/` | 73 | 3,986 | classic algorithms, one directory per algorithm | -| `benchmarks/Data_structures/` | 5 | 404 | array stack, BIT and three priority-queue interfaces | +| `benchmarks/Algorithms/` | 77 | 4,111 | classic algorithms, one directory per algorithm | +| `benchmarks/Data_structures/` | 10 | 618 | array stack, BIT, three priority-queue interfaces, linked lists and three linked queues | | `benchmarks/Engineering/` | 8 | 338 | MiniSat vectors and C string / memory routines | -| total | 233 | 11,627 | | +| total | 242 | 11,966 | | "C lines" counts the unannotated `solution.c` — the program a model is asked to specify and -verify. They are small by design: a median of 40 lines, 50 on average, from 5 up to 189 +verify. They are small by design: a median of 40 lines, 49 on average, from 5 up to 189 (`Algorithms/kosaraju`). The difficulty is in the property to be proved, not in the size of the code. @@ -93,7 +93,7 @@ backend's assertion language. └── groundtruth/ ``` -`rocq/` is present for all 233 problems; `lean/` for 83 of them — 45 Algorithms, +`rocq/` is present for all 242 problems; `lean/` for 83 of them — 45 Algorithms, 34 Codeforces (14 in `examples_shard00`, 20 in `examples_shard01`), 3 Data_structures and 1 Engineering. The `.lean` libraries mirror the corresponding `.v` files; cases without private definitions import shared libraries directly from the C annotations. diff --git a/benchmarks/Algorithms/exgcd/manifest.json b/benchmarks/Algorithms/exgcd/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..9e8c1abcbaf7bdf8119e4f8b17c91eb8ff8848a8 --- /dev/null +++ b/benchmarks/Algorithms/exgcd/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "exgcd", + "source": { + "dataset": "classical_algorithm", + "problem_id": "exgcd", + "title": "Extended Euclidean Algorithm", + "tags": [ + "gcd", + "bezout", + "recursion" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Algorithms/exgcd/problem.md b/benchmarks/Algorithms/exgcd/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..d9e1d2f1d57e6ec7a21a3dbe0292960a34e96631 --- /dev/null +++ b/benchmarks/Algorithms/exgcd/problem.md @@ -0,0 +1,13 @@ +# Extended Euclidean Algorithm + +## Description + +Compute the greatest common divisor of two integers together with a pair of Bézout coefficients, using the recursive extended Euclidean algorithm. + +## Input + +The function receives two integers $a$ and $b$ ($-2^{31} < a, b \le 2^{31} - 1$), and two pointers `x` and `y` to two distinct writable `int` cells. + +## Output + +Return $g = \gcd(a, b)$ and store integers in `*x` and `*y` such that $a \cdot x + b \cdot y = g$. diff --git a/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_goal.v b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..5d4776b6cf81ed1eba3b0da6078af9b668b5fb0f --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_goal.v @@ -0,0 +1,1035 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Local Open Scope sac. + +(*----- Function abs -----*) + +Definition abs_safety_wit_1 := +forall (x_pre: Z) (PreH1 : (INT_MIN < x_pre)) (PreH2 : (x_pre <= INT_MAX)) , + ((( &( "x" ) )) # Int |-> x_pre) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition abs_safety_wit_2 := +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + ((( &( "x" ) )) # Int |-> x_pre) +|-- + “ (x_pre <> (INT_MIN)) ” +. + +Definition abs_return_wit_1 := +( +forall (x_pre: Z) (PreH1 : (x_pre >= 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ (x_pre = (Zabs (x_pre))) ” + && emp +) \/ +( +forall (x_pre: Z) (PreH1 : (x_pre >= 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ (x_pre = (Zabs (x_pre))) ” + && emp +). + +Definition abs_return_wit_1_split_goal_1 := +forall (x_pre: Z) (PreH1 : (x_pre >= 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + (x_pre = (Zabs (x_pre))) +. + +Definition abs_return_wit_2 := +( +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ ((-x_pre) = (Zabs (x_pre))) ” + && emp +) \/ +( +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ ((-x_pre) = (Zabs (x_pre))) ” + && emp +). + +Definition abs_return_wit_2_split_goal_1 := +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + ((-x_pre) = (Zabs (x_pre))) +. + +(*----- Function exgcd -----*) + +Definition exgcd_safety_wit_1 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (INT_MIN < a_pre)) (PreH2 : (a_pre <= INT_MAX)) (PreH3 : (INT_MIN < b_pre)) (PreH4 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_2 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre = 0)) (PreH2 : (INT_MIN < a_pre)) (PreH3 : (a_pre <= INT_MAX)) (PreH4 : (INT_MIN < b_pre)) (PreH5 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_3 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre < 0)) (PreH2 : (b_pre = 0)) (PreH3 : (INT_MIN < a_pre)) (PreH4 : (a_pre <= INT_MAX)) (PreH5 : (INT_MIN < b_pre)) (PreH6 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (1 <> (INT_MIN)) ” +. + +Definition exgcd_safety_wit_4 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre < 0)) (PreH2 : (b_pre = 0)) (PreH3 : (INT_MIN < a_pre)) (PreH4 : (a_pre <= INT_MAX)) (PreH5 : (INT_MIN < b_pre)) (PreH6 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (1 <= INT_MAX) ” + && “ ((INT_MIN) <= 1) ” +. + +Definition exgcd_safety_wit_5 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre >= 0)) (PreH2 : (b_pre = 0)) (PreH3 : (INT_MIN < a_pre)) (PreH4 : (a_pre <= INT_MAX)) (PreH5 : (INT_MIN < b_pre)) (PreH6 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_6 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre = 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_7 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre <> 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (1 <= INT_MAX) ” + && “ ((INT_MIN) <= 1) ” +. + +Definition exgcd_safety_wit_8 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre < 0)) (PreH2 : (b_pre = 0)) (PreH3 : (INT_MIN < a_pre)) (PreH4 : (a_pre <= INT_MAX)) (PreH5 : (INT_MIN < b_pre)) (PreH6 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |-> (-1)) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_9 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre = 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |-> 0) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_10 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre <> 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |-> 1) + ** ((y_pre) # Int |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition exgcd_safety_wit_11 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre <> 0)) (PreH2 : (INT_MIN < a_pre)) (PreH3 : (a_pre <= INT_MAX)) (PreH4 : (INT_MIN < b_pre)) (PreH5 : (b_pre <= INT_MAX)) , + ((( &( "g" ) )) # Int |->_) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ ((a_pre <> (INT_MIN)) \/ (b_pre <> (-1))) ” + && “ (b_pre <> 0) ” +. + +Definition exgcd_safety_wit_12 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” + && “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +. + +Definition exgcd_safety_wit_13 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” + && “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +. + +Definition exgcd_safety_wit_14 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((a_pre <> (INT_MIN)) \/ (b_pre <> (-1))) ” + && “ (b_pre <> 0) ” +. + +Definition exgcd_safety_wit_15 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” + && “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +) \/ +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” + && “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +). + +Definition exgcd_safety_wit_15_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” +. + +Definition exgcd_safety_wit_15_split_goal_2 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +. + +Definition exgcd_safety_wit_16 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” + && “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +) \/ +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” + && “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +). + +Definition exgcd_safety_wit_16_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” +. + +Definition exgcd_safety_wit_16_split_goal_2 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +. + +Definition exgcd_safety_wit_17 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((a_pre <> (INT_MIN)) \/ (b_pre <> (-1))) ” + && “ (b_pre <> 0) ” +. + +Definition exgcd_safety_wit_18 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” + && “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +) \/ +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” + && “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +). + +Definition exgcd_safety_wit_18_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) <= INT_MAX) ” +. + +Definition exgcd_safety_wit_18_split_goal_2 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((INT_MIN) <= (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) ” +. + +Definition exgcd_safety_wit_19 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” + && “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +) \/ +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” + && “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +). + +Definition exgcd_safety_wit_19_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ (((a_pre ÷ b_pre ) * y_callee_v ) <= INT_MAX) ” +. + +Definition exgcd_safety_wit_19_split_goal_2 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((INT_MIN) <= ((a_pre ÷ b_pre ) * y_callee_v )) ” +. + +Definition exgcd_safety_wit_20 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> x_callee_v) + ** ((x_pre) # Int |-> y_callee_v) + ** ((( &( "g" ) )) # Int |-> retval) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) +|-- + “ ((a_pre <> (INT_MIN)) \/ (b_pre <> (-1))) ” + && “ (b_pre <> 0) ” +. + +Definition exgcd_return_wit_1 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) + ** ((x_pre) # Int |-> y_callee_v) +|-- + EX (y_pre_v_2: Z) (x_pre_v_2: Z) , + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v_2 ) + (b_pre * y_pre_v_2 ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre <> 0) ” + && “ ((a_pre % ( b_pre ) ) = 0) ” + && “ (x_pre_v_2 = 0) ” + && “ ((Zabs (y_pre_v_2)) <= 1) ” + && ((x_pre) # Int |-> x_pre_v_2) + ** ((y_pre) # Int |-> y_pre_v_2) +) \/ +( +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + TT && emp +|-- + “ ((Zabs ((x_callee_v - ((a_pre ÷ b_pre ) * 0 ) ))) <= 1) ” + && “ (((a_pre * 0 ) + (b_pre * (x_callee_v - ((a_pre ÷ b_pre ) * 0 ) ) ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (retval = (Zgcd (a_pre) (b_pre))) ” + && emp +). + +Definition exgcd_return_wit_1_split_goal_1 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + ((Zabs ((x_callee_v - ((a_pre ÷ b_pre ) * 0 ) ))) <= 1) +. + +Definition exgcd_return_wit_1_split_goal_2 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + (((a_pre * 0 ) + (b_pre * (x_callee_v - ((a_pre ÷ b_pre ) * 0 ) ) ) ) = (Zgcd (a_pre) (b_pre))) +. + +Definition exgcd_return_wit_1_split_goal_3 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) = 0)) (PreH4 : ((Zabs (x_callee_v)) <= 1)) (PreH5 : (y_callee_v = 0)) (PreH6 : (b_pre <> 0)) (PreH7 : (INT_MIN < a_pre)) (PreH8 : (a_pre <= INT_MAX)) (PreH9 : (INT_MIN < b_pre)) (PreH10 : (b_pre <= INT_MAX)) , + (retval = (Zgcd (a_pre) (b_pre))) +. + +Definition exgcd_return_wit_2 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) + ** ((x_pre) # Int |-> y_callee_v) +|-- + EX (y_pre_v_3: Z) (x_pre_v_3: Z) , + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v_3 ) + (b_pre * y_pre_v_3 ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre <> 0) ” + && “ ((a_pre % ( b_pre ) ) <> 0) ” + && “ ((Zabs (x_pre_v_3)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ ((Zabs (y_pre_v_3)) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && ((x_pre) # Int |-> x_pre_v_3) + ** ((y_pre) # Int |-> y_pre_v_3) +) \/ +( +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + TT && emp +|-- + “ ((Zabs ((0 - ((a_pre ÷ b_pre ) * y_callee_v ) ))) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ (((a_pre * y_callee_v ) + (b_pre * (0 - ((a_pre ÷ b_pre ) * y_callee_v ) ) ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (retval = (Zgcd (a_pre) (b_pre))) ” + && emp +). + +Definition exgcd_return_wit_2_split_goal_1 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((Zabs ((0 - ((a_pre ÷ b_pre ) * y_callee_v ) ))) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) +. + +Definition exgcd_return_wit_2_split_goal_2 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) +. + +Definition exgcd_return_wit_2_split_goal_3 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + (((a_pre * y_callee_v ) + (b_pre * (0 - ((a_pre ÷ b_pre ) * y_callee_v ) ) ) ) = (Zgcd (a_pre) (b_pre))) +. + +Definition exgcd_return_wit_2_split_goal_4 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) = 0)) (PreH5 : (x_callee_v = 0)) (PreH6 : ((Zabs (y_callee_v)) <= 1)) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + (retval = (Zgcd (a_pre) (b_pre))) +. + +Definition exgcd_return_wit_3 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((y_pre) # Int |-> (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) )) + ** ((x_pre) # Int |-> y_callee_v) +|-- + EX (y_pre_v_3: Z) (x_pre_v_3: Z) , + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v_3 ) + (b_pre * y_pre_v_3 ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre <> 0) ” + && “ ((a_pre % ( b_pre ) ) <> 0) ” + && “ ((Zabs (x_pre_v_3)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ ((Zabs (y_pre_v_3)) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && ((x_pre) # Int |-> x_pre_v_3) + ** ((y_pre) # Int |-> y_pre_v_3) +) \/ +( +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + TT && emp +|-- + “ ((Zabs ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ))) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ (((a_pre * y_callee_v ) + (b_pre * (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (retval = (Zgcd (a_pre) (b_pre))) ” + && emp +). + +Definition exgcd_return_wit_3_split_goal_1 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((Zabs ((x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ))) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) +. + +Definition exgcd_return_wit_3_split_goal_2 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) +. + +Definition exgcd_return_wit_3_split_goal_3 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + (((a_pre * y_callee_v ) + (b_pre * (x_callee_v - ((a_pre ÷ b_pre ) * y_callee_v ) ) ) ) = (Zgcd (a_pre) (b_pre))) +. + +Definition exgcd_return_wit_3_split_goal_4 := +forall (b_pre: Z) (a_pre: Z) (y_callee_v: Z) (x_callee_v: Z) (retval: Z) (PreH1 : (retval = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH2 : (((b_pre * x_callee_v ) + ((a_pre % ( b_pre ) ) * y_callee_v ) ) = (Zgcd (b_pre) ((a_pre % ( b_pre ) ))))) (PreH3 : ((a_pre % ( b_pre ) ) <> 0)) (PreH4 : ((b_pre % ( (a_pre % ( b_pre ) ) ) ) <> 0)) (PreH5 : ((Zabs (x_callee_v)) <= ((Zabs ((a_pre % ( b_pre ) ))) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH6 : ((Zabs (y_callee_v)) <= ((Zabs (b_pre)) ÷ (Zgcd (b_pre) ((a_pre % ( b_pre ) ))) ))) (PreH7 : (b_pre <> 0)) (PreH8 : (INT_MIN < a_pre)) (PreH9 : (a_pre <= INT_MAX)) (PreH10 : (INT_MIN < b_pre)) (PreH11 : (b_pre <= INT_MAX)) , + (retval = (Zgcd (a_pre) (b_pre))) +. + +Definition exgcd_return_wit_4 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre < 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |-> (-1)) + ** ((y_pre) # Int |-> 0) +|-- + EX (y_pre_v: Z) (x_pre_v: Z) , + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v ) + (b_pre * y_pre_v ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre = 0) ” + && “ ((Zabs (x_pre_v)) <= 1) ” + && “ (y_pre_v = 0) ” + && ((x_pre) # Int |-> x_pre_v) + ** ((y_pre) # Int |-> y_pre_v) +) \/ +( +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre < 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + TT && emp +|-- + “ ((Zabs ((-1))) <= 1) ” + && “ (((a_pre * (-1) ) + (0 * 0 ) ) = (Zgcd (a_pre) (0))) ” + && “ (retval = (Zgcd (a_pre) (0))) ” + && emp +). + +Definition exgcd_return_wit_4_split_goal_1 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre < 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((Zabs ((-1))) <= 1) +. + +Definition exgcd_return_wit_4_split_goal_2 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre < 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + (((a_pre * (-1) ) + (0 * 0 ) ) = (Zgcd (a_pre) (0))) +. + +Definition exgcd_return_wit_4_split_goal_3 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre < 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + (retval = (Zgcd (a_pre) (0))) +. + +Definition exgcd_return_wit_5 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre = 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |-> 0) + ** ((y_pre) # Int |-> 0) +|-- + EX (y_pre_v: Z) (x_pre_v: Z) , + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v ) + (b_pre * y_pre_v ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre = 0) ” + && “ ((Zabs (x_pre_v)) <= 1) ” + && “ (y_pre_v = 0) ” + && ((x_pre) # Int |-> x_pre_v) + ** ((y_pre) # Int |-> y_pre_v) +) \/ +( +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre = 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + TT && emp +|-- + “ ((Zabs (0)) <= 1) ” + && “ (((0 * 0 ) + (0 * 0 ) ) = (Zgcd (0) (0))) ” + && “ (retval = (Zgcd (0) (0))) ” + && emp +). + +Definition exgcd_return_wit_5_split_goal_1 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre = 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + ((Zabs (0)) <= 1) +. + +Definition exgcd_return_wit_5_split_goal_2 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre = 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + (((0 * 0 ) + (0 * 0 ) ) = (Zgcd (0) (0))) +. + +Definition exgcd_return_wit_5_split_goal_3 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre = 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + (retval = (Zgcd (0) (0))) +. + +Definition exgcd_return_wit_6 := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre <> 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |-> 1) + ** ((y_pre) # Int |-> 0) +|-- + EX (y_pre_v: Z) (x_pre_v: Z) , + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v ) + (b_pre * y_pre_v ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre = 0) ” + && “ ((Zabs (x_pre_v)) <= 1) ” + && “ (y_pre_v = 0) ” + && ((x_pre) # Int |-> x_pre_v) + ** ((y_pre) # Int |-> y_pre_v) +) \/ +( +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre <> 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + TT && emp +|-- + “ ((Zabs (1)) <= 1) ” + && “ (((a_pre * 1 ) + (0 * 0 ) ) = (Zgcd (a_pre) (0))) ” + && “ (retval = (Zgcd (a_pre) (0))) ” + && emp +). + +Definition exgcd_return_wit_6_split_goal_1 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre <> 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + ((Zabs (1)) <= 1) +. + +Definition exgcd_return_wit_6_split_goal_2 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre <> 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + (((a_pre * 1 ) + (0 * 0 ) ) = (Zgcd (a_pre) (0))) +. + +Definition exgcd_return_wit_6_split_goal_3 := +forall (b_pre: Z) (a_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (a_pre)))) (PreH2 : (a_pre <> 0)) (PreH3 : (a_pre >= 0)) (PreH4 : (b_pre = 0)) (PreH5 : (INT_MIN < a_pre)) (PreH6 : (a_pre <= INT_MAX)) (PreH7 : (INT_MIN < b_pre)) (PreH8 : (b_pre <= INT_MAX)) , + (retval = (Zgcd (a_pre) (0))) +. + +Definition exgcd_partial_solve_wit_1_pure := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre < 0)) (PreH2 : (b_pre = 0)) (PreH3 : (INT_MIN < a_pre)) (PreH4 : (a_pre <= INT_MAX)) (PreH5 : (INT_MIN < b_pre)) (PreH6 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |-> (-1)) + ** ((y_pre) # Int |-> 0) +|-- + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” +. + +Definition exgcd_partial_solve_wit_1_aux := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre < 0)) (PreH2 : (b_pre = 0)) (PreH3 : (INT_MIN < a_pre)) (PreH4 : (a_pre <= INT_MAX)) (PreH5 : (INT_MIN < b_pre)) (PreH6 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |-> (-1)) + ** ((y_pre) # Int |-> 0) +|-- + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (a_pre < 0) ” + && “ (b_pre = 0) ” + && “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && ((x_pre) # Int |-> (-1)) + ** ((y_pre) # Int |-> 0) +. + +Definition exgcd_partial_solve_wit_1 := exgcd_partial_solve_wit_1_pure -> exgcd_partial_solve_wit_1_aux. + +Definition exgcd_partial_solve_wit_2_pure := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre = 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |-> 0) + ** ((y_pre) # Int |-> 0) +|-- + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” +. + +Definition exgcd_partial_solve_wit_2_aux := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre = 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |-> 0) + ** ((y_pre) # Int |-> 0) +|-- + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (a_pre = 0) ” + && “ (a_pre >= 0) ” + && “ (b_pre = 0) ” + && “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && ((x_pre) # Int |-> 0) + ** ((y_pre) # Int |-> 0) +. + +Definition exgcd_partial_solve_wit_2 := exgcd_partial_solve_wit_2_pure -> exgcd_partial_solve_wit_2_aux. + +Definition exgcd_partial_solve_wit_3_pure := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre <> 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |-> 1) + ** ((y_pre) # Int |-> 0) +|-- + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” +. + +Definition exgcd_partial_solve_wit_3_aux := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (a_pre <> 0)) (PreH2 : (a_pre >= 0)) (PreH3 : (b_pre = 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |-> 1) + ** ((y_pre) # Int |-> 0) +|-- + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (a_pre <> 0) ” + && “ (a_pre >= 0) ” + && “ (b_pre = 0) ” + && “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && ((x_pre) # Int |-> 1) + ** ((y_pre) # Int |-> 0) +. + +Definition exgcd_partial_solve_wit_3 := exgcd_partial_solve_wit_3_pure -> exgcd_partial_solve_wit_3_aux. + +Definition exgcd_partial_solve_wit_4_pure := +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre <> 0)) (PreH2 : (INT_MIN < a_pre)) (PreH3 : (a_pre <= INT_MAX)) (PreH4 : (INT_MIN < b_pre)) (PreH5 : (b_pre <= INT_MAX)) , + ((( &( "g" ) )) # Int |->_) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && “ ((a_pre % ( b_pre ) ) <= INT_MAX) ” + && “ (INT_MIN < (a_pre % ( b_pre ) )) ” +) \/ +( +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre >= INT_MIN)) (PreH2 : (a_pre >= INT_MIN)) (PreH3 : (b_pre <> 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "g" ) )) # Int |->_) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (INT_MIN < (a_pre % ( b_pre ) )) ” + && “ ((a_pre % ( b_pre ) ) <= INT_MAX) ” +). + +Definition exgcd_partial_solve_wit_4_pure_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre >= INT_MIN)) (PreH2 : (a_pre >= INT_MIN)) (PreH3 : (b_pre <> 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "g" ) )) # Int |->_) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (INT_MIN < (a_pre % ( b_pre ) )) ” +. + +Definition exgcd_partial_solve_wit_4_pure_split_goal_2 := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre >= INT_MIN)) (PreH2 : (a_pre >= INT_MIN)) (PreH3 : (b_pre <> 0)) (PreH4 : (INT_MIN < a_pre)) (PreH5 : (a_pre <= INT_MAX)) (PreH6 : (INT_MIN < b_pre)) (PreH7 : (b_pre <= INT_MAX)) , + ((( &( "g" ) )) # Int |->_) + ** ((( &( "a" ) )) # Int |-> a_pre) + ** ((( &( "b" ) )) # Int |-> b_pre) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ ((a_pre % ( b_pre ) ) <= INT_MAX) ” +. + +Definition exgcd_partial_solve_wit_4_aux := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) (PreH1 : (b_pre <> 0)) (PreH2 : (INT_MIN < a_pre)) (PreH3 : (a_pre <= INT_MAX)) (PreH4 : (INT_MIN < b_pre)) (PreH5 : (b_pre <= INT_MAX)) , + ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && “ ((a_pre % ( b_pre ) ) <= INT_MAX) ” + && “ (INT_MIN < (a_pre % ( b_pre ) )) ” + && “ (b_pre <> 0) ” + && “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && ((y_pre) # Int |->_) + ** ((x_pre) # Int |->_) +. + +Definition exgcd_partial_solve_wit_4 := exgcd_partial_solve_wit_4_pure -> exgcd_partial_solve_wit_4_aux. + +Definition exgcd_derive_Inter_by_Proof := +forall (y_pre: Z) (x_pre: Z) (b_pre: Z) (a_pre: Z) , + “ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_) +|-- + (“ (INT_MIN < a_pre) ” + && “ (a_pre <= INT_MAX) ” + && “ (INT_MIN < b_pre) ” + && “ (b_pre <= INT_MAX) ” + && ((x_pre) # Int |->_) + ** ((y_pre) # Int |->_)) + ** + (((EX y_callee_v x_callee_v retval_2, + “ (retval_2 = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_callee_v ) + (b_pre * y_callee_v ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre = 0) ” + && “ ((Zabs (x_callee_v)) <= 1) ” + && “ (y_callee_v = 0) ” + && ((x_pre) # Int |-> x_callee_v) + ** ((y_pre) # Int |-> y_callee_v)) + || + (EX y_callee_v_2 x_callee_v_2 retval_2, + “ (retval_2 = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_callee_v_2 ) + (b_pre * y_callee_v_2 ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre <> 0) ” + && “ ((a_pre % ( b_pre ) ) = 0) ” + && “ (x_callee_v_2 = 0) ” + && “ ((Zabs (y_callee_v_2)) <= 1) ” + && ((x_pre) # Int |-> x_callee_v_2) + ** ((y_pre) # Int |-> y_callee_v_2)) + || + (EX y_callee_v_3 x_callee_v_3 retval_2, + “ (retval_2 = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_callee_v_3 ) + (b_pre * y_callee_v_3 ) ) = (Zgcd (a_pre) (b_pre))) ” + && “ (b_pre <> 0) ” + && “ ((a_pre % ( b_pre ) ) <> 0) ” + && “ ((Zabs (x_callee_v_3)) <= ((Zabs (b_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && “ ((Zabs (y_callee_v_3)) <= ((Zabs (a_pre)) ÷ (Zgcd (a_pre) (b_pre)) )) ” + && ((x_pre) # Int |-> x_callee_v_3) + ** ((y_pre) # Int |-> y_callee_v_3))) + -* + (EX y_pre_v x_pre_v retval, + “ (retval = (Zgcd (a_pre) (b_pre))) ” + && “ (((a_pre * x_pre_v ) + (b_pre * y_pre_v ) ) = (Zgcd (a_pre) (b_pre))) ” + && ((x_pre) # Int |-> x_pre_v) + ** ((y_pre) # Int |-> y_pre_v))) +. + +Module Type VC_Correct. + + +Axiom proof_of_abs_safety_wit_1 : abs_safety_wit_1. +Axiom proof_of_abs_safety_wit_2 : abs_safety_wit_2. +Axiom proof_of_abs_return_wit_1 : abs_return_wit_1. +Axiom proof_of_abs_return_wit_2 : abs_return_wit_2. +Axiom proof_of_exgcd_safety_wit_1 : exgcd_safety_wit_1. +Axiom proof_of_exgcd_safety_wit_2 : exgcd_safety_wit_2. +Axiom proof_of_exgcd_safety_wit_3 : exgcd_safety_wit_3. +Axiom proof_of_exgcd_safety_wit_4 : exgcd_safety_wit_4. +Axiom proof_of_exgcd_safety_wit_5 : exgcd_safety_wit_5. +Axiom proof_of_exgcd_safety_wit_6 : exgcd_safety_wit_6. +Axiom proof_of_exgcd_safety_wit_7 : exgcd_safety_wit_7. +Axiom proof_of_exgcd_safety_wit_8 : exgcd_safety_wit_8. +Axiom proof_of_exgcd_safety_wit_9 : exgcd_safety_wit_9. +Axiom proof_of_exgcd_safety_wit_10 : exgcd_safety_wit_10. +Axiom proof_of_exgcd_safety_wit_11 : exgcd_safety_wit_11. +Axiom proof_of_exgcd_safety_wit_12 : exgcd_safety_wit_12. +Axiom proof_of_exgcd_safety_wit_13 : exgcd_safety_wit_13. +Axiom proof_of_exgcd_safety_wit_14 : exgcd_safety_wit_14. +Axiom proof_of_exgcd_safety_wit_15 : exgcd_safety_wit_15. +Axiom proof_of_exgcd_safety_wit_16 : exgcd_safety_wit_16. +Axiom proof_of_exgcd_safety_wit_17 : exgcd_safety_wit_17. +Axiom proof_of_exgcd_safety_wit_18 : exgcd_safety_wit_18. +Axiom proof_of_exgcd_safety_wit_19 : exgcd_safety_wit_19. +Axiom proof_of_exgcd_safety_wit_20 : exgcd_safety_wit_20. +Axiom proof_of_exgcd_return_wit_1 : exgcd_return_wit_1. +Axiom proof_of_exgcd_return_wit_2 : exgcd_return_wit_2. +Axiom proof_of_exgcd_return_wit_3 : exgcd_return_wit_3. +Axiom proof_of_exgcd_return_wit_4 : exgcd_return_wit_4. +Axiom proof_of_exgcd_return_wit_5 : exgcd_return_wit_5. +Axiom proof_of_exgcd_return_wit_6 : exgcd_return_wit_6. +Axiom proof_of_exgcd_partial_solve_wit_1_pure : exgcd_partial_solve_wit_1_pure. +Axiom proof_of_exgcd_partial_solve_wit_1 : exgcd_partial_solve_wit_1. +Axiom proof_of_exgcd_partial_solve_wit_2_pure : exgcd_partial_solve_wit_2_pure. +Axiom proof_of_exgcd_partial_solve_wit_2 : exgcd_partial_solve_wit_2. +Axiom proof_of_exgcd_partial_solve_wit_3_pure : exgcd_partial_solve_wit_3_pure. +Axiom proof_of_exgcd_partial_solve_wit_3 : exgcd_partial_solve_wit_3. +Axiom proof_of_exgcd_partial_solve_wit_4_pure : exgcd_partial_solve_wit_4_pure. +Axiom proof_of_exgcd_partial_solve_wit_4 : exgcd_partial_solve_wit_4. +Axiom proof_of_exgcd_derive_Inter_by_Proof : exgcd_derive_Inter_by_Proof. + +End VC_Correct. diff --git a/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_goal_check.v b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..6f96795c741f37b719ba91f7369c2061fabcfbdf --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_goal_check.v @@ -0,0 +1,6 @@ +From PVbench.Algorithms.exgcd.rocq.groundtruth Require Import exgcd_goal exgcd_proof_auto exgcd_proof_manual. + +Module VC_Correctness : VC_Correct. + Include exgcd_proof_auto. + Include exgcd_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_proof_auto.v b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..ced2ffd3cc66e907e7b4d2696b5c1f6469b6984d --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_proof_auto.v @@ -0,0 +1,96 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.exgcd.rocq.groundtruth Require Import exgcd_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Local Open Scope sac. + +Lemma proof_of_abs_safety_wit_1 : abs_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_abs_safety_wit_2 : abs_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_1 : exgcd_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_2 : exgcd_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_3 : exgcd_safety_wit_3. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_4 : exgcd_safety_wit_4. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_5 : exgcd_safety_wit_5. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_6 : exgcd_safety_wit_6. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_7 : exgcd_safety_wit_7. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_8 : exgcd_safety_wit_8. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_9 : exgcd_safety_wit_9. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_10 : exgcd_safety_wit_10. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_11 : exgcd_safety_wit_11. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_12 : exgcd_safety_wit_12. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_13 : exgcd_safety_wit_13. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_14 : exgcd_safety_wit_14. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_17 : exgcd_safety_wit_17. +Proof. Admitted. + +Lemma proof_of_exgcd_safety_wit_20 : exgcd_safety_wit_20. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_1_pure : exgcd_partial_solve_wit_1_pure. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_1 : exgcd_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_2_pure : exgcd_partial_solve_wit_2_pure. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_2 : exgcd_partial_solve_wit_2. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_3_pure : exgcd_partial_solve_wit_3_pure. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_3 : exgcd_partial_solve_wit_3. +Proof. Admitted. + +Lemma proof_of_exgcd_partial_solve_wit_4 : exgcd_partial_solve_wit_4. +Proof. Admitted. + diff --git a/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_proof_manual.v b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..53270a28d7625902e97319c3bcfdc08f3665f886 --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/groundtruth/exgcd_proof_manual.v @@ -0,0 +1,394 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.exgcd.rocq.groundtruth Require Import exgcd_goal. +From PVbench.Algorithms.exgcd.rocq.groundtruth Require Import exgcd_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Algorithms.exgcd.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + + +Lemma proof_of_exgcd_safety_wit_15_split_goal_1 : exgcd_safety_wit_15_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + assert (Zabs (a_pre ÷ b_pre * y_callee_v) <= 2147483647). + { rewrite Z.abs_mul. + rewrite <- Z.quot_abs by lia. + pose proof Z.quot_le_upper_bound (Zabs a_pre) (Zabs b_pre) 2147483647 ltac:(lia) ltac:(lia). + nia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_15_split_goal_2 : exgcd_safety_wit_15_split_goal_2. +Proof. + LLM_pre_process ltac:(int_auto). + assert (Zabs (a_pre ÷ b_pre * y_callee_v) <= 2147483647). + { rewrite Z.abs_mul. + rewrite <- Z.quot_abs by lia. + pose proof Z.quot_le_upper_bound (Zabs a_pre) (Zabs b_pre) 2147483647 ltac:(lia) ltac:(lia). + nia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_15 : exgcd_safety_wit_15. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_safety_wit_15_split_goal_1. + - Goal_apply proof_of_exgcd_safety_wit_15_split_goal_2. +Qed. + +Lemma proof_of_exgcd_safety_wit_16_split_goal_1 : exgcd_safety_wit_16_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + assert (Zabs (a_pre ÷ b_pre * y_callee_v) <= 2147483647). + { rewrite Z.abs_mul. + rewrite <- Z.quot_abs by lia. + pose proof Z.quot_le_upper_bound (Zabs a_pre) (Zabs b_pre) 2147483647 ltac:(lia) ltac:(lia). + nia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_16_split_goal_2 : exgcd_safety_wit_16_split_goal_2. +Proof. + LLM_pre_process ltac:(int_auto). + assert (Zabs (a_pre ÷ b_pre * y_callee_v) <= 2147483647). + { rewrite Z.abs_mul. + rewrite <- Z.quot_abs by lia. + pose proof Z.quot_le_upper_bound (Zabs a_pre) (Zabs b_pre) 2147483647 ltac:(lia) ltac:(lia). + nia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_16 : exgcd_safety_wit_16. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_safety_wit_16_split_goal_1. + - Goal_apply proof_of_exgcd_safety_wit_16_split_goal_2. +Qed. + +Lemma proof_of_exgcd_safety_wit_18_split_goal_1 : exgcd_safety_wit_18_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + pose proof exgcd_reduction a_pre b_pre x_callee_v y_callee_v PreH7 PreH5 PreH6. + pose proof Z_gcd_pos_l b_pre (a_pre % (b_pre)) PreH7. + assert (Zabs a_pre ÷ Zgcd b_pre (a_pre % (b_pre)) <= 2147483647). + { apply Z.quot_le_upper_bound; lia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_18_split_goal_2 : exgcd_safety_wit_18_split_goal_2. +Proof. + LLM_pre_process ltac:(int_auto). + pose proof exgcd_reduction a_pre b_pre x_callee_v y_callee_v PreH7 PreH5 PreH6. + pose proof Z_gcd_pos_l b_pre (a_pre % (b_pre)) PreH7. + assert (Zabs a_pre ÷ Zgcd b_pre (a_pre % (b_pre)) <= 2147483647). + { apply Z.quot_le_upper_bound; lia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_18 : exgcd_safety_wit_18. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_safety_wit_18_split_goal_1. + - Goal_apply proof_of_exgcd_safety_wit_18_split_goal_2. +Qed. + +Lemma proof_of_exgcd_safety_wit_19_split_goal_1 : exgcd_safety_wit_19_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + pose proof Z_gcd_pos_l b_pre (a_pre % (b_pre)) PreH7. + assert (Zabs b_pre ÷ Zgcd b_pre (a_pre % (b_pre)) <= Zabs b_pre). + { apply Z.quot_le_upper_bound; nia. } + pose proof Z_abs_quot_rem a_pre b_pre PreH7. + assert (Zabs (a_pre ÷ b_pre * y_callee_v) <= Zabs a_pre). + { rewrite Z.abs_mul. nia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_19_split_goal_2 : exgcd_safety_wit_19_split_goal_2. +Proof. + LLM_pre_process ltac:(int_auto). + pose proof Z_gcd_pos_l b_pre (a_pre % (b_pre)) PreH7. + assert (Zabs b_pre ÷ Zgcd b_pre (a_pre % (b_pre)) <= Zabs b_pre). + { apply Z.quot_le_upper_bound; nia. } + pose proof Z_abs_quot_rem a_pre b_pre PreH7. + assert (Zabs (a_pre ÷ b_pre * y_callee_v) <= Zabs a_pre). + { rewrite Z.abs_mul. nia. } + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_safety_wit_19 : exgcd_safety_wit_19. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_safety_wit_19_split_goal_1. + - Goal_apply proof_of_exgcd_safety_wit_19_split_goal_2. +Qed. + +Lemma proof_of_exgcd_return_wit_1_split_goal_1 : exgcd_return_wit_1_split_goal_1. +Proof. + unfold exgcd_return_wit_1_split_goal_1; intros. + subst y_callee_v. lia. +Qed. + +Lemma proof_of_exgcd_return_wit_1_split_goal_2 : exgcd_return_wit_1_split_goal_2. +Proof. + unfold exgcd_return_wit_1_split_goal_2; intros. + subst y_callee_v. + rewrite <- exgcd_gcd_step by auto. + nia. +Qed. + +Lemma proof_of_exgcd_return_wit_1_split_goal_3 : exgcd_return_wit_1_split_goal_3. +Proof. + unfold exgcd_return_wit_1_split_goal_3; intros. + subst retval. + apply exgcd_gcd_step; auto. +Qed. + +Lemma proof_of_exgcd_return_wit_1 : exgcd_return_wit_1. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_return_wit_1_split_goal_1. + - Goal_apply proof_of_exgcd_return_wit_1_split_goal_2. + - Goal_apply proof_of_exgcd_return_wit_1_split_goal_3. +Qed. + +Lemma proof_of_exgcd_return_wit_2_split_goal_1 : exgcd_return_wit_2_split_goal_1. +Proof. + unfold exgcd_return_wit_2_split_goal_1; intros. + rewrite (exgcd_gcd_last_rem a_pre b_pre) by auto. + pose proof Z.rem_bound_abs a_pre b_pre PreH7. + replace (0 - a_pre ÷ b_pre * y_callee_v) with (-(a_pre ÷ b_pre * y_callee_v)) by lia. + rewrite Z.abs_opp, Z.abs_mul. + apply (Z.le_trans _ (Zabs (a_pre ÷ b_pre))); [nia |]. + rewrite <- (Z.quot_abs _ _ PreH7). + pose proof Z.abs_nonneg a_pre. + apply Z.quot_le_compat_l; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_2_split_goal_2 : exgcd_return_wit_2_split_goal_2. +Proof. + unfold exgcd_return_wit_2_split_goal_2; intros. + rewrite (exgcd_gcd_last_rem a_pre b_pre) by auto. + pose proof Z.rem_bound_abs a_pre b_pre PreH7. + apply (Z.le_trans _ (Zabs b_pre ÷ Zabs b_pre)). + { rewrite Z.quot_same; lia. } + apply Z.quot_le_compat_l; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_2_split_goal_3 : exgcd_return_wit_2_split_goal_3. +Proof. + unfold exgcd_return_wit_2_split_goal_3; intros. + subst x_callee_v. + rewrite <- exgcd_gcd_step by auto. + rewrite <- PreH2. + pose proof Z.quot_rem a_pre b_pre PreH7. + nia. +Qed. + +Lemma proof_of_exgcd_return_wit_2_split_goal_4 : exgcd_return_wit_2_split_goal_4. +Proof. + unfold exgcd_return_wit_2_split_goal_4; intros. + subst retval. + apply exgcd_gcd_step; auto. +Qed. + +Lemma proof_of_exgcd_return_wit_2 : exgcd_return_wit_2. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_return_wit_2_split_goal_1. + - Goal_apply proof_of_exgcd_return_wit_2_split_goal_2. + - Goal_apply proof_of_exgcd_return_wit_2_split_goal_3. + - Goal_apply proof_of_exgcd_return_wit_2_split_goal_4. +Qed. + +Lemma proof_of_exgcd_return_wit_3_split_goal_1 : exgcd_return_wit_3_split_goal_1. +Proof. + unfold exgcd_return_wit_3_split_goal_1; intros. + rewrite <- exgcd_gcd_step by auto. + apply exgcd_reduction; auto. +Qed. + +Lemma proof_of_exgcd_return_wit_3_split_goal_2 : exgcd_return_wit_3_split_goal_2. +Proof. + unfold exgcd_return_wit_3_split_goal_2; intros. + rewrite <- exgcd_gcd_step by auto. + exact PreH6. +Qed. + +Lemma proof_of_exgcd_return_wit_3_split_goal_3 : exgcd_return_wit_3_split_goal_3. +Proof. + unfold exgcd_return_wit_3_split_goal_3; intros. + rewrite <- exgcd_gcd_step by auto. + rewrite <- PreH2. + pose proof Z.quot_rem a_pre b_pre PreH7. + nia. +Qed. + +Lemma proof_of_exgcd_return_wit_3_split_goal_4 : exgcd_return_wit_3_split_goal_4. +Proof. + unfold exgcd_return_wit_3_split_goal_4; intros. + subst retval. + apply exgcd_gcd_step; auto. +Qed. + +Lemma proof_of_exgcd_return_wit_3 : exgcd_return_wit_3. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_return_wit_3_split_goal_1. + - Goal_apply proof_of_exgcd_return_wit_3_split_goal_2. + - Goal_apply proof_of_exgcd_return_wit_3_split_goal_3. + - Goal_apply proof_of_exgcd_return_wit_3_split_goal_4. +Qed. + +Lemma proof_of_exgcd_return_wit_4_split_goal_1 : exgcd_return_wit_4_split_goal_1. +Proof. + unfold exgcd_return_wit_4_split_goal_1; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_4_split_goal_2 : exgcd_return_wit_4_split_goal_2. +Proof. + unfold exgcd_return_wit_4_split_goal_2; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_4_split_goal_3 : exgcd_return_wit_4_split_goal_3. +Proof. + unfold exgcd_return_wit_4_split_goal_3; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_4 : exgcd_return_wit_4. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_return_wit_4_split_goal_1. + - Goal_apply proof_of_exgcd_return_wit_4_split_goal_2. + - Goal_apply proof_of_exgcd_return_wit_4_split_goal_3. +Qed. + +Lemma proof_of_exgcd_return_wit_5_split_goal_1 : exgcd_return_wit_5_split_goal_1. +Proof. + unfold exgcd_return_wit_5_split_goal_1; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_5_split_goal_2 : exgcd_return_wit_5_split_goal_2. +Proof. + unfold exgcd_return_wit_5_split_goal_2; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_5_split_goal_3 : exgcd_return_wit_5_split_goal_3. +Proof. + unfold exgcd_return_wit_5_split_goal_3; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_5 : exgcd_return_wit_5. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_return_wit_5_split_goal_1. + - Goal_apply proof_of_exgcd_return_wit_5_split_goal_2. + - Goal_apply proof_of_exgcd_return_wit_5_split_goal_3. +Qed. + +Lemma proof_of_exgcd_return_wit_6_split_goal_1 : exgcd_return_wit_6_split_goal_1. +Proof. + unfold exgcd_return_wit_6_split_goal_1; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_6_split_goal_2 : exgcd_return_wit_6_split_goal_2. +Proof. + unfold exgcd_return_wit_6_split_goal_2; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_6_split_goal_3 : exgcd_return_wit_6_split_goal_3. +Proof. + unfold exgcd_return_wit_6_split_goal_3; intros. + subst; rewrite ?Z.gcd_0_r; simpl; lia. +Qed. + +Lemma proof_of_exgcd_return_wit_6 : exgcd_return_wit_6. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_return_wit_6_split_goal_1. + - Goal_apply proof_of_exgcd_return_wit_6_split_goal_2. + - Goal_apply proof_of_exgcd_return_wit_6_split_goal_3. +Qed. + +Lemma proof_of_exgcd_partial_solve_wit_4_pure_split_goal_1 : exgcd_partial_solve_wit_4_pure_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + pose proof Z.rem_bound_abs a_pre b_pre PreH3. + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_partial_solve_wit_4_pure_split_goal_2 : exgcd_partial_solve_wit_4_pure_split_goal_2. +Proof. + LLM_pre_process ltac:(int_auto). + pose proof Z.rem_bound_abs a_pre b_pre PreH3. + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_exgcd_partial_solve_wit_4_pure : exgcd_partial_solve_wit_4_pure. +Proof. + aggressive_pre_process. + - Goal_apply proof_of_exgcd_partial_solve_wit_4_pure_split_goal_1. + - Goal_apply proof_of_exgcd_partial_solve_wit_4_pure_split_goal_2. +Qed. + +Lemma proof_of_exgcd_derive_Inter_by_Proof : exgcd_derive_Inter_by_Proof. +Proof. + LLM_pre_process ltac:(int_auto). + split_pure_spatial. + - cancel (x_pre # Int |->_). cancel (y_pre # Int |->_). + apply derivable1_wand_sepcon_adjoint. + eapply derivable1_trans. { apply derivable1_sepcon_comm. } + eapply derivable1_trans. { apply derivable1_sepcon_emp_l. } + repeat apply derivable1_orp_elim. + all: Intros y x r; Exists y x r. + all: split_pure_spatial; [cancel | split_pures; dump_pre_spatial; auto]. + - split_pures; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_abs_return_wit_1_split_goal_1 : abs_return_wit_1_split_goal_1. +Proof. + unfold abs_return_wit_1_split_goal_1; intros. + lia. +Qed. + +Lemma proof_of_abs_return_wit_1 : abs_return_wit_1. +Proof. + aggressive_pre_process. + Goal_apply proof_of_abs_return_wit_1_split_goal_1. +Qed. + +Lemma proof_of_abs_return_wit_2_split_goal_1 : abs_return_wit_2_split_goal_1. +Proof. + unfold abs_return_wit_2_split_goal_1; intros. + lia. +Qed. + +Lemma proof_of_abs_return_wit_2 : abs_return_wit_2. +Proof. + aggressive_pre_process. + Goal_apply proof_of_abs_return_wit_2_split_goal_1. +Qed. diff --git a/benchmarks/Algorithms/exgcd/rocq/groundtruth/proof_lib.v b/benchmarks/Algorithms/exgcd/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..e08b9d43b1677bda3dec65e9e43173a089a3e89c --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/groundtruth/proof_lib.v @@ -0,0 +1,181 @@ +(* Supporting lemmas for exgcd: Bezout-coefficient bounds across one Euclid step. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.micromega.Psatz. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +From SimpleC.SL Require Import Mem SeparationLogic. +Local Open Scope Z_scope. + +Lemma Zabs_triangle: forall a b, Zabs(a - b) <= Zabs a + Zabs b. +Proof. lia. Qed. + +Lemma Z_gcd_divide_l: forall a b, exists a', a = a' * (Zgcd a b). +Proof. + intros. + pose proof Z.gcd_divide_l a b. + unfold Z.divide in H. + exact H. +Qed. + +Lemma Z_gcd_divide_r: forall a b, exists b', b = b' * (Zgcd a b). +Proof. + intros. + pose proof Z.gcd_divide_r a b. + unfold Z.divide in H. + exact H. +Qed. + +Lemma Z_abs_quot_rem: + forall a b: Z, b <> 0 -> Zabs (a % (b)) + Zabs (a ÷ b) * Zabs b = Zabs a. +Proof. + intros. + assert(Zabs b <> 0) by lia. + pose proof Z.quot_rem (Zabs a) (Zabs b) H0. + rewrite <- Z.quot_abs. 2 : lia. + rewrite <- Z.rem_abs. 2 : lia. + lia. +Qed. + +Lemma Z_gcd_pos_l: + forall a b, a <> 0 -> Zgcd a b > 0. +Proof. + intros. + assert(Zgcd a b <> 0). { + intros. intro. + pose proof Z.gcd_eq_0_l a b. + lia. + } + pose proof Z.gcd_nonneg a b. + lia. +Qed. + +Lemma Z_gcd_pos_r: + forall a b, b <> 0 -> Zgcd a b > 0. +Proof. + intros. + assert(Zgcd a b <> 0). { + intros. intro. + pose proof Z.gcd_eq_0_r a b. + lia. + } + pose proof Z.gcd_nonneg a b. + lia. +Qed. + +(* Proof goal: + |x'| <= |(a % b) / g| + |y'| <= |b / g| + x = y' + y = x' - (a / b) * y' + ===> + |x| <= |b / g| + |y| <= |a / g| + + informal Proof: + |y| = |x' - (a / b) * y'| + <= |x'| + |a / b| * |y'| + <= |(a % b) / g| + |a / b| * |b / g| + = |(|a % b| + |a / b| * |b|) / g| (since g | (a % b) and g | b) + = |a / g| +*) + +Lemma exgcd_reduction_pre: + forall a b y, + b <> 0 -> + Zabs y <= Zabs b ÷ Zgcd b (a % (b)) -> + Zabs (a ÷ b * y) <= Zabs (a ÷ b) * (Zabs b ÷ Zgcd b (a % (b))). +Proof. + intros. + rewrite Z.abs_mul. nia. +Qed. + +Lemma exgcd_reduction': + forall a b x y, + b <> 0 -> + Zabs x <= Zabs (a % (b)) ÷ Zgcd b (a % (b)) -> + Zabs y <= Zabs b ÷ Zgcd b (a % (b)) -> + Zabs (x) + Zabs (a ÷ b * y) <= Zabs a ÷ Zgcd b (a % (b)). +Proof. + intros. + eapply Z.le_trans. 1: apply (Zplus_le_compat_r _ _ _ H0). + pose proof exgcd_reduction_pre a b y H H1. + eapply Z.le_trans. 1: apply (Zplus_le_compat_l _ _ _ H2). + replace (Zabs (a % (b)) ÷ Zgcd b (a % (b)) + + Zabs (a ÷ b) * (Zabs b ÷ Zgcd b (a % (b)))) + with (Zabs(((Zabs(a % (b))) + Zabs(a ÷ b) * Zabs(b)) ÷ Zgcd b (a % (b)))). + 2: { + replace (Zgcd b (a % (b))) with (Zgcd a b) in *. + 2: { rewrite Z.gcd_comm. rewrite <- Z.gcd_rem. rewrite Z.gcd_comm. lia. lia. } + pose proof Z_gcd_divide_l a b as H_adiv. + pose proof Z_gcd_divide_r a b as H_bdiv. + destruct H_adiv as [a' H_adiv]. + destruct H_bdiv as [b' H_bdiv]. + pose proof Z_gcd_pos_r a b H. + set (g := Zgcd a b) in *. + replace (a % (b)) with (a' % (b') * g). + 2: { rewrite H_adiv, H_bdiv. rewrite Zquot.Zmult_rem_distr_r. reflexivity. } + replace (a ÷ b) with (a' ÷ b'). + 2: { rewrite H_adiv, H_bdiv. rewrite Zquot.Zquot_mult_cancel_r; lia. } + replace (Zabs (a' ÷ b') * (Zabs b ÷ g)) with (Zabs (a' ÷ b') * Zabs b ÷ g). + 2: { rewrite Z.divide_quot_mul_exact; try lia. + unfold Z.divide. + exists (Z.abs b'). + rewrite H_bdiv. + replace g with (Zabs g) at 2 by lia. + apply Z.abs_mul. } + replace (Zabs ((Zabs (a' % (b') * g) + Zabs (a' ÷ b') * Zabs b) ÷ g)) + with ((Zabs (a' % (b') * g) + Zabs (a' ÷ b') * Zabs b) ÷ g). + 2: { + pose proof Z.abs_eq_iff ((Zabs (a' % (b') * g) + Zabs (a' ÷ b') * Zabs b) ÷ g) as H_abspos. + rewrite (proj2 H_abspos). 1 : reflexivity. + assert((Zabs (a' % (b') * g) + Zabs (a' ÷ b') * Zabs b) >= 0) by lia. + apply Z.quot_pos; lia. + } + replace (Zabs b) with (Zabs b' * g) by lia. + rewrite Z.mul_assoc. + rewrite Zquot.Z_quot_plus. + + rewrite Z.quot_mul; lia. + + lia. + + lia. + } + pose proof Z_gcd_pos_l b (a % (b)) H. + rewrite <- Z.quot_abs by ltac:(lia). + rewrite Z_abs_quot_rem by ltac:(lia). + rewrite Z.abs_idemp. + replace (Zabs (Zgcd b (a % (b)))) with (Zgcd b (a % (b))) by lia. + lia. +Qed. + +Lemma exgcd_reduction: + forall a b x y, + b <> 0 -> + Zabs x <= Zabs (a % (b)) ÷ Zgcd b (a % (b)) -> + Zabs y <= Zabs b ÷ Zgcd b (a % (b)) -> + Zabs (x - a ÷ b * y) <= Zabs a ÷ Zgcd b (a % (b)). +Proof. + intros. + eapply Z.le_trans. 1: apply Zabs_triangle. + apply (exgcd_reduction' _ _ _ _ H H0 H1). +Qed. + + +(* One Euclid step preserves the gcd. *) +Lemma exgcd_gcd_step: + forall a b, b <> 0 -> Zgcd b (a % (b)) = Zgcd a b. +Proof. + intros. + rewrite Z.gcd_comm, Z.gcd_rem by auto. + apply Z.gcd_comm. +Qed. + +(* When the remainder divides the divisor, it is the gcd up to sign. *) +Lemma exgcd_gcd_last_rem: + forall a b, b <> 0 -> a % (b) <> 0 -> b % (a % (b)) = 0 -> + Zgcd a b = Zabs (a % (b)). +Proof. + intros. + rewrite <- exgcd_gcd_step by auto. + rewrite Z.gcd_comm. + rewrite <- (Z.gcd_rem b (a % (b))) by auto. + rewrite H1. + apply Z.gcd_0_l. +Qed. diff --git a/benchmarks/Algorithms/exgcd/rocq/solution_annotated.c b/benchmarks/Algorithms/exgcd/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..c08fa8a47650df5333713a1da162001e9ea59d67 --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/solution_annotated.c @@ -0,0 +1,55 @@ +/*@ Extern Coq (Zgcd: Z -> Z -> Z) + (Zabs: Z -> Z) */ + +int abs(int x) +/*@ Require + INT_MIN < x && x <= INT_MAX && emp + Ensure + __return == Zabs(x) && emp +*/ +{ + if (x < 0) { + return -x; + } + return x; +} + +/* The public contract, derived from the stronger one the body is verified against. */ +int exgcd(int a, int b, int *x, int *y) +/*@ Inter <= Proof + Require + INT_MIN < a && a <= INT_MAX && INT_MIN < b && b <= INT_MAX && + has_int_permission(x) * has_int_permission(y) + Ensure + __return == Zgcd(a, b) && a * (*x) + b * (*y) == Zgcd(a, b) +*/ +; + +/* The coefficient bounds keep the recursive update free of overflow. */ +int exgcd(int a, int b, int *x, int *y) +/*@ Proof + Require + INT_MIN < a && a <= INT_MAX && INT_MIN < b && b <= INT_MAX && + has_int_permission(x) * has_int_permission(y) + Ensure + (__return == Zgcd(a, b) && a * (*x) + b * (*y) == Zgcd(a, b) && b == 0 && Zabs(*x) <= 1 && (*y) == 0) || + (__return == Zgcd(a, b) && a * (*x) + b * (*y) == Zgcd(a, b) && b != 0 && a % b == 0 && (*x) == 0 && Zabs(*y) <= 1) || + (__return == Zgcd(a, b) && a * (*x) + b * (*y) == Zgcd(a, b) && b != 0 && a % b != 0 && + Zabs(*x) <= Zabs(b) / Zgcd(a, b) && Zabs(*y) <= Zabs(a) / Zgcd(a, b)) +*/ +{ + if (b == 0) { + if (a < 0) { + *x = -1; + } else if (a == 0) { + *x = 0; + } else { + *x = 1; + } + *y = 0; + return abs(a); + } + int g = exgcd(b, a % b, y, x); + *y -= (a / b) * (*x); + return g; +} diff --git a/benchmarks/Algorithms/exgcd/rocq/solution_spec.c b/benchmarks/Algorithms/exgcd/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..92f6b54728fa616652f396dd4c59525abedd397a --- /dev/null +++ b/benchmarks/Algorithms/exgcd/rocq/solution_spec.c @@ -0,0 +1,33 @@ +/*@ Extern Coq (Zgcd: Z -> Z -> Z) */ + +int abs(int x) +{ + if (x < 0) { + return -x; + } + return x; +} + +int exgcd(int a, int b, int *x, int *y) +/*@ Require + INT_MIN < a && a <= INT_MAX && INT_MIN < b && b <= INT_MAX && + has_int_permission(x) * has_int_permission(y) + Ensure + __return == Zgcd(a, b) && a * (*x) + b * (*y) == Zgcd(a, b) +*/ +{ + if (b == 0) { + if (a < 0) { + *x = -1; + } else if (a == 0) { + *x = 0; + } else { + *x = 1; + } + *y = 0; + return abs(a); + } + int g = exgcd(b, a % b, y, x); + *y -= (a / b) * (*x); + return g; +} diff --git a/benchmarks/Algorithms/exgcd/solution.c b/benchmarks/Algorithms/exgcd/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..30ba752a6dc9a70655559ede7d0bb6876b337ed3 --- /dev/null +++ b/benchmarks/Algorithms/exgcd/solution.c @@ -0,0 +1,25 @@ +int abs(int x) +{ + if (x < 0) { + return -x; + } + return x; +} + +int exgcd(int a, int b, int *x, int *y) +{ + if (b == 0) { + if (a < 0) { + *x = -1; + } else if (a == 0) { + *x = 0; + } else { + *x = 1; + } + *y = 0; + return abs(a); + } + int g = exgcd(b, a % b, y, x); + *y -= (a / b) * (*x); + return g; +} diff --git a/benchmarks/Algorithms/gcd/manifest.json b/benchmarks/Algorithms/gcd/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..a661ecc1febbf3f90e98cc095ed8f78d5c53cf8a --- /dev/null +++ b/benchmarks/Algorithms/gcd/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "gcd", + "source": { + "dataset": "classical_algorithm", + "problem_id": "gcd", + "title": "Euclidean Greatest Common Divisor", + "tags": [ + "gcd", + "euclid", + "recursion" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "COUNTOPT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Algorithms/gcd/problem.md b/benchmarks/Algorithms/gcd/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..2c331f0adccff1fed8d9171c01e53c3b80a29486 --- /dev/null +++ b/benchmarks/Algorithms/gcd/problem.md @@ -0,0 +1,13 @@ +# Euclidean Greatest Common Divisor + +## Description + +Compute the greatest common divisor of two integers with the recursive Euclidean algorithm. + +## Input + +The function receives two integers $x$ and $y$ ($-2^{31} < x, y \le 2^{31} - 1$). + +## Output + +Return $\gcd(x, y)$, the non-negative greatest common divisor, with $\gcd(x, 0) = |x|$. diff --git a/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_goal.v b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..e02d38bde0dfe55bffe1bd52c6f473968940dc0c --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_goal.v @@ -0,0 +1,241 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Local Open Scope sac. + +(*----- Function abs -----*) + +Definition abs_safety_wit_1 := +forall (x_pre: Z) (PreH1 : (INT_MIN < x_pre)) (PreH2 : (x_pre <= INT_MAX)) , + ((( &( "x" ) )) # Int |-> x_pre) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition abs_safety_wit_2 := +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + ((( &( "x" ) )) # Int |-> x_pre) +|-- + “ (x_pre <> (INT_MIN)) ” +. + +Definition abs_return_wit_1 := +( +forall (x_pre: Z) (PreH1 : (x_pre >= 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ (x_pre = (Zabs (x_pre))) ” + && emp +) \/ +( +forall (x_pre: Z) (PreH1 : (x_pre >= 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ (x_pre = (Zabs (x_pre))) ” + && emp +). + +Definition abs_return_wit_1_split_goal_1 := +forall (x_pre: Z) (PreH1 : (x_pre >= 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + (x_pre = (Zabs (x_pre))) +. + +Definition abs_return_wit_2 := +( +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ ((-x_pre) = (Zabs (x_pre))) ” + && emp +) \/ +( +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + TT && emp +|-- + “ ((-x_pre) = (Zabs (x_pre))) ” + && emp +). + +Definition abs_return_wit_2_split_goal_1 := +forall (x_pre: Z) (PreH1 : (x_pre < 0)) (PreH2 : (INT_MIN < x_pre)) (PreH3 : (x_pre <= INT_MAX)) , + ((-x_pre) = (Zabs (x_pre))) +. + +(*----- Function gcd -----*) + +Definition gcd_safety_wit_1 := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (y_pre <= INT_MAX)) (PreH3 : (y_pre >= INT_MIN)) (PreH4 : (INT_MIN < x_pre)) (PreH5 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition gcd_safety_wit_2 := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (y_pre <> 0)) (PreH2 : (x_pre <= INT_MAX)) (PreH3 : (y_pre <= INT_MAX)) (PreH4 : (y_pre >= INT_MIN)) (PreH5 : (INT_MIN < x_pre)) (PreH6 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ ((x_pre <> (INT_MIN)) \/ (y_pre <> (-1))) ” + && “ (y_pre <> 0) ” +. + +Definition gcd_entail_wit_1 := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (INT_MIN < x_pre)) (PreH2 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ (x_pre <= INT_MAX) ” + && “ (y_pre <= INT_MAX) ” + && “ (y_pre >= INT_MIN) ” + && “ (INT_MIN < x_pre) ” + && “ (INT_MIN < y_pre) ” + && ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +. + +Definition gcd_return_wit_1 := +( +forall (y_pre: Z) (x_pre: Z) (retval: Z) (PreH1 : (retval = (Zgcd (y_pre) ((x_pre % ( y_pre ) ))))) (PreH2 : (y_pre <> 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + TT && emp +|-- + “ (retval = (Zgcd (x_pre) (y_pre))) ” + && emp +) \/ +( +forall (y_pre: Z) (x_pre: Z) (retval: Z) (PreH1 : (retval = (Zgcd (y_pre) ((x_pre % ( y_pre ) ))))) (PreH2 : (y_pre <> 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + TT && emp +|-- + “ (retval = (Zgcd (x_pre) (y_pre))) ” + && emp +). + +Definition gcd_return_wit_1_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (retval: Z) (PreH1 : (retval = (Zgcd (y_pre) ((x_pre % ( y_pre ) ))))) (PreH2 : (y_pre <> 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + (retval = (Zgcd (x_pre) (y_pre))) +. + +Definition gcd_return_wit_2 := +( +forall (y_pre: Z) (x_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (x_pre)))) (PreH2 : (y_pre = 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + TT && emp +|-- + “ (retval = (Zgcd (x_pre) (y_pre))) ” + && emp +) \/ +( +forall (y_pre: Z) (x_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (x_pre)))) (PreH2 : (y_pre = 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + TT && emp +|-- + “ (retval = (Zgcd (x_pre) (0))) ” + && emp +). + +Definition gcd_return_wit_2_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (retval: Z) (PreH1 : (retval = (Zabs (x_pre)))) (PreH2 : (y_pre = 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + (retval = (Zgcd (x_pre) (0))) +. + +Definition gcd_partial_solve_wit_1_pure := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (y_pre = 0)) (PreH2 : (x_pre <= INT_MAX)) (PreH3 : (y_pre <= INT_MAX)) (PreH4 : (y_pre >= INT_MIN)) (PreH5 : (INT_MIN < x_pre)) (PreH6 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ (INT_MIN < x_pre) ” + && “ (x_pre <= INT_MAX) ” +. + +Definition gcd_partial_solve_wit_1_aux := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (y_pre = 0)) (PreH2 : (x_pre <= INT_MAX)) (PreH3 : (y_pre <= INT_MAX)) (PreH4 : (y_pre >= INT_MIN)) (PreH5 : (INT_MIN < x_pre)) (PreH6 : (INT_MIN < y_pre)) , + TT && emp +|-- + “ (INT_MIN < x_pre) ” + && “ (x_pre <= INT_MAX) ” + && “ (y_pre = 0) ” + && “ (x_pre <= INT_MAX) ” + && “ (y_pre <= INT_MAX) ” + && “ (y_pre >= INT_MIN) ” + && “ (INT_MIN < x_pre) ” + && “ (INT_MIN < y_pre) ” + && emp +. + +Definition gcd_partial_solve_wit_1 := gcd_partial_solve_wit_1_pure -> gcd_partial_solve_wit_1_aux. + +Definition gcd_partial_solve_wit_2_pure := +( +forall (y_pre: Z) (x_pre: Z) (PreH1 : (y_pre <> 0)) (PreH2 : (x_pre <= INT_MAX)) (PreH3 : (y_pre <= INT_MAX)) (PreH4 : (y_pre >= INT_MIN)) (PreH5 : (INT_MIN < x_pre)) (PreH6 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ (INT_MIN < y_pre) ” + && “ (INT_MIN < (x_pre % ( y_pre ) )) ” +) \/ +( +forall (y_pre: Z) (x_pre: Z) (PreH1 : (x_pre >= INT_MIN)) (PreH2 : (y_pre <> 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ (INT_MIN < (x_pre % ( y_pre ) )) ” +). + +Definition gcd_partial_solve_wit_2_pure_split_goal_1 := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (x_pre >= INT_MIN)) (PreH2 : (y_pre <> 0)) (PreH3 : (x_pre <= INT_MAX)) (PreH4 : (y_pre <= INT_MAX)) (PreH5 : (y_pre >= INT_MIN)) (PreH6 : (INT_MIN < x_pre)) (PreH7 : (INT_MIN < y_pre)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "y" ) )) # Int |-> y_pre) +|-- + “ (INT_MIN < (x_pre % ( y_pre ) )) ” +. + +Definition gcd_partial_solve_wit_2_aux := +forall (y_pre: Z) (x_pre: Z) (PreH1 : (y_pre <> 0)) (PreH2 : (x_pre <= INT_MAX)) (PreH3 : (y_pre <= INT_MAX)) (PreH4 : (y_pre >= INT_MIN)) (PreH5 : (INT_MIN < x_pre)) (PreH6 : (INT_MIN < y_pre)) , + TT && emp +|-- + “ (INT_MIN < y_pre) ” + && “ (INT_MIN < (x_pre % ( y_pre ) )) ” + && “ (y_pre <> 0) ” + && “ (x_pre <= INT_MAX) ” + && “ (y_pre <= INT_MAX) ” + && “ (y_pre >= INT_MIN) ” + && “ (INT_MIN < x_pre) ” + && “ (INT_MIN < y_pre) ” + && emp +. + +Definition gcd_partial_solve_wit_2 := gcd_partial_solve_wit_2_pure -> gcd_partial_solve_wit_2_aux. + +Module Type VC_Correct. + + +Axiom proof_of_abs_safety_wit_1 : abs_safety_wit_1. +Axiom proof_of_abs_safety_wit_2 : abs_safety_wit_2. +Axiom proof_of_abs_return_wit_1 : abs_return_wit_1. +Axiom proof_of_abs_return_wit_2 : abs_return_wit_2. +Axiom proof_of_gcd_safety_wit_1 : gcd_safety_wit_1. +Axiom proof_of_gcd_safety_wit_2 : gcd_safety_wit_2. +Axiom proof_of_gcd_entail_wit_1 : gcd_entail_wit_1. +Axiom proof_of_gcd_return_wit_1 : gcd_return_wit_1. +Axiom proof_of_gcd_return_wit_2 : gcd_return_wit_2. +Axiom proof_of_gcd_partial_solve_wit_1_pure : gcd_partial_solve_wit_1_pure. +Axiom proof_of_gcd_partial_solve_wit_1 : gcd_partial_solve_wit_1. +Axiom proof_of_gcd_partial_solve_wit_2_pure : gcd_partial_solve_wit_2_pure. +Axiom proof_of_gcd_partial_solve_wit_2 : gcd_partial_solve_wit_2. + +End VC_Correct. diff --git a/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_goal_check.v b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..152066ad46fa5ffb1585a9b1704ba979e123bb18 --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_goal_check.v @@ -0,0 +1,6 @@ +From PVbench.Algorithms.gcd.rocq.groundtruth Require Import gcd_goal gcd_proof_auto gcd_proof_manual. + +Module VC_Correctness : VC_Correct. + Include gcd_proof_auto. + Include gcd_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_proof_auto.v b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..ff9ecdf7ed346cfcb233d2bdfd2d8b9e26870160 --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_proof_auto.v @@ -0,0 +1,45 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.gcd.rocq.groundtruth Require Import gcd_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Local Open Scope sac. + +Lemma proof_of_abs_safety_wit_1 : abs_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_abs_safety_wit_2 : abs_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_gcd_safety_wit_1 : gcd_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_gcd_safety_wit_2 : gcd_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_gcd_entail_wit_1 : gcd_entail_wit_1. +Proof. Admitted. + +Lemma proof_of_gcd_partial_solve_wit_1_pure : gcd_partial_solve_wit_1_pure. +Proof. Admitted. + +Lemma proof_of_gcd_partial_solve_wit_1 : gcd_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_gcd_partial_solve_wit_2 : gcd_partial_solve_wit_2. +Proof. Admitted. + diff --git a/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_proof_manual.v b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..fefee469eb48540146b33b2eb60b7901c133819f --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/groundtruth/gcd_proof_manual.v @@ -0,0 +1,95 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.gcd.rocq.groundtruth Require Import gcd_goal. +From PVbench.Algorithms.gcd.rocq.groundtruth Require Import gcd_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Algorithms.gcd.rocq.groundtruth.proof_lib. +Local Open Scope sac. + +Lemma proof_of_gcd_return_wit_1_split_goal_1 : gcd_return_wit_1_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + subst. + pose proof Z.gcd_rem x_pre y_pre ltac:(lia). + rewrite Z.gcd_comm, H, Z.gcd_comm. + reflexivity. +Qed. + +Lemma proof_of_gcd_return_wit_1 : gcd_return_wit_1. +Proof. + aggressive_pre_process. + Goal_apply proof_of_gcd_return_wit_1_split_goal_1. +Qed. + +Lemma proof_of_gcd_return_wit_2_split_goal_1 : gcd_return_wit_2_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + subst. + rewrite Z.gcd_0_r. + reflexivity. +Qed. + +Lemma proof_of_gcd_return_wit_2 : gcd_return_wit_2. +Proof. + aggressive_pre_process. + Goal_apply proof_of_gcd_return_wit_2_split_goal_1. +Qed. + +Lemma proof_of_gcd_partial_solve_wit_2_pure_split_goal_1 : gcd_partial_solve_wit_2_pure_split_goal_1. +Proof. + LLM_pre_process ltac:(int_auto). + prop_apply (store_int_range (&("y")) y_pre). + Intros. + change (Int.min_signed) with (-2147483648) in H. + change (Int.max_signed) with (2147483647) in H. + pose proof Z.rem_bound_pos_pos x_pre y_pre. + pose proof Z.rem_bound_neg_pos x_pre y_pre. + pose proof Z.rem_bound_pos_neg x_pre y_pre. + pose proof Z.rem_bound_neg_neg x_pre y_pre. + repeat (split_pure_spatial || split_pures); try cancel; dump_pre_spatial; lia. +Qed. + +Lemma proof_of_gcd_partial_solve_wit_2_pure : gcd_partial_solve_wit_2_pure. +Proof. + aggressive_pre_process. + Goal_apply proof_of_gcd_partial_solve_wit_2_pure_split_goal_1. +Qed. + +Lemma proof_of_abs_return_wit_1_split_goal_1 : abs_return_wit_1_split_goal_1. +Proof. + unfold abs_return_wit_1_split_goal_1; intros. + lia. +Qed. + +Lemma proof_of_abs_return_wit_1 : abs_return_wit_1. +Proof. + aggressive_pre_process. + Goal_apply proof_of_abs_return_wit_1_split_goal_1. +Qed. + +Lemma proof_of_abs_return_wit_2_split_goal_1 : abs_return_wit_2_split_goal_1. +Proof. + unfold abs_return_wit_2_split_goal_1; intros. + lia. +Qed. + +Lemma proof_of_abs_return_wit_2 : abs_return_wit_2. +Proof. + aggressive_pre_process. + Goal_apply proof_of_abs_return_wit_2_split_goal_1. +Qed. diff --git a/benchmarks/Algorithms/gcd/rocq/groundtruth/proof_lib.v b/benchmarks/Algorithms/gcd/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..55420951efc50cd94d4881c62009b693db873376 --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/groundtruth/proof_lib.v @@ -0,0 +1,2 @@ +(* gcd needs no supporting lemmas: Coq's Z.gcd library closes every goal. *) +From Coq Require Import ZArith. diff --git a/benchmarks/Algorithms/gcd/rocq/solution_annotated.c b/benchmarks/Algorithms/gcd/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..7bccbc268e679124e2f5894a198ed2d6216be637 --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/solution_annotated.c @@ -0,0 +1,32 @@ +/*@ Extern Coq (Zgcd: Z -> Z -> Z) + (Zabs: Z -> Z) */ + +int abs(int x) +/*@ Require + INT_MIN < x && x <= INT_MAX && emp + Ensure + __return == Zabs(x) && emp +*/ +{ + if (x < 0) { + return -x; + } + return x; +} + +int gcd(int x, int y) +/*@ Require + INT_MIN < x && INT_MIN < y + Ensure + __return == Zgcd(x, y) +*/ +{ + /*@ x <= INT_MAX by local */ + if (y == 0) + { + return abs(x); + } + else { + return gcd(y, x % y); + } +} diff --git a/benchmarks/Algorithms/gcd/rocq/solution_spec.c b/benchmarks/Algorithms/gcd/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..9a1443e8f1607d41512940f1a717154682d54c2b --- /dev/null +++ b/benchmarks/Algorithms/gcd/rocq/solution_spec.c @@ -0,0 +1,25 @@ +/*@ Extern Coq (Zgcd: Z -> Z -> Z) */ + +int abs(int x) +{ + if (x < 0) { + return -x; + } + return x; +} + +int gcd(int x, int y) +/*@ Require + INT_MIN < x && INT_MIN < y + Ensure + __return == Zgcd(x, y) +*/ +{ + if (y == 0) + { + return abs(x); + } + else { + return gcd(y, x % y); + } +} diff --git a/benchmarks/Algorithms/gcd/solution.c b/benchmarks/Algorithms/gcd/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..8388738e58f3ea2064d408039dd2c518ad9f4647 --- /dev/null +++ b/benchmarks/Algorithms/gcd/solution.c @@ -0,0 +1,18 @@ +int abs(int x) +{ + if (x < 0) { + return -x; + } + return x; +} + +int gcd(int x, int y) +{ + if (y == 0) + { + return abs(x); + } + else { + return gcd(y, x % y); + } +} diff --git a/benchmarks/Algorithms/sll_insertion_sort/manifest.json b/benchmarks/Algorithms/sll_insertion_sort/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..00724fc412b905a1e24146dad40d2eff85b6054b --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "sll_insertion_sort", + "source": { + "dataset": "classical_algorithm", + "problem_id": "sll_insertion_sort", + "title": "Insertion Sort on a Singly Linked List", + "tags": [ + "sort", + "insertion", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Algorithms/sll_insertion_sort/problem.md b/benchmarks/Algorithms/sll_insertion_sort/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..ad6da7fc701bd8adeb32563810c28296da7a6ea1 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/problem.md @@ -0,0 +1,22 @@ +# Insertion Sort on a Singly Linked List + +## Description + +Sort a null-terminated singly linked list of integers into nondecreasing order using insertion sort, relinking the existing nodes. + +## Input + +A list is given by a pointer to its first node, or `NULL` when empty: + +```c +struct list { + int data; + struct list *next; +}; +``` + +The function receives the head `x` of the list. + +## Output + +Return the head of a list holding the same values in nondecreasing order. diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/proof_lib.v b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..47addf8b2de4ff4cc6405a4c22b33e407bc21431 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/proof_lib.v @@ -0,0 +1,105 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Algorithms.sll_insertion_sort.rocq.helper_lib. +Local Open Scope sac. +Import ListNotations. +Local Open Scope list. + +Lemma upperbound_insert_nil: + forall x l, + strict_upperbound x l -> + insert x l = l ++ [x]. +Proof. + intros. + induction l; simpl; try easy. + simpl in H. destruct H. + destruct (x >? a) eqn:b; simpl; try lia. + apply IHl in H0. rewrite H0. reflexivity. +Qed. + +Lemma upperbound_insert_cons: + forall x l1 l2 y, + strict_upperbound x l1 -> + x <= y -> + insert x (l1 ++ y :: l2) = l1 ++ x :: y :: l2. +Proof. + intros. + induction l1; simpl; try easy; simpl in H. + - destruct (x >? y) eqn:b; simpl; [lia | easy]. + - destruct H. destruct (x >? a) eqn:b; simpl; try lia. + apply IHl1 in H1. rewrite H1. reflexivity. +Qed. + +Lemma increasing_aux_insert: + forall x l a, + increasing_aux l a -> + a <= x -> + increasing_aux (insert x l) a. +Proof. + intros. revert a H H0. + induction l; intros; simpl; try easy. + simpl in H. + destruct (x >? a) eqn:b; simpl. + - split; try easy. + apply IHl; [easy | lia]. + - repeat split; try easy. lia. +Qed. + +Lemma increasing_insert: + forall x l, + increasing l -> + increasing (insert x l). +Proof. + intros. destruct l; simpl; try easy. + simpl in H. + destruct (x >? z) eqn:b; simpl. + - apply increasing_aux_insert; [easy | lia]. + - split; [lia | easy]. +Qed. + +Lemma perm_insert: + forall x l, + Permutation (l ++ [x]) (insert x l). +Proof. + intros. induction l; simpl; try easy. + destruct (x >? a). + - rewrite IHl. reflexivity. + - rewrite <- Permutation_cons_append. apply perm_swap. +Qed. + + +Lemma upperbound_insert_app: + forall x l1 l2, + strict_upperbound x l1 -> + insert x (l1 ++ l2) = l1 ++ insert x l2. +Proof. + intros x l1 l2 Hupper. + revert l2 Hupper. + induction l1; intros l2 Hupper. + - reflexivity. + - simpl in Hupper. + destruct Hupper. + simpl. + destruct (x >? a) eqn:Hgt. + + f_equal. + apply IHl1. + exact H0. + + lia. +Qed. diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_goal.v b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..017d383e345823d8b56331d9d142ef24253c4ebf --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_goal.v @@ -0,0 +1,506 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Algorithms.sll_insertion_sort.rocq.helper_lib. +Local Open Scope sac. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_proof. + +(*----- Function insertion -----*) + +Definition insertion_safety_wit_1 := +forall (node_pre: Z) (p_pre: Z) (a: Z) (l: (@list Z)) (p2_v: Z) (p2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (node_pre <> 0)) (PreH2 : (l = (app (l1) (l2)))) (PreH3 : (strict_upperbound a l1 )) , + ((( &( "node" ) )) # Ptr |-> node_pre) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((( &( "p2" ) )) # Ptr |-> p2) + ** (sllbseg ( &( "res" ) ) p2 l1 ) + ** ((p2) # Ptr |-> p2_v) + ** (sll p2_v l2 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition insertion_entail_wit_1 := +( +forall (node_pre: Z) (p_pre: Z) (a: Z) (l: (@list Z)) (PreH1 : (node_pre <> 0)) , + ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sll p_pre l ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) (l2))) ” + && “ (strict_upperbound a l1 ) ” + && ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) ( &( "res" ) ) l1 ) + ** (sll p_pre l2 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +) \/ +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (PreH1 : (node_pre <> 0)) , + TT && emp +|-- + EX (l1: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) (l))) ” + && “ (strict_upperbound a l1 ) ” + && (sllbseg ( &( "res" ) ) ( &( "res" ) ) l1 ) +). + +Definition insertion_entail_wit_2 := +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (p2_v_2: Z) (p2: Z) (l1_2: (@list Z)) (l2_2: (@list Z)) (x: Z) (l0: (@list Z)) (y: Z) (PreH1 : (x < a)) (PreH2 : (l2_2 = (cons (x) (l0)))) (PreH3 : (p2_v_2 <> 0)) (PreH4 : (node_pre <> 0)) (PreH5 : (l = (app (l1_2) (l2_2)))) (PreH6 : (strict_upperbound a l1_2 )) , + ((&((p2_v_2) # "list" ->ₛ "data")) # Int |-> x) + ** (sll y l0 ) + ** ((&((p2_v_2) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_2 ) + ** ((p2) # Ptr |-> p2_v_2) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +|-- + EX (p2_v: Z) (l1: (@list Z)) (l2: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) (l2))) ” + && “ (strict_upperbound a l1 ) ” + && ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) &((p2_v_2) # "list" ->ₛ "next") l1 ) + ** ((&((p2_v_2) # "list" ->ₛ "next")) # Ptr |-> p2_v) + ** (sll p2_v l2 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +) \/ +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (p2_v_2: Z) (p2: Z) (l1_2: (@list Z)) (l2_2: (@list Z)) (x: Z) (l0: (@list Z)) (PreH1 : (x <= INT_MAX)) (PreH2 : (x >= INT_MIN)) (PreH3 : (x < a)) (PreH4 : (l2_2 = (cons (x) (l0)))) (PreH5 : (p2_v_2 <> 0)) (PreH6 : (node_pre <> 0)) (PreH7 : (l = (app (l1_2) (l2_2)))) (PreH8 : (strict_upperbound a l1_2 )) , + ((&((p2_v_2) # "list" ->ₛ "data")) # Int |-> x) + ** (sllbseg ( &( "res" ) ) p2 l1_2 ) + ** ((p2) # Ptr |-> p2_v_2) +|-- + EX (l1: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) (l0))) ” + && “ (strict_upperbound a l1 ) ” + && (sllbseg ( &( "res" ) ) &((p2_v_2) # "list" ->ₛ "next") l1 ) +). + +Definition insertion_entail_wit_3_1 := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (p2_v: Z) (p2: Z) (l1_3: (@list Z)) (l2: (@list Z)) (PreH1 : (p2_v = 0)) (PreH2 : (node_pre <> 0)) (PreH3 : (l = (app (l1_3) (l2)))) (PreH4 : (strict_upperbound a l1_3 )) , + ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_3 ) + ** ((p2) # Ptr |-> p2_v) + ** (sll p2_v l2 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +|-- + (EX (l1: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) ((@nil Z)))) ” + && “ (strict_upperbound a l1 ) ” + && ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1 ) + ** ((p2) # Ptr |-> 0) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_)) + || + (EX (unext: Z) (l1_2: (@list Z)) (l0: (@list Z)) (x: Z) (u: Z) , + “ (node_pre <> 0) ” + && “ (u <> 0) ” + && “ (x >= a) ” + && “ (l = (app (l1_2) ((cons (x) (l0))))) ” + && “ (strict_upperbound a l1_2 ) ” + && ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_2 ) + ** ((p2) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_)) +. + +Definition insertion_entail_wit_3_2 := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (p2_v: Z) (p2: Z) (l1_3: (@list Z)) (l2: (@list Z)) (x_2: Z) (l0_2: (@list Z)) (y: Z) (PreH1 : (x_2 >= a)) (PreH2 : (l2 = (cons (x_2) (l0_2)))) (PreH3 : (p2_v <> 0)) (PreH4 : (node_pre <> 0)) (PreH5 : (l = (app (l1_3) (l2)))) (PreH6 : (strict_upperbound a l1_3 )) , + ((&((p2_v) # "list" ->ₛ "data")) # Int |-> x_2) + ** (sll y l0_2 ) + ** ((&((p2_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_3 ) + ** ((p2) # Ptr |-> p2_v) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +|-- + (EX (l1: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) ((@nil Z)))) ” + && “ (strict_upperbound a l1 ) ” + && ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1 ) + ** ((p2) # Ptr |-> 0) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_)) + || + (EX (unext: Z) (l1_2: (@list Z)) (l0: (@list Z)) (x: Z) (u: Z) , + “ (node_pre <> 0) ” + && “ (u <> 0) ” + && “ (x >= a) ” + && “ (l = (app (l1_2) ((cons (x) (l0))))) ” + && “ (strict_upperbound a l1_2 ) ” + && ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_2 ) + ** ((p2) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_)) +. + +Definition insertion_entail_wit_4_1 := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (l1_3: (@list Z)) (p2: Z) (PreH1 : (node_pre <> 0)) (PreH2 : (l = (app (l1_3) ((@nil Z))))) (PreH3 : (strict_upperbound a l1_3 )) , + ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_3 ) + ** ((p2) # Ptr |-> node_pre) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0) +|-- + (EX (resv: Z) (l1: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) ((@nil Z)))) ” + && “ (strict_upperbound a l1 ) ” + && ((( &( "res" ) )) # Ptr |-> resv) + ** (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0)) + || + (EX (unext: Z) (resv_2: Z) (l1_2: (@list Z)) (l0: (@list Z)) (x: Z) (u: Z) , + “ (node_pre <> 0) ” + && “ (u <> 0) ” + && “ (x >= a) ” + && “ (l = (app (l1_2) ((cons (x) (l0))))) ” + && “ (strict_upperbound a l1_2 ) ” + && ((( &( "res" ) )) # Ptr |-> resv_2) + ** (sllseg resv_2 node_pre l1_2 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0 )) +. + +Definition insertion_entail_wit_4_2 := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (l1_3: (@list Z)) (x_2: Z) (l0_2: (@list Z)) (u_2: Z) (unext_2: Z) (p2: Z) (PreH1 : (node_pre <> 0)) (PreH2 : (u_2 <> 0)) (PreH3 : (x_2 >= a)) (PreH4 : (l = (app (l1_3) ((cons (x_2) (l0_2)))))) (PreH5 : (strict_upperbound a l1_3 )) , + ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1_3 ) + ** ((p2) # Ptr |-> node_pre) + ** ((&((u_2) # "list" ->ₛ "data")) # Int |-> x_2) + ** ((&((u_2) # "list" ->ₛ "next")) # Ptr |-> unext_2) + ** (sll unext_2 l0_2 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u_2) +|-- + (EX (resv: Z) (l1: (@list Z)) , + “ (node_pre <> 0) ” + && “ (l = (app (l1) ((@nil Z)))) ” + && “ (strict_upperbound a l1 ) ” + && ((( &( "res" ) )) # Ptr |-> resv) + ** (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0)) + || + (EX (unext: Z) (resv_2: Z) (l1_2: (@list Z)) (l0: (@list Z)) (x: Z) (u: Z) , + “ (node_pre <> 0) ” + && “ (u <> 0) ” + && “ (x >= a) ” + && “ (l = (app (l1_2) ((cons (x) (l0))))) ” + && “ (strict_upperbound a l1_2 ) ” + && ((( &( "res" ) )) # Ptr |-> resv_2) + ** (sllseg resv_2 node_pre l1_2 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0 )) +. + +Definition insertion_return_wit_1 := +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (resv: Z) (l1: (@list Z)) (PreH1 : (node_pre <> 0)) (PreH2 : (l = (app (l1) ((@nil Z))))) (PreH3 : (strict_upperbound a l1 )) , + (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0) +|-- + EX (l0: (@list Z)) , + “ (l0 = (insert (a) (l))) ” + && (sll resv l0 ) +) \/ +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (resv: Z) (l1: (@list Z)) (PreH1 : (a <= INT_MAX)) (PreH2 : (a >= INT_MIN)) (PreH3 : (node_pre <> 0)) (PreH4 : (l = (app (l1) ((@nil Z))))) (PreH5 : (strict_upperbound a l1 )) , + (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0) +|-- + (sll resv (insert (a) (l)) ) +). + +Definition insertion_return_wit_1_split_goal_spatial := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (resv: Z) (l1: (@list Z)) (PreH1 : (a <= INT_MAX)) (PreH2 : (a >= INT_MIN)) (PreH3 : (node_pre <> 0)) (PreH4 : (l = (app (l1) ((@nil Z))))) (PreH5 : (strict_upperbound a l1 )) , + (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0) +|-- + (sll resv (insert (a) (l)) ) +. + +Definition insertion_return_wit_2 := +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (resv: Z) (l1: (@list Z)) (x: Z) (l0_2: (@list Z)) (u: Z) (unext: Z) (PreH1 : (node_pre <> 0)) (PreH2 : (u <> 0)) (PreH3 : (x >= a)) (PreH4 : (l = (app (l1) ((cons (x) (l0_2)))))) (PreH5 : (strict_upperbound a l1 )) , + (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0_2 ) +|-- + EX (l0: (@list Z)) , + “ (l0 = (insert (a) (l))) ” + && (sll resv l0 ) +) \/ +( +forall (node_pre: Z) (a: Z) (l: (@list Z)) (resv: Z) (l1: (@list Z)) (x: Z) (l0_2: (@list Z)) (u: Z) (unext: Z) (PreH1 : (x <= INT_MAX)) (PreH2 : (a <= INT_MAX)) (PreH3 : (x >= INT_MIN)) (PreH4 : (a >= INT_MIN)) (PreH5 : (node_pre <> 0)) (PreH6 : (u <> 0)) (PreH7 : (x >= a)) (PreH8 : (l = (app (l1) ((cons (x) (l0_2)))))) (PreH9 : (strict_upperbound a l1 )) , + (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0_2 ) +|-- + (sll resv (insert (a) (l)) ) +). + +Definition insertion_return_wit_2_split_goal_spatial := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (resv: Z) (l1: (@list Z)) (x: Z) (l0_2: (@list Z)) (u: Z) (unext: Z) (PreH1 : (x <= INT_MAX)) (PreH2 : (a <= INT_MAX)) (PreH3 : (x >= INT_MIN)) (PreH4 : (a >= INT_MIN)) (PreH5 : (node_pre <> 0)) (PreH6 : (u <> 0)) (PreH7 : (x >= a)) (PreH8 : (l = (app (l1) ((cons (x) (l0_2)))))) (PreH9 : (strict_upperbound a l1 )) , + (sllseg resv node_pre l1 ) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l0_2 ) +|-- + (sll resv (insert (a) (l)) ) +. + +Definition insertion_partial_solve_wit_1 := +forall (node_pre: Z) (a: Z) (l: (@list Z)) (p2_v: Z) (p2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (p2_v <> 0)) (PreH2 : (node_pre <> 0)) (PreH3 : (l = (app (l1) (l2)))) (PreH4 : (strict_upperbound a l1 )) , + ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1 ) + ** ((p2) # Ptr |-> p2_v) + ** (sll p2_v l2 ) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +|-- + EX (x: Z) (l0: (@list Z)) (y: Z) , + “ (l2 = (cons (x) (l0))) ” + && “ (p2_v <> 0) ” + && “ (node_pre <> 0) ” + && “ (l = (app (l1) (l2))) ” + && “ (strict_upperbound a l1 ) ” + && ((&((p2_v) # "list" ->ₛ "data")) # Int |-> x) + ** (sll y l0 ) + ** ((&((p2_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a) + ** (sllbseg ( &( "res" ) ) p2 l1 ) + ** ((p2) # Ptr |-> p2_v) + ** ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_) +. + +(*----- Function insertion_sort -----*) + +Definition insertion_sort_safety_wit_1 := +forall (x_pre: Z) (l: (@list Z)) , + ((( &( "res" ) )) # Ptr |->_) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** (sll x_pre l ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition insertion_sort_safety_wit_2 := +forall (x_pre: Z) (l: (@list Z)) (p: Z) (res: Z) (l0: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : (Permutation l1 l0 )) (PreH3 : (increasing l0 )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "q" ) )) # Ptr |->_) + ** ((( &( "res" ) )) # Ptr |-> res) + ** (sll res l0 ) + ** ((( &( "p" ) )) # Ptr |-> p) + ** (sll p l2 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition insertion_sort_entail_wit_1 := +( +forall (x_pre: Z) (l: (@list Z)) , + (sll x_pre l ) +|-- + EX (l0: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) (l2))) ” + && “ (Permutation l1 l0 ) ” + && “ (increasing l0 ) ” + && (sll 0 l0 ) + ** (sll x_pre l2 ) +) \/ +( +forall (l: (@list Z)) , + TT && emp +|-- + EX (l1: (@list Z)) , + “ (l = (app (l1) (l))) ” + && “ (Permutation l1 (@nil Z) ) ” + && “ (increasing (@nil Z) ) ” + && emp +). + +Definition insertion_sort_entail_wit_2 := +( +forall (l: (@list Z)) (p: Z) (l0_2: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (x: Z) (l0_3: (@list Z)) (y: Z) (l0_4: (@list Z)) (retval: Z) (PreH1 : (l0_4 = (insert (x) (l0_2)))) (PreH2 : (l2_2 = (cons (x) (l0_3)))) (PreH3 : (p <> 0)) (PreH4 : (l = (app (l1_2) (l2_2)))) (PreH5 : (Permutation l1_2 l0_2 )) (PreH6 : (increasing l0_2 )) , + (sll retval l0_4 ) + ** (sll y l0_3 ) + ** ((( &( "q" ) )) # Ptr |-> y) +|-- + EX (l0: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) (l2))) ” + && “ (Permutation l1 l0 ) ” + && “ (increasing l0 ) ” + && ((( &( "q" ) )) # Ptr |->_) + ** (sll retval l0 ) + ** (sll y l2 ) +) \/ +( +forall (l: (@list Z)) (p: Z) (l0_2: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (x: Z) (l0_3: (@list Z)) (l0_4: (@list Z)) (PreH1 : (l0_4 = (insert (x) (l0_2)))) (PreH2 : (l2_2 = (cons (x) (l0_3)))) (PreH3 : (p <> 0)) (PreH4 : (l = (app (l1_2) (l2_2)))) (PreH5 : (Permutation l1_2 l0_2 )) (PreH6 : (increasing l0_2 )) , + TT && emp +|-- + EX (l1: (@list Z)) , + “ ((app (l1_2) (l2_2)) = (app (l1) (l0_3))) ” + && “ (Permutation l1 (insert (x) (l0_2)) ) ” + && “ (increasing (insert (x) (l0_2)) ) ” + && emp +). + +Definition insertion_sort_return_wit_1 := +( +forall (l: (@list Z)) (p: Z) (res: Z) (l0_2: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (p = 0)) (PreH2 : (l = (app (l1) (l2)))) (PreH3 : (Permutation l1 l0_2 )) (PreH4 : (increasing l0_2 )) , + (sll res l0_2 ) + ** (sll p l2 ) +|-- + EX (l0: (@list Z)) , + “ (Permutation l l0 ) ” + && “ (increasing l0 ) ” + && (sll res l0 ) +) \/ +( +forall (l: (@list Z)) (p: Z) (l0_2: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (p = 0)) (PreH2 : (l = (app (l1) (l2)))) (PreH3 : (Permutation l1 l0_2 )) (PreH4 : (increasing l0_2 )) , + (sll p l2 ) +|-- + “ (Permutation l l0_2 ) ” + && emp +). + +Definition insertion_sort_return_wit_1_split_goal_1 := +forall (l: (@list Z)) (p: Z) (l0_2: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (p = 0)) (PreH2 : (l = (app (l1) (l2)))) (PreH3 : (Permutation l1 l0_2 )) (PreH4 : (increasing l0_2 )) , + (sll p l2 ) +|-- + “ (Permutation l l0_2 ) ” +. + +Definition insertion_sort_return_wit_1_split_goal_spatial := +forall (l: (@list Z)) (p: Z) (l0_2: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (p = 0)) (PreH2 : (l = (app (l1) (l2)))) (PreH3 : (Permutation l1 l0_2 )) (PreH4 : (increasing l0_2 )) , + (sll p l2 ) +|-- + TT && emp +. + +Definition insertion_sort_partial_solve_wit_1 := +forall (l: (@list Z)) (p: Z) (res: Z) (l0: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (p <> 0)) (PreH2 : (l = (app (l1) (l2)))) (PreH3 : (Permutation l1 l0 )) (PreH4 : (increasing l0 )) , + (sll res l0 ) + ** (sll p l2 ) +|-- + EX (x: Z) (l0_2: (@list Z)) (y: Z) , + “ (l2 = (cons (x) (l0_2))) ” + && “ (p <> 0) ” + && “ (l = (app (l1) (l2))) ” + && “ (Permutation l1 l0 ) ” + && “ (increasing l0 ) ” + && ((&((p) # "list" ->ₛ "next")) # Ptr |-> y) + ** (sll y l0_2 ) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x) + ** (sll res l0 ) +. + +Definition insertion_sort_partial_solve_wit_2_pure := +forall (x_pre: Z) (l: (@list Z)) (p: Z) (res: Z) (l0: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (x: Z) (l0_2: (@list Z)) (y: Z) (PreH1 : (l2 = (cons (x) (l0_2)))) (PreH2 : (p <> 0)) (PreH3 : (l = (app (l1) (l2)))) (PreH4 : (Permutation l1 l0 )) (PreH5 : (increasing l0 )) , + ((&((p) # "list" ->ₛ "next")) # Ptr |-> y) + ** (sll y l0_2 ) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "q" ) )) # Ptr |-> y) + ** ((( &( "res" ) )) # Ptr |-> res) + ** (sll res l0 ) + ** ((( &( "p" ) )) # Ptr |-> p) +|-- + “ (p <> 0) ” +. + +Definition insertion_sort_partial_solve_wit_2_aux := +forall (l: (@list Z)) (p: Z) (res: Z) (l0: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (x: Z) (l0_2: (@list Z)) (y: Z) (PreH1 : (l2 = (cons (x) (l0_2)))) (PreH2 : (p <> 0)) (PreH3 : (l = (app (l1) (l2)))) (PreH4 : (Permutation l1 l0 )) (PreH5 : (increasing l0 )) , + ((&((p) # "list" ->ₛ "next")) # Ptr |-> y) + ** (sll y l0_2 ) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x) + ** (sll res l0 ) +|-- + “ (p <> 0) ” + && “ (l2 = (cons (x) (l0_2))) ” + && “ (p <> 0) ” + && “ (l = (app (l1) (l2))) ” + && “ (Permutation l1 l0 ) ” + && “ (increasing l0 ) ” + && ((&((p) # "list" ->ₛ "data")) # Int |-> x) + ** (sll res l0 ) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |->_) + ** (sll y l0_2 ) +. + +Definition insertion_sort_partial_solve_wit_2 := insertion_sort_partial_solve_wit_2_pure -> insertion_sort_partial_solve_wit_2_aux. + +Module Type VC_Correct. + +Include sll_Strategy_Correct. + +Axiom proof_of_insertion_safety_wit_1 : insertion_safety_wit_1. +Axiom proof_of_insertion_entail_wit_1 : insertion_entail_wit_1. +Axiom proof_of_insertion_entail_wit_2 : insertion_entail_wit_2. +Axiom proof_of_insertion_entail_wit_3_1 : insertion_entail_wit_3_1. +Axiom proof_of_insertion_entail_wit_3_2 : insertion_entail_wit_3_2. +Axiom proof_of_insertion_entail_wit_4_1 : insertion_entail_wit_4_1. +Axiom proof_of_insertion_entail_wit_4_2 : insertion_entail_wit_4_2. +Axiom proof_of_insertion_return_wit_1 : insertion_return_wit_1. +Axiom proof_of_insertion_return_wit_2 : insertion_return_wit_2. +Axiom proof_of_insertion_partial_solve_wit_1 : insertion_partial_solve_wit_1. +Axiom proof_of_insertion_sort_safety_wit_1 : insertion_sort_safety_wit_1. +Axiom proof_of_insertion_sort_safety_wit_2 : insertion_sort_safety_wit_2. +Axiom proof_of_insertion_sort_entail_wit_1 : insertion_sort_entail_wit_1. +Axiom proof_of_insertion_sort_entail_wit_2 : insertion_sort_entail_wit_2. +Axiom proof_of_insertion_sort_return_wit_1 : insertion_sort_return_wit_1. +Axiom proof_of_insertion_sort_partial_solve_wit_1 : insertion_sort_partial_solve_wit_1. +Axiom proof_of_insertion_sort_partial_solve_wit_2_pure : insertion_sort_partial_solve_wit_2_pure. +Axiom proof_of_insertion_sort_partial_solve_wit_2 : insertion_sort_partial_solve_wit_2. + +End VC_Correct. diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_goal_check.v b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..80aa66af5570d63ae9a91ed8a412fc032e5f7135 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_goal_check.v @@ -0,0 +1,7 @@ +From PVbench.Algorithms.sll_insertion_sort.rocq.groundtruth Require Import sll_insertion_sort_goal sll_insertion_sort_proof_auto sll_insertion_sort_proof_manual. + +Module VC_Correctness : VC_Correct. + Include sll_strategy_proof. + Include sll_insertion_sort_proof_auto. + Include sll_insertion_sort_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_proof_auto.v b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..1db54d659fc0308eb6970bbebf89c62d6c5a1809 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_proof_auto.v @@ -0,0 +1,47 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.sll_insertion_sort.rocq.groundtruth Require Import sll_insertion_sort_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Algorithms.sll_insertion_sort.rocq.helper_lib. +Local Open Scope sac. + +Lemma proof_of_insertion_safety_wit_1 : insertion_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_insertion_entail_wit_3_2 : insertion_entail_wit_3_2. +Proof. Admitted. + +Lemma proof_of_insertion_partial_solve_wit_1 : insertion_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_insertion_sort_safety_wit_1 : insertion_sort_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_insertion_sort_safety_wit_2 : insertion_sort_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_insertion_sort_partial_solve_wit_1 : insertion_sort_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_insertion_sort_partial_solve_wit_2_pure : insertion_sort_partial_solve_wit_2_pure. +Proof. Admitted. + +Lemma proof_of_insertion_sort_partial_solve_wit_2 : insertion_sort_partial_solve_wit_2. +Proof. Admitted. + diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_proof_manual.v b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..493a8b47cfc199f1d2992b5b7b48d4862df15607 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/groundtruth/sll_insertion_sort_proof_manual.v @@ -0,0 +1,252 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.sll_insertion_sort.rocq.groundtruth Require Import sll_insertion_sort_goal. +From PVbench.Algorithms.sll_insertion_sort.rocq.groundtruth Require Import sll_insertion_sort_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Algorithms.sll_insertion_sort.rocq.helper_lib. +Require Import PVbench.Algorithms.sll_insertion_sort.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_insertion_entail_wit_1 : insertion_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + Exists nil. + Exists l. + split_pure_spatial. + - cancel (&((node_pre) # "list" ->ₛ "data") # Int |-> a). + cancel (sll p_pre l). + cancel (&((node_pre) # "list" ->ₛ "next") # Ptr |->_). + simpl sllbseg. + split_pure_spatial. + + cancel. + + dump_pre_spatial. + reflexivity. + - split_pures; try (dump_pre_spatial; auto). +Qed. + +Lemma proof_of_insertion_entail_wit_2 : insertion_entail_wit_2. +Proof. + LLM_pre_process ltac:(int_auto). + Exists y. + Exists (l1_2 ++ x :: nil)%list. + Exists l0. + split_pure_spatial. + - sep_apply (sllbseg_len1 p2 p2_v_2 x); [ | assumption ]. + sep_apply (sllbseg_sllbseg (&( "res" )) p2 (&((p2_v_2) # "list" ->ₛ "next")) l1_2 (x :: nil)%list). + cancel. + - split_pures; try (dump_pre_spatial; apply upperbound_app; try assumption; lia). + dump_pre_spatial ; auto. + dump_pre_spatial. + rewrite PreH5. + rewrite PreH2. + rewrite <- app_assoc. + reflexivity. +Qed. + +Lemma proof_of_insertion_entail_wit_3_1 : insertion_entail_wit_3_1. +Proof. + LLM_pre_process ltac:(int_auto). + subst p2_v. + sep_apply (sll_zero 0 l2); [ | reflexivity ]. + Intros_p Hl2. + Left. + Exists l1_3. + split_pure_spatial. + - cancel ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a). + cancel (sllbseg ( &( "res" ) ) p2 l1_3). + cancel ((p2) # Ptr |-> 0). + cancel ((&((node_pre) # "list" ->ₛ "next")) # Ptr |->_). + - split_pures. + + dump_pre_spatial. + exact PreH2. + + dump_pre_spatial. + rewrite Hl2 in PreH3. + exact PreH3. + + dump_pre_spatial. + exact PreH4. +Qed. + +Lemma proof_of_insertion_entail_wit_4_1 : insertion_entail_wit_4_1. +Proof. + LLM_pre_process ltac:(int_auto). + Left. + sep_apply (sllbseg_2_sllseg (&( "res" )) p2 node_pre l1_3). + Intros resv_2. + Exists resv_2. + Exists l1_3. + split_pure_spatial. + - cancel ((( &( "res" ) )) # Ptr |-> resv_2). + cancel (sllseg resv_2 node_pre l1_3). + cancel ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a). + cancel ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> 0). + - split_pures. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + exact PreH2. + + dump_pre_spatial. + exact PreH3. +Qed. + +Lemma proof_of_insertion_entail_wit_4_2 : insertion_entail_wit_4_2. +Proof. + LLM_pre_process ltac:(int_auto). + Right. + sep_apply (sllbseg_2_sllseg (&( "res" )) p2 node_pre l1_3). + Intros resv. + Exists unext_2. + Exists resv. + Exists l1_3. + Exists l0_2. + Exists x_2. + Exists u_2. + split_pure_spatial. + - cancel ((( &( "res" ) )) # Ptr |-> resv). + cancel (sllseg resv node_pre l1_3). + cancel ((&((node_pre) # "list" ->ₛ "data")) # Int |-> a). + cancel ((&((node_pre) # "list" ->ₛ "next")) # Ptr |-> u_2). + cancel ((&((u_2) # "list" ->ₛ "data")) # Int |-> x_2). + cancel ((&((u_2) # "list" ->ₛ "next")) # Ptr |-> unext_2). + cancel (sll unext_2 l0_2). + - split_pures. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + exact PreH2. + + dump_pre_spatial. + exact PreH3. + + dump_pre_spatial. + exact PreH4. + + dump_pre_spatial. + exact PreH5. +Qed. + +Lemma proof_of_insertion_return_wit_1 : insertion_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists ((l1 ++ a :: nil)%list). + split_pure_spatial. + - sep_apply (sllseg_len1 node_pre a 0); [ | tauto ]. + sep_apply (sllseg_sll resv node_pre l1 (a :: nil)%list). + cancel (sll resv (l1 ++ a :: nil)%list). + - dump_pre_spatial. + rewrite PreH2. + rewrite app_nil_r. + symmetry. + apply upperbound_insert_nil. + exact PreH3. +Qed. + +Lemma proof_of_insertion_return_wit_2 : insertion_return_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists (((l1 ++ a :: nil)%list ++ x :: l0_2)%list). + split_pure_spatial. + - sep_apply (sllseg_len1 node_pre a u); [ | tauto ]. + sep_apply (sllseg_sllseg resv node_pre u l1 (a :: nil)%list). + sep_apply_r_atomic (sllseg_sll resv u (l1 ++ a :: nil)%list (x :: l0_2)). + simpl sll. + Exists unext. + split_pure_spatial. + + cancel (sllseg resv u (l1 ++ a :: nil)%list). + cancel ((&((u) # "list" ->ₛ "data")) # Int |-> x). + cancel ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext). + cancel (sll unext l0_2). + + dump_pre_spatial. + exact PreH2. + - dump_pre_spatial. + rewrite PreH4. + assert (a <= x) by lia. + rewrite (upperbound_insert_cons a l1 l0_2 x PreH5 H). + rewrite <- app_assoc. + reflexivity. +Qed. + +Lemma proof_of_insertion_sort_entail_wit_1 : insertion_sort_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + Exists nil. + Exists nil. + Exists l. + split_pure_spatial. + - simpl sll. + split_pure_spatial. + + cancel (sll x_pre l). + + dump_pre_spatial. + reflexivity. + - split_pures. + + dump_pre_spatial. + reflexivity. + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma proof_of_insertion_sort_entail_wit_2 : insertion_sort_entail_wit_2. +Proof. + LLM_pre_process ltac:(int_auto). + Exists l0_4. + Exists (l1_2 ++ x :: nil)%list. + Exists l0_3. + split_pure_spatial. + - sep_apply store_ptr_undef_store_ptr. + cancel (sll retval l0_4). + cancel (sll y l0_3). + cancel (((&( "q" ))) # Ptr |->_). + - split_pures. + + dump_pre_spatial. + rewrite PreH4. + rewrite PreH2. + rewrite <- app_assoc. + reflexivity. + + dump_pre_spatial. + rewrite PreH1. + rewrite <- perm_insert. + rewrite PreH5. + reflexivity. + + dump_pre_spatial. + rewrite PreH1. + apply increasing_insert. + exact PreH6. +Qed. + +Lemma proof_of_insertion_sort_return_wit_1 : insertion_sort_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + rewrite PreH1. + sep_apply (sll_zero 0 l2); [ | reflexivity ]. + Intros_p Hl2. + Exists l0_2. + split_pure_spatial. + - rewrite Hl2 in PreH2. + rewrite app_nil_r in PreH2. + subst l. + cancel (sll res l0_2). + - split_pures. + + dump_pre_spatial. + rewrite Hl2 in PreH2. + rewrite app_nil_r in PreH2. + subst l. + exact PreH3. + + dump_pre_spatial. + exact PreH4. +Qed. diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/helper_lib.v b/benchmarks/Algorithms/sll_insertion_sort/rocq/helper_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..d6dd7c59f620f909aef124373646981fca605b92 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/helper_lib.v @@ -0,0 +1,23 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Import ListNotations. +Local Open Scope string. +Local Open Scope list. + +Fixpoint insert (x: Z) (l: list Z): list Z := + match l with + | nil => [x] + | y :: l' => if x >? y then y :: insert x l' else x :: l + end. diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/solution_annotated.c b/benchmarks/Algorithms/sll_insertion_sort/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..c6207aa03e02acc69a0173cda6dcf87991ec5fb2 --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/solution_annotated.c @@ -0,0 +1,116 @@ +#include "sll_def.h" + +/*@ Import Coq Require Import PVbench.Algorithms.sll_insertion_sort.rocq.helper_lib */ + +/*@ Extern Coq (Permutation: list Z -> list Z -> Prop) + (increasing: list Z -> Prop) + (insert: Z -> list Z -> list Z) + (strict_upperbound: Z -> list Z -> Prop) + */ + +struct list * insertion(struct list * p, struct list * node) + /*@ With l a + Require node != 0 && node->data == a && + sll(p, l) * + undef_data_at(&(node->next), struct list*) + Ensure exists l0, + l0 == insert(a, l) && sll(__return, l0) + */ +{ + struct list * res = p; + struct list * * p2 = & res; + /*@ Inv Assert + exists l1 l2, + node == node@pre && p == p@pre && + node != (void *)0 && + l == app(l1, l2) && + node->data == a && + strict_upperbound(a, l1) && + sllbseg(&res, p2, l1) * sll(*p2, l2) * + undef_data_at(&(node->next), struct list*) + */ + while (* p2 != (void * )0 && (* p2) -> data < node -> data) { + p2 = &((* p2) -> next); + } + /*@ Assert + (exists l1, + node == node@pre && p == p@pre && + node != (void *)0 && + l == app(l1, nil) && + node->data == a && + strict_upperbound(a, l1) && + sllbseg(&res, p2, l1) * + store(p2, struct list*, (void *)0) * + undef_data_at(&(node->next), struct list*)) + || + (exists l1 x l0 u unext, + node == node@pre && p == p@pre && + node != (void *)0 && + u != (void *)0 && + x >= a && + l == app(l1, cons(x, l0)) && + node->data == a && + strict_upperbound(a, l1) && + sllbseg(&res, p2, l1) * + store(p2, struct list*, u) * + store(&(u->data), x) * + store(&(u->next), struct list*, unext) * + sll(unext, l0) * + undef_data_at(&(node->next), struct list*)) + */ + node -> next = * p2; + * p2 = node; + /*@ Assert + (exists resv l1, + node == node@pre && p == p@pre && + node != (void *)0 && + l == app(l1, nil) && + strict_upperbound(a, l1) && + store(&p2, struct list**, p2) * + store(&res, struct list*, resv) * + sllseg(resv, node, l1) * + store(&(node->data), a) * + store(&(node->next), struct list*, (void *)0)) + || + (exists resv l1 x l0 u unext, + node == node@pre && p == p@pre && + node != (void *)0 && + u != (void *)0 && + x >= a && + l == app(l1, cons(x, l0)) && + strict_upperbound(a, l1) && + store(&p2, struct list**, p2) * + store(&res, struct list*, resv) * + sllseg(resv, node, l1) * + store(&(node->data), a) * + store(&(node->next), struct list*, u) * + store(&(u->data), x) * + store(&(u->next), struct list*, unext) * + sll(unext, l0)) + */ + return res; +} + +struct list * insertion_sort(struct list * x) + /*@ With l + Require sll(x, l) + Ensure exists l0, + Permutation(l, l0) && increasing(l0) && + sll(__return, l0) + */ +{ + struct list * res = (void *)0, * p = x, * q; + /*@ Inv Assert + exists l0 l1 l2, + l == app(l1, l2) && x == x@pre && + Permutation(l1, l0) && increasing(l0) && + has_ptr_permission(&q) * + sll(res, l0) * sll(p, l2) + */ + while (p != (void * )0) { + q = p -> next; + res = insertion(res, p); + p = q; + } + return res; +} diff --git a/benchmarks/Algorithms/sll_insertion_sort/rocq/solution_spec.c b/benchmarks/Algorithms/sll_insertion_sort/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..070e48adaabc34592c1d8445e74a7e21c233a79a --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/rocq/solution_spec.c @@ -0,0 +1,39 @@ +#include "sll_def.h" + +/*@ Extern Coq + (Permutation : list Z -> list Z -> Prop) + (increasing : list Z -> Prop) + */ + +struct list * insertion(struct list * p, struct list * node) +{ + struct list * res = p; + struct list * * p2 = & res; + + while (* p2 != (void * )0 && (* p2) -> data < node -> data) { + p2 = &((* p2) -> next); + } + + node -> next = * p2; + * p2 = node; + + return res; +} + +struct list * insertion_sort(struct list * x) + /*@ With l + Require sll(x, l) + Ensure exists l0, + Permutation(l, l0) && increasing(l0) && + sll(__return, l0) + */ +{ + struct list * res = (void *)0, * p = x, * q; + + while (p != (void * )0) { + q = p -> next; + res = insertion(res, p); + p = q; + } + return res; +} diff --git a/benchmarks/Algorithms/sll_insertion_sort/solution.c b/benchmarks/Algorithms/sll_insertion_sort/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..81e5ffc3928f3f7ee66e3e8d74442868d5fcefdb --- /dev/null +++ b/benchmarks/Algorithms/sll_insertion_sort/solution.c @@ -0,0 +1,28 @@ +#include "sll_def.h" + +struct list * insertion(struct list * p, struct list * node) +{ + struct list * res = p; + struct list * * p2 = & res; + + while (* p2 != (void * )0 && (* p2) -> data < node -> data) { + p2 = &((* p2) -> next); + } + + node -> next = * p2; + * p2 = node; + + return res; +} + +struct list * insertion_sort(struct list * x) +{ + struct list * res = (void *)0, * p = x, * q; + + while (p != (void * )0) { + q = p -> next; + res = insertion(res, p); + p = q; + } + return res; +} diff --git a/benchmarks/Algorithms/sll_merge_sort/manifest.json b/benchmarks/Algorithms/sll_merge_sort/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..d83292a38d311ebccafb068f834505ee7b768967 --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "sll_merge_sort", + "source": { + "dataset": "classical_algorithm", + "problem_id": "sll_merge_sort", + "title": "Merge Sort on a Singly Linked List", + "tags": [ + "sort", + "merge", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Algorithms/sll_merge_sort/problem.md b/benchmarks/Algorithms/sll_merge_sort/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..8e3103590b5b7801aac4c69111346035e76c8b02 --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/problem.md @@ -0,0 +1,22 @@ +# Merge Sort on a Singly Linked List + +## Description + +Sort a null-terminated singly linked list of integers into nondecreasing order using top-down merge sort, relinking the existing nodes. + +## Input + +A list is given by a pointer to its first node, or `NULL` when empty: + +```c +struct list { + int data; + struct list *next; +}; +``` + +The function receives the head `x` of the list. + +## Output + +Return the head of a list holding the same values in nondecreasing order. diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/proof_lib.v b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..0edfc4e50808873fcdc0648af38c061b827a305d --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/proof_lib.v @@ -0,0 +1,302 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +From FP Require Import SetsFixedpoints. +Require Import MonadLib.StateRelMonad.StateRelMonad. +Export MonadNotation. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.helper_lib. +Local Open Scope monad. +Local Open Scope sac. +Import ListNotations. +Local Open Scope list. + +(* From QCP's MonadLib/Examples/mergesort.v: the monadic merge sort is a sorted permutation. *) + +Lemma split_rec_rel_unfold: split_rec_rel' == split_rec_rel_f split_rec_rel'. +Proof. + intros. + unfold split_rec_rel'. + apply Lfix_fixpoint'. + unfold split_rec_rel_f. + mono_cont_auto. +Qed. + + +Lemma split_rec_rel_eval_xnil: forall p q P, + P -@ (split_rec_rel' (nil, p, q)) -⥅ + P ♯ (p, q). +Proof. + intros. + erewrite (program_para_equiv (split_rec_rel_unfold)). + unfold split_rec_rel_f. + apply highret_eval2. +Qed. + + +Lemma split_rel_eval_xnotnil: forall z x p q, + forall P X, safeExec P (split_rec_rel' (z::x, p, q)) X -> + safeExec P (x <- split_rec_rel' (x, q, z::p) ;; reversepair x ) X. +Proof. + unfold split_rel, reversepair. intros. + erewrite (program_para_equiv (split_rec_rel_unfold)) in H. + unfold split_rec_rel_f in H. + apply H. +Qed. + +Lemma bind_2_reversepair_equiv_Id: + (fun p => z <- reversepair p ;; reversepair z) == ret. +Proof. + intros [x y]. + unfold reversepair;sets_unfold. + intros s [u v] s'. + split;intros. + - destruct H as ([x' y'] & s'' & ? & ? ). + unfold_monad in H. destruct H. + unfold_monad in H0. destruct H0. + inversion H; inversion H0. subst. + unfold_monad. auto. + - unfold_monad in H. destruct H. + inversion H;subst. + do 3 eexists. + split;eauto. + cbn. sets_unfold. unfold_monad. auto. +Qed. + +Lemma mergesortrec_unfold: mergesortrec == mergesortrec_f mergesortrec. +Proof. + intros. + unfold mergesortrec. + apply Lfix_fixpoint'. + unfold mergesortrec_f. + mono_cont_auto. +Qed. + + + +Theorem merge_perm: + forall l1 l2, + Hoare (fun _ => True) + (merge_rel l1 l2) + (fun r _ => Permutation (l1 ++ l2) r). +Proof. + intros. + unfold merge_rel. + eapply Hoare_conseq_pre. + 2: + apply (Hoare_repeat_break _ + (fun '(l1', l2', l3') _ => + Permutation (l1 ++ l2) (l1' ++ l2' ++ l3'))). + { intros. simpl. rewrite app_nil_r. reflexivity. } + + intros [[l1' l2'] l3']. + unfold merge_body. + destruct l1' as [ | x l1']; [| destruct l2' as [| y l2']]. + + hoare_auto. + rewrite H; simpl. + apply Permutation_app_comm. + + hoare_auto. + rewrite H. + rewrite Permutation_app_comm. + reflexivity. + + hoare_auto. + - rewrite H0. + rewrite ! app_assoc. + rewrite (Permutation_app_comm _ [x]). + reflexivity. + - rewrite H0. + apply Permutation_app; [reflexivity |]. + rewrite ! app_assoc. + rewrite (Permutation_app_comm _ [y]). + reflexivity. +Qed. + +Lemma incr_app_cons: forall l1 x l2, + incr (l1 ++ [x]) -> + incr (x :: l2) -> + incr (l1 ++ x :: l2). +Proof. + intros. + simpl in H0. + destruct l1 as [| a l1]; simpl in *. + { tauto. } + revert a H; induction l1; simpl; intros. + + tauto. + + split; [tauto |]. + apply IHl1. + tauto. +Qed. + +Lemma incr_app_cons_inv1: forall l1 x l2, + incr (l1 ++ x :: l2) -> + incr (l1 ++ [x]). +Proof. + intros. + destruct l1 as [| a l1]; simpl in *. + { tauto. } + revert a H; induction l1; simpl; intros. + + tauto. + + split; [tauto |]. + apply IHl1. + tauto. +Qed. + +Lemma incr_app_cons_inv2: forall l1 x l2, + incr (l1 ++ x :: l2) -> + incr (x :: l2). +Proof. + intros. + simpl. + induction l1; simpl in *. + + tauto. + + apply IHl1. + destruct l1; simpl in *; tauto. +Qed. + +Theorem merge_incr: + forall l1 l2, + incr l1 -> + incr l2 -> + Hoare (fun _ => True) (merge_rel l1 l2) (fun r _ => incr r). +Proof. + intros. + unfold merge_rel. + eapply Hoare_conseq_pre. + 2: + apply (Hoare_repeat_break _ + (fun '(l1', l2', l3') _ => + incr (l3' ++ l1') /\ + incr (l3' ++ l2'))). + 1: { + tauto. + } + clear l1 l2 H H0. + intros [[l1 l2] l3]. + unfold merge_body. + destruct l1 as [ | x l1]; [| destruct l2 as [| y l2]]. + + hoare_auto. tauto. + + hoare_auto. tauto. + + hoare_auto. + - split. + * rewrite <- app_assoc. + tauto. + * rewrite <- app_assoc. + simpl. + destruct H0. + apply incr_app_cons_inv1 in H0. + apply incr_app_cons_inv2 in H1. + apply incr_app_cons; simpl in *; tauto. + - split. + * rewrite <- app_assoc. + simpl. + destruct H0. + apply incr_app_cons_inv1 in H1. + apply incr_app_cons_inv2 in H0. + apply incr_app_cons; simpl in *; tauto. + * rewrite <- app_assoc. + tauto. +Qed. + +Theorem functional_correctness_merge: + forall l1 l2, + incr l1 -> + incr l2 -> + Hoare (fun _ => True) + (merge_rel l1 l2) + (fun l3 _ => Permutation (l1 ++ l2) l3 /\ incr l3). +Proof. + intros. + apply Hoare_conj. + + apply merge_perm. + + apply merge_incr; tauto. +Qed. + + +Theorem functional_correctness_split: + forall l, + Hoare (fun _ => True) + (split_rel l) + (fun '(l1, l2) _ => Permutation l (l1 ++ l2) /\ (0 <= length l1 - length l2 <= 1)%nat). +Proof. + intros. + unfold split_rel, split_rec_rel'. + apply Hoare_conseq_post with (Q2 := fun '(l1, l2) _ => + Permutation ((fst (fst (l, @nil Z, @nil Z))) ++ (snd (fst (l, [], @nil Z))) ++ (snd (l, @nil Z, []))) (l1 ++ l2) /\ + (@length Z (snd (fst (l, [], @nil Z))) <= length l1 /\ + @length Z (snd (l, @nil Z, [])) <= length l2 /\ + length l2 - @length Z (snd (l, @nil Z, [])) <= length l1 - @length Z (snd (fst (l, [], @nil Z))) <= S (length l2 - @length Z (snd (l, @nil Z, []))))%nat). + { simpl. rewrite app_nil_r. + intros [l1 l2];intros. + split; try tauto. + lia. } + hoare_fix_nolv_auto ((list Z * list Z)%type * list Z)%type. + simpl;intros * H [[l0 l1] l2]. simpl. + destruct l0. + - hoare_auto. split;auto. lia. + - eapply Hoare_bind;[apply H |]. + simpl. + intros [? ?]. + unfold reversepair. + hoare_auto. + split. + + rewrite (Permutation_app_comm l1 l2). + rewrite !Permutation_middle. + destruct H0 as [H0 _]. + rewrite H0. + apply Permutation_app_comm. + + lia. +Qed. + + +Theorem functional_correctness_mergesort: + forall l, + Hoare ATrue (mergesortrec l) (fun l0 _ => Permutation l l0 /\ incr l0). +Proof. + intros. + unfold mergesortrec, ATrue. + hoare_fix_nolv_auto (list Z). + simpl. + intros. + unfold mergesortrec_f. + eapply Hoare_bind;[apply functional_correctness_split | ]. + intros [l1 l2]. + destruct l2. + - hoare_auto. + rewrite app_nil_r in H0. destruct H0. split;auto. + simpl in H1. + destruct l1;[cbn;auto | ]. + destruct l1;[ | simpl in H1; lia]. + cbn. auto. + - apply Hoare_stateless;intros. + eapply Hoare_bind;[apply H| ]. + intros lp;simpl. + apply Hoare_stateless;intros. + eapply Hoare_bind;[apply H| ]. + intros lq;simpl. + apply Hoare_stateless;intros. + eapply Hoare_conseq_post. + 2: { apply functional_correctness_merge;try tauto. } + destruct H0. + destruct H1. destruct H2. + intros lr ? [? ?]. + rewrite H0. + rewrite H1, H2. + tauto. +Qed. + + diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_goal.v b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..2e6d02bc2371708284bddc2e7fbcb15f64dc527f --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_goal.v @@ -0,0 +1,900 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +From MonadLib Require Export MonadLib. +From MonadLib.StateRelMonad Require Export StateRelMonad. +Export MonadNotation. +Local Open Scope monad. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap relations. +From FP Require Import PartialOrder_Setoid BourbakiWitt. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.spec_lib. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.helper_lib. +Local Open Scope sac. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_proof. +From SimpleC.EE.QCP_demos_LLM Require Import safeexec_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import safeexec_strategy_proof. + +(*----- Function merge -----*) + +Definition merge_safety_wit_1 := +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + ((( &( "x" ) )) # Ptr |-> x) + ** (sll x l1 ) + ** ((( &( "y" ) )) # Ptr |-> y) + ** (sll y l2 ) + ** ((( &( "t" ) )) # Ptr |-> t) + ** ((t) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + “ (1 <= INT_MAX) ” + && “ ((INT_MIN) <= 1) ” +. + +Definition merge_safety_wit_2 := +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + ((( &( "x" ) )) # Ptr |-> x) + ** (sll x l1 ) + ** ((( &( "y" ) )) # Ptr |-> y) + ** (sll y l2 ) + ** ((( &( "t" ) )) # Ptr |-> t) + ** ((t) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition merge_safety_wit_3 := +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (x <> 0)) (PreH2 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + ((( &( "x" ) )) # Ptr |-> x) + ** (sll x l1 ) + ** ((( &( "y" ) )) # Ptr |-> y) + ** (sll y l2 ) + ** ((( &( "t" ) )) # Ptr |-> t) + ** ((t) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition merge_entail_wit_1 := +( +forall (y_pre: Z) (x_pre: Z) (X: ((@list Z) -> (unit -> Prop))) (s2: (@list Z)) (s1: (@list Z)) (PreH1 : (safeExec ATrue (merge_rel (s1) (s2)) X )) , + ((( &( "ret" ) )) # Ptr |->_) + ** (sll x_pre s1 ) + ** (sll y_pre s2 ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) , + “ (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X ) ” + && (sll x_pre l1 ) + ** (sll y_pre l2 ) + ** ((( &( "ret" ) )) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) ( &( "ret" ) ) l3 ) +) \/ +( +forall (X: ((@list Z) -> (unit -> Prop))) (s2: (@list Z)) (s1: (@list Z)) (PreH1 : (safeExec ATrue (merge_rel (s1) (s2)) X )) , + TT && emp +|-- + “ (safeExec ATrue (merge_from_mid_rel (s1) (s2) ((@nil Z))) X ) ” + && emp +). + +Definition merge_entail_wit_1_split_goal_1 := +forall (X: ((@list Z) -> (unit -> Prop))) (s2: (@list Z)) (s1: (@list Z)) (PreH1 : (safeExec ATrue (merge_rel (s1) (s2)) X )) , + (safeExec ATrue (merge_from_mid_rel (s1) (s2) ((@nil Z))) X ) +. + +Definition merge_entail_wit_2 := +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3_2: (@list Z)) (PreH1 : (y <> 0)) (PreH2 : (x <> 0)) (PreH3 : (safeExec ATrue (merge_from_mid_rel (l1_2) (l2_2) (l3_2)) X )) , + (sll x l1_2 ) + ** (sll y l2_2 ) + ** ((t) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) t l3_2 ) +|-- + EX (ynext: Z) (xnext: Z) (ydata: Z) (l2_new: (@list Z)) (xdata: Z) (l1_new: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) , + “ (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X ) ” + && “ (x <> 0) ” + && “ (y <> 0) ” + && “ (l1 = (cons (xdata) (l1_new))) ” + && “ (l2 = (cons (ydata) (l2_new))) ” + && ((&((x) # "list" ->ₛ "data")) # Int |-> xdata) + ** ((&((y) # "list" ->ₛ "data")) # Int |-> ydata) + ** ((&((x) # "list" ->ₛ "next")) # Ptr |-> xnext) + ** ((&((y) # "list" ->ₛ "next")) # Ptr |-> ynext) + ** (sll xnext l1_new ) + ** (sll ynext l2_new ) + ** ((t) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) t l3 ) +. + +Definition merge_entail_wit_3_1 := +( +forall (X: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3_2: (@list Z)) (l1_new: (@list Z)) (l2_new: (@list Z)) (xdata: Z) (ydata: Z) (xnext: Z) (ynext: Z) (x: Z) (y: Z) (t: Z) (PreH1 : (xdata < ydata)) (PreH2 : (safeExec ATrue (merge_from_mid_rel (l1_2) (l2_2) (l3_2)) X )) (PreH3 : (x <> 0)) (PreH4 : (y <> 0)) (PreH5 : (l1_2 = (cons (xdata) (l1_new)))) (PreH6 : (l2_2 = (cons (ydata) (l2_new)))) , + ((&((x) # "list" ->ₛ "data")) # Int |-> xdata) + ** ((&((y) # "list" ->ₛ "data")) # Int |-> ydata) + ** ((&((x) # "list" ->ₛ "next")) # Ptr |-> xnext) + ** ((&((y) # "list" ->ₛ "next")) # Ptr |-> ynext) + ** (sll xnext l1_new ) + ** (sll ynext l2_new ) + ** ((t) # Ptr |-> x) + ** (sllbseg ( &( "ret" ) ) t l3_2 ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) , + “ (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X ) ” + && (sll xnext l1 ) + ** (sll y l2 ) + ** ((&((x) # "list" ->ₛ "next")) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) &((x) # "list" ->ₛ "next") l3 ) +) \/ +( +forall (X: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3_2: (@list Z)) (l1_new: (@list Z)) (l2_new: (@list Z)) (xdata: Z) (ydata: Z) (x: Z) (y: Z) (t: Z) (PreH1 : (xdata <= INT_MAX)) (PreH2 : (xdata >= INT_MIN)) (PreH3 : (xdata < ydata)) (PreH4 : (safeExec ATrue (merge_from_mid_rel (l1_2) (l2_2) (l3_2)) X )) (PreH5 : (x <> 0)) (PreH6 : (y <> 0)) (PreH7 : (l1_2 = (cons (xdata) (l1_new)))) (PreH8 : (l2_2 = (cons (ydata) (l2_new)))) , + ((&((x) # "list" ->ₛ "data")) # Int |-> xdata) + ** ((t) # Ptr |-> x) + ** (sllbseg ( &( "ret" ) ) t l3_2 ) +|-- + EX (l3: (@list Z)) , + “ (y <> 0) ” + && “ (safeExec ATrue (merge_from_mid_rel (l1_new) ((cons (ydata) (l2_new))) (l3)) X ) ” + && (sllbseg ( &( "ret" ) ) &((x) # "list" ->ₛ "next") l3 ) +). + +Definition merge_entail_wit_3_2 := +( +forall (X: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3_2: (@list Z)) (l1_new: (@list Z)) (l2_new: (@list Z)) (xdata: Z) (ydata: Z) (xnext: Z) (ynext: Z) (x: Z) (y: Z) (t: Z) (PreH1 : (xdata >= ydata)) (PreH2 : (safeExec ATrue (merge_from_mid_rel (l1_2) (l2_2) (l3_2)) X )) (PreH3 : (x <> 0)) (PreH4 : (y <> 0)) (PreH5 : (l1_2 = (cons (xdata) (l1_new)))) (PreH6 : (l2_2 = (cons (ydata) (l2_new)))) , + ((&((x) # "list" ->ₛ "data")) # Int |-> xdata) + ** ((&((y) # "list" ->ₛ "data")) # Int |-> ydata) + ** ((&((x) # "list" ->ₛ "next")) # Ptr |-> xnext) + ** ((&((y) # "list" ->ₛ "next")) # Ptr |-> ynext) + ** (sll xnext l1_new ) + ** (sll ynext l2_new ) + ** ((t) # Ptr |-> y) + ** (sllbseg ( &( "ret" ) ) t l3_2 ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) , + “ (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X ) ” + && (sll x l1 ) + ** (sll ynext l2 ) + ** ((&((y) # "list" ->ₛ "next")) # Ptr |->_) + ** (sllbseg ( &( "ret" ) ) &((y) # "list" ->ₛ "next") l3 ) +) \/ +( +forall (X: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3_2: (@list Z)) (l1_new: (@list Z)) (l2_new: (@list Z)) (xdata: Z) (ydata: Z) (x: Z) (y: Z) (t: Z) (PreH1 : (ydata <= INT_MAX)) (PreH2 : (ydata >= INT_MIN)) (PreH3 : (xdata >= ydata)) (PreH4 : (safeExec ATrue (merge_from_mid_rel (l1_2) (l2_2) (l3_2)) X )) (PreH5 : (x <> 0)) (PreH6 : (y <> 0)) (PreH7 : (l1_2 = (cons (xdata) (l1_new)))) (PreH8 : (l2_2 = (cons (ydata) (l2_new)))) , + ((&((y) # "list" ->ₛ "data")) # Int |-> ydata) + ** ((t) # Ptr |-> y) + ** (sllbseg ( &( "ret" ) ) t l3_2 ) +|-- + EX (l3: (@list Z)) , + “ (x <> 0) ” + && “ (safeExec ATrue (merge_from_mid_rel ((cons (xdata) (l1_new))) (l2_new) (l3)) X ) ” + && (sllbseg ( &( "ret" ) ) &((y) # "list" ->ₛ "next") l3 ) +). + +Definition merge_entail_wit_4_1 := +( +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (x = 0)) (PreH2 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + (sll x l1 ) + ** (sll y l2 ) + ** ((t) # Ptr |-> y) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + EX (ret: Z) (s3: (@list Z)) , + “ (safeExec ATrue (return (s3)) X ) ” + && ((( &( "ret" ) )) # Ptr |-> ret) + ** (sll ret s3 ) +) \/ +( +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (x = 0)) (PreH2 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + (sll x l1 ) + ** (sll y l2 ) + ** ((t) # Ptr |-> y) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + EX (ret: Z) (s3: (@list Z)) , + “ (safeExec ATrue (return (s3)) X ) ” + && ((( &( "ret" ) )) # Ptr |-> ret) + ** (sll ret s3 ) +). + +Definition merge_entail_wit_4_2 := +( +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (y = 0)) (PreH2 : (x <> 0)) (PreH3 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + (sll x l1 ) + ** (sll y l2 ) + ** ((t) # Ptr |-> x) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + EX (ret: Z) (s3: (@list Z)) , + “ (safeExec ATrue (return (s3)) X ) ” + && ((( &( "ret" ) )) # Ptr |-> ret) + ** (sll ret s3 ) +) \/ +( +forall (X: ((@list Z) -> (unit -> Prop))) (t: Z) (y: Z) (x: Z) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (PreH1 : (y = 0)) (PreH2 : (x <> 0)) (PreH3 : (safeExec ATrue (merge_from_mid_rel (l1) (l2) (l3)) X )) , + (sll x l1 ) + ** (sll y l2 ) + ** ((t) # Ptr |-> x) + ** (sllbseg ( &( "ret" ) ) t l3 ) +|-- + EX (ret: Z) (s3: (@list Z)) , + “ (safeExec ATrue (return (s3)) X ) ” + && ((( &( "ret" ) )) # Ptr |-> ret) + ** (sll ret s3 ) +). + +Definition merge_return_wit_1 := +forall (X: ((@list Z) -> (unit -> Prop))) (s3_2: (@list Z)) (ret: Z) (PreH1 : (safeExec ATrue (return (s3_2)) X )) , + (sll ret s3_2 ) +|-- + EX (s3: (@list Z)) , + “ (safeExec ATrue (return (s3)) X ) ” + && (sll ret s3 ) +. + +(*----- Function split_rec -----*) + +Definition split_rec_safety_wit_1 := +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec: Z) (pv_low_level_spec: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (PreH1 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((p_pre) # Ptr |-> pv_low_level_spec) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre l_low_level_spec ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition split_rec_entail_wit_1 := +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec: Z) (pv_low_level_spec: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (PreH1 : (x_pre <> 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) , + ((p_pre) # Ptr |-> pv_low_level_spec) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre l_low_level_spec ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec ) +|-- + EX (x_next: Z) (x_data: Z) (l_new: (@list Z)) , + “ (x_pre <> 0) ” + && “ (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec ) ” + && “ (l_low_level_spec = (cons (x_data) (l_new))) ” + && ((&((x_pre) # "list" ->ₛ "data")) # Int |-> x_data) + ** ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> x_next) + ** ((p_pre) # Ptr |-> pv_low_level_spec) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_next l_new ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec ) +. + +Definition split_rec_entail_wit_2 := +( +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec: Z) (pv_low_level_spec: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (l_new_2: (@list Z)) (x_data_2: Z) (x_next: Z) (PreH1 : (x_pre <> 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) (PreH3 : (l_low_level_spec = (cons (x_data_2) (l_new_2)))) , + ((&((x_pre) # "list" ->ₛ "data")) # Int |-> x_data_2) + ** ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> pv_low_level_spec) + ** ((p_pre) # Ptr |-> x_pre) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_next l_new_2 ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec ) +|-- + EX (l_new: (@list Z)) (x_data: Z) , + “ (x_pre <> 0) ” + && “ (safeExec ATrue (bind ((split_rec_rel (l_new) (l2_low_level_spec) ((cons (x_data) (l1_low_level_spec))))) (reversepair)) X_low_level_spec ) ” + && “ (l_low_level_spec = (cons (x_data) (l_new))) ” + && ((p_pre) # Ptr |-> x_pre) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre (cons (x_data) (l1_low_level_spec)) ) + ** (sll x_next l_new ) + ** (sll qv_low_level_spec l2_low_level_spec ) +) \/ +( +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (l_new_2: (@list Z)) (x_data_2: Z) (PreH1 : (x_pre <> 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) (PreH3 : (l_low_level_spec = (cons (x_data_2) (l_new_2)))) , + TT && emp +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_new_2) (l2_low_level_spec) ((cons (x_data_2) (l1_low_level_spec))))) (reversepair)) X_low_level_spec ) ” + && emp +). + +Definition split_rec_entail_wit_2_split_goal_1 := +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (l_new_2: (@list Z)) (x_data_2: Z) (PreH1 : (x_pre <> 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) (PreH3 : (l_low_level_spec = (cons (x_data_2) (l_new_2)))) , + (safeExec ATrue (bind ((split_rec_rel (l_new_2) (l2_low_level_spec) ((cons (x_data_2) (l1_low_level_spec))))) (reversepair)) X_low_level_spec ) +. + +Definition split_rec_return_wit_1 := +( +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec: Z) (pv_low_level_spec: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (PreH1 : (x_pre = 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) , + ((p_pre) # Ptr |-> pv_low_level_spec) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre l_low_level_spec ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec ) +|-- + EX (qv': Z) (pv': Z) (s1: (@list Z)) (s2: (@list Z)) , + “ (safeExec ATrue (return ((maketuple (s1) (s2)))) X_low_level_spec ) ” + && ((p_pre) # Ptr |-> pv') + ** ((q_pre) # Ptr |-> qv') + ** (sll pv' s1 ) + ** (sll qv' s2 ) +) \/ +( +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (PreH1 : (x_pre = 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) , + (sll x_pre l_low_level_spec ) +|-- + “ (safeExec ATrue (return ((maketuple (l1_low_level_spec) (l2_low_level_spec)))) X_low_level_spec ) ” + && emp +). + +Definition split_rec_return_wit_1_split_goal_1 := +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (PreH1 : (x_pre = 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) , + (sll x_pre l_low_level_spec ) +|-- + “ (safeExec ATrue (return ((maketuple (l1_low_level_spec) (l2_low_level_spec)))) X_low_level_spec ) ” +. + +Definition split_rec_return_wit_1_split_goal_spatial := +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (PreH1 : (x_pre = 0)) (PreH2 : (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec )) , + (sll x_pre l_low_level_spec ) +|-- + TT && emp +. + +Definition split_rec_return_wit_2 := +( +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (l_new: (@list Z)) (x_data: Z) (qv'_2: Z) (pv'_2: Z) (s1_2: (@list Z)) (s2_2: (@list Z)) (PreH1 : (safeExec ATrue (applyf (reversepair) ((maketuple (s1_2) (s2_2)))) X_low_level_spec )) (PreH2 : (x_pre <> 0)) (PreH3 : (l_low_level_spec = (cons (x_data) (l_new)))) , + ((q_pre) # Ptr |-> pv'_2) + ** ((p_pre) # Ptr |-> qv'_2) + ** (sll pv'_2 s1_2 ) + ** (sll qv'_2 s2_2 ) +|-- + EX (qv': Z) (pv': Z) (s1: (@list Z)) (s2: (@list Z)) , + “ (safeExec ATrue (return ((maketuple (s1) (s2)))) X_low_level_spec ) ” + && ((p_pre) # Ptr |-> pv') + ** ((q_pre) # Ptr |-> qv') + ** (sll pv' s1 ) + ** (sll qv' s2 ) +) \/ +( +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (l_new: (@list Z)) (x_data: Z) (s1_2: (@list Z)) (s2_2: (@list Z)) (PreH1 : (safeExec ATrue (applyf (reversepair) ((maketuple (s1_2) (s2_2)))) X_low_level_spec )) (PreH2 : (x_pre <> 0)) (PreH3 : (l_low_level_spec = (cons (x_data) (l_new)))) , + TT && emp +|-- + “ (safeExec ATrue (return ((maketuple (s2_2) (s1_2)))) X_low_level_spec ) ” + && emp +). + +Definition split_rec_return_wit_2_split_goal_1 := +forall (x_pre: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (l_new: (@list Z)) (x_data: Z) (s1_2: (@list Z)) (s2_2: (@list Z)) (PreH1 : (safeExec ATrue (applyf (reversepair) ((maketuple (s1_2) (s2_2)))) X_low_level_spec )) (PreH2 : (x_pre <> 0)) (PreH3 : (l_low_level_spec = (cons (x_data) (l_new)))) , + (safeExec ATrue (return ((maketuple (s2_2) (s1_2)))) X_low_level_spec ) +. + +Definition split_rec_partial_solve_wit_1_pure := +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (l_new: (@list Z)) (x_data: Z) (t: Z) (PreH1 : (x_pre <> 0)) (PreH2 : (safeExec ATrue (bind ((split_rec_rel (l_new) (l2_low_level_spec) ((cons (x_data) (l1_low_level_spec))))) (reversepair)) X_low_level_spec )) (PreH3 : (l_low_level_spec = (cons (x_data) (l_new)))) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((p_pre) # Ptr |-> x_pre) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre (cons (x_data) (l1_low_level_spec)) ) + ** ((( &( "t" ) )) # Ptr |-> t) + ** (sll t l_new ) + ** (sll qv_low_level_spec l2_low_level_spec ) +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_new) (l2_low_level_spec) ((cons (x_data) (l1_low_level_spec))))) (reversepair)) X_low_level_spec ) ” +. + +Definition split_rec_partial_solve_wit_1_aux := +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec: Z) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l2_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l_low_level_spec: (@list Z)) (l_new: (@list Z)) (x_data: Z) (t: Z) (PreH1 : (x_pre <> 0)) (PreH2 : (safeExec ATrue (bind ((split_rec_rel (l_new) (l2_low_level_spec) ((cons (x_data) (l1_low_level_spec))))) (reversepair)) X_low_level_spec )) (PreH3 : (l_low_level_spec = (cons (x_data) (l_new)))) , + ((p_pre) # Ptr |-> x_pre) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre (cons (x_data) (l1_low_level_spec)) ) + ** (sll t l_new ) + ** (sll qv_low_level_spec l2_low_level_spec ) +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_new) (l2_low_level_spec) ((cons (x_data) (l1_low_level_spec))))) (reversepair)) X_low_level_spec ) ” + && “ (x_pre <> 0) ” + && “ (safeExec ATrue (bind ((split_rec_rel (l_new) (l2_low_level_spec) ((cons (x_data) (l1_low_level_spec))))) (reversepair)) X_low_level_spec ) ” + && “ (l_low_level_spec = (cons (x_data) (l_new))) ” + && ((q_pre) # Ptr |-> qv_low_level_spec) + ** ((p_pre) # Ptr |-> x_pre) + ** (sll t l_new ) + ** (sll qv_low_level_spec l2_low_level_spec ) + ** (sll x_pre (cons (x_data) (l1_low_level_spec)) ) +. + +Definition split_rec_partial_solve_wit_1 := split_rec_partial_solve_wit_1_pure -> split_rec_partial_solve_wit_1_aux. + +(*----- Function merge_sort -----*) + +Definition merge_sort_safety_wit_1 := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (PreH1 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + ((( &( "q" ) )) # Ptr |->_) + ** ((( &( "p" ) )) # Ptr |->_) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** (sll x_pre l_low_level_spec ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition merge_sort_safety_wit_2 := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (PreH1 : (p = 0)) (PreH2 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((( &( "q" ) )) # Ptr |->_) + ** (sll p (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition merge_sort_safety_wit_3 := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (pv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH2 : (q = 0)) (PreH3 : (p = 0)) (PreH4 : (p = 0)) (PreH5 : (q = 0)) , + ((( &( "p" ) )) # Ptr |-> pv') + ** ((( &( "q" ) )) # Ptr |-> qv') + ** (sll pv' s1 ) + ** (sll qv' s2 ) + ** ((( &( "x" ) )) # Ptr |-> x_pre) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition merge_sort_entail_wit_1 := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (PreH1 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + (sll x_pre l_low_level_spec ) +|-- + “ (0 = 0) ” + && “ (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec ) ” + && (sll 0 (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +. + +Definition merge_sort_entail_wit_2 := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (PreH1 : (p = 0)) (PreH2 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + (sll p (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +|-- + “ (p = 0) ” + && “ (0 = 0) ” + && “ (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec ) ” + && (sll p (@nil Z) ) + ** (sll 0 (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +. + +Definition merge_sort_entail_wit_3 := +( +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (p = 0)) (PreH2 : (q = 0)) (PreH3 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + (sll p (@nil Z) ) + ** (sll q (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +|-- + “ (p = 0) ” + && “ (q = 0) ” + && “ (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec ) ” + && (sll p (@nil Z) ) + ** (sll q (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +) \/ +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (q = 0)) (PreH2 : (p = 0)) (PreH3 : (p = 0)) (PreH4 : (q = 0)) (PreH5 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + TT && emp +|-- + “ (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec ) ” + && emp +). + +Definition merge_sort_entail_wit_3_split_goal_1 := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (q = 0)) (PreH2 : (p = 0)) (PreH3 : (p = 0)) (PreH4 : (q = 0)) (PreH5 : (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec )) , + (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec ) +. + +Definition merge_sort_entail_wit_4 := +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (pv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' <> 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + (sll pv' s1 ) + ** (sll qv' s2 ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (qv' <> 0) ” + && “ (safeExec ATrue (bind ((mergesortrec (l1))) ((mergesortrec_loc1 (l2)))) X_low_level_spec ) ” + && (sll pv' l1 ) + ** (sll qv' l2 ) +) \/ +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' <> 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + TT && emp +|-- + “ (safeExec ATrue (bind ((mergesortrec (s1))) ((mergesortrec_loc1 (s2)))) X_low_level_spec ) ” + && emp +). + +Definition merge_sort_entail_wit_4_split_goal_1 := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' <> 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + (safeExec ATrue (bind ((mergesortrec (s1))) ((mergesortrec_loc1 (s2)))) X_low_level_spec ) +. + +Definition merge_sort_entail_wit_5 := +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l2_2: (@list Z)) (q: Z) (l0: (@list Z)) (retval: Z) (PreH1 : (safeExec ATrue (applyf ((mergesortrec_loc1 (l2_2))) (l0)) X_low_level_spec )) (PreH2 : (q <> 0)) , + (sll retval l0 ) + ** (sll q l2_2 ) +|-- + EX (l2: (@list Z)) (l1: (@list Z)) , + “ (q <> 0) ” + && “ (safeExec ATrue (bind ((mergesortrec (l2))) ((mergesortrec_loc2 (l1)))) X_low_level_spec ) ” + && (sll retval l1 ) + ** (sll q l2 ) +) \/ +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l2_2: (@list Z)) (q: Z) (l0: (@list Z)) (PreH1 : (safeExec ATrue (applyf ((mergesortrec_loc1 (l2_2))) (l0)) X_low_level_spec )) (PreH2 : (q <> 0)) , + TT && emp +|-- + “ (safeExec ATrue (bind ((mergesortrec (l2_2))) ((mergesortrec_loc2 (l0)))) X_low_level_spec ) ” + && emp +). + +Definition merge_sort_entail_wit_5_split_goal_1 := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l2_2: (@list Z)) (q: Z) (l0: (@list Z)) (PreH1 : (safeExec ATrue (applyf ((mergesortrec_loc1 (l2_2))) (l0)) X_low_level_spec )) (PreH2 : (q <> 0)) , + (safeExec ATrue (bind ((mergesortrec (l2_2))) ((mergesortrec_loc2 (l0)))) X_low_level_spec ) +. + +Definition merge_sort_entail_wit_6 := +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (q: Z) (p: Z) (l0: (@list Z)) (retval: Z) (PreH1 : (safeExec ATrue (applyf ((mergesortrec_loc2 (l1_2))) (l0)) X_low_level_spec )) (PreH2 : (q <> 0)) , + (sll retval l0 ) + ** (sll p l1_2 ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (safeExec ATrue (merge_rel (l1) (l2)) X_low_level_spec ) ” + && (sll p l1 ) + ** (sll retval l2 ) +) \/ +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (q: Z) (l0: (@list Z)) (PreH1 : (safeExec ATrue (applyf ((mergesortrec_loc2 (l1_2))) (l0)) X_low_level_spec )) (PreH2 : (q <> 0)) , + TT && emp +|-- + “ (safeExec ATrue (merge_rel (l1_2) (l0)) X_low_level_spec ) ” + && emp +). + +Definition merge_sort_entail_wit_6_split_goal_1 := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1_2: (@list Z)) (q: Z) (l0: (@list Z)) (PreH1 : (safeExec ATrue (applyf ((mergesortrec_loc2 (l1_2))) (l0)) X_low_level_spec )) (PreH2 : (q <> 0)) , + (safeExec ATrue (merge_rel (l1_2) (l0)) X_low_level_spec ) +. + +Definition merge_sort_return_wit_1 := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (s3: (@list Z)) (retval: Z) (PreH1 : (safeExec ATrue (return (s3)) X_low_level_spec )) , + (sll retval s3 ) +|-- + EX (l0: (@list Z)) , + “ (safeExec ATrue (return (l0)) X_low_level_spec ) ” + && (sll retval l0 ) +. + +Definition merge_sort_return_wit_2 := +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (pv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' = 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + (sll pv' s1 ) + ** (sll qv' s2 ) +|-- + EX (l0: (@list Z)) , + “ (safeExec ATrue (return (l0)) X_low_level_spec ) ” + && (sll pv' l0 ) +) \/ +( +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' = 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + (sll qv' s2 ) +|-- + “ (safeExec ATrue (return (s1)) X_low_level_spec ) ” + && emp +). + +Definition merge_sort_return_wit_2_split_goal_1 := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' = 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + (sll qv' s2 ) +|-- + “ (safeExec ATrue (return (s1)) X_low_level_spec ) ” +. + +Definition merge_sort_return_wit_2_split_goal_spatial := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (p: Z) (q: Z) (qv': Z) (s1: (@list Z)) (s2: (@list Z)) (PreH1 : (qv' = 0)) (PreH2 : (safeExec ATrue (applyf (mergesortrec_loc0) ((maketuple (s1) (s2)))) X_low_level_spec )) (PreH3 : (q = 0)) (PreH4 : (p = 0)) (PreH5 : (p = 0)) (PreH6 : (q = 0)) , + (sll qv' s2 ) +|-- + TT && emp +. + +Definition merge_sort_partial_solve_wit_1_pure := +( +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (p = 0)) (PreH2 : (q = 0)) (PreH3 : (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((( &( "q" ) )) # Ptr |-> q) + ** (sll p (@nil Z) ) + ** (sll q (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_low_level_spec) ((@nil Z)) ((@nil Z)))) (mergesortrec_loc0)) X_low_level_spec ) ” +) \/ +( +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (q = 0)) (PreH2 : (p = 0)) (PreH3 : (p = 0)) (PreH4 : (q = 0)) (PreH5 : (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((( &( "q" ) )) # Ptr |-> q) + ** (sll x_pre l_low_level_spec ) +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_low_level_spec) ((@nil Z)) ((@nil Z)))) (mergesortrec_loc0)) X_low_level_spec ) ” +). + +Definition merge_sort_partial_solve_wit_1_pure_split_goal_1 := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (q = 0)) (PreH2 : (p = 0)) (PreH3 : (p = 0)) (PreH4 : (q = 0)) (PreH5 : (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((( &( "q" ) )) # Ptr |-> q) + ** (sll x_pre l_low_level_spec ) +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_low_level_spec) ((@nil Z)) ((@nil Z)))) (mergesortrec_loc0)) X_low_level_spec ) ” +. + +Definition merge_sort_partial_solve_wit_1_aux := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l_low_level_spec: (@list Z)) (p: Z) (q: Z) (PreH1 : (p = 0)) (PreH2 : (q = 0)) (PreH3 : (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec )) , + (sll p (@nil Z) ) + ** (sll q (@nil Z) ) + ** (sll x_pre l_low_level_spec ) +|-- + “ (safeExec ATrue (bind ((split_rec_rel (l_low_level_spec) ((@nil Z)) ((@nil Z)))) (mergesortrec_loc0)) X_low_level_spec ) ” + && “ (q = 0) ” + && “ (p = 0) ” + && “ (p = 0) ” + && “ (q = 0) ” + && “ (safeExec ATrue (bind ((split_rel (l_low_level_spec))) (mergesortrec_loc0)) X_low_level_spec ) ” + && (sll x_pre l_low_level_spec ) + ** (sll p (@nil Z) ) + ** (sll q (@nil Z) ) +. + +Definition merge_sort_partial_solve_wit_1 := merge_sort_partial_solve_wit_1_pure -> merge_sort_partial_solve_wit_1_aux. + +Definition merge_sort_partial_solve_wit_2_pure := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1: (@list Z)) (l2: (@list Z)) (q: Z) (p: Z) (PreH1 : (q <> 0)) (PreH2 : (safeExec ATrue (bind ((mergesortrec (l1))) ((mergesortrec_loc1 (l2)))) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "q" ) )) # Ptr |-> q) + ** ((( &( "p" ) )) # Ptr |-> p) + ** (sll p l1 ) + ** (sll q l2 ) +|-- + “ (safeExec ATrue (bind ((mergesortrec (l1))) ((mergesortrec_loc1 (l2)))) X_low_level_spec ) ” +. + +Definition merge_sort_partial_solve_wit_2_aux := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1: (@list Z)) (l2: (@list Z)) (q: Z) (p: Z) (PreH1 : (q <> 0)) (PreH2 : (safeExec ATrue (bind ((mergesortrec (l1))) ((mergesortrec_loc1 (l2)))) X_low_level_spec )) , + (sll p l1 ) + ** (sll q l2 ) +|-- + “ (safeExec ATrue (bind ((mergesortrec (l1))) ((mergesortrec_loc1 (l2)))) X_low_level_spec ) ” + && “ (q <> 0) ” + && “ (safeExec ATrue (bind ((mergesortrec (l1))) ((mergesortrec_loc1 (l2)))) X_low_level_spec ) ” + && (sll p l1 ) + ** (sll q l2 ) +. + +Definition merge_sort_partial_solve_wit_2 := merge_sort_partial_solve_wit_2_pure -> merge_sort_partial_solve_wit_2_aux. + +Definition merge_sort_partial_solve_wit_3_pure := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1: (@list Z)) (l2: (@list Z)) (q: Z) (p: Z) (PreH1 : (q <> 0)) (PreH2 : (safeExec ATrue (bind ((mergesortrec (l2))) ((mergesortrec_loc2 (l1)))) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "q" ) )) # Ptr |-> q) + ** ((( &( "p" ) )) # Ptr |-> p) + ** (sll p l1 ) + ** (sll q l2 ) +|-- + “ (safeExec ATrue (bind ((mergesortrec (l2))) ((mergesortrec_loc2 (l1)))) X_low_level_spec ) ” +. + +Definition merge_sort_partial_solve_wit_3_aux := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1: (@list Z)) (l2: (@list Z)) (q: Z) (p: Z) (PreH1 : (q <> 0)) (PreH2 : (safeExec ATrue (bind ((mergesortrec (l2))) ((mergesortrec_loc2 (l1)))) X_low_level_spec )) , + (sll p l1 ) + ** (sll q l2 ) +|-- + “ (safeExec ATrue (bind ((mergesortrec (l2))) ((mergesortrec_loc2 (l1)))) X_low_level_spec ) ” + && “ (q <> 0) ” + && “ (safeExec ATrue (bind ((mergesortrec (l2))) ((mergesortrec_loc2 (l1)))) X_low_level_spec ) ” + && (sll q l2 ) + ** (sll p l1 ) +. + +Definition merge_sort_partial_solve_wit_3 := merge_sort_partial_solve_wit_3_pure -> merge_sort_partial_solve_wit_3_aux. + +Definition merge_sort_partial_solve_wit_4_pure := +forall (x_pre: Z) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1: (@list Z)) (l2: (@list Z)) (p: Z) (q: Z) (PreH1 : (safeExec ATrue (merge_rel (l1) (l2)) X_low_level_spec )) , + ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> p) + ** (sll p l1 ) + ** ((( &( "q" ) )) # Ptr |-> q) + ** (sll q l2 ) +|-- + “ (safeExec ATrue (merge_rel (l1) (l2)) X_low_level_spec ) ” +. + +Definition merge_sort_partial_solve_wit_4_aux := +forall (X_low_level_spec: ((@list Z) -> (unit -> Prop))) (l1: (@list Z)) (l2: (@list Z)) (p: Z) (q: Z) (PreH1 : (safeExec ATrue (merge_rel (l1) (l2)) X_low_level_spec )) , + (sll p l1 ) + ** (sll q l2 ) +|-- + “ (safeExec ATrue (merge_rel (l1) (l2)) X_low_level_spec ) ” + && “ (safeExec ATrue (merge_rel (l1) (l2)) X_low_level_spec ) ” + && (sll p l1 ) + ** (sll q l2 ) +. + +Definition merge_sort_partial_solve_wit_4 := merge_sort_partial_solve_wit_4_pure -> merge_sort_partial_solve_wit_4_aux. + +Definition merge_sort_derive_low_level_spec_aux_by_low_level_spec := +forall (B: Type) , +forall (x_pre: Z) (X_low_level_spec_aux: (B -> (unit -> Prop))) (c_low_level_spec_aux: ((@list Z) -> (@ StateRelMonad.M unit B))) (l_low_level_spec_aux: (@list Z)) , + “ (safeExec ATrue (bind ((mergesortrec (l_low_level_spec_aux))) (c_low_level_spec_aux)) X_low_level_spec_aux ) ” + && (sll x_pre l_low_level_spec_aux ) +|-- +EX (l_low_level_spec: (@list Z)) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) , + (“ (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec ) ” + && (sll x_pre l_low_level_spec )) + ** + ((EX l0_2 retval_2, + “ (safeExec ATrue (return (l0_2)) X_low_level_spec ) ” + && (sll retval_2 l0_2 )) + -* + (EX l0 retval, + “ (safeExec ATrue (applyf (c_low_level_spec_aux) (l0)) X_low_level_spec_aux ) ” + && (sll retval l0 ))) +. + +Definition merge_sort_derive_high_level_spec_by_low_level_spec := +forall (x_pre: Z) (l_high_level_spec: (@list Z)) , + (sll x_pre l_high_level_spec ) +|-- +EX (l_low_level_spec: (@list Z)) (X_low_level_spec: ((@list Z) -> (unit -> Prop))) , + (“ (safeExec ATrue (mergesortrec (l_low_level_spec)) X_low_level_spec ) ” + && (sll x_pre l_low_level_spec )) + ** + ((EX l0_2 retval_2, + “ (safeExec ATrue (return (l0_2)) X_low_level_spec ) ” + && (sll retval_2 l0_2 )) + -* + (EX l0 retval, + “ (Permutation l_high_level_spec l0 ) ” + && “ (incr l0 ) ” + && (sll retval l0 ))) +. + +Definition split_rec_derive_low_level_spec_aux_by_low_level_spec := +forall (B: Type) , +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_low_level_spec_aux: Z) (pv_low_level_spec_aux: Z) (X_low_level_spec_aux: (B -> (unit -> Prop))) (c_low_level_spec_aux: (((@list Z) * (@list Z)) -> (@ StateRelMonad.M unit B))) (l2_low_level_spec_aux: (@list Z)) (l1_low_level_spec_aux: (@list Z)) (l_low_level_spec_aux: (@list Z)) , + “ (safeExec ATrue (bind ((split_rec_rel (l_low_level_spec_aux) (l1_low_level_spec_aux) (l2_low_level_spec_aux))) (c_low_level_spec_aux)) X_low_level_spec_aux ) ” + && ((p_pre) # Ptr |-> pv_low_level_spec_aux) + ** ((q_pre) # Ptr |-> qv_low_level_spec_aux) + ** (sll x_pre l_low_level_spec_aux ) + ** (sll pv_low_level_spec_aux l1_low_level_spec_aux ) + ** (sll qv_low_level_spec_aux l2_low_level_spec_aux ) +|-- +EX (l_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l2_low_level_spec: (@list Z)) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (pv_low_level_spec: Z) (qv_low_level_spec: Z) , + (“ (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec ) ” + && ((p_pre) # Ptr |-> pv_low_level_spec) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre l_low_level_spec ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec )) + ** + ((EX qv'_2 pv'_2 s1_2 s2_2, + “ (safeExec ATrue (return ((maketuple (s1_2) (s2_2)))) X_low_level_spec ) ” + && ((p_pre) # Ptr |-> pv'_2) + ** ((q_pre) # Ptr |-> qv'_2) + ** (sll pv'_2 s1_2 ) + ** (sll qv'_2 s2_2 )) + -* + (EX qv' pv' s1 s2, + “ (safeExec ATrue (applyf (c_low_level_spec_aux) ((maketuple (s1) (s2)))) X_low_level_spec_aux ) ” + && ((p_pre) # Ptr |-> pv') + ** ((q_pre) # Ptr |-> qv') + ** (sll pv' s1 ) + ** (sll qv' s2 ))) +. + +Definition split_rec_derive_high_level_spec_by_low_level_spec := +forall (q_pre: Z) (p_pre: Z) (x_pre: Z) (qv_high_level_spec: Z) (pv_high_level_spec: Z) (X_high_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (l_high_level_spec: (@list Z)) , + “ (safeExec ATrue (split_rel (l_high_level_spec)) X_high_level_spec ) ” + && ((p_pre) # Ptr |-> pv_high_level_spec) + ** ((q_pre) # Ptr |-> qv_high_level_spec) + ** (sll x_pre l_high_level_spec ) + ** (sll pv_high_level_spec nil ) + ** (sll qv_high_level_spec nil ) +|-- +EX (l_low_level_spec: (@list Z)) (l1_low_level_spec: (@list Z)) (l2_low_level_spec: (@list Z)) (X_low_level_spec: (((@list Z) * (@list Z)) -> (unit -> Prop))) (pv_low_level_spec: Z) (qv_low_level_spec: Z) , + (“ (safeExec ATrue (split_rec_rel (l_low_level_spec) (l1_low_level_spec) (l2_low_level_spec)) X_low_level_spec ) ” + && ((p_pre) # Ptr |-> pv_low_level_spec) + ** ((q_pre) # Ptr |-> qv_low_level_spec) + ** (sll x_pre l_low_level_spec ) + ** (sll pv_low_level_spec l1_low_level_spec ) + ** (sll qv_low_level_spec l2_low_level_spec )) + ** + ((EX qv'_2 pv'_2 s1_2 s2_2, + “ (safeExec ATrue (return ((maketuple (s1_2) (s2_2)))) X_low_level_spec ) ” + && ((p_pre) # Ptr |-> pv'_2) + ** ((q_pre) # Ptr |-> qv'_2) + ** (sll pv'_2 s1_2 ) + ** (sll qv'_2 s2_2 )) + -* + (EX qv' pv' s1 s2, + “ (safeExec ATrue (return ((maketuple (s1) (s2)))) X_high_level_spec ) ” + && ((p_pre) # Ptr |-> pv') + ** ((q_pre) # Ptr |-> qv') + ** (sll pv' s1 ) + ** (sll qv' s2 ))) +. + +Module Type VC_Correct. + +Include sll_Strategy_Correct. +Include safeexec_Strategy_Correct. + +Axiom proof_of_merge_safety_wit_1 : merge_safety_wit_1. +Axiom proof_of_merge_safety_wit_2 : merge_safety_wit_2. +Axiom proof_of_merge_safety_wit_3 : merge_safety_wit_3. +Axiom proof_of_merge_entail_wit_1 : merge_entail_wit_1. +Axiom proof_of_merge_entail_wit_2 : merge_entail_wit_2. +Axiom proof_of_merge_entail_wit_3_1 : merge_entail_wit_3_1. +Axiom proof_of_merge_entail_wit_3_2 : merge_entail_wit_3_2. +Axiom proof_of_merge_entail_wit_4_1 : merge_entail_wit_4_1. +Axiom proof_of_merge_entail_wit_4_2 : merge_entail_wit_4_2. +Axiom proof_of_merge_return_wit_1 : merge_return_wit_1. +Axiom proof_of_split_rec_safety_wit_1 : split_rec_safety_wit_1. +Axiom proof_of_split_rec_entail_wit_1 : split_rec_entail_wit_1. +Axiom proof_of_split_rec_entail_wit_2 : split_rec_entail_wit_2. +Axiom proof_of_split_rec_return_wit_1 : split_rec_return_wit_1. +Axiom proof_of_split_rec_return_wit_2 : split_rec_return_wit_2. +Axiom proof_of_split_rec_partial_solve_wit_1_pure : split_rec_partial_solve_wit_1_pure. +Axiom proof_of_split_rec_partial_solve_wit_1 : split_rec_partial_solve_wit_1. +Axiom proof_of_merge_sort_safety_wit_1 : merge_sort_safety_wit_1. +Axiom proof_of_merge_sort_safety_wit_2 : merge_sort_safety_wit_2. +Axiom proof_of_merge_sort_safety_wit_3 : merge_sort_safety_wit_3. +Axiom proof_of_merge_sort_entail_wit_1 : merge_sort_entail_wit_1. +Axiom proof_of_merge_sort_entail_wit_2 : merge_sort_entail_wit_2. +Axiom proof_of_merge_sort_entail_wit_3 : merge_sort_entail_wit_3. +Axiom proof_of_merge_sort_entail_wit_4 : merge_sort_entail_wit_4. +Axiom proof_of_merge_sort_entail_wit_5 : merge_sort_entail_wit_5. +Axiom proof_of_merge_sort_entail_wit_6 : merge_sort_entail_wit_6. +Axiom proof_of_merge_sort_return_wit_1 : merge_sort_return_wit_1. +Axiom proof_of_merge_sort_return_wit_2 : merge_sort_return_wit_2. +Axiom proof_of_merge_sort_partial_solve_wit_1_pure : merge_sort_partial_solve_wit_1_pure. +Axiom proof_of_merge_sort_partial_solve_wit_1 : merge_sort_partial_solve_wit_1. +Axiom proof_of_merge_sort_partial_solve_wit_2_pure : merge_sort_partial_solve_wit_2_pure. +Axiom proof_of_merge_sort_partial_solve_wit_2 : merge_sort_partial_solve_wit_2. +Axiom proof_of_merge_sort_partial_solve_wit_3_pure : merge_sort_partial_solve_wit_3_pure. +Axiom proof_of_merge_sort_partial_solve_wit_3 : merge_sort_partial_solve_wit_3. +Axiom proof_of_merge_sort_partial_solve_wit_4_pure : merge_sort_partial_solve_wit_4_pure. +Axiom proof_of_merge_sort_partial_solve_wit_4 : merge_sort_partial_solve_wit_4. +Axiom proof_of_merge_sort_derive_low_level_spec_aux_by_low_level_spec : merge_sort_derive_low_level_spec_aux_by_low_level_spec. +Axiom proof_of_merge_sort_derive_high_level_spec_by_low_level_spec : merge_sort_derive_high_level_spec_by_low_level_spec. +Axiom proof_of_split_rec_derive_low_level_spec_aux_by_low_level_spec : split_rec_derive_low_level_spec_aux_by_low_level_spec. +Axiom proof_of_split_rec_derive_high_level_spec_by_low_level_spec : split_rec_derive_high_level_spec_by_low_level_spec. + +End VC_Correct. diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_goal_check.v b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..b2cec93c7af76820ad881ad2c8b9e39d21d86255 --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_goal_check.v @@ -0,0 +1,8 @@ +From PVbench.Algorithms.sll_merge_sort.rocq.groundtruth Require Import sll_merge_sort_goal sll_merge_sort_proof_auto sll_merge_sort_proof_manual. + +Module VC_Correctness : VC_Correct. + Include sll_strategy_proof. + Include safeexec_strategy_proof. + Include sll_merge_sort_proof_auto. + Include sll_merge_sort_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_proof_auto.v b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..e3f721916b4018e83d127ffae7e67851a5d6e3c7 --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_proof_auto.v @@ -0,0 +1,96 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.sll_merge_sort.rocq.groundtruth Require Import sll_merge_sort_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +From MonadLib Require Export MonadLib. +From MonadLib.StateRelMonad Require Export StateRelMonad. +Export MonadNotation. +Local Open Scope monad. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap relations. +From FP Require Import PartialOrder_Setoid BourbakiWitt. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.spec_lib. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.helper_lib. +Local Open Scope sac. + +Lemma proof_of_merge_safety_wit_1 : merge_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_merge_safety_wit_2 : merge_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_merge_safety_wit_3 : merge_safety_wit_3. +Proof. Admitted. + +Lemma proof_of_merge_entail_wit_2 : merge_entail_wit_2. +Proof. Admitted. + +Lemma proof_of_merge_return_wit_1 : merge_return_wit_1. +Proof. Admitted. + +Lemma proof_of_split_rec_safety_wit_1 : split_rec_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_split_rec_entail_wit_1 : split_rec_entail_wit_1. +Proof. Admitted. + +Lemma proof_of_split_rec_partial_solve_wit_1_pure : split_rec_partial_solve_wit_1_pure. +Proof. Admitted. + +Lemma proof_of_split_rec_partial_solve_wit_1 : split_rec_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_merge_sort_safety_wit_1 : merge_sort_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_merge_sort_safety_wit_2 : merge_sort_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_merge_sort_safety_wit_3 : merge_sort_safety_wit_3. +Proof. Admitted. + +Lemma proof_of_merge_sort_entail_wit_1 : merge_sort_entail_wit_1. +Proof. Admitted. + +Lemma proof_of_merge_sort_entail_wit_2 : merge_sort_entail_wit_2. +Proof. Admitted. + +Lemma proof_of_merge_sort_return_wit_1 : merge_sort_return_wit_1. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_1 : merge_sort_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_2_pure : merge_sort_partial_solve_wit_2_pure. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_2 : merge_sort_partial_solve_wit_2. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_3_pure : merge_sort_partial_solve_wit_3_pure. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_3 : merge_sort_partial_solve_wit_3. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_4_pure : merge_sort_partial_solve_wit_4_pure. +Proof. Admitted. + +Lemma proof_of_merge_sort_partial_solve_wit_4 : merge_sort_partial_solve_wit_4. +Proof. Admitted. + diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_proof_manual.v b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..6499d507004100fbce4ee0fdd0473e75be188d10 --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/groundtruth/sll_merge_sort_proof_manual.v @@ -0,0 +1,421 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Algorithms.sll_merge_sort.rocq.groundtruth Require Import sll_merge_sort_goal. +From PVbench.Algorithms.sll_merge_sort.rocq.groundtruth Require Import sll_merge_sort_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +From MonadLib Require Export MonadLib. +From MonadLib.StateRelMonad Require Export StateRelMonad. +Export MonadNotation. +Local Open Scope monad. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap relations. +From FP Require Import PartialOrder_Setoid BourbakiWitt. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.helper_lib. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Algorithms.sll_merge_sort.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_merge_entail_wit_1 : merge_entail_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists s1. Exists s2. Exists (@nil Z). + repeat (split_pure_spatial || split_pures). + + cancel (sll x_pre s1). + cancel (sll y_pre s2). + cancel (((&( "ret" ))) # Ptr |->_). + simpl. + split_pure_spatial. + - cancel. + - dump_pre_spatial. reflexivity. + + dump_pre_spatial. + unfold merge_rel, merge_from_mid_rel. + exact PreH1. +Qed. + +Lemma proof_of_merge_entail_wit_3_1 : merge_entail_wit_3_1. +Proof. + LLM_pre_process ltac:(int_auto). + Exists l1_new. Exists (ydata :: l2_new). Exists (l3_2 ++ (xdata :: nil))%list. + simpl sll. Exists ynext. + repeat (split_pure_spatial || split_pures). + + cancel (&((y) # "list" ->ₛ"data") # Int |-> ydata). + cancel (&((y) # "list" ->ₛ"next") # Ptr |-> ynext). + cancel (sll ynext l2_new). + cancel (sll xnext l1_new). + sep_apply_l_atomic (sllbseg_len1 t x xdata). + * dump_pre_spatial. exact PreH3. + * sep_apply_l_atomic (store_ptr_undef_store_ptr (&((x) # "list" ->ₛ"next")) xnext). + cancel (&((x) # "list" ->ₛ"next") # Ptr |->_). + sep_apply_l_atomic (sllbseg_sllbseg (&( "ret")) t (&((x) # "list" ->ₛ"next")) l3_2 (xdata :: nil)). + cancel (sllbseg (&( "ret")) (&((x) # "list" ->ₛ"next")) (l3_2 ++ (xdata :: nil))%list). + + dump_pre_spatial. + rewrite PreH5 in PreH2. + rewrite PreH6 in PreH2. + unfold merge_from_mid_rel in PreH2 at 1. + prog_nf in PreH2. + unfold_loop in PreH2. + prog_nf in PreH2. + unfold merge_body in PreH2 at 1. + prog_nf in PreH2. + safe_choice_l PreH2; try lia. + exact PreH2. + + dump_pre_spatial. exact PreH4. +Qed. + +Lemma proof_of_merge_entail_wit_3_2 : merge_entail_wit_3_2. +Proof. + LLM_pre_process ltac:(int_auto). + Exists (xdata :: l1_new). Exists l2_new. Exists (l3_2 ++ (ydata :: nil))%list. + simpl sll. Exists xnext. + repeat (split_pure_spatial || split_pures). + + cancel (&((x) # "list" ->ₛ"data") # Int |-> xdata). + cancel (&((x) # "list" ->ₛ"next") # Ptr |-> xnext). + cancel (sll xnext l1_new). + cancel (sll ynext l2_new). + sep_apply_l_atomic (sllbseg_len1 t y ydata). + * dump_pre_spatial. exact PreH4. + * sep_apply_l_atomic (store_ptr_undef_store_ptr (&((y) # "list" ->ₛ"next")) ynext). + cancel (&((y) # "list" ->ₛ"next") # Ptr |->_). + sep_apply_l_atomic (sllbseg_sllbseg (&( "ret")) t (&((y) # "list" ->ₛ"next")) l3_2 (ydata :: nil)). + cancel (sllbseg (&( "ret")) (&((y) # "list" ->ₛ"next")) (l3_2 ++ (ydata :: nil))%list). + + dump_pre_spatial. + rewrite PreH5 in PreH2. + rewrite PreH6 in PreH2. + unfold merge_from_mid_rel in PreH2 at 1. + prog_nf in PreH2. + unfold_loop in PreH2. + prog_nf in PreH2. + unfold merge_body in PreH2 at 1. + prog_nf in PreH2. + safe_choice_r PreH2; try lia. + exact PreH2. + + dump_pre_spatial. exact PreH3. +Qed. + +Lemma proof_of_merge_entail_wit_4_1 : merge_entail_wit_4_1. +Proof. + LLM_pre_process ltac:(int_auto). + subst x. + sep_apply_l_atomic (sll_zero 0 l1). + * dump_pre_spatial. reflexivity. + * Intros_p Hl1nil. + subst l1. + sep_apply_l_atomic (sllbseg_2_sllseg (&( "ret")) t y l3). + Intros ret. + Exists ret. Exists (l3 ++ l2). + repeat (split_pure_spatial || split_pures). + + cancel (&( "ret") # Ptr |-> ret). + sep_apply_l_atomic (sllseg_sll ret y l3 l2). + cancel (sll ret (l3 ++ l2)). + + dump_pre_spatial. + unfold merge_from_mid_rel in PreH2 at 1. + prog_nf in PreH2. + unfold_loop in PreH2. + prog_nf in PreH2. + unfold merge_body in PreH2 at 1. + prog_nf in PreH2. + exact PreH2. +Qed. + +Lemma proof_of_merge_entail_wit_4_2 : merge_entail_wit_4_2. +Proof. + LLM_pre_process ltac:(int_auto). + subst y. + sep_apply_l_atomic (sll_zero 0 l2). + * dump_pre_spatial. reflexivity. + * Intros_p Hl2nil. + subst l2. + sep_apply_l_atomic (sllbseg_2_sllseg (&( "ret")) t x l3). + Intros ret. + Exists ret. Exists (l3 ++ l1). + repeat (split_pure_spatial || split_pures). + + cancel (&( "ret") # Ptr |-> ret). + sep_apply_l_atomic (sllseg_sll ret x l3 l1). + cancel (sll ret (l3 ++ l1)). + + dump_pre_spatial. + unfold merge_from_mid_rel in PreH3 at 1. + prog_nf in PreH3. + unfold_loop in PreH3. + prog_nf in PreH3. + unfold merge_body in PreH3 at 1. + destruct l1 as [|h tl]; prog_nf in PreH3; exact PreH3. +Qed. + +Lemma proof_of_split_rec_return_wit_2 : split_rec_return_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists pv'_2. Exists qv'_2. Exists s2_2. Exists s1_2. + repeat (split_pure_spatial || split_pures). + + cancel ((q_pre) # Ptr |-> pv'_2). + cancel (sll pv'_2 s1_2). + cancel ((p_pre) # Ptr |-> qv'_2). + cancel (sll qv'_2 s2_2). + + dump_pre_spatial. + unfold reversepair, applyf. + exact PreH1. +Qed. + +Lemma proof_of_split_rec_return_wit_1 : split_rec_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst x_pre. + sep_apply_l_atomic (sll_zero 0 l_low_level_spec). + * dump_pre_spatial. reflexivity. + * Intros_p Hlnil. + subst l_low_level_spec. + Exists qv_low_level_spec. Exists pv_low_level_spec. Exists l1_low_level_spec. Exists l2_low_level_spec. + repeat (split_pure_spatial || split_pures). + + cancel ((p_pre) # Ptr |-> pv_low_level_spec). + cancel (sll pv_low_level_spec l1_low_level_spec). + cancel ((q_pre) # Ptr |-> qv_low_level_spec). + cancel (sll qv_low_level_spec l2_low_level_spec). + + dump_pre_spatial. + unfold split_rec_rel in PreH2. + rewrite (split_rec_rel_unfold (nil, l1_low_level_spec, l2_low_level_spec)) in PreH2. + simpl in PreH2. + exact PreH2. +Qed. + +Lemma proof_of_split_rec_entail_wit_2 : split_rec_entail_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists l_new_2. Exists x_data_2. + repeat (split_pure_spatial || split_pures). + + cancel ((q_pre) # Ptr |-> qv_low_level_spec). + cancel (sll qv_low_level_spec l2_low_level_spec). + cancel (sll x_next l_new_2). + simpl sll. + Exists pv_low_level_spec. + split_pure_spatial. + - cancel (&((x_pre) # "list" ->ₛ"data") # Int |-> x_data_2). + cancel (&((x_pre) # "list" ->ₛ"next") # Ptr |-> pv_low_level_spec). + cancel (sll pv_low_level_spec l1_low_level_spec). + cancel. + - dump_pre_spatial. exact PreH1. + + dump_pre_spatial. exact PreH1. + + dump_pre_spatial. + rewrite PreH3 in PreH2. + unfold split_rec_rel in PreH2. + rewrite (split_rec_rel_unfold (x_data_2 :: l_new_2, l1_low_level_spec, l2_low_level_spec)) in PreH2. + simpl in PreH2. + exact PreH2. + + dump_pre_spatial. exact PreH3. +Qed. + +Lemma proof_of_merge_sort_partial_solve_wit_1_pure : merge_sort_partial_solve_wit_1_pure. +Proof. + left. + LLM_pre_process ltac:(int_auto). +Qed. + +Lemma proof_of_merge_sort_entail_wit_3 : merge_sort_entail_wit_3. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst p. subst q. + simpl sll. + repeat (split_pure_spatial || split_pures). + + Intros_p Hp0. Intros_p Hq0. cancel. + + dump_pre_spatial. reflexivity. + + dump_pre_spatial. reflexivity. + + dump_pre_spatial. + unfold mergesortrec in PreH3 at 1. + erewrite (program_para_equiv (mergesortrec_unfold)) in PreH3. + unfold mergesortrec_f, mergesortrec_loc0 in PreH3. + exact PreH3. + + dump_pre_spatial. reflexivity. + + dump_pre_spatial. reflexivity. +Qed. + +Lemma proof_of_merge_sort_entail_wit_4 : merge_sort_entail_wit_4. +Proof. + left. + LLM_pre_process ltac:(int_auto). + sep_apply_l_atomic (sll_not_zero qv' s2). + - dump_pre_spatial. exact PreH1. + - Intros q_next. Intros h. Intros t. + Exists s1. Exists (h :: t). + repeat (split_pure_spatial || split_pures). + + cancel (sll pv' s1). + simpl. + Exists q_next. + repeat (split_pure_spatial || split_pures). + * cancel (&(qv' # "list" ->ₛ"data") # Int |-> h). + cancel (&(qv' # "list" ->ₛ"next") # Ptr |-> q_next). + cancel (sll q_next t). + * dump_pre_spatial. exact PreH1. + + dump_pre_spatial. exact PreH1. + + dump_pre_spatial. + unfold applyf, maketuple, mergesortrec_loc0 in PreH2. + rewrite H in PreH2. + simpl in PreH2. exact PreH2. +Qed. + +Lemma proof_of_merge_sort_entail_wit_5 : merge_sort_entail_wit_5. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists l2_2. Exists l0. + repeat (split_pure_spatial || split_pures). + + cancel (sll retval l0). + cancel (sll q l2_2). + + dump_pre_spatial. exact PreH2. + + dump_pre_spatial. + unfold applyf, mergesortrec_loc1 in PreH1. + unfold mergesortrec_loc2. + exact PreH1. +Qed. + +Lemma proof_of_merge_sort_entail_wit_6 : merge_sort_entail_wit_6. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists l1_2. Exists l0. + repeat (split_pure_spatial || split_pures). + + cancel (sll retval l0). + cancel (sll p l1_2). + + dump_pre_spatial. + unfold applyf in PreH1 at 1. + unfold mergesortrec_loc2 in PreH1 at 1. + prog_nf in PreH1. + exact PreH1. +Qed. + +Lemma proof_of_merge_sort_return_wit_2 : merge_sort_return_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + sep_apply_l_atomic (sll_zero qv' s2). + * dump_pre_spatial. rewrite PreH1. reflexivity. + * Intros_p Hs2nil. + subst s2. + Exists s1. + repeat (split_pure_spatial || split_pures). + + cancel (sll pv' s1). + + dump_pre_spatial. + unfold applyf, maketuple, mergesortrec_loc0. + simpl. + exact PreH2. +Qed. + +Lemma proof_of_merge_sort_derive_low_level_spec_aux_by_low_level_spec : merge_sort_derive_low_level_spec_aux_by_low_level_spec. +Proof. + LLM_pre_process ltac:(int_auto). + apply safeExec_bind in H as (X_low_level_spec & Hsafe_first & Hsafe_cont). + Exists l_low_level_spec_aux. + Exists X_low_level_spec. + split_pure_spatial. + + cancel (sll x_pre l_low_level_spec_aux). + apply derivable1_wand_sepcon_adjoint. + Intros l0_2. Intros retval_2. + Exists l0_2. Exists retval_2. + repeat (split_pure_spatial || split_pures). + - cancel (sll retval_2 l0_2). + - dump_pre_spatial. + apply (Hsafe_cont ATrue l0_2). + exact H. + + dump_pre_spatial. exact Hsafe_first. +Qed. + +Lemma proof_of_merge_sort_derive_high_level_spec_by_low_level_spec : merge_sort_derive_high_level_spec_by_low_level_spec. +Proof. + LLM_pre_process ltac:(int_auto). + Exists l_high_level_spec. + Exists (fun l0 _ => Permutation l_high_level_spec l0 /\ incr l0). + split_pure_spatial. + + cancel (sll x_pre l_high_level_spec). + apply derivable1_wand_sepcon_adjoint. + Intros l0_2. Intros retval_2. + Exists l0_2. Exists retval_2. + repeat (split_pure_spatial || split_pures). + - cancel (sll retval_2 l0_2). + - dump_pre_spatial. + apply safeExec_ret in H as (? & _ & Hret). + sets_unfold in Hret. + exact (proj1 Hret). + - dump_pre_spatial. + apply safeExec_ret in H as (? & _ & Hret). + sets_unfold in Hret. + exact (proj2 Hret). + + dump_pre_spatial. + eapply safeExec_X_subset. + - apply Hoare_result_state. + apply functional_correctness_mergesort. + - apply safeExec_result_state. + exists tt. exact I. +Qed. + +Lemma proof_of_split_rec_derive_low_level_spec_aux_by_low_level_spec : split_rec_derive_low_level_spec_aux_by_low_level_spec. +Proof. + LLM_pre_process ltac:(int_auto). + apply safeExec_bind in H as (X_low_level_spec & Hsafe_first & Hsafe_cont). + Exists l_low_level_spec_aux. Exists l1_low_level_spec_aux. Exists l2_low_level_spec_aux. + Exists X_low_level_spec. + Exists pv_low_level_spec_aux. Exists qv_low_level_spec_aux. + split_pure_spatial. + + cancel (sll x_pre l_low_level_spec_aux). + cancel ((p_pre) # Ptr |-> pv_low_level_spec_aux). + cancel (sll pv_low_level_spec_aux l1_low_level_spec_aux). + cancel ((q_pre) # Ptr |-> qv_low_level_spec_aux). + cancel (sll qv_low_level_spec_aux l2_low_level_spec_aux). + apply derivable1_wand_sepcon_adjoint. + Intros qv'_2. Intros pv'_2. Intros s1_2. Intros s2_2. + Exists qv'_2. Exists pv'_2. Exists s1_2. Exists s2_2. + repeat (split_pure_spatial || split_pures). + - cancel ((p_pre) # Ptr |-> pv'_2). + cancel (sll pv'_2 s1_2). + cancel ((q_pre) # Ptr |-> qv'_2). + cancel (sll qv'_2 s2_2). + - dump_pre_spatial. + unfold applyf, maketuple. + apply (Hsafe_cont ATrue (s1_2, s2_2)). + exact H. + + dump_pre_spatial. exact Hsafe_first. +Qed. + +Lemma proof_of_split_rec_derive_high_level_spec_by_low_level_spec : split_rec_derive_high_level_spec_by_low_level_spec. +Proof. + LLM_pre_process ltac:(int_auto). + Exists l_high_level_spec. Exists (@nil Z). Exists (@nil Z). + Exists X_high_level_spec. + Exists pv_high_level_spec. Exists qv_high_level_spec. + split_pure_spatial. + + cancel (sll x_pre l_high_level_spec). + cancel ((p_pre) # Ptr |-> pv_high_level_spec). + cancel (sll pv_high_level_spec (@nil Z)). + cancel ((q_pre) # Ptr |-> qv_high_level_spec). + cancel (sll qv_high_level_spec (@nil Z)). + apply derivable1_wand_sepcon_adjoint. + Intros qv'_2. Intros pv'_2. Intros s1_2. Intros s2_2. + Exists qv'_2. Exists pv'_2. Exists s1_2. Exists s2_2. + repeat (split_pure_spatial || split_pures). + - cancel ((p_pre) # Ptr |-> pv'_2). + cancel (sll pv'_2 s1_2). + cancel ((q_pre) # Ptr |-> qv'_2). + cancel (sll qv'_2 s2_2). + - dump_pre_spatial. exact H0. + + dump_pre_spatial. + unfold split_rel in H. + unfold split_rec_rel. + exact H. +Qed. diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/helper_lib.v b/benchmarks/Algorithms/sll_merge_sort/rocq/helper_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..b95603c7f6afe938cb8b1d250e3b63a8ae0f4b67 --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/helper_lib.v @@ -0,0 +1,95 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From SetsClass Require Import SetsClass. +From FP Require Import SetsFixedpoints. +Require Import MonadLib.StateRelMonad.StateRelMonad. + + +Local Open Scope Z_scope. +Import SetsNotation. +Local Open Scope sets. +Import ListNotations. +Local Open Scope string. +Local Open Scope list. + +Export MonadNotation. +Local Open Scope monad. + +Require Export PVbench.Algorithms.sll_merge_sort.rocq.spec_lib. + +Definition merge_body: + list Z * list Z * list Z -> + MONAD (CntOrBrk (list Z * list Z * list Z) (list Z)) := + fun '(l1, l2, l3) => + match l1, l2 with + | nil, _ => return (by_break (l3 ++ l2)) + | _, nil => return (by_break (l3 ++ l1)) + | x :: l1', y :: l2' => + choice + (test' (x <= y);; return (by_continue (l1', l2, l3 ++ x :: nil))) + (test' (y <= x);; return (by_continue (l1, l2', l3 ++ y :: nil))) + end. + + Definition merge_rel l l0 := + repeat_break merge_body (l, l0, nil). + + Definition merge_from_mid_rel l1 l2 l3 := + repeat_break merge_body (l1, l2, l3). + +Definition reversepair : ((list Z) * (list Z)) -> MONAD ((list Z) * (list Z)) := + fun '(p,q) => return (q,p). + +Definition split_rec_rel_f (W : ((list Z) * (list Z) * (list Z)) -> MONAD ((list Z) * (list Z))) + : ((list Z) * (list Z) * (list Z)) -> MONAD ((list Z) * (list Z)) := + fun '(x, p, q) => match x with + | nil => return (p, q) + | xh :: x' => x <- W (x', q, xh::p) ;; + reversepair x + end. + +Definition split_rec_rel' : ((list Z) * (list Z) * (list Z)) -> MONAD ((list Z) * (list Z)) := + Lfix split_rec_rel_f. + +Definition split_rec_rel l1 l2 l3: MONAD ((list Z) * (list Z)) := + split_rec_rel' (l1, l2, l3). + +Definition split_rel x := + split_rec_rel' (x, nil, nil). + +Definition mergesortrec_f (W : (list Z) -> MONAD (list Z) ) + : ((list Z) -> MONAD (list Z)) := + fun x => '(p1, q1) <- split_rel x ;; + match q1 with + | nil => return p1 + | _ :: _ => p2 <- W (p1) ;; + q2 <- W (q1) ;; + merge_rel p2 q2 + end. + +Definition mergesortrec := Lfix (mergesortrec_f). + +Definition mergesortrec_loc0: ((list Z) * (list Z)) -> MONAD (list Z) := + fun x => match x with + | (p1, q1) => + match q1 with + | nil => return p1 + | _ :: _ => p2 <- mergesortrec p1 ;; + q2 <- mergesortrec q1 ;; + merge_rel p2 q2 + end + end. + +Definition mergesortrec_loc1 q1: list Z -> MONAD (list Z) := + fun p2 => q2 <- mergesortrec q1 ;; + merge_rel p2 q2. + +Definition mergesortrec_loc2 p2: list Z -> MONAD (list Z) := + fun q2 => merge_rel p2 q2. + +Definition maketuple (x p :list Z): ((list Z) * (list Z)) := (x, p). +Definition applyf {A B: Type} (f: A -> B) (a: A) := f a. diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/solution_annotated.c b/benchmarks/Algorithms/sll_merge_sort/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..fa200af13d1b078d2c5379df645c9ed25afcc4ce --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/solution_annotated.c @@ -0,0 +1,205 @@ +#include "sll_def.h" +#include "safeexec_def.h" + +/*@ Extern Coq + (Permutation : list Z -> list Z -> Prop) + (incr : list Z -> Prop) + */ +/*@ Import Coq Require Import PVbench.Algorithms.sll_merge_sort.rocq.spec_lib */ +/*@ Import Coq Require Import PVbench.Algorithms.sll_merge_sort.rocq.helper_lib */ +/*@ Extern Coq + (maketuple : list Z -> list Z -> ((list Z) * (list Z))) + (merge_rel : list Z -> list Z -> program unit (list Z)) + (merge_from_mid_rel : list Z -> list Z -> list Z -> program unit (list Z)) + (split_rec_rel : list Z -> list Z -> list Z -> program unit ((list Z) * (list Z))) + (split_rel : list Z -> program unit ((list Z) * (list Z))) + (reversepair : ((list Z) * (list Z)) -> program unit ((list Z) * (list Z))) + (mergesortrec : list Z -> program unit (list Z)) + (mergesortrec_loc1 : list Z -> list Z -> program unit (list Z)) + (mergesortrec_loc2 : list Z -> list Z -> program unit (list Z)) + (mergesortrec_loc0 : ((list Z) * (list Z)) -> program unit (list Z)) + */ + +struct list *merge(struct list *x, struct list *y) +/*@ With s1 s2 X + Require safeExec(ATrue, merge_rel(s1, s2), X) && sll(x, s1) * sll(y, s2) + Ensure exists s3, safeExec(ATrue, return(s3), X) && sll(__return, s3) +*/ +{ + struct list **t, *ret; + t = &ret; + /*@ Inv Assert + exists l1 l2 l3, + safeExec(ATrue, merge_from_mid_rel(l1, l2, l3), X) && + sll(x, l1) * sll(y, l2) * + has_ptr_permission(t) * sllbseg(&ret, t, l3) + */ + while (1) + { + if (x == (void *)0) { + *t = y; + break; + } + if (y == (void *)0) { + *t = x; + break; + } + /*@ Assert + exists l1 l2 l3 l1_new l2_new xdata ydata xnext ynext, + safeExec(ATrue, merge_from_mid_rel(l1, l2, l3), X) && + x != 0 && y != 0 && + l1 == cons(xdata, l1_new) && + l2 == cons(ydata, l2_new) && + store(&(x->data), xdata) * store(&(y->data), ydata) * + store(&(x->next), xnext) * store(&(y->next), ynext) * + sll(xnext, l1_new) * sll(ynext, l2_new) * + has_ptr_permission(t) * sllbseg(&ret, t, l3) + */ + if (x->data < y->data) { + *t = x; + t = &(x->next); + x = x->next; + } else { + *t = y; + t = &(y->next); + y = y->next; + } + } + /*@ Assert + exists s3, + safeExec(ATrue, return(s3), X) && + store(&x, struct list*, x) * + store(&y, struct list*, y) * + store(&t, struct list**, t) * + sll(ret, s3) + */ + return ret; +} + +void split_rec(struct list * x, struct list * * p, struct list * * q) + /*@ high_level_spec <= low_level_spec + With l X pv qv + Require safeExec(ATrue, split_rel(l), X) && + store(p, pv) * store(q, qv) * + sll(x, l) * sll(pv, nil) * sll(qv, nil) + Ensure exists s1 s2 pv' qv', + safeExec(ATrue, return(maketuple(s1, s2)), X) && + store(p, pv') * store(q, qv') * + sll(pv', s1) * sll(qv', s2) + */ +; + +void split_rec(struct list * x, struct list * * p, struct list * * q) + /*@ low_level_spec_aux <= low_level_spec + With {B} l l1 l2 (c : ((list Z) * (list Z)) -> program unit B) X pv qv + Require safeExec(ATrue, bind(split_rec_rel(l, l1, l2), c), X) && + store(p, pv) * store(q, qv) * + sll(x, l) * sll(pv, l1) * sll(qv, l2) + Ensure exists s1 s2 pv' qv', + safeExec(ATrue, applyf(c, maketuple(s1,s2)), X) && + store(p, pv') * store(q, qv') * + sll(pv', s1) * sll(qv', s2) + */ +; + +void split_rec(struct list * x, struct list * * p, struct list * * q) + /*@ low_level_spec + With l l1 l2 X pv qv + Require safeExec(ATrue, split_rec_rel(l, l1, l2), X) && + store(p, pv) * store(q, qv) * + sll(x, l) * sll(pv, l1) * sll(qv, l2) + Ensure exists s1 s2 pv' qv', + safeExec(ATrue, return(maketuple(s1, s2)), X) && + store(p, pv') * store(q, qv') * + sll(pv', s1) * sll(qv', s2) + */ +{ + if (x == (void *)0) { + return; + } + /*@ Assert + exists l_new x_data x_next, + x == x@pre && p == p@pre && q == q@pre && + x != 0 && + safeExec(ATrue, split_rec_rel(l, l1, l2), X) && + l == cons(x_data, l_new) && + store(&(x->data), x_data) * store(&(x->next), x_next) * + store(p, pv) * store(q, qv) * + sll(x_next, l_new) * sll(pv, l1) * sll(qv, l2) + */ + struct list * t; + t = x -> next; + x -> next = * p; + * p = x; + /*@ Assert + exists l_new x_data, + x == x@pre && p == p@pre && q == q@pre && + x != 0 && + safeExec(ATrue, bind(split_rec_rel(l_new, l2, cons(x_data, l1)), reversepair), X) && + l == cons(x_data, l_new) && + store(p, x) * store(q, qv) * + sll(x, cons(x_data, l1)) * sll(t, l_new) * sll(qv, l2) + */ + split_rec(t, q, p) /*@ where(low_level_spec_aux) l1 = l2, c = reversepair, X = X; B = (list Z) * (list Z) */; +} + +struct list * merge_sort(struct list * x) + /*@ high_level_spec <= low_level_spec + With l + Require sll(x, l) + Ensure exists l0, + Permutation(l, l0) && incr(l0) && + sll(__return, l0) + */ +; + +struct list * merge_sort(struct list * x) + /*@ low_level_spec_aux <= low_level_spec + With {B} l (c: list Z -> program unit B) X + Require safeExec(ATrue, bind(mergesortrec(l), c), X) && sll(x, l) + Ensure exists l0, + safeExec(ATrue, applyf(c, l0), X) && + sll(__return, l0) + */ +; + +struct list * merge_sort(struct list * x) + /*@ low_level_spec + With l X + Require safeExec(ATrue, mergesortrec(l), X) && sll(x, l) + Ensure exists l0, + safeExec(ATrue, return(l0), X) && + sll(__return, l0) + */ +{ + struct list * p, * q; + p = (void *)0; + /*@ Assert + x == x@pre && p == 0 && has_ptr_permission(&q) && safeExec(ATrue, mergesortrec(l), X) && sll(p, nil) * sll(x, l) + */ + q = (void *)0; + /*@ Assert + x == x@pre && p == 0 && q == 0 && safeExec(ATrue, mergesortrec(l), X) && sll(p, nil) * sll(q, nil) * sll(x, l) + */ + /*@ Assert + x == x@pre && p == 0 && q == 0 && safeExec(ATrue, bind(split_rel(l), mergesortrec_loc0), X) && sll(p, nil) * sll(q, nil) * sll(x, l) + */ + split_rec(x, &p, &q) /*@ where(low_level_spec_aux) X = X, c = mergesortrec_loc0; B = (list Z) */; + if (q == (void *)0) { + return p; + } + /*@ Assert + exists l1 l2, + x == x@pre && q != 0 && + safeExec(ATrue, bind(mergesortrec(l1), mergesortrec_loc1(l2)), X) && sll(p, l1) * sll(q, l2) */ + p = merge_sort(p) /*@ where(low_level_spec_aux) X = X; B = (list Z) */; + /*@ Assert + exists l1 l2, + x == x@pre && q != 0 && + safeExec(ATrue, bind(mergesortrec(l2), mergesortrec_loc2(l1)), X) && sll(p, l1) * sll(q, l2) */ + q = merge_sort(q) /*@ where(low_level_spec_aux) X = X; B = (list Z) */; + /*@ Assert + exists l1 l2, x == x@pre && + safeExec(ATrue, merge_rel(l1, l2), X) && sll(p, l1) * sll(q, l2) */ + return merge(p, q) /*@ where X = X */; +} diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/solution_spec.c b/benchmarks/Algorithms/sll_merge_sort/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..4757ae61bd52a9660b03847e3f70e8d21ec681da --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/solution_spec.c @@ -0,0 +1,66 @@ +#include "sll_def.h" + +/*@ Extern Coq + (Permutation : list Z -> list Z -> Prop) + (incr : list Z -> Prop) + */ +/*@ Import Coq Require Import PVbench.Algorithms.sll_merge_sort.rocq.spec_lib */ + +struct list *merge(struct list *x, struct list *y) +{ + struct list **t, *ret; + t = &ret; + while (1) + { + if (x == (void *)0) { + *t = y; + break; + } + if (y == (void *)0) { + *t = x; + break; + } + if (x->data < y->data) { + *t = x; + t = &(x->next); + x = x->next; + } else { + *t = y; + t = &(y->next); + y = y->next; + } + } + return ret; +} + +void split_rec(struct list * x, struct list * * p, struct list * * q) +{ + if (x == (void *)0) { + return; + } + struct list * t; + t = x -> next; + x -> next = * p; + * p = x; + split_rec(t, q, p); +} + +struct list * merge_sort(struct list * x) +/*@ With l + Require sll(x, l) + Ensure exists l0, + Permutation(l, l0) && incr(l0) && + sll(__return, l0) + */ +{ + struct list * p, * q; + p = (void *)0; + q = (void *)0; + split_rec(x, &p, &q); + if (q == (void *)0) { + return p; + } + p = merge_sort(p); + q = merge_sort(q); + return merge(p, q); +} diff --git a/benchmarks/Algorithms/sll_merge_sort/rocq/spec_lib.v b/benchmarks/Algorithms/sll_merge_sort/rocq/spec_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..697f755d2073555d56db5dbc499142105ec074aa --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/rocq/spec_lib.v @@ -0,0 +1,18 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Lists.List. + +Local Open Scope Z_scope. +Import ListNotations. +Local Open Scope list. + +Fixpoint incr_aux (l: list Z) (x: Z): Prop := + match l with + | nil => True + | y :: l0 => x <= y /\ incr_aux l0 y + end. + +Definition incr (l: list Z): Prop := + match l with + | nil => True + | x :: l0 => incr_aux l0 x + end. diff --git a/benchmarks/Algorithms/sll_merge_sort/solution.c b/benchmarks/Algorithms/sll_merge_sort/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..67c9c062ad678a51dc1ce59c8dfe57a8dbbc7f4e --- /dev/null +++ b/benchmarks/Algorithms/sll_merge_sort/solution.c @@ -0,0 +1,54 @@ +#include "sll_def.h" + +struct list *merge(struct list *x, struct list *y) +{ + struct list **t, *ret; + t = &ret; + while (1) + { + if (x == (void *)0) { + *t = y; + break; + } + if (y == (void *)0) { + *t = x; + break; + } + if (x->data < y->data) { + *t = x; + t = &(x->next); + x = x->next; + } else { + *t = y; + t = &(y->next); + y = y->next; + } + } + return ret; +} + +void split_rec(struct list * x, struct list * * p, struct list * * q) +{ + if (x == (void *)0) { + return; + } + struct list * t; + t = x -> next; + x -> next = * p; + * p = x; + split_rec(t, q, p); +} + +struct list * merge_sort(struct list * x) +{ + struct list * p, * q; + p = (void *)0; + q = (void *)0; + split_rec(x, &p, &q); + if (q == (void *)0) { + return p; + } + p = merge_sort(p); + q = merge_sort(q); + return merge(p, q); +} diff --git a/benchmarks/Data_structures/dll_queue/manifest.json b/benchmarks/Data_structures/dll_queue/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..5be03484c317c8a1c807335e9a75eb0bf61402e9 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "dll_queue", + "source": { + "dataset": "classical_data_structure", + "problem_id": "dll_queue", + "title": "Queue on a Doubly Linked List", + "tags": [ + "data structures", + "queue", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Data_structures/dll_queue/problem.md b/benchmarks/Data_structures/dll_queue/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..0c29bf5f62a2e612437e634a433e3da273c0c67b --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/problem.md @@ -0,0 +1,15 @@ +# Queue on a Doubly Linked List + +## Description + +Maintain a first-in first-out queue of integers stored in a doubly linked list with head and tail pointers, supporting insertion at the back and removal from the front. + +## Input + +- `enqueue` receives a queue `q` and an integer `x`. +- `dequeue` receives a non-empty queue `q`. + +## Output + +- `enqueue` appends `x` at the back of `q`. +- `dequeue` removes the element at the front of `q` and returns it. diff --git a/benchmarks/Data_structures/dll_queue/rocq/dll_queue_store.strategies b/benchmarks/Data_structures/dll_queue/rocq/dll_queue_store.strategies new file mode 100644 index 0000000000000000000000000000000000000000..8c70814ecdca5ce1a9fe36e8de7087fb6b71e359 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/dll_queue_store.strategies @@ -0,0 +1,24 @@ +//test curent rules +//max rule id:30 + +#include "dll_queue_store_def.h" + + + + +id : 0 +priority : core(2) +left : store_queue(?p, ?l0) at 0 +right : store_queue(p, ?l1) at 1 +action : left_erase(0); + right_erase(1); + right_add(l0 == l1); + +id : 1 +priority : core(2) +left : dllseg(?p, 0, ?q, ?r, ?l0) at 0 +right : dllseg(p, 0, q, r, ?l1) at 1 +action : left_erase(0); + right_erase(1); + right_add(l0 == l1); + diff --git a/benchmarks/Data_structures/dll_queue/rocq/dll_queue_store_def.h b/benchmarks/Data_structures/dll_queue/rocq/dll_queue_store_def.h new file mode 100644 index 0000000000000000000000000000000000000000..c9a6439706774b3a43f79c01c9cfb8f4eb0ded94 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/dll_queue_store_def.h @@ -0,0 +1,16 @@ +struct list { + int data; + struct list *next; + struct list *prev; +}; + +struct queue { + struct list * head; + struct list * tail; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib */ + +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) + (dllseg: Z -> Z -> Z -> Z -> list Z -> Assertion) + */ diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_goal.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..d124461dfb21a1abf9eb738adb69ad0b8ac5f991 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_goal.v @@ -0,0 +1,453 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib. +Local Open Scope sac. +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_store_strategy_goal. +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_store_strategy_proof. + +(*----- Function enqueue -----*) + +Definition enqueue_safety_wit_1 := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval: Z) (PreH1 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> retval) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((( &( "x" ) )) # Int |-> x_pre) + ** (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition enqueue_safety_wit_2 := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval: Z) (PreH1 : (qhead = 0)) (PreH2 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> retval) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((( &( "x" ) )) # Int |-> x_pre) + ** (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition enqueue_safety_wit_3 := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval: Z) (PreH1 : (qhead = 0)) (PreH2 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((( &( "p" ) )) # Ptr |-> retval) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((( &( "x" ) )) # Int |-> x_pre) + ** (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition enqueue_safety_wit_4 := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (l0: (@list Z)) (qtailv: Z) (qtail: Z) (qhead: Z) (qtailnext: Z) (qtailprev: Z) (p: Z) (PreH1 : (p <> 0)) (PreH2 : (qtail <> 0)) (PreH3 : (qhead <> 0)) (PreH4 : (l = (app (l0) ((cons (qtailv) ((@nil Z))))))) (PreH5 : (qtailnext = 0)) , + ((( &( "x" ) )) # Int |-> x_pre) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((( &( "p" ) )) # Ptr |-> p) + ** (dllseg qhead qtail 0 qtailprev l0 ) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> p) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> p) + ** ((&((qtail) # "list" ->ₛ "prev")) # Ptr |-> qtailprev) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> qtailv) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((p) # "list" ->ₛ "prev")) # Ptr |-> qtail) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x_pre) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition enqueue_entail_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) , + (store_queue q_pre l ) +|-- + EX (qhead: Z) (qtail: Z) , + (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) , + (store_queue q_pre l ) +|-- + EX (qhead: Z) (qtail: Z) , + (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +). + +Definition enqueue_entail_wit_2 := +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead_2: Z) (qtail_2: Z) (retval: Z) (PreH1 : (qhead_2 <> 0)) (PreH2 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** (dllseg qhead_2 0 0 qtail_2 l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead_2) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail_2) +|-- + EX (qtailprev: Z) (qtailnext: Z) (l0: (@list Z)) (qtailv: Z) (qhead: Z) (qtail: Z) , + “ (retval <> 0) ” + && “ (qtail <> 0) ” + && “ (qhead <> 0) ” + && “ (l = (app (l0) ((cons (qtailv) ((@nil Z)))))) ” + && “ (qtailnext = 0) ” + && (dllseg qhead qtail 0 qtailprev l0 ) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> qtailnext) + ** ((&((qtail) # "list" ->ₛ "prev")) # Ptr |-> qtailprev) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> qtailv) + ** ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) +) \/ +( +forall (l: (@list Z)) (qhead_2: Z) (qtail_2: Z) (retval: Z) (PreH1 : (qhead_2 <> 0)) (PreH2 : (retval <> 0)) , + (dllseg qhead_2 0 0 qtail_2 l ) +|-- + EX (qtailprev: Z) (l0: (@list Z)) (qtailv: Z) , + “ (retval <> 0) ” + && “ (qtail_2 <> 0) ” + && “ (qhead_2 <> 0) ” + && “ (l = (app (l0) ((cons (qtailv) ((@nil Z)))))) ” + && (dllseg qhead_2 qtail_2 0 qtailprev l0 ) + ** ((&((qtail_2) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((qtail_2) # "list" ->ₛ "prev")) # Ptr |-> qtailprev) + ** ((&((qtail_2) # "list" ->ₛ "data")) # Int |-> qtailv) +). + +Definition enqueue_return_wit_1 := +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval: Z) (PreH1 : (qhead = 0)) (PreH2 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +) \/ +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (x_pre >= INT_MIN)) (PreH3 : (qhead = 0)) (PreH4 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +). + +Definition enqueue_return_wit_1_split_goal_spatial := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (x_pre >= INT_MIN)) (PreH3 : (qhead = 0)) (PreH4 : (retval <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +. + +Definition enqueue_return_wit_2 := +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (l0: (@list Z)) (qtailv: Z) (qtail: Z) (qhead: Z) (qtailnext: Z) (qtailprev: Z) (p: Z) (PreH1 : (p <> 0)) (PreH2 : (qtail <> 0)) (PreH3 : (qhead <> 0)) (PreH4 : (l = (app (l0) ((cons (qtailv) ((@nil Z))))))) (PreH5 : (qtailnext = 0)) , + (dllseg qhead qtail 0 qtailprev l0 ) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> p) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> p) + ** ((&((qtail) # "list" ->ₛ "prev")) # Ptr |-> qtailprev) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> qtailv) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((p) # "list" ->ₛ "prev")) # Ptr |-> qtail) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x_pre) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +) \/ +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (l0: (@list Z)) (qtailv: Z) (qtail: Z) (qhead: Z) (qtailnext: Z) (qtailprev: Z) (p: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (qtailv <= INT_MAX)) (PreH3 : (x_pre >= INT_MIN)) (PreH4 : (qtailv >= INT_MIN)) (PreH5 : (p <> 0)) (PreH6 : (qtail <> 0)) (PreH7 : (qhead <> 0)) (PreH8 : (l = (app (l0) ((cons (qtailv) ((@nil Z))))))) (PreH9 : (qtailnext = 0)) , + (dllseg qhead qtail 0 qtailprev l0 ) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> p) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> p) + ** ((&((qtail) # "list" ->ₛ "prev")) # Ptr |-> qtailprev) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> qtailv) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((p) # "list" ->ₛ "prev")) # Ptr |-> qtail) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x_pre) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +). + +Definition enqueue_return_wit_2_split_goal_spatial := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (l0: (@list Z)) (qtailv: Z) (qtail: Z) (qhead: Z) (qtailnext: Z) (qtailprev: Z) (p: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (qtailv <= INT_MAX)) (PreH3 : (x_pre >= INT_MIN)) (PreH4 : (qtailv >= INT_MIN)) (PreH5 : (p <> 0)) (PreH6 : (qtail <> 0)) (PreH7 : (qhead <> 0)) (PreH8 : (l = (app (l0) ((cons (qtailv) ((@nil Z))))))) (PreH9 : (qtailnext = 0)) , + (dllseg qhead qtail 0 qtailprev l0 ) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> p) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> p) + ** ((&((qtail) # "list" ->ₛ "prev")) # Ptr |-> qtailprev) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> qtailv) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> 0) + ** ((&((p) # "list" ->ₛ "prev")) # Ptr |-> qtail) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> x_pre) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +. + +Definition enqueue_partial_solve_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) , + (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + (dllseg qhead 0 0 qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +. + +(*----- Function dequeue -----*) + +Definition dequeue_safety_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (qheadnext: Z) (PreH1 : (qhead <> 0)) , + ((( &( "x0" ) )) # Int |-> x) + ** ((( &( "p" ) )) # Ptr |-> qhead) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition dequeue_safety_wit_2 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (qheadnext: Z) (PreH1 : (qheadnext = 0)) (PreH2 : (qhead <> 0)) , + ((( &( "x0" ) )) # Int |-> x) + ** ((( &( "p" ) )) # Ptr |-> qhead) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition dequeue_safety_wit_3 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (headv: Z) (qheadnext: Z) (l0: (@list Z)) (p: Z) (PreH1 : (qhead <> 0)) (PreH2 : (l = (cons (headv) (l0)))) , + ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((( &( "x0" ) )) # Int |-> x) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> p) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> headv) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l0 ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition dequeue_entail_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) , + (store_queue q_pre (cons (x) (l)) ) +|-- + EX (qtail: Z) (qheadnext: Z) (qhead: Z) , + “ (qhead <> 0) ” + && ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) , + (store_queue q_pre (cons (x) (l)) ) +|-- + EX (qtail: Z) (qheadnext: Z) (qhead: Z) , + “ (qhead <> 0) ” + && ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +). + +Definition dequeue_entail_wit_2 := +( +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail_2: Z) (qheadnext_2: Z) (PreH1 : (qheadnext_2 <> 0)) (PreH2 : (qhead <> 0)) , + (dllseg qheadnext_2 0 qhead qtail_2 l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext_2) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail_2) +|-- + EX (qtail: Z) (qheadnext: Z) (headv: Z) (l0: (@list Z)) (qhead_2: Z) , + “ (qhead_2 <> 0) ” + && “ (l = (cons (headv) (l0))) ” + && ((&((qhead_2) # "list" ->ₛ "prev")) # Ptr |-> qhead) + ** ((&((qhead_2) # "list" ->ₛ "data")) # Int |-> headv) + ** ((&((qhead_2) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead_2 qtail l0 ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead_2) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +) \/ +( +forall (l: (@list Z)) (qhead: Z) (qtail_2: Z) (qheadnext_2: Z) (PreH1 : (qheadnext_2 <> 0)) (PreH2 : (qhead <> 0)) , + (dllseg qheadnext_2 0 qhead qtail_2 l ) +|-- + EX (qheadnext: Z) (headv: Z) (l0: (@list Z)) , + “ (qheadnext_2 <> 0) ” + && “ (l = (cons (headv) (l0))) ” + && ((&((qheadnext_2) # "list" ->ₛ "prev")) # Ptr |-> qhead) + ** ((&((qheadnext_2) # "list" ->ₛ "data")) # Int |-> headv) + ** ((&((qheadnext_2) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qheadnext_2 qtail_2 l0 ) +). + +Definition dequeue_return_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (qheadnext: Z) (PreH1 : (qheadnext = 0)) (PreH2 : (qhead <> 0)) , + (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> 0) +|-- + “ (x = x) ” + && (store_queue q_pre l ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (qheadnext: Z) (PreH1 : (qheadnext = 0)) (PreH2 : (qhead <> 0)) , + (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> 0) +|-- + (store_queue q_pre l ) +). + +Definition dequeue_return_wit_1_split_goal_spatial := +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (qheadnext: Z) (PreH1 : (qheadnext = 0)) (PreH2 : (qhead <> 0)) , + (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> 0) +|-- + (store_queue q_pre l ) +. + +Definition dequeue_return_wit_2 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (headv: Z) (qheadnext: Z) (l0: (@list Z)) (PreH1 : (qhead <> 0)) (PreH2 : (l = (cons (headv) (l0)))) , + ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> headv) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l0 ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + “ (x = x) ” + && (store_queue q_pre l ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (headv: Z) (qheadnext: Z) (l0: (@list Z)) (PreH1 : (headv <= INT_MAX)) (PreH2 : (headv >= INT_MIN)) (PreH3 : (qhead <> 0)) (PreH4 : (l = (cons (headv) (l0)))) , + ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> headv) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l0 ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + (store_queue q_pre l ) +). + +Definition dequeue_return_wit_2_split_goal_spatial := +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (headv: Z) (qheadnext: Z) (l0: (@list Z)) (PreH1 : (headv <= INT_MAX)) (PreH2 : (headv >= INT_MIN)) (PreH3 : (qhead <> 0)) (PreH4 : (l = (cons (headv) (l0)))) , + ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> headv) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l0 ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + (store_queue q_pre l ) +. + +Definition dequeue_partial_solve_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (qheadnext: Z) (PreH1 : (qhead <> 0)) , + ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +|-- + “ (qhead <> 0) ” + && ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** (dllseg qheadnext 0 qhead qtail l ) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) +. + +Module Type VC_Correct. + +Include dll_queue_store_Strategy_Correct. + +Axiom proof_of_enqueue_safety_wit_1 : enqueue_safety_wit_1. +Axiom proof_of_enqueue_safety_wit_2 : enqueue_safety_wit_2. +Axiom proof_of_enqueue_safety_wit_3 : enqueue_safety_wit_3. +Axiom proof_of_enqueue_safety_wit_4 : enqueue_safety_wit_4. +Axiom proof_of_enqueue_entail_wit_1 : enqueue_entail_wit_1. +Axiom proof_of_enqueue_entail_wit_2 : enqueue_entail_wit_2. +Axiom proof_of_enqueue_return_wit_1 : enqueue_return_wit_1. +Axiom proof_of_enqueue_return_wit_2 : enqueue_return_wit_2. +Axiom proof_of_enqueue_partial_solve_wit_1 : enqueue_partial_solve_wit_1. +Axiom proof_of_dequeue_safety_wit_1 : dequeue_safety_wit_1. +Axiom proof_of_dequeue_safety_wit_2 : dequeue_safety_wit_2. +Axiom proof_of_dequeue_safety_wit_3 : dequeue_safety_wit_3. +Axiom proof_of_dequeue_entail_wit_1 : dequeue_entail_wit_1. +Axiom proof_of_dequeue_entail_wit_2 : dequeue_entail_wit_2. +Axiom proof_of_dequeue_return_wit_1 : dequeue_return_wit_1. +Axiom proof_of_dequeue_return_wit_2 : dequeue_return_wit_2. +Axiom proof_of_dequeue_partial_solve_wit_1 : dequeue_partial_solve_wit_1. + +End VC_Correct. diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_goal_check.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..888f65d6590a6d196222e16b9ec00cf802ffe19d --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_goal_check.v @@ -0,0 +1,7 @@ +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_goal dll_queue_proof_auto dll_queue_proof_manual. + +Module VC_Correctness : VC_Correct. + Include dll_queue_store_strategy_proof. + Include dll_queue_proof_auto. + Include dll_queue_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_proof_auto.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..dac0d140972a9127cd8515d6746ef24e09f182b9 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_proof_auto.v @@ -0,0 +1,49 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib. +Local Open Scope sac. + +Lemma proof_of_enqueue_safety_wit_1 : enqueue_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_enqueue_safety_wit_2 : enqueue_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_enqueue_safety_wit_3 : enqueue_safety_wit_3. +Proof. Admitted. + +Lemma proof_of_enqueue_safety_wit_4 : enqueue_safety_wit_4. +Proof. Admitted. + +Lemma proof_of_enqueue_partial_solve_wit_1 : enqueue_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_dequeue_safety_wit_1 : dequeue_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_dequeue_safety_wit_2 : dequeue_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_dequeue_safety_wit_3 : dequeue_safety_wit_3. +Proof. Admitted. + +Lemma proof_of_dequeue_partial_solve_wit_1 : dequeue_partial_solve_wit_1. +Proof. Admitted. + diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_proof_manual.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..c9081c0ffebdcef9d561e539a1dcaca644922a4c --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_proof_manual.v @@ -0,0 +1,189 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_goal. +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib. +Require Import PVbench.Data_structures.dll_queue.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_enqueue_entail_wit_1 : enqueue_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Intros qhead qtail. + Exists qhead qtail. + change (dllseg qhead NULL NULL qtail l) with (dllseg qhead 0 0 qtail l). + cancel (&((q_pre) # "queue" ->ₛ "head") # Ptr |-> qhead). + cancel (&((q_pre) # "queue" ->ₛ "tail") # Ptr |-> qtail). + cancel (dllseg qhead 0 0 qtail l). +Qed. + +Lemma proof_of_enqueue_entail_wit_2 : enqueue_entail_wit_2. +Proof. + LLM_pre_process ltac:(int_auto). + assert (Hqhead_neq : qhead_2 <> 0) by lia. + sep_apply_l_atomic (dllseg_head_neq_destruct_tail qhead_2 0 0 qtail_2 l Hqhead_neq). + Intros qtailprev l0 qtailv. + Exists qtailprev. + Exists 0. + Exists l0. + Exists qtailv. + Exists qhead_2. + Exists qtail_2. + split_pure_spatial. + - cancel ((&((retval) # "list" ->ₛ "next")) # Ptr |-> 0). + cancel ((&((retval) # "list" ->ₛ "prev")) # Ptr |-> 0). + cancel ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre). + cancel ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead_2). + cancel ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail_2). + cancel (dllseg qhead_2 qtail_2 0 qtailprev l0). + cancel ((&((qtail_2) # "list" ->ₛ "data")) # Int |-> qtailv). + cancel ((&((qtail_2) # "list" ->ₛ "next")) # Ptr |-> 0). + cancel ((&((qtail_2) # "list" ->ₛ "prev")) # Ptr |-> qtailprev). + - split_pures. + + dump_pre_spatial. + exact PreH2. + + dump_pre_spatial. + exact H. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + exact H0. + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma proof_of_enqueue_return_wit_1 : enqueue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst. + unfold store_queue. + sep_apply dllseg_head_zero; [ | tauto ]. + Intros. + subst. + Exists retval retval. + sep_apply dllseg_len1; [ | tauto ]. + cancel. + change NULL with 0. + change (nil +:: x_pre) with (x_pre :: nil). + cancel. +Qed. + +Lemma proof_of_enqueue_return_wit_2 : enqueue_return_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst. + unfold store_queue. + Exists qhead p. + sep_apply (dllseg_len1 qtail); [ | tauto ]. + sep_apply (dllseg_len1 p); [ | tauto ]. + sep_apply (dllseg_dllseg qtail). + sep_apply (dllseg_dllseg qhead). + cancel. + change NULL with 0. + cancel. + rewrite app_assoc. + cancel. +Qed. + +Lemma proof_of_dequeue_entail_wit_1 : dequeue_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Intros qhead qtail. + simpl. + Intros qhead_next. + Exists qtail qhead_next qhead. + split_pure_spatial. + - unfold NULL. + cancel ((&((qhead) # "list" ->ₛ "prev")) # Ptr |-> 0). + cancel ((&((qhead) # "list" ->ₛ "data")) # Int |-> x). + cancel ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qhead_next). + cancel (dllseg qhead_next 0 qhead qtail l). + cancel ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead). + cancel ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail). + - dump_pre_spatial. + exact H. +Qed. + +Lemma proof_of_dequeue_entail_wit_2 : dequeue_entail_wit_2. +Proof. + LLM_pre_process ltac:(int_auto). + sep_apply_l_atomic (dllseg_head_neq qheadnext_2 0 qhead qtail_2 l PreH1). + Intros qhead_next headv l0. + Exists qtail_2. + Exists qhead_next. + Exists headv. + Exists l0. + Exists qheadnext_2. + split_pure_spatial. + - cancel ((&((qheadnext_2) # "list" ->ₛ "prev")) # Ptr |-> qhead). + cancel ((&((qheadnext_2) # "list" ->ₛ "data")) # Int |-> headv). + cancel ((&((qheadnext_2) # "list" ->ₛ "next")) # Ptr |-> qhead_next). + cancel (dllseg qhead_next 0 qheadnext_2 qtail_2 l0). + cancel ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext_2). + cancel ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail_2). + - split_pures. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + exact H. +Qed. + +Lemma proof_of_dequeue_return_wit_1 : dequeue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst. + unfold store_queue. + sep_apply dllseg_head_zero; [ | tauto ]. + Intros. + subst. + Exists 0 0. + simpl. + repeat (split_pure_spatial || split_pures). + - cancel. + - dump_pre_spatial. unfold NULL. reflexivity. + - dump_pre_spatial. unfold NULL. reflexivity. + - dump_pre_spatial. reflexivity. +Qed. + +Lemma proof_of_dequeue_return_wit_2 : dequeue_return_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst. + unfold store_queue. + Exists qhead qtail. + simpl. + Exists qheadnext. + change NULL with 0. + repeat (split_pure_spatial || split_pures). + - cancel (&(qhead # "list" ->ₛ "data") # Int |-> headv). + cancel (&(qhead # "list" ->ₛ "next") # Ptr |-> qheadnext). + cancel (&(qhead # "list" ->ₛ "prev") # Ptr |-> 0). + cancel (dllseg qheadnext 0 qhead qtail l0). + cancel (&(q_pre # "queue" ->ₛ "head") # Ptr |-> qhead). + cancel (&(q_pre # "queue" ->ₛ "tail") # Ptr |-> qtail). + - dump_pre_spatial. reflexivity. + - dump_pre_spatial. exact PreH1. +Qed. diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_goal.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..a04653936a981919c4fbfc0eaad3c87761499b9d --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_goal.v @@ -0,0 +1,56 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +Require Import Coq.micromega.Psatz. +From SimpleC.SL Require Import SeparationLogic. +Import naive_C_Rules. +Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Definition dll_queue_store_strategy0 := + forall (p : Z) (l0 : (@list Z)), + TT && + emp ** + ((store_queue p l0)) + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list Z)), + TT && + (“ (l0 = l1) ”) && + emp -* + TT && + emp ** + ((store_queue p l1)) + ). + +Definition dll_queue_store_strategy1 := + forall (p : Z) (q : Z) (l0 : (@list Z)) (r : Z), + TT && + emp ** + ((dllseg p 0 q r l0)) + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list Z)), + TT && + (“ (l0 = l1) ”) && + emp -* + TT && + emp ** + ((dllseg p 0 q r l1)) + ). + +Module Type dll_queue_store_Strategy_Correct. + + Axiom dll_queue_store_strategy0_correctness : dll_queue_store_strategy0. + Axiom dll_queue_store_strategy1_correctness : dll_queue_store_strategy1. + +End dll_queue_store_Strategy_Correct. diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_goal_check.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..e9c543c39c26b94c0eaf2dd081628f1e5cda8ded --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_goal_check.v @@ -0,0 +1,5 @@ +From PVbench.Data_structures.dll_queue.rocq.groundtruth Require Import dll_queue_store_strategy_goal dll_queue_store_strategy_proof. + +Module dll_queue_store_Strategy_Correctness : dll_queue_store_Strategy_Correct. + Include dll_queue_store_strategy_proof. +End dll_queue_store_Strategy_Correctness. diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_proof.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_proof.v new file mode 100644 index 0000000000000000000000000000000000000000..f7d907a2268434f89eba1297dfd8cf9e8eea288e --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/dll_queue_store_strategy_proof.v @@ -0,0 +1,28 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +From SimpleC.SL Require Import SeparationLogic. +Require Import PVbench.Data_structures.dll_queue.rocq.groundtruth.dll_queue_store_strategy_goal. +Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib. +Require Import PVbench.Data_structures.dll_queue.rocq.groundtruth.proof_lib. +Import naive_C_Rules. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Lemma dll_queue_store_strategy0_correctness : dll_queue_store_strategy0. +Proof. + pre_process_default. + Intros_p H. + subst l1. + cancel. +Qed. + +Lemma dll_queue_store_strategy1_correctness : dll_queue_store_strategy1. +Proof. + pre_process_default. + Intros_p H. + subst l1. + cancel. +Qed. diff --git a/benchmarks/Data_structures/dll_queue/rocq/groundtruth/proof_lib.v b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..d4051ccbde3c6a9d36eb83e967266acd2113a7b8 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/groundtruth/proof_lib.v @@ -0,0 +1,345 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib. +Local Open Scope sac. +Import ListNotations. +Local Open Scope list. + +Lemma dllseg_len1: forall (x px nx: addr) (a: Z), + x <> NULL -> + &(x # "list" ->ₛ "data") # Int |-> a ** + &(x # "list" ->ₛ "next") # Ptr |-> nx ** + &(x # "list" ->ₛ "prev") # Ptr |-> px |-- + dllseg x nx px x [a]. +Proof. + intros x px nx a Hx. + simpl. + Exists nx. + split_pure_spatial. + - cancel. + - split_pures. + + dump_pre_spatial. + exact Hx. + + dump_pre_spatial. + reflexivity. + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma dllseg_dllseg: forall (x y z px py pz: addr) l1 l2, + dllseg x y px py l1 ** + dllseg y z py pz l2 |-- + dllseg x z px pz (l1 ++ l2). +Proof. + intros x y z px py pz l1. + revert x y z px py pz. + induction l1; intros x y z px py pz l2. + - simpl. + Intros_p Hxy. + Intros_p Hpxpy. + subst y. + subst py. + cancel. + - simpl. + Intros z0. + Exists z0. + split_pure_spatial. + + cancel (&(x # "list" ->ₛ "data") # Int |-> a). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> z0). + cancel (&(x # "list" ->ₛ "prev") # Ptr |-> px). + apply (IHl1 z0 y z x py pz l2). + + dump_pre_spatial. + exact H. +Qed. + +Lemma dllseg_head_zero: forall x y px py l, + x = 0 -> + dllseg x y px py l |-- + “ y = 0 ” && “ px = py ” && “ l = nil ” && emp. +Proof. + intros x y px py l Hx. + destruct l. + - simpl. + subst x. + repeat (split_pure_spatial || split_pures). + + Intros_p Hxy. + Intros_p Hpxpy. + cancel. + + Intros_p Hxy. + dump_pre_spatial. + symmetry. + exact Hxy. + + Intros_p Hxy. + Intros_p Hpxpy. + dump_pre_spatial. + exact Hpxpy. + + Intros_p Hxy. + Intros_p Hpxpy. + dump_pre_spatial. + reflexivity. + - simpl. + rename z into a. + rename l into l0. + subst x. + Intros z. + contradiction. +Qed. + +Lemma dllseg_head_neq: forall x y px py l, + x <> y -> + dllseg x y px py l |-- + EX z a l0, + “ l = a :: l0 ” && + &(x # "list" ->ₛ "data") # Int |-> a ** + &(x # "list" ->ₛ "next") # Ptr |-> z ** + &(x # "list" ->ₛ "prev") # Ptr |-> px ** + dllseg z y x py l0. +Proof. + intros x y px py l Hxy. + destruct l. + - simpl. + Intros_p Hxy0. + contradiction. + - simpl. + rename z into a. + rename l into l0. + Intros z. + Exists z. + Exists a. + Exists l0. + split_pure_spatial. + + cancel (&(x # "list" ->ₛ "data") # Int |-> a). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> z). + cancel (&(x # "list" ->ₛ "prev") # Ptr |-> px). + cancel (dllseg z y x py l0). + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma dllseg_head_neq_destruct_tail_aux: forall x y px py l, + dllseg x y px py l |-- + “ x = y ” && “ px = py ” && “ l = nil ” && emp || + EX z l0 a, + “ py <> 0 ” && + “ l = (l0 ++ a :: nil)%list ” && + dllseg x py px z l0 ** + &(py # "list" ->ₛ "data") # Int |-> a ** + &(py # "list" ->ₛ "next") # Ptr |-> y ** + &(py # "list" ->ₛ "prev") # Ptr |-> z. +Proof. + intros x y px py l. + revert x y px py. + induction l; intros x y px py. + - simpl. + Left. + repeat (split_pure_spatial || split_pures). + + Intros_p Hxy. + Intros_p Hpxpy. + cancel. + + Intros_p Hxy. + dump_pre_spatial. + exact Hxy. + + Intros_p Hxy. + Intros_p Hpxpy. + dump_pre_spatial. + exact Hpxpy. + + Intros_p Hxy. + Intros_p Hpxpy. + dump_pre_spatial. + reflexivity. + - simpl. + Intros z0. + sep_apply (IHl z0 y x py). + Split. + + Right. + Exists px. + Exists (@nil Z). + Exists a. + repeat (split_pure_spatial || split_pures). + * Intros_p Hz0y. + Intros_p Hxpy. + Intros_p Hl. + subst y. + subst py. + simpl. + repeat (split_pure_spatial || split_pures). + -- cancel (&(x # "list" ->ₛ "data") # Int |-> a). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> z0). + cancel (&(x # "list" ->ₛ "prev") # Ptr |-> px). + -- dump_pre_spatial. + reflexivity. + -- dump_pre_spatial. + reflexivity. + * Intros_p Hz0y. + Intros_p Hxpy. + Intros_p Hl. + dump_pre_spatial. + subst py. + exact H. + * Intros_p Hz0y. + Intros_p Hxpy. + Intros_p Hl. + dump_pre_spatial. + subst l. + reflexivity. + + Intros z. + Intros l0. + Intros a0. + Right. + Exists z. + Exists (a :: l0)%list. + Exists a0. + repeat (split_pure_spatial || split_pures). + * cancel (&(py # "list" ->ₛ "data") # Int |-> a0). + cancel (&(py # "list" ->ₛ "next") # Ptr |-> y). + cancel (&(py # "list" ->ₛ "prev") # Ptr |-> z). + simpl. + Exists z0. + split_pure_spatial. + -- cancel (&(x # "list" ->ₛ "data") # Int |-> a). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> z0). + cancel (&(x # "list" ->ₛ "prev") # Ptr |-> px). + cancel (dllseg z0 py x z l0). + -- dump_pre_spatial. + exact H. + * dump_pre_spatial. + exact H0. + * dump_pre_spatial. + subst l. + reflexivity. +Qed. + +Lemma dllseg_head_neq_destruct_tail: forall x y px py l, + x <> y -> + dllseg x y px py l |-- + EX z l0 a, + “ py <> 0 ” && + “ l = (l0 ++ a :: nil)%list ” && + dllseg x py px z l0 ** + &(py # "list" ->ₛ "data") # Int |-> a ** + &(py # "list" ->ₛ "next") # Ptr |-> y ** + &(py # "list" ->ₛ "prev") # Ptr |-> z. +Proof. + intros x y px py l Hxy. + sep_apply dllseg_head_neq_destruct_tail_aux. + normalize. + Split. + - Intros_p Hxy'. + contradiction. + - cancel. +Qed. + +Lemma dllseg_head_neq_destruct_tail': forall x y px py l, + px <> py -> + dllseg x y px py l |-- + EX z l0 a, + “ py <> 0 ” && + “ l = (l0 ++ a :: nil)%list ” && + dllseg x py px z l0 ** + &(py # "list" ->ₛ "data") # Int |-> a ** + &(py # "list" ->ₛ "next") # Ptr |-> y ** + &(py # "list" ->ₛ "prev") # Ptr |-> z. +Proof. + intros x y px py l Hpxpy. + sep_apply dllseg_head_neq_destruct_tail_aux. + normalize. + Split. + - Intros_p Hxy. + Intros_p Hpxpy'. + contradiction. + - cancel. +Qed. + +Lemma dll_zero : forall (x prev : addr) (l : list Z), + x = NULL -> + dlistrep x prev l |-- “ l = nil ” && emp. +Proof. + intros x prev l Hx. + destruct l. + - simpl. + subst x. + split_pure_spatial. + + Intros_p Hnil. + cancel. + + dump_pre_spatial. + reflexivity. + - simpl. + rename z into a. + rename l into l0. + subst x. + Intros y. + contradiction. +Qed. + +Lemma dll_not_zero: forall x prev l, + x <> NULL -> + dlistrep x prev l |-- + EX y a l0, + “ l = a :: l0 ” && + &(x # "list" ->ₛ "data") # Int |-> a ** + &(x # "list" ->ₛ "next") # Ptr |-> y ** + &(x # "list" ->ₛ "prev") # Ptr |-> prev ** + dlistrep y x l0. +Proof. + intros x prev l Hx. + destruct l. + - simpl. + Intros_p Hnull. + contradiction. + - simpl. + rename z into a. + rename l into l0. + Intros y. + Exists y. + Exists a. + Exists l0. + split_pure_spatial. + + cancel (&(x # "list" ->ₛ "data") # Int |-> a). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> y). + cancel (&(x # "list" ->ₛ "prev") # Ptr |-> prev). + cancel (dlistrep y x l0). + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma dllseg_dlistrep : forall x y px py l1 l2, + dllseg x y px py l1 ** dlistrep y py l2 |-- dlistrep x px (l1 ++ l2). +Proof. + intros x y px py l1. + revert x y px py. + induction l1; intros x y px py l2. + - simpl. + Intros_p Hxy. + Intros_p Hpxpy. + subst x. + subst px. + cancel. + - simpl. + Intros z0. + Exists z0. + split_pure_spatial. + + cancel (&(x # "list" ->ₛ "data") # Int |-> a). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> z0). + cancel (&(x # "list" ->ₛ "prev") # Ptr |-> px). + apply (IHl1 z0 y x py l2). + + dump_pre_spatial. + exact H. +Qed. + + diff --git a/benchmarks/Data_structures/dll_queue/rocq/solution_annotated.c b/benchmarks/Data_structures/dll_queue/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..960d74769e7d22e075ec7f9d0d85f7c83bf4b431 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/solution_annotated.c @@ -0,0 +1,120 @@ +struct list { + int data; + struct list *next; + struct list *prev; +}; + +struct queue { + struct list * head; + struct list * tail; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib */ +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) */ +/*@ Extern Coq (dllseg : Z -> Z -> Z -> Z -> list Z -> Assertion) */ +/*@ include strategies "dll_queue_store.strategies" */ + +struct list * malloc_list_cell() + /*@ Require emp + Ensure __return != 0 && + store(&(__return -> next), 0) * + store(&(__return -> prev), 0) * + store(&(__return -> data), 0) + */ + ; + +void free_list_cell(struct list * p) + /*@ Require exists x y z, + store(&(p -> next), x) * + store(&(p -> prev), y) * + store(&(p -> data), z) + Ensure emp + */ + ; + +void enqueue(struct queue * q, int x) + /*@ With l + Require store_queue(q, l) + Ensure store_queue(q, app(l, cons(x, nil))) + */ +{ + /*@ Assert + exists qhead qtail, + q == q@pre && x == x@pre && + dllseg(qhead, 0, 0, qtail, l) * + store(&(q -> head), qhead) * + store(&(q -> tail), qtail) + */ + struct list * p = malloc_list_cell(); + p -> data = x; + if (q -> head == (void *)0) { + q -> head = p; + q -> tail = p; + p -> next = (void *)0; + p -> prev = (void *)0; + } + else { + /*@ Assert exists l0 qtailv qtail qhead qtailnext qtailprev, + x == x@pre && q == q@pre && + p != 0 && + qtail != 0 && qhead != 0 && + l == app(l0, cons(qtailv, nil)) && + qtailnext == 0 && + dllseg(qhead, qtail, 0, qtailprev, l0) * + store(&(q -> tail), qtail) * + store(&(q -> head), qhead) * + store(&(qtail -> next), qtailnext) * + store(&(qtail -> prev), qtailprev) * + store(&(qtail -> data), qtailv) * + store(&(p -> next), 0) * + store(&(p -> prev), 0) * + store(&(p -> data), x) + */ + q -> tail -> next = p; + p -> prev = q -> tail; + q -> tail = p; + p -> next = (void *)0; + } +} + +int dequeue(struct queue * q) + /*@ With x l + Require store_queue(q, cons(x, l)) + Ensure __return == x && store_queue(q, l) + */ +{ + /*@ Assert + exists qhead qtail qheadnext, + q == q@pre && + qhead != 0 && + store(&(qhead -> prev), 0) * + store(&(qhead -> data), x) * + store(&(qhead -> next), qheadnext) * + dllseg(qheadnext, 0, qhead, qtail, l) * + store(&(q -> head), qhead) * + store(&(q -> tail), qtail) + */ + struct list * p = q -> head; + int x0 = p -> data; + q -> head = p -> next; + free_list_cell(p); + if (q -> head == (void *)0) { + q -> tail = (void *)0; + } + else { + /*@ Assert exists qhead qtail headv qheadnext l0, + q == q@pre && + x0 == x && + qhead != 0 && + l == cons(headv, l0) && + store(&(qhead -> prev), p) * + store(&(qhead -> data), headv) * + store(&(qhead -> next), qheadnext) * + dllseg(qheadnext, 0, qhead, qtail, l0) * + store(&(q -> head), qhead) * + store(&(q -> tail), qtail) + */ + q -> head -> prev = (void *)0; + } + return x0; +} diff --git a/benchmarks/Data_structures/dll_queue/rocq/solution_spec.c b/benchmarks/Data_structures/dll_queue/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..535e7aecb5deea2bfc3a5ee09090e904e2599208 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/solution_spec.c @@ -0,0 +1,60 @@ +struct list { + int data; + struct list *next; + struct list *prev; +}; + +struct queue { + struct list * head; + struct list * tail; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.dll_queue.rocq.spec_lib */ +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) */ + +struct list * malloc_list_cell() +; + +void free_list_cell(struct list * p) +; + +void enqueue(struct queue * q, int x) + /*@ With l + Require store_queue(q, l) + Ensure store_queue(q, app(l, cons(x, nil))) + */ +{ + struct list * p = malloc_list_cell(); + p -> data = x; + if (q -> head == (void *)0) { + q -> head = p; + q -> tail = p; + p -> next = (void *)0; + p -> prev = (void *)0; + } + else { + q -> tail -> next = p; + p -> prev = q -> tail; + q -> tail = p; + p -> next = (void *)0; + } +} + +int dequeue(struct queue * q) + /*@ With x l + Require store_queue(q, cons(x, l)) + Ensure __return == x && store_queue(q, l) + */ +{ + struct list * p = q -> head; + int x0 = p -> data; + q -> head = p -> next; + free_list_cell(p); + if (q -> head == (void *)0) { + q -> tail = (void *)0; + } + else { + q -> head -> prev = (void *)0; + } + return x0; +} diff --git a/benchmarks/Data_structures/dll_queue/rocq/spec_lib.v b/benchmarks/Data_structures/dll_queue/rocq/spec_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..3fb19edcccbfa3e53e03ecfe93205649df4dd513 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/rocq/spec_lib.v @@ -0,0 +1,49 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Permutation. +Require Import String. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Import ListNotations. +Local Open Scope list. +Require Import String. +Local Open Scope string. + +Import naive_C_Rules. +Local Open Scope sac. + +Fixpoint dlistrep (x prev: addr) (l: list Z): Assertion := + match l with + | nil => “ x = NULL ” && emp + | a :: l0 => “ x <> NULL ” && + EX y: addr, + &(x # "list" ->ₛ "data") # Int |-> a ** + &(x # "list" ->ₛ "next") # Ptr |-> y ** + &(x # "list" ->ₛ "prev") # Ptr |-> prev ** + dlistrep y x l0 + end. + +Fixpoint dllseg (x y px py: addr) (l: list Z): Assertion := + match l with + | nil => “ x = y ” && “ px = py ” && emp + | a :: l0 => “ x <> NULL ” && + EX z: addr, + &(x # "list" ->ₛ "data") # Int |-> a ** + &(x # "list" ->ₛ "next") # Ptr |-> z ** + &(x # "list" ->ₛ "prev") # Ptr |-> px ** + dllseg z y x py l0 + end. + +Definition store_queue (x: addr) (l: list Z): Assertion := + EX h t: addr, + &(x # "queue" ->ₛ "head") # Ptr |-> h ** + &(x # "queue" ->ₛ "tail") # Ptr |-> t ** + dllseg h NULL NULL t l. diff --git a/benchmarks/Data_structures/dll_queue/solution.c b/benchmarks/Data_structures/dll_queue/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..50b8d2e257959686ab435a42fd7dc8aef41b4716 --- /dev/null +++ b/benchmarks/Data_structures/dll_queue/solution.c @@ -0,0 +1,49 @@ +struct list { + int data; + struct list *next; + struct list *prev; +}; + +struct queue { + struct list * head; + struct list * tail; +}; + +struct list * malloc_list_cell() +; + +void free_list_cell(struct list * p) +; + +void enqueue(struct queue * q, int x) +{ + struct list * p = malloc_list_cell(); + p -> data = x; + if (q -> head == (void *)0) { + q -> head = p; + q -> tail = p; + p -> next = (void *)0; + p -> prev = (void *)0; + } + else { + q -> tail -> next = p; + p -> prev = q -> tail; + q -> tail = p; + p -> next = (void *)0; + } +} + +int dequeue(struct queue * q) +{ + struct list * p = q -> head; + int x0 = p -> data; + q -> head = p -> next; + free_list_cell(p); + if (q -> head == (void *)0) { + q -> tail = (void *)0; + } + else { + q -> head -> prev = (void *)0; + } + return x0; +} diff --git a/benchmarks/Data_structures/functional_queue/manifest.json b/benchmarks/Data_structures/functional_queue/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..ae5ce792b32a9b5ea6f2dffc469c58d991380db2 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "functional_queue", + "source": { + "dataset": "classical_data_structure", + "problem_id": "functional_queue", + "title": "Queue from Two Stacks", + "tags": [ + "data structures", + "queue", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Data_structures/functional_queue/problem.md b/benchmarks/Data_structures/functional_queue/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..966e0ab4a1425591c7f3426457d4326c18165718 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/problem.md @@ -0,0 +1,26 @@ +# Queue from Two Stacks + +## Description + +Maintain a first-in first-out queue of integers represented by two singly linked stacks, a front stack and a back stack, supporting insertion at the back and removal from the front. + +## Input + +List nodes have this type: + +```c +struct list { + int data; + struct list *next; +}; +``` + +In a queue, `l1` is the front stack and `l2` the back stack. + +- `enqueue` receives a queue `q` and an integer `x`. +- `dequeue` receives a non-empty queue `q`. + +## Output + +- `enqueue` appends `x` at the back of `q`. +- `dequeue` removes the element at the front of `q` and returns it. diff --git a/benchmarks/Data_structures/functional_queue/rocq/functional_queue_store.strategies b/benchmarks/Data_structures/functional_queue/rocq/functional_queue_store.strategies new file mode 100644 index 0000000000000000000000000000000000000000..ae95a7dd19f66893da456d3dcf02aa48ef99d909 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/functional_queue_store.strategies @@ -0,0 +1,23 @@ +//test curent rules +//max rule id:30 + +#include "sll_def.h" +#include "functional_queue_store_def.h" + + + + +id : 0 +priority : core(2) +left : store_queue(?p, ?l0) at 0 +right : store_queue(p, ?l1) at 1 +action : left_erase(0); + right_erase(1); + right_add(l0 == l1); + +id : 1 +priority : core(2) +right: cons{Z}(?x1, ?l1) == cons{Z}(?x2, ?l2) at 0 +action : right_erase(0); + right_add(x1 == x2); + right_add(l1 == l2); diff --git a/benchmarks/Data_structures/functional_queue/rocq/functional_queue_store_def.h b/benchmarks/Data_structures/functional_queue/rocq/functional_queue_store_def.h new file mode 100644 index 0000000000000000000000000000000000000000..afdc946ab0b0c0ed980fe788403ffb6110455870 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/functional_queue_store_def.h @@ -0,0 +1,9 @@ +struct queue { + struct list * l1; + struct list * l2; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib */ + +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) + */ diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_goal.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..73f39b64280f71dfa0290c40fd9888d380b0adb3 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_goal.v @@ -0,0 +1,508 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +Local Open Scope sac. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_proof. +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_store_strategy_goal. +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_store_strategy_proof. + +(*----- Function reverse -----*) + +Definition reverse_safety_wit_1 := +forall (p_pre: Z) (l: (@list Z)) , + ((( &( "w" ) )) # Ptr |->_) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** (sll p_pre l ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition reverse_entail_wit_1 := +( +forall (p_pre: Z) (l: (@list Z)) , + (sll p_pre l ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app ((rev (l1))) (l2))) ” + && (sll 0 l1 ) + ** (sll p_pre l2 ) +) \/ +( +forall (l: (@list Z)) , + TT && emp +|-- + “ (l = (app ((rev ((@nil Z)))) (l))) ” + && emp +). + +Definition reverse_entail_wit_1_split_goal_1 := +forall (l: (@list Z)) , + (l = (app ((rev ((@nil Z)))) (l))) +. + +Definition reverse_entail_wit_2 := +forall (l: (@list Z)) (v: Z) (w: Z) (l1_2: (@list Z)) (l2_2: (@list Z)) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) , + (sll w l1_2 ) + ** (sll v l2_2 ) +|-- + EX (vnext: Z) (vdata: Z) (l2_new: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app ((rev (l1))) (l2))) ” + && “ (v <> 0) ” + && “ (l2 = (cons (vdata) (l2_new))) ” + && (sll w l1 ) + ** ((&((v) # "list" ->ₛ "data")) # Int |-> vdata) + ** ((&((v) # "list" ->ₛ "next")) # Ptr |-> vnext) + ** (sll vnext l2_new ) +. + +Definition reverse_entail_wit_3 := +( +forall (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l2_new: (@list Z)) (vnext: Z) (vdata: Z) (v: Z) (w: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (vdata) (l2_new)))) , + (sll w l1_2 ) + ** ((&((v) # "list" ->ₛ "data")) # Int |-> vdata) + ** ((&((v) # "list" ->ₛ "next")) # Ptr |-> w) + ** (sll vnext l2_new ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app ((rev (l1))) (l2))) ” + && (sll v l1 ) + ** (sll vnext l2 ) +) \/ +( +forall (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l2_new: (@list Z)) (vdata: Z) (v: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (vdata) (l2_new)))) , + TT && emp +|-- + “ (l = (app ((rev ((cons (vdata) (l1_2))))) (l2_new))) ” + && emp +). + +Definition reverse_entail_wit_3_split_goal_1 := +forall (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l2_new: (@list Z)) (vdata: Z) (v: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (vdata) (l2_new)))) , + (l = (app ((rev ((cons (vdata) (l1_2))))) (l2_new))) +. + +Definition reverse_return_wit_1 := +( +forall (l: (@list Z)) (v: Z) (w: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll w l1 ) + ** (sll v l2 ) +|-- + (sll w (rev (l)) ) +) \/ +( +forall (l: (@list Z)) (v: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll v l2 ) +|-- + “ (l1 = (rev (l))) ” + && emp +). + +Definition reverse_return_wit_1_split_goal_1 := +forall (l: (@list Z)) (v: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll v l2 ) +|-- + “ (l1 = (rev (l))) ” +. + +Definition reverse_return_wit_1_split_goal_spatial := +forall (l: (@list Z)) (v: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll v l2 ) +|-- + TT && emp +. + +(*----- Function push -----*) + +Definition push_return_wit_1 := +forall (x_pre: Z) (p_pre: Z) (l: (@list Z)) (p_pre_v_2: Z) (retval_data: Z) (retval_next: Z) (retval: Z) (PreH1 : (retval <> 0)) (PreH2 : (retval_next = 0)) (PreH3 : (retval_data = 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> p_pre_v_2) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((p_pre) # Ptr |-> retval) + ** (sll p_pre_v_2 l ) +|-- + EX (p_pre_v: Z) , + ((p_pre) # Ptr |-> p_pre_v) + ** (sll p_pre_v (cons (x_pre) (l)) ) +. + +Definition push_partial_solve_wit_1 := +forall (p_pre: Z) (l: (@list Z)) (p_pre_v: Z) , + ((p_pre) # Ptr |-> p_pre_v) + ** (sll p_pre_v l ) +|-- + ((p_pre) # Ptr |-> p_pre_v) + ** (sll p_pre_v l ) +. + +(*----- Function pop -----*) + +Definition pop_return_wit_1 := +forall (p_pre: Z) (l: (@list Z)) (x: Z) (y: Z) , + (sll y l ) + ** ((p_pre) # Ptr |-> y) +|-- + EX (p_pre_v: Z) , + “ (x = x) ” + && ((p_pre) # Ptr |-> p_pre_v) + ** (sll p_pre_v l ) +. + +Definition pop_partial_solve_wit_1 := +forall (p_pre: Z) (l: (@list Z)) (x: Z) (p_pre_v: Z) , + ((p_pre) # Ptr |-> p_pre_v) + ** (sll p_pre_v (cons (x) (l)) ) +|-- + EX (y: Z) , + ((&((p_pre_v) # "list" ->ₛ "data")) # Int |-> x) + ** (sll y l ) + ** ((&((p_pre_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((p_pre) # Ptr |-> p_pre_v) +. + +Definition pop_partial_solve_wit_2 := +forall (p_pre: Z) (l: (@list Z)) (x: Z) (p_pre_v: Z) (y: Z) , + ((&((p_pre_v) # "list" ->ₛ "data")) # Int |-> x) + ** (sll y l ) + ** ((&((p_pre_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((p_pre) # Ptr |-> y) +|-- + ((&((p_pre_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((p_pre_v) # "list" ->ₛ "data")) # Int |-> x) + ** (sll y l ) + ** ((p_pre) # Ptr |-> y) +. + +(*----- Function enqueue -----*) + +Definition enqueue_entail_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) , + (store_queue q_pre l ) +|-- + EX (ql2: Z) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) , + (store_queue q_pre l ) +|-- + EX (ql2: Z) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +). + +Definition enqueue_return_wit_1 := +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) (p_callee_v: Z) (PreH1 : (l = (app (l1) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> p_callee_v) + ** (sll p_callee_v (cons (x_pre) (l2)) ) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** (sll ql1 l1 ) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +) \/ +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) (p_callee_v: Z) (y: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (x_pre >= INT_MIN)) (PreH3 : (l = (app (l1) ((rev (l2)))))) , + (sll y l2 ) + ** ((&((p_callee_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((p_callee_v) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> p_callee_v) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** (sll ql1 l1 ) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +). + +Definition enqueue_return_wit_1_split_goal_spatial := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) (p_callee_v: Z) (y: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (x_pre >= INT_MIN)) (PreH3 : (l = (app (l1) ((rev (l2)))))) , + (sll y l2 ) + ** ((&((p_callee_v) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((p_callee_v) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> p_callee_v) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** (sll ql1 l1 ) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +. + +Definition enqueue_partial_solve_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (ql1: Z) (ql2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app (l1) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +|-- + “ (l = (app (l1) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql2 l2 ) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** (sll ql1 l1 ) +. + +(*----- Function dequeue -----*) + +Definition dequeue_safety_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1: Z) (ql2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition dequeue_safety_wit_2 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1: Z) (ql2: Z) (l1: (@list Z)) (l2: (@list Z)) (retval: Z) (PreH1 : (ql1 = 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + (sll retval (rev (l2)) ) + ** ((( &( "q" ) )) # Ptr |-> q_pre) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition dequeue_entail_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) , + (store_queue q_pre (cons (x) (l)) ) +|-- + EX (ql2: Z) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) , + “ ((cons (x) (l)) = (app (l1) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) , + (store_queue q_pre (cons (x) (l)) ) +|-- + EX (ql2: Z) (ql1: Z) (l1: (@list Z)) (l2: (@list Z)) , + “ ((cons (x) (l)) = (app (l1) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +). + +Definition dequeue_entail_wit_2 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1_2: Z) (l1: (@list Z)) (l2: (@list Z)) (retval: Z) (PreH1 : (ql1_2 = 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + (sll retval (rev (l2)) ) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> retval) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> 0) + ** (sll ql1_2 l1 ) +|-- + EX (ql1: Z) (rev_l2: (@list Z)) , + “ ((cons (x) (l)) = rev_l2) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> 0) + ** (sll ql1 rev_l2 ) +) \/ +( +forall (l: (@list Z)) (x: Z) (ql1_2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (ql1_2 = 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + (sll ql1_2 l1 ) +|-- + “ ((rev (l2)) = (cons (x) (l))) ” + && emp +). + +Definition dequeue_entail_wit_2_split_goal_1 := +forall (l: (@list Z)) (x: Z) (ql1_2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (ql1_2 = 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + (sll ql1_2 l1 ) +|-- + “ ((rev (l2)) = (cons (x) (l))) ” +. + +Definition dequeue_entail_wit_2_split_goal_spatial := +forall (l: (@list Z)) (x: Z) (ql1_2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (ql1_2 = 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + (sll ql1_2 l1 ) +|-- + TT && emp +. + +Definition dequeue_entail_wit_3 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1_2: Z) (ql2_2: Z) (l1: (@list Z)) (l2_2: (@list Z)) (PreH1 : (ql1_2 <> 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2_2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1_2) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2_2) + ** (sll ql1_2 l1 ) + ** (sll ql2_2 l2_2 ) +|-- + EX (ql2: Z) (l1_tail: (@list Z)) (l2: (@list Z)) (ql1: Z) , + “ (ql1 <> 0) ” + && “ ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 (cons (x) (l1_tail)) ) + ** (sll ql2 l2 ) +) \/ +( +forall (l: (@list Z)) (x: Z) (ql1_2: Z) (l1: (@list Z)) (l2_2: (@list Z)) (PreH1 : (ql1_2 <> 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2_2)))))) , + TT && emp +|-- + EX (l1_tail: (@list Z)) , + “ (l1 = (cons (x) (l1_tail))) ” + && “ ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2_2))))) ” + && emp +). + +Definition dequeue_entail_wit_4_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (rev_l2: (@list Z)) (ql1_2: Z) (PreH1 : ((cons (x) (l)) = rev_l2)) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1_2) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> 0) + ** (sll ql1_2 rev_l2 ) +|-- + EX (ql2: Z) (ql1: Z) (l1_tail: (@list Z)) (l2: (@list Z)) , + “ ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 (cons (x) (l1_tail)) ) + ** (sll ql2 l2 ) +) \/ +( +forall (l: (@list Z)) (x: Z) (rev_l2: (@list Z)) (PreH1 : ((cons (x) (l)) = rev_l2)) , + TT && emp +|-- + EX (l1_tail: (@list Z)) , + “ ((cons (x) (l)) = (cons (x) (l1_tail))) ” + && “ ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev ((@nil Z)))))) ” + && emp +). + +Definition dequeue_entail_wit_4_2 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1_2: Z) (ql2_2: Z) (l1_tail_2: (@list Z)) (l2_2: (@list Z)) (PreH1 : (ql1_2 <> 0)) (PreH2 : ((cons (x) (l)) = (app ((cons (x) (l1_tail_2))) ((rev (l2_2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1_2) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2_2) + ** (sll ql1_2 (cons (x) (l1_tail_2)) ) + ** (sll ql2_2 l2_2 ) +|-- + EX (ql2: Z) (ql1: Z) (l1_tail: (@list Z)) (l2: (@list Z)) , + “ ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 (cons (x) (l1_tail)) ) + ** (sll ql2 l2 ) +. + +Definition dequeue_return_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql2: Z) (l1_tail: (@list Z)) (l2: (@list Z)) (p_callee_v: Z) (retval: Z) (PreH1 : (retval = x)) (PreH2 : ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> p_callee_v) + ** (sll p_callee_v l1_tail ) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql2 l2 ) +|-- + “ (retval = x) ” + && (store_queue q_pre l ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql2: Z) (l1_tail: (@list Z)) (l2: (@list Z)) (p_callee_v: Z) (retval: Z) (PreH1 : (retval = x)) (PreH2 : ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> p_callee_v) + ** (sll p_callee_v l1_tail ) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql2 l2 ) +|-- + (store_queue q_pre l ) +). + +Definition dequeue_return_wit_1_split_goal_spatial := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql2: Z) (l1_tail: (@list Z)) (l2: (@list Z)) (p_callee_v: Z) (retval: Z) (PreH1 : (retval = x)) (PreH2 : ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> p_callee_v) + ** (sll p_callee_v l1_tail ) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql2 l2 ) +|-- + (store_queue q_pre l ) +. + +Definition dequeue_partial_solve_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1: Z) (ql2: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (ql1 = 0)) (PreH2 : ((cons (x) (l)) = (app (l1) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) + ** (sll ql2 l2 ) +|-- + “ (ql1 = 0) ” + && “ ((cons (x) (l)) = (app (l1) ((rev (l2))))) ” + && (sll ql2 l2 ) + ** ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 l1 ) +. + +Definition dequeue_partial_solve_wit_2 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (ql1: Z) (ql2: Z) (l1_tail: (@list Z)) (l2: (@list Z)) (PreH1 : ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2)))))) , + ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql1 (cons (x) (l1_tail)) ) + ** (sll ql2 l2 ) +|-- + “ ((cons (x) (l)) = (app ((cons (x) (l1_tail))) ((rev (l2))))) ” + && ((&((q_pre) # "queue" ->ₛ "l1")) # Ptr |-> ql1) + ** (sll ql1 (cons (x) (l1_tail)) ) + ** ((&((q_pre) # "queue" ->ₛ "l2")) # Ptr |-> ql2) + ** (sll ql2 l2 ) +. + +Module Type VC_Correct. + +Include sll_Strategy_Correct. +Include functional_queue_store_Strategy_Correct. + +Axiom proof_of_reverse_safety_wit_1 : reverse_safety_wit_1. +Axiom proof_of_reverse_entail_wit_1 : reverse_entail_wit_1. +Axiom proof_of_reverse_entail_wit_2 : reverse_entail_wit_2. +Axiom proof_of_reverse_entail_wit_3 : reverse_entail_wit_3. +Axiom proof_of_reverse_return_wit_1 : reverse_return_wit_1. +Axiom proof_of_push_return_wit_1 : push_return_wit_1. +Axiom proof_of_push_partial_solve_wit_1 : push_partial_solve_wit_1. +Axiom proof_of_pop_return_wit_1 : pop_return_wit_1. +Axiom proof_of_pop_partial_solve_wit_1 : pop_partial_solve_wit_1. +Axiom proof_of_pop_partial_solve_wit_2 : pop_partial_solve_wit_2. +Axiom proof_of_enqueue_entail_wit_1 : enqueue_entail_wit_1. +Axiom proof_of_enqueue_return_wit_1 : enqueue_return_wit_1. +Axiom proof_of_enqueue_partial_solve_wit_1 : enqueue_partial_solve_wit_1. +Axiom proof_of_dequeue_safety_wit_1 : dequeue_safety_wit_1. +Axiom proof_of_dequeue_safety_wit_2 : dequeue_safety_wit_2. +Axiom proof_of_dequeue_entail_wit_1 : dequeue_entail_wit_1. +Axiom proof_of_dequeue_entail_wit_2 : dequeue_entail_wit_2. +Axiom proof_of_dequeue_entail_wit_3 : dequeue_entail_wit_3. +Axiom proof_of_dequeue_entail_wit_4_1 : dequeue_entail_wit_4_1. +Axiom proof_of_dequeue_entail_wit_4_2 : dequeue_entail_wit_4_2. +Axiom proof_of_dequeue_return_wit_1 : dequeue_return_wit_1. +Axiom proof_of_dequeue_partial_solve_wit_1 : dequeue_partial_solve_wit_1. +Axiom proof_of_dequeue_partial_solve_wit_2 : dequeue_partial_solve_wit_2. + +End VC_Correct. diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_goal_check.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..457e847ffc52c4013af5d8a790c92818c6713da7 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_goal_check.v @@ -0,0 +1,8 @@ +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_goal functional_queue_proof_auto functional_queue_proof_manual. + +Module VC_Correctness : VC_Correct. + Include sll_strategy_proof. + Include functional_queue_store_strategy_proof. + Include functional_queue_proof_auto. + Include functional_queue_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_proof_auto.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..3d0e5576f301e3d18facbc5ebbbb863d26fee595 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_proof_auto.v @@ -0,0 +1,62 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +Local Open Scope sac. + +Lemma proof_of_reverse_safety_wit_1 : reverse_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_reverse_entail_wit_2 : reverse_entail_wit_2. +Proof. Admitted. + +Lemma proof_of_push_return_wit_1 : push_return_wit_1. +Proof. Admitted. + +Lemma proof_of_push_partial_solve_wit_1 : push_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_pop_return_wit_1 : pop_return_wit_1. +Proof. Admitted. + +Lemma proof_of_pop_partial_solve_wit_1 : pop_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_pop_partial_solve_wit_2 : pop_partial_solve_wit_2. +Proof. Admitted. + +Lemma proof_of_enqueue_partial_solve_wit_1 : enqueue_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_dequeue_safety_wit_1 : dequeue_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_dequeue_safety_wit_2 : dequeue_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_dequeue_entail_wit_4_2 : dequeue_entail_wit_4_2. +Proof. Admitted. + +Lemma proof_of_dequeue_partial_solve_wit_1 : dequeue_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_dequeue_partial_solve_wit_2 : dequeue_partial_solve_wit_2. +Proof. Admitted. + diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_proof_manual.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..661d3ab8a359a9f6a80a682d8e504d13a6cad0e4 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_proof_manual.v @@ -0,0 +1,215 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_goal. +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_enqueue_return_wit_1 : enqueue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + subst. + Exists ql1 p_callee_v l1 (x_pre :: l2). + split_pure_spatial. + - cancel (&((q_pre) # "queue" ->ₛ "l1") # Ptr |-> ql1). + cancel (&((q_pre) # "queue" ->ₛ "l2") # Ptr |-> p_callee_v). + cancel (sll ql1 l1). + cancel (sll p_callee_v (x_pre :: l2)). + - dump_pre_spatial. + simpl. + rewrite app_assoc. + reflexivity. +Qed. + +Lemma proof_of_enqueue_entail_wit_1 : enqueue_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Intros p1 p2 l1 l2. + Exists p2 p1 l1 l2. + split_pure_spatial. + - cancel (&((q_pre) # "queue" ->ₛ "l1") # Ptr |-> p1). + cancel (&((q_pre) # "queue" ->ₛ "l2") # Ptr |-> p2). + cancel (sll p1 l1). + cancel (sll p2 l2). + - dump_pre_spatial. + auto. +Qed. + +Lemma proof_of_dequeue_return_wit_1 : dequeue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst. + unfold store_queue. + simpl in PreH2. + inversion PreH2; subst. + Exists p_callee_v ql2 l1_tail l2. + split_pure_spatial. + - cancel (&((q_pre) # "queue" ->ₛ "l1") # Ptr |-> p_callee_v). + cancel (&((q_pre) # "queue" ->ₛ "l2") # Ptr |-> ql2). + cancel (sll p_callee_v l1_tail). + cancel (sll ql2 l2). + - split_pures ; dump_pre_spatial ; reflexivity. +Qed. + +Lemma proof_of_dequeue_entail_wit_1 : dequeue_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Intros p1 p2 l1 l2. + Exists p2 p1 l1 l2. + split_pure_spatial. + - cancel (&((q_pre) # "queue" ->ₛ "l1") # Ptr |-> p1). + cancel (&((q_pre) # "queue" ->ₛ "l2") # Ptr |-> p2). + cancel (sll p1 l1). + cancel (sll p2 l2). + - dump_pre_spatial. + auto. +Qed. + +Lemma proof_of_dequeue_entail_wit_2 : dequeue_entail_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + sep_apply (sll_zero ql1_2 l1); [ | tauto ]. + Intros. + subst. + Exists retval. + Exists (rev l2). + split_pure_spatial. + - cancel (&((q_pre) # "queue" ->ₛ "l1") # Ptr |-> retval). + cancel (&((q_pre) # "queue" ->ₛ "l2") # Ptr |-> 0). + cancel (sll retval (rev l2)). + - dump_pre_spatial. + simpl in PreH2. + auto. +Qed. + +Lemma proof_of_dequeue_entail_wit_3 : dequeue_entail_wit_3. +Proof. + LLM_pre_process ltac:(int_auto). + sep_apply sll_not_zero; [ | tauto]. + Intros y a l0. + Exists ql2_2. + Exists l0. + Exists l2_2. + Exists ql1_2. + split_pure_spatial. + - match goal with + | Hcons : l1 = _ :: _ |- _ => rewrite Hcons in PreH2 + end. + inversion PreH2; subst. + cancel (&((q_pre) # "queue" ->ₛ "l1") # Ptr |-> ql1_2). + cancel (&((q_pre) # "queue" ->ₛ "l2") # Ptr |-> ql2_2). + simpl. + Exists y. + split_pure_spatial. + * cancel ((&((ql1_2) # "list" ->ₛ "data")) # Int |-> a). + cancel ((&((ql1_2) # "list" ->ₛ "next")) # Ptr |-> y). + cancel (sll y l0). + cancel (sll ql2_2 l2_2). + * dump_pre_spatial. + auto. + - split_pures ; dump_pre_spatial ; auto. + match goal with + | Hcons : l1 = _ :: _ |- _ => rewrite Hcons in PreH2 + end. + inversion PreH2; subst. + reflexivity. +Qed. + +Lemma proof_of_dequeue_entail_wit_4_1 : dequeue_entail_wit_4_1. +Proof. + LLM_pre_process ltac:(int_auto). + Exists 0 ql1_2. + destruct rev_l2 ; try discriminate. + inversion PreH1. subst. + Exists rev_l2. + Exists nil. + split_pure_spatial. + + cancel (&( q_pre # "queue" ->ₛ "l1") # Ptr |-> ql1_2). + cancel (&( q_pre # "queue" ->ₛ "l2") # Ptr |-> 0). + cancel (sll ql1_2 (z :: rev_l2)). + simpl. + split_pure_spatial. + * reflexivity. + * easy. + + dump_pre_spatial. + simpl. + rewrite app_nil_r. + reflexivity. +Qed. + +Lemma proof_of_reverse_entail_wit_1 : reverse_entail_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists nil l. + split_pure_spatial. + - simpl sll. + split_pure_spatial. + + cancel (sll p_pre l). + + dump_pre_spatial. + reflexivity. + - dump_pre_spatial. + simpl. + reflexivity. +Qed. + +Lemma proof_of_reverse_entail_wit_3 : reverse_entail_wit_3. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists (vdata :: l1_2) l2_new. + split_pure_spatial. + - cancel (sll vnext l2_new). + simpl sll. + Exists w. + split_pure_spatial. + + cancel. + + dump_pre_spatial. + exact PreH2. + - dump_pre_spatial. + subst l2_2. + simpl. + rewrite <- app_assoc. + simpl. + exact PreH1. +Qed. + +Lemma proof_of_reverse_return_wit_1 : reverse_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + sep_apply (sll_zero v l2); [ | tauto ]. + Intros_p Hl2. + rewrite Hl2 in PreH1. + rewrite app_nil_r in PreH1. + subst l. + rewrite rev_involutive. + cancel (sll w l1). +Qed. diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_goal.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..feb9822af707dc7a99abc998b5bc5d453be30201 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_goal.v @@ -0,0 +1,56 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +Require Import Coq.micromega.Psatz. +From SimpleC.SL Require Import SeparationLogic. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Definition functional_queue_store_strategy0 := + forall (p : Z) (l0 : (@list Z)), + TT && + emp ** + ((store_queue p l0)) + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list Z)), + TT && + (“ (l0 = l1) ”) && + emp -* + TT && + emp ** + ((store_queue p l1)) + ). + +Definition functional_queue_store_strategy1 := + TT && + emp + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list Z)) (l2 : (@list Z)) (x2 : Z) (x1 : Z), + TT && + (“ (x1 = x2) ”) && + (“ (l1 = l2) ”) && + emp -* + TT && + (“ ((@cons Z x1 l1) = (@cons Z x2 l2)) ”) && + emp + ). + +Module Type functional_queue_store_Strategy_Correct. + + Axiom functional_queue_store_strategy0_correctness : functional_queue_store_strategy0. + Axiom functional_queue_store_strategy1_correctness : functional_queue_store_strategy1. + +End functional_queue_store_Strategy_Correct. diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_goal_check.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..72f78971e18a83fddec72cdd3b68ed2f8f51209d --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_goal_check.v @@ -0,0 +1,5 @@ +From PVbench.Data_structures.functional_queue.rocq.groundtruth Require Import functional_queue_store_strategy_goal functional_queue_store_strategy_proof. + +Module functional_queue_store_Strategy_Correctness : functional_queue_store_Strategy_Correct. + Include functional_queue_store_strategy_proof. +End functional_queue_store_Strategy_Correctness. diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_proof.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_proof.v new file mode 100644 index 0000000000000000000000000000000000000000..51ebc0df653129973fb02708ce1f817a9c4203bc --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/functional_queue_store_strategy_proof.v @@ -0,0 +1,35 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +From SimpleC.SL Require Import SeparationLogic. +Require Import PVbench.Data_structures.functional_queue.rocq.groundtruth.functional_queue_store_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.groundtruth.proof_lib. +Import naive_C_Rules. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Lemma functional_queue_store_strategy0_correctness : functional_queue_store_strategy0. +Proof. + pre_process_default. + Intros_p H. + subst l1. + cancel. +Qed. + +Lemma functional_queue_store_strategy1_correctness : functional_queue_store_strategy1. +Proof. + pre_process_default. + Intros_p H. + Intros_p H0. + subst x2 l2. + split_pure_spatial. + 2: { + dump_pre_spatial. + reflexivity. + } + cancel. +Qed. diff --git a/benchmarks/Data_structures/functional_queue/rocq/groundtruth/proof_lib.v b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..85e62aeae20400fb97f0cf110edb5487c0801906 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/groundtruth/proof_lib.v @@ -0,0 +1,22 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib. +Local Open Scope sac. + diff --git a/benchmarks/Data_structures/functional_queue/rocq/solution_annotated.c b/benchmarks/Data_structures/functional_queue/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..e8dae302975935631be80c220df6b0febdc6896c --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/solution_annotated.c @@ -0,0 +1,144 @@ +#include "sll_def.h" +struct queue { + struct list * l1; + struct list * l2; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib */ +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) */ +/*@ include strategies "functional_queue_store.strategies" */ + +struct list * malloc_list_cell() + /*@ Require emp + Ensure __return != 0 && + __return -> next == 0 && + __return -> data == 0 && emp + */ + ; + +void free_list_cell(struct list * p) + /*@ Require exists x y, p -> next == x && p -> data == y && emp + Ensure emp + */ + ; + +struct list *reverse(struct list *p) +/*@ With (l: list Z) + Require sll(p, l) + Ensure sll(__return, rev(l)) +*/ +{ + struct list * w = (void *) 0, * v = p; + /*@ Inv Assert + exists l1 l2, + p == p@pre && + l == app(rev(l1), l2) && + sll(w, l1) * sll(v, l2) + */ + while (v) { + /*@ Assert exists l1 l2 l2_new vnext vdata, + p == p@pre && + l == app(rev(l1), l2) && + v != 0 && + l2 == cons(vdata, l2_new) && + sll(w, l1) * + store(&(v -> data), vdata) * + store(&(v -> next), vnext) * + sll(vnext, l2_new) + */ + struct list * t = v -> next; + v -> next = w; + w = v; + v = t; + } + return w; +} + +void push(struct list * * p, int x) +/*@ With l + Require sll(* p, l) + Ensure sll(* p, cons(x, l)) + */ +{ + struct list * px = malloc_list_cell(); + px -> data = x; + px -> next = * p; + * p = px; +} + +int pop(struct list * * p) +/*@ With x l + Require sll(* p, cons(x, l)) + Ensure __return == x && sll(* p, l) + */ +{ + struct list * px = * p; + int x0 = px -> data; + * p = px -> next; + free_list_cell(px); + return x0; +} + +void enqueue(struct queue * q, int x) +/*@ With l + Require store_queue(q, l) + Ensure store_queue(q, app(l, cons(x, nil))) + */ +{ + /*@ Assert exists ql1 ql2 l1 l2, + q == q@pre && x == x@pre && + l == app(l1, rev(l2)) && + store(&(q -> l1), ql1) * + store(&(q -> l2), ql2) * + sll(ql1, l1) * + sll(ql2, l2) + */ + push(&(q -> l2), x); +} + +int dequeue(struct queue * q) +/*@ With x l + Require store_queue(q, cons(x, l)) + Ensure __return == x && store_queue(q, l) + */ +{ + /*@ Assert exists ql1 ql2 l1 l2, + q == q@pre && + cons(x, l) == app(l1, rev(l2)) && + store(&(q -> l1), ql1) * + store(&(q -> l2), ql2) * + sll(ql1, l1) * + sll(ql2, l2) + */ + if (q -> l1 == (void *) 0) { + q -> l1 = reverse(q -> l2); + q -> l2 = (void *) 0; + /*@ Assert exists rev_l2 ql1, + q == q@pre && + cons(x, l) == rev_l2 && + store(&(q -> l1), ql1) * + store(&(q -> l2), 0) * + sll(ql1, rev_l2) + */ + } + else { + /*@ Assert exists ql1 ql2 l1_tail l2, + q == q@pre && + ql1 != 0 && + cons(x, l) == app(cons(x, l1_tail), rev(l2)) && + store(&(q -> l1), ql1) * + store(&(q -> l2), ql2) * + sll(ql1, cons(x, l1_tail)) * + sll(ql2, l2) + */ + } + /*@ Assert exists ql1 ql2 l1_tail l2, + q == q@pre && + cons(x, l) == app(cons(x, l1_tail), rev(l2)) && + store(&(q -> l1), ql1) * + store(&(q -> l2), ql2) * + sll(ql1, cons(x, l1_tail)) * + sll(ql2, l2) + */ + return pop(&(q -> l1)); +} diff --git a/benchmarks/Data_structures/functional_queue/rocq/solution_spec.c b/benchmarks/Data_structures/functional_queue/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..cc949b2b5e09624253ca80c82bc532956efa406a --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/solution_spec.c @@ -0,0 +1,70 @@ +#include "sll_def.h" +struct queue { + struct list * l1; + struct list * l2; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.functional_queue.rocq.spec_lib */ +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) */ + +struct list * malloc_list_cell() +; + +void free_list_cell(struct list * p) +; + +struct list *reverse(struct list *p) +{ + struct list * w = (void *) 0, * v = p; + + while (v) { + struct list * t = v -> next; + v -> next = w; + w = v; + v = t; + } + return w; +} + +void push(struct list * * p, int x) +{ + struct list * px = malloc_list_cell(); + px -> data = x; + px -> next = * p; + * p = px; +} + +int pop(struct list * * p) +{ + struct list * px = * p; + int x0 = px -> data; + * p = px -> next; + free_list_cell(px); + return x0; +} + +void enqueue(struct queue * q, int x) +/*@ With l + Require store_queue(q, l) + Ensure store_queue(q, app(l, cons(x, nil))) + */ +{ + push(&(q -> l2), x); +} + +int dequeue(struct queue * q) +/*@ With x l + Require store_queue(q, cons(x, l)) + Ensure __return == x && store_queue(q, l) + */ +{ + if (q -> l1 == (void *) 0) { + q -> l1 = reverse(q -> l2); + q -> l2 = (void *) 0; + + } + else { + } + + return pop(&(q -> l1)); +} diff --git a/benchmarks/Data_structures/functional_queue/rocq/spec_lib.v b/benchmarks/Data_structures/functional_queue/rocq/spec_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..b77f8e461a81b2305d565b2485ce8af0b8e77f9d --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/rocq/spec_lib.v @@ -0,0 +1,27 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Permutation. +Require Import String. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Local Open Scope Z_scope. +Local Open Scope sets. +Import ListNotations. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +Local Open Scope sac. + +Definition store_queue (x: addr) (l: list Z): Assertion := + EX (p1 p2: addr) (l1 l2: list Z), + “ l = l1 ++ rev l2 ” && + &(x # "queue" ->ₛ "l1") # Ptr |-> p1 ** + &(x # "queue" ->ₛ "l2") # Ptr |-> p2 ** + sll p1 l1 ** sll p2 l2. diff --git a/benchmarks/Data_structures/functional_queue/solution.c b/benchmarks/Data_structures/functional_queue/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..ba936768bfe31b310a5af985952de3cb498ad333 --- /dev/null +++ b/benchmarks/Data_structures/functional_queue/solution.c @@ -0,0 +1,59 @@ +#include "sll_def.h" +struct queue { + struct list * l1; + struct list * l2; +}; + +struct list * malloc_list_cell() +; + +void free_list_cell(struct list * p) +; + +struct list *reverse(struct list *p) +{ + struct list * w = (void *) 0, * v = p; + + while (v) { + struct list * t = v -> next; + v -> next = w; + w = v; + v = t; + } + return w; +} + +void push(struct list * * p, int x) +{ + struct list * px = malloc_list_cell(); + px -> data = x; + px -> next = * p; + * p = px; +} + +int pop(struct list * * p) +{ + struct list * px = * p; + int x0 = px -> data; + * p = px -> next; + free_list_cell(px); + return x0; +} + +void enqueue(struct queue * q, int x) +{ + push(&(q -> l2), x); +} + +int dequeue(struct queue * q) +{ + if (q -> l1 == (void *) 0) { + q -> l1 = reverse(q -> l2); + q -> l2 = (void *) 0; + + } + else { + } + + return pop(&(q -> l1)); +} diff --git a/benchmarks/Data_structures/polymorphic_sll/manifest.json b/benchmarks/Data_structures/polymorphic_sll/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..48ddd0df39479b504199d555a1555cda745a334b --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/manifest.json @@ -0,0 +1,18 @@ +{ + "id": "polymorphic_sll", + "source": { + "dataset": "classical_data_structure", + "problem_id": "polymorphic_sll", + "title": "Generic Singly Linked List Reversal", + "tags": [ + "data structures", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Data_structures/polymorphic_sll/problem.md b/benchmarks/Data_structures/polymorphic_sll/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..f0b2109faf392ecd3cb8a5819b28428dad5f21bd --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/problem.md @@ -0,0 +1,13 @@ +# Generic Singly Linked List Reversal + +## Description + +Reverse, in place, a null-terminated singly linked list whose nodes hold untyped data pointers. The payload behind each data pointer may be any representation; it must be preserved unchanged. + +## Input + +The function receives the head `p` of the list. + +## Output + +Return the head of the reversed list. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_goal.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..5ccc6f442a7969189ba16aa4b2a79ab4d6b3da9c --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_goal.v @@ -0,0 +1,154 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib. +Local Open Scope sac. +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_strategy_goal. +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_strategy_proof. + +(*----- Function reverse -----*) + +Definition reverse_safety_wit_1 := +forall (A: Type) (p_pre: Z) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) , + ((( &( "w" ) )) # Ptr |->_) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** (sll storeA p_pre l ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition reverse_entail_wit_1 := +forall (A: Type) (p_pre: Z) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) , + (sll storeA p_pre l ) +|-- + “ (0 = 0) ” + && “ (p_pre = p_pre) ” + && (sll storeA 0 (@nil A) ) + ** (sll storeA p_pre l ) +. + +Definition reverse_entail_wit_2 := +( +forall (A: Type) (p_pre: Z) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (w: Z) (v: Z) (PreH1 : (w = 0)) (PreH2 : (v = p_pre)) , + (sll storeA w (@nil A) ) + ** (sll storeA v l ) +|-- + EX (l1: (@list A)) (l2: (@list A)) , + “ (l = (app ((rev (l1))) (l2))) ” + && (sll storeA w l1 ) + ** (sll storeA v l2 ) +) \/ +( +forall (A: Type) (p_pre: Z) (l: (@list A)) (w: Z) (v: Z) (PreH1 : (w = 0)) (PreH2 : (v = p_pre)) , + TT && emp +|-- + “ (l = (app ((rev ((@nil A)))) (l))) ” + && emp +). + +Definition reverse_entail_wit_2_split_goal_1 := +forall (A: Type) (p_pre: Z) (l: (@list A)) (w: Z) (v: Z) (PreH1 : (w = 0)) (PreH2 : (v = p_pre)) , + (l = (app ((rev ((@nil A)))) (l))) +. + +Definition reverse_entail_wit_3 := +forall (A: Type) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (v: Z) (w: Z) (l1_2: (@list A)) (l2_2: (@list A)) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) , + (sll storeA w l1_2 ) + ** (sll storeA v l2_2 ) +|-- + EX (vnext: Z) (vdata: Z) (x: A) (xs: (@list A)) (l1: (@list A)) (l2: (@list A)) , + “ (l = (app ((rev (l1))) (l2))) ” + && “ (v <> 0) ” + && “ (l2 = (cons (x) (xs))) ” + && (sll storeA w l1 ) + ** ((&((v) # "list" ->ₛ "data")) # Ptr |-> vdata) + ** (storeA vdata x ) + ** ((&((v) # "list" ->ₛ "next")) # Ptr |-> vnext) + ** (sll storeA vnext xs ) +. + +Definition reverse_entail_wit_4 := +( +forall (A: Type) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (l1_2: (@list A)) (l2_2: (@list A)) (x: A) (xs: (@list A)) (vnext: Z) (vdata: Z) (v: Z) (w: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (x) (xs)))) , + (sll storeA w l1_2 ) + ** ((&((v) # "list" ->ₛ "data")) # Ptr |-> vdata) + ** (storeA vdata x ) + ** ((&((v) # "list" ->ₛ "next")) # Ptr |-> w) + ** (sll storeA vnext xs ) +|-- + EX (l1: (@list A)) (l2: (@list A)) , + “ (l = (app ((rev (l1))) (l2))) ” + && (sll storeA v l1 ) + ** (sll storeA vnext l2 ) +) \/ +( +forall (A: Type) (l: (@list A)) (l1_2: (@list A)) (l2_2: (@list A)) (x: A) (xs: (@list A)) (v: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (x) (xs)))) , + TT && emp +|-- + “ (l = (app ((rev ((cons (x) (l1_2))))) (xs))) ” + && emp +). + +Definition reverse_entail_wit_4_split_goal_1 := +forall (A: Type) (l: (@list A)) (l1_2: (@list A)) (l2_2: (@list A)) (x: A) (xs: (@list A)) (v: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (x) (xs)))) , + (l = (app ((rev ((cons (x) (l1_2))))) (xs))) +. + +Definition reverse_return_wit_1 := +( +forall (A: Type) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (v: Z) (w: Z) (l1: (@list A)) (l2: (@list A)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll storeA w l1 ) + ** (sll storeA v l2 ) +|-- + (sll storeA w (rev (l)) ) +) \/ +( +forall (A: Type) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (v: Z) (l1: (@list A)) (l2: (@list A)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll storeA v l2 ) +|-- + “ (l1 = (rev (l))) ” + && emp +). + +Definition reverse_return_wit_1_split_goal_1 := +forall (A: Type) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (v: Z) (l1: (@list A)) (l2: (@list A)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll storeA v l2 ) +|-- + “ (l1 = (rev (l))) ” +. + +Definition reverse_return_wit_1_split_goal_spatial := +forall (A: Type) (l: (@list A)) (storeA: (Z -> (A -> Assertion))) (v: Z) (l1: (@list A)) (l2: (@list A)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll storeA v l2 ) +|-- + TT && emp +. + +Module Type VC_Correct. + +Include polymorphic_sll_Strategy_Correct. + +Axiom proof_of_reverse_safety_wit_1 : reverse_safety_wit_1. +Axiom proof_of_reverse_entail_wit_1 : reverse_entail_wit_1. +Axiom proof_of_reverse_entail_wit_2 : reverse_entail_wit_2. +Axiom proof_of_reverse_entail_wit_3 : reverse_entail_wit_3. +Axiom proof_of_reverse_entail_wit_4 : reverse_entail_wit_4. +Axiom proof_of_reverse_return_wit_1 : reverse_return_wit_1. + +End VC_Correct. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_goal_check.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..10a297432ad761e7fc2d1c123359dee6530b2216 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_goal_check.v @@ -0,0 +1,7 @@ +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_goal polymorphic_sll_proof_auto polymorphic_sll_proof_manual. + +Module VC_Correctness : VC_Correct. + Include polymorphic_sll_strategy_proof. + Include polymorphic_sll_proof_auto. + Include polymorphic_sll_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_proof_auto.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..4b670e4241ef8459e62ff24173daa32a6c79e049 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_proof_auto.v @@ -0,0 +1,31 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib. +Local Open Scope sac. + +Lemma proof_of_reverse_safety_wit_1 : reverse_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_reverse_entail_wit_1 : reverse_entail_wit_1. +Proof. Admitted. + +Lemma proof_of_reverse_entail_wit_3 : reverse_entail_wit_3. +Proof. Admitted. + diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_proof_manual.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..c7e9cb506d3b3fe4e351bf6c8a69a98742737e52 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_proof_manual.v @@ -0,0 +1,77 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_goal. +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_reverse_entail_wit_2 : reverse_entail_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists nil. + Exists l. + split_pure_spatial. + - cancel (sll storeA w nil). + cancel (sll storeA v l). + - dump_pre_spatial. + simpl. + reflexivity. +Qed. + +Lemma proof_of_reverse_entail_wit_4 : reverse_entail_wit_4. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists (x :: l1_2). + Exists xs. + split_pure_spatial. + - cancel (sll storeA vnext xs). + simpl sll. + Exists vdata. + Exists w. + split_pure_spatial. + + cancel (sll storeA w l1_2). + cancel (((&((v) # "list" ->ₛ "data")) # Ptr |-> vdata)). + cancel (((&((v) # "list" ->ₛ "next")) # Ptr |-> w)). + cancel (storeA vdata x). + + dump_pre_spatial. + exact PreH2. + - dump_pre_spatial. + subst l2_2. + simpl. + rewrite <- app_assoc. + simpl. + exact PreH1. +Qed. + +Lemma proof_of_reverse_return_wit_1 : reverse_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + sep_apply (sll_zero A storeA v l2); [ | tauto]. + Intros_p Hl2. + rewrite Hl2 in PreH1. + rewrite app_nil_r in PreH1. + subst l. + rewrite rev_involutive. + cancel (sll storeA w l1). +Qed. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_goal.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..1fc3eb7c81d21435a29a818adb83d39a74343b50 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_goal.v @@ -0,0 +1,296 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +Require Import Coq.micromega.Psatz. +From SimpleC.SL Require Import SeparationLogic. +Import naive_C_Rules. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Definition polymorphic_sll_strategy1 := + forall (A : Type) (storeA : (Z -> (A -> Assertion))) (l : (@list A)) (x : Z), + TT && + emp ** + ((sll storeA x l)) + |-- + ( + TT && + (“ (sll_para storeA) ”) && + emp ** + ((sll storeA x l)) + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy2 := + forall (A : Type) (storeA : (Z -> (A -> Assertion))) (y : Z) (l : (@list A)) (x : Z), + TT && + emp ** + ((sllseg storeA x y l)) + |-- + ( + TT && + (“ (sll_para storeA) ”) && + emp ** + ((sllseg storeA x y l)) + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy4 := + forall (A : Type) (l : (@list A)) (storeA : (Z -> (A -> Assertion))), + TT && + emp ** + ((sll storeA 0 l)) + |-- + ( + TT && + (“ (l = (@nil A)) ”) && + emp + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy5 := + TT && + emp + |-- + ( + TT && + emp + ) ** ( + ALL (A : Type) (l : (@list A)) (storeA : (Z -> (A -> Assertion))), + TT && + (“ (l = (@nil A)) ”) && + emp -* + TT && + emp ** + ((sll storeA 0 l)) + ). + +Definition polymorphic_sll_strategy16 := + forall (A : Type) (p : Z) (x : A) (storeA : (Z -> (A -> Assertion))), + TT && + emp ** + ((storeA p x)) + |-- + ( + TT && + emp + ) ** ( + ALL (y : A), + TT && + (“ (x = y) ”) && + emp -* + TT && + emp ** + ((storeA p y)) + ). + +Definition polymorphic_sll_strategy17 := + forall (A : Type) (l : (@list A)) (storeA : (Z -> (A -> Assertion))) (l0 : (@list A)) (p : Z), + TT && + emp ** + ((sllseg storeA p p l)) ** + ((sll storeA p l0)) + |-- + ( + TT && + (“ (l = (@nil A)) ”) && + emp ** + ((sll storeA p l0)) + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy18 := + TT && + emp + |-- + ( + TT && + emp + ) ** ( + ALL (A : Type) (l : (@list A)) (storeA : (Z -> (A -> Assertion))) (l0 : (@list A)) (p : Z), + TT && + (“ (l = (@nil A)) ”) && + emp ** + ((sll storeA p l0)) -* + TT && + emp ** + ((sllseg storeA p p l)) ** + ((sll storeA p l0)) + ). + +Definition polymorphic_sll_strategy19 := + forall (A : Type) (storeA : (Z -> (A -> Assertion))), + TT && + (“ (sll_para storeA) ”) && + emp + |-- + ( + TT && + emp + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy7 := + forall (A : Type) (storeA : (Z -> (A -> Assertion))) (l0 : (@list A)) (p : Z), + TT && + emp ** + ((sll storeA p l0)) + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list A)), + TT && + (“ (l0 = l1) ”) && + emp -* + TT && + emp ** + ((sll storeA p l1)) + ). + +Definition polymorphic_sll_strategy10 := + forall (A : Type) (storeA : (Z -> (A -> Assertion))) (l : (@list A)) (x : A) (p : Z), + TT && + emp ** + ((sll storeA p (@cons A x l))) + |-- + EX (y : Z) (h : Z), + ( + TT && + emp ** + ((poly_store FET_ptr &( ((p)) # "list" ->ₛ "data") h)) ** + ((storeA h x)) ** + ((poly_store FET_ptr &( ((p)) # "list" ->ₛ "next") y)) ** + ((sll storeA y l)) + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy11 := + TT && + emp + |-- + ( + TT && + emp + ) ** ( + ALL (A : Type) (p : Z) (h : Z) (x : A) (storeA : (Z -> (A -> Assertion))) (l : (@list A)) (y : Z), + TT && + (“ (p <> 0) ”) && + emp ** + ((poly_store FET_ptr &( ((p)) # "list" ->ₛ "data") h)) ** + ((storeA h x)) ** + ((poly_store FET_ptr &( ((p)) # "list" ->ₛ "next") y)) ** + ((sll storeA y l)) -* + TT && + emp ** + ((sll storeA p (@cons A x l))) + ). + +Definition polymorphic_sll_strategy12 := + forall (A : Type) (storeA : (Z -> (A -> Assertion))) (q : Z) (l0 : (@list A)) (p : Z), + TT && + emp ** + ((sllseg storeA p q l0)) + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list A)) (l2 : (@list A)), + TT && + (“ (l1 = (@app A l0 l2)) ”) && + emp ** + ((sll storeA q l2)) -* + TT && + emp ** + ((sll storeA p l1)) + ). + +Definition polymorphic_sll_strategy8 := + forall (A : Type) (p : Z) (l : (@list A)) (storeA : (Z -> (A -> Assertion))), + TT && + (“ (p <> 0) ” || “ (0 <> p) ”) && + emp ** + ((sll storeA p l)) + |-- + EX (x : A) (l0 : (@list A)), + ( + TT && + (“ (p <> 0) ” || “ (0 <> p) ”) && + (“ (l = (@cons A x l0)) ”) && + emp ** + ((sll storeA p (@cons A x l0))) + ) ** ( + TT && + emp -* + TT && + emp + ). + +Definition polymorphic_sll_strategy9 := + forall (p : Z), + TT && + (“ (p <> 0) ” || “ (0 <> p) ”) && + emp + |-- + ( + TT && + (“ (p <> 0) ” || “ (0 <> p) ”) && + emp + ) ** ( + ALL (A : Type) (l : (@list A)) (x : A) (l0 : (@list A)) (storeA : (Z -> (A -> Assertion))), + TT && + (“ (l = (@cons A x l0)) ”) && + emp ** + ((sll storeA p (@cons A x l0))) -* + TT && + emp ** + ((sll storeA p l)) + ). + +Module Type polymorphic_sll_Strategy_Correct. + + Axiom polymorphic_sll_strategy1_correctness : polymorphic_sll_strategy1. + Axiom polymorphic_sll_strategy2_correctness : polymorphic_sll_strategy2. + Axiom polymorphic_sll_strategy4_correctness : polymorphic_sll_strategy4. + Axiom polymorphic_sll_strategy5_correctness : polymorphic_sll_strategy5. + Axiom polymorphic_sll_strategy16_correctness : polymorphic_sll_strategy16. + Axiom polymorphic_sll_strategy17_correctness : polymorphic_sll_strategy17. + Axiom polymorphic_sll_strategy18_correctness : polymorphic_sll_strategy18. + Axiom polymorphic_sll_strategy19_correctness : polymorphic_sll_strategy19. + Axiom polymorphic_sll_strategy7_correctness : polymorphic_sll_strategy7. + Axiom polymorphic_sll_strategy10_correctness : polymorphic_sll_strategy10. + Axiom polymorphic_sll_strategy11_correctness : polymorphic_sll_strategy11. + Axiom polymorphic_sll_strategy12_correctness : polymorphic_sll_strategy12. + Axiom polymorphic_sll_strategy8_correctness : polymorphic_sll_strategy8. + Axiom polymorphic_sll_strategy9_correctness : polymorphic_sll_strategy9. + +End polymorphic_sll_Strategy_Correct. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_goal_check.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..3bf9df20a2b3929e6cc04710b382f3f5b046b8c0 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_goal_check.v @@ -0,0 +1,5 @@ +From PVbench.Data_structures.polymorphic_sll.rocq.groundtruth Require Import polymorphic_sll_strategy_goal polymorphic_sll_strategy_proof. + +Module polymorphic_sll_Strategy_Correctness : polymorphic_sll_Strategy_Correct. + Include polymorphic_sll_strategy_proof. +End polymorphic_sll_Strategy_Correctness. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_proof.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_proof.v new file mode 100644 index 0000000000000000000000000000000000000000..6effb0a2d698b1f1b93345c889270806ad9e0052 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/polymorphic_sll_strategy_proof.v @@ -0,0 +1,214 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +From SimpleC.SL Require Import SeparationLogic. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.groundtruth.polymorphic_sll_strategy_goal. +Import naive_C_Rules. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.groundtruth.proof_lib. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Lemma polymorphic_sll_strategy1_correctness : polymorphic_sll_strategy1. + pre_process_default. +Qed. + +Lemma polymorphic_sll_strategy2_correctness : polymorphic_sll_strategy2. + pre_process_default. +Qed. + +Lemma polymorphic_sll_strategy4_correctness : polymorphic_sll_strategy4. +Proof. + pre_process_default. + sep_apply_l_atomic (sll_zero A storeA 0 l eq_refl). + Intros_p H. + split_pure_spatial. + - cancel. + - dump_pre_spatial. + exact H. +Qed. + +Lemma polymorphic_sll_strategy5_correctness : polymorphic_sll_strategy5. +Proof. + pre_process_default. + Intros_p H. + subst l. + simpl. + split_pure_spatial. + - cancel. + - dump_pre_spatial. + reflexivity. +Qed. + +Lemma polymorphic_sll_strategy16_correctness : polymorphic_sll_strategy16. +Proof. + pre_process_default. + Intros_p H. + subst y. + cancel. +Qed. + +Lemma polymorphic_sll_strategy17_correctness : polymorphic_sll_strategy17. +Proof. + pre_process_default. + destruct l. + - simpl. + Intros_p H. + split_pure_spatial. + + cancel. + + dump_pre_spatial. + reflexivity. + - simpl. + destruct l0. + + simpl. + split_pure_spatial. + * Intros h. + Intros q. + split_pures. + contradiction. + * Intros h. + Intros q. + split_pures. + contradiction. + contradiction. + + simpl. + split_pure_spatial. + * Intros h. + Intros q. + Intros h0. + Intros y. + sep_apply_l_atomic (dup_store_ptr (&( p # "list" ->ₛ "data")) h h0). + Intros_p H1. + contradiction. + * Intros h. + Intros q. + Intros h0. + Intros y. + sep_apply_l_atomic (dup_store_ptr (&( p # "list" ->ₛ "data")) h h0). + Intros_p H1. + contradiction. +Qed. + +Lemma polymorphic_sll_strategy18_correctness : polymorphic_sll_strategy18. +Proof. + pre_process_default. + Intros_p H. + subst l. + simpl. + cancel (sll storeA p l0). + split_pure_spatial. + - cancel. + - dump_pre_spatial. + reflexivity. +Qed. + +Lemma polymorphic_sll_strategy7_correctness : polymorphic_sll_strategy7. +Proof. + pre_process_default. + Intros_p H. + subst l1. + cancel. +Qed. + +Lemma polymorphic_sll_strategy10_correctness : polymorphic_sll_strategy10. +Proof. + pre_process_default. + Intros h. + Intros y. + Exists y. + Exists h. + normalize. + wand_elim. + cancel. + cancel. + cancel. +Qed. + +Lemma polymorphic_sll_strategy11_correctness : polymorphic_sll_strategy11. +Proof. + pre_process_default. + Intros_p H. + Exists h. + Exists y. + split_pure_spatial. + - cancel. + cancel. + cancel. + - dump_pre_spatial. + exact H. +Qed. + +Lemma polymorphic_sll_strategy12_correctness : polymorphic_sll_strategy12. +Proof. + pre_process_default. + Intros_p H. + subst l1. + sep_apply_l_atomic (sllseg_sll A storeA p q l0 l2). + cancel. +Qed. + +Lemma polymorphic_sll_strategy8_correctness : polymorphic_sll_strategy8. +Proof. + pre_process_default. + rewrite <- logic_equiv_coq_prop_or. + Intros_p Hnz. + assert (Hp : p <> 0). + { + destruct Hnz as [Hnz | Hnz]. + - exact Hnz. + - intro Hp0. + apply Hnz. + symmetry. + exact Hp0. + } + sep_apply_l_atomic (sll_not_zero A storeA p l Hp). + Intros h. + Intros y. + Intros x. + Intros l0. + Exists x. + Exists l0. + simpl. + normalize. + Exists h. + Exists y. + wand_elim. + cancel. + rewrite <- logic_equiv_coq_prop_or. + split_pure_spatial. + - cancel. + cancel. + cancel. + - split_pures. + + dump_pre_spatial. + exact Hnz. + + dump_pre_spatial. + exact H. + + dump_pre_spatial. + exact Hp. +Qed. + +Lemma polymorphic_sll_strategy9_correctness : polymorphic_sll_strategy9. +Proof. + pre_process_default. + rewrite <- logic_equiv_coq_prop_or. + Intros_p Hnz. + split_pure_spatial. + - Intros_r A. + Intros_r l. + Intros_r x. + Intros_r l0. + Intros_r storeA. + apply_sepcon_adjoint. + Intros_p H. + subst l. + cancel. + - dump_pre_spatial. + exact Hnz. +Qed. + +Lemma polymorphic_sll_strategy19_correctness : polymorphic_sll_strategy19. + pre_process_default. +Qed. diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/proof_lib.v b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..f66ad5edc780ab37381f4c3bb865cf65db0ee334 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/groundtruth/proof_lib.v @@ -0,0 +1,104 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib. +Local Open Scope sac. +Import ListNotations. +Local Open Scope list. + +Lemma sll_zero: forall A (storeA: addr -> A -> Assertion) x l, + x = NULL -> + sll storeA x l |-- “ l = nil ” && emp. +Proof. + intros A storeA x l Hx. + destruct l. + - simpl. + subst x. + split_pure_spatial. + + Intros_p Hnil. + cancel. + + dump_pre_spatial. + reflexivity. + - simpl. + rename a into v. + rename l into l0. + subst x. + Intros h. + Intros y. + contradiction. +Qed. + +Lemma sll_not_zero: forall A (storeA: addr -> A -> Assertion) x l, + x <> NULL -> + sll storeA x l |-- + EX h y a l0, + “ l = a :: l0 ” && + &(x # "list" ->ₛ "data") # Ptr |-> h ** + &(x # "list" ->ₛ "next") # Ptr |-> y ** + storeA h a ** + sll storeA y l0. +Proof. + intros A storeA x l Hx. + destruct l. + - simpl. + Intros_p Hnull. + contradiction. + - simpl. + rename a into v. + rename l into l0. + Intros h. + Intros y. + Exists h. + Exists y. + Exists v. + Exists l0. + split_pure_spatial. + + cancel (&(x # "list" ->ₛ "data") # Ptr |-> h). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> y). + cancel (storeA h v). + cancel (sll storeA y l0). + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma sllseg_sll: forall A (storeA: addr -> A -> Assertion) x y l1 l2, + sllseg storeA x y l1 ** sll storeA y l2 |-- + sll storeA x (l1 ++ l2). +Proof. + intros A storeA x y l1. + revert x y. + induction l1; intros x y l2. + - simpl. + Intros_p Hxy. + subst x. + cancel. + - simpl. + Intros h. + Intros q. + Exists h. + Exists q. + split_pure_spatial. + + cancel (&(x # "list" ->ₛ "data") # Ptr |-> h). + cancel (&(x # "list" ->ₛ "next") # Ptr |-> q). + cancel (storeA h a). + apply (IHl1 q y l2). + + dump_pre_spatial. + exact H. +Qed. + + diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/polymorphic_sll.strategies b/benchmarks/Data_structures/polymorphic_sll/rocq/polymorphic_sll.strategies new file mode 100644 index 0000000000000000000000000000000000000000..c3e423bf278f01e6af52db02e8d8d0076bc4fa06 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/polymorphic_sll.strategies @@ -0,0 +1,125 @@ +//test curent rules +//max rule id:30 + + + + +#include "polymorphic_sll_def.h" + +id : 1 +priority : core(0) +left : sll{?A}(?storeA, ?x, ?l) at 0 +check : absense(sll_para{A}(storeA)); +action : left_add(sll_para{A}(storeA)); + +id : 2 +priority : core(0) +left : sllseg{?A}(?storeA, ?x, ?y, ?l) at 0 +check : absense(sll_para{A}(storeA)); +action : left_add(sll_para{A}(storeA)); + +id : 4 +priority : core(1) +left : sll{?A}(?storeA, null, ?l) at 0 +action : left_erase(0); + left_add(l == nil{A}); + +id : 5 +priority : core(1) +right : sll{?A}(?storeA, null, ?l) at 0 +action : right_erase(0); + right_add(l == nil{A}); + +id : 7 +priority : core(2) +left : sll{?A}(?storeA,?p, ?l0) at 0 +right : sll{A}(storeA, p, ?l1) at 1 +action : left_erase(0); + right_erase(1); + right_add(l0 == l1); + +id : 8 +priority : core(4) +left : sll{?A}(?storeA, ?p, ?l) at 0 + (p != NULL || NULL != p) at 1 +action : left_erase(0); + left_exist_add(x : A); + left_exist_add(l0 : list{A}); + left_add(sll{A}(storeA, p, cons{A}(x, l0))); + left_add(l == cons{A}(x, l0)); + +id : 9 +priority : core(4) +left : (?p != NULL || NULL != ?p) at 0 +right : sll{?A}(?storeA, p, ?l) at 1 +action : right_erase(1); + right_exist_add(x); + right_exist_add(l0); + right_add(sll{A}(storeA, p, cons{A}(x, l0))); + right_add(l == cons{A}(x, l0)); + + +id : 10 +priority : core(3) +left : sll{?A}(?storeA, ?p, cons{A}(?x, ?l)) at 0 +action : left_erase(0); + left_exist_add(y); + left_exist_add(h); + left_add(store(field_addr(p, list, data), PTR(struct list), h)); + left_add(storeA(h, x)); + left_add(store(field_addr(p, list, next), PTR(struct list), y)); + left_add(sll{A}(storeA, y, l)); + +id : 11 +priority : core(3) +right : sll{?A}(?storeA, ?p, cons{A}(?x, ?l)) at 0 +action : right_erase(0); + right_exist_add(y); + right_exist_add(h); + right_add(p != NULL); + right_add(store(field_addr(p, list, data), PTR(struct list), h)); + right_add(storeA(h, x)); + right_add(store(field_addr(p, list, next), PTR(struct list), y)); + right_add(sll{A}(storeA, y, l)); + +id : 12 +priority : core(3) +left : sllseg{A}(?storeA, ?p, ?q, ?l0) at 0 +right : sll{A}(storeA, p, ?l1) at 1 +action : left_erase(0); + right_erase(1); + right_exist_add(l2); + right_add(l1 == app{A}(l0, l2)); + right_add(sll{A}(storeA, q, l2)); + +id : 16 +priority : core(1) +left : (?storeA : Z -> ?A -> asrt)(?p, ?x) at 1 +right : storeA(p, ?y) at 2 +action : left_erase(1); + right_erase(2); + right_add(x == y); + +id : 17 +priority : core(1) +left : sllseg{A}(?storeA, ?p, p, ?l) at 0 +left : sll{A}(storeA, p, ?l0) at 1 +check : absense(l == nil{A}); + absense(nil{A} == l); +action : left_erase(0); + left_add(l == nil{A}); + +id : 18 +priority : core(1) +right : sllseg{A}(?storeA, ?p, p, ?l) at 0 + sll{A}(storeA, p, ?l0) at 1 +check : absense(l == nil{A}); + absense(nil{A} == l); +action : right_erase(0); + right_add(l == nil{A}); + + +id : 19 +priority : Tagcancel(1) +left : sll_para{?A}(?storeA) at 0 +action : left_erase(0); \ No newline at end of file diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/polymorphic_sll_def.h b/benchmarks/Data_structures/polymorphic_sll/rocq/polymorphic_sll_def.h new file mode 100644 index 0000000000000000000000000000000000000000..d0b471f6b01e5b9d427752e700438ab1caace3e7 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/polymorphic_sll_def.h @@ -0,0 +1,11 @@ +struct list { + void* data; + struct list *next; +}; + +/*@ Extern Coq (sll : {A} -> (Z -> A -> Assertion) -> Z-> list A -> Assertion) + (sllseg: {A} -> (Z -> A -> Assertion) -> Z -> Z -> list A -> Assertion) + (sll_para: {A} -> (Z -> A -> Assertion) -> Prop) + */ + +/*@ Import Coq Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib */ diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/solution_annotated.c b/benchmarks/Data_structures/polymorphic_sll/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..199fbc663a9ab5053c3ebaf77849c0056dc2fa49 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/solution_annotated.c @@ -0,0 +1,45 @@ +struct list { + void* data; + struct list *next; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib */ +/*@ Extern Coq (sll : {A} -> (Z -> A -> Assertion) -> Z -> list A -> Assertion) */ +/*@ Extern Coq (sllseg : {A} -> (Z -> A -> Assertion) -> Z -> Z -> list A -> Assertion) + (sll_para : {A} -> (Z -> A -> Assertion) -> Prop) */ +/*@ include strategies "polymorphic_sll.strategies" */ + +struct list *reverse(struct list *p) +/*@ With {A} storeA (l : list A) + Require sll(storeA, p, l) + Ensure sll(storeA, __return, rev(l)) +*/ +{ + struct list *w = (void *)0, *v = p; + /*@ Assert w == 0 && v == p && p == p@pre && + sll(storeA, w, nil) * sll(storeA, v, l) + */ + /*@ Inv Assert exists l1 l2, + p == p@pre && + l == app(rev(l1), l2) && + sll(storeA, w, l1) * sll(storeA, v, l2) + */ + while (v) { + /*@ Assert exists l1 l2 x xs vnext vdata, + p == p@pre && + l == app(rev(l1), l2) && + v != 0 && + l2 == cons(x, xs) && + sll(storeA, w, l1) * + store(&(v -> data), vdata) * + storeA(vdata, x) * + store(&(v -> next), vnext) * + sll(storeA, vnext, xs) + */ + struct list *t = v->next; + v->next = w; + w = v; + v = t; + } + return w; +} diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/solution_spec.c b/benchmarks/Data_structures/polymorphic_sll/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..b6ee76c9319f610d1727c8d503050681bd870e78 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/solution_spec.c @@ -0,0 +1,24 @@ +struct list { + void* data; + struct list *next; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.polymorphic_sll.rocq.spec_lib */ +/*@ Extern Coq (sll : {A} -> (Z -> A -> Assertion) -> Z -> list A -> Assertion) */ + +struct list *reverse(struct list *p) +/*@ With {A} storeA (l : list A) + Require sll(storeA, p, l) + Ensure sll(storeA, __return, rev(l)) +*/ +{ + struct list *w = (void *)0, *v = p; + + while (v) { + struct list *t = v->next; + v->next = w; + w = v; + v = t; + } + return w; +} diff --git a/benchmarks/Data_structures/polymorphic_sll/rocq/spec_lib.v b/benchmarks/Data_structures/polymorphic_sll/rocq/spec_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..f9daf1d2017a3969315d81df543995c984ef0588 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/rocq/spec_lib.v @@ -0,0 +1,45 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Permutation. +Require Import String. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Require Import String. +Local Open Scope string. + +Import naive_C_Rules. +Local Open Scope sac. + +Fixpoint sll {A: Type} (storeA: addr -> A -> Assertion) (x: addr) (l: list A): Assertion := + match l with + | nil => “ x = NULL ” && emp + | a :: l0 => “ x <> NULL ” && + EX h y: addr, + &(x # "list" ->ₛ "data") # Ptr |-> h ** + &(x # "list" ->ₛ "next") # Ptr |-> y ** + storeA h a ** + sll storeA y l0 + end. + +Fixpoint sllseg {A : Type} (storeA : addr -> A -> Assertion) (x : addr) (y : addr) (l : list A) : Assertion := + match l with + | nil => “ x = y ” && emp + | a :: l0 => “ x <> NULL ” && + EX h q: addr, + &(x # "list" ->ₛ "data") # Ptr |-> h ** + &(x # "list" ->ₛ "next") # Ptr |-> q ** + storeA h a ** + sllseg storeA q y l0 + end. + +Definition append {A : Type} (l1 : list A) (l2 : list A) := app l1 l2. + +Definition sll_para {A: Type} (storeA: addr -> A -> Assertion): Prop := True. diff --git a/benchmarks/Data_structures/polymorphic_sll/solution.c b/benchmarks/Data_structures/polymorphic_sll/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..e3b018b3e7d6382ddb4dfc0c08c0c6b12eaf1317 --- /dev/null +++ b/benchmarks/Data_structures/polymorphic_sll/solution.c @@ -0,0 +1,17 @@ +struct list { + void* data; + struct list *next; +}; + +struct list *reverse(struct list *p) +{ + struct list *w = (void *)0, *v = p; + + while (v) { + struct list *t = v->next; + v->next = w; + w = v; + v = t; + } + return w; +} diff --git a/benchmarks/Data_structures/singly_linked_list/manifest.json b/benchmarks/Data_structures/singly_linked_list/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..efad2c2fa41c31fadab4523361a5eb3998d62685 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/manifest.json @@ -0,0 +1,18 @@ +{ + "id": "singly_linked_list", + "source": { + "dataset": "classical_data_structure", + "problem_id": "singly_linked_list", + "title": "Singly Linked List Operations", + "tags": [ + "data structures", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Data_structures/singly_linked_list/problem.md b/benchmarks/Data_structures/singly_linked_list/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..e8b9eb84c8b1cab39e815f2f0b5bb5306d5268bd --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/problem.md @@ -0,0 +1,26 @@ +# Singly Linked List Operations + +## Description + +Implement three basic operations on null-terminated singly linked lists of integers. + +## Input + +A list is given by a pointer to its first node, or `NULL` when empty: + +```c +struct list { + int data; + struct list *next; +}; +``` + +- `length` receives a list `p` with at most $2^{31} - 1$ nodes. +- `reverse` receives a list `p`. +- `append` receives two disjoint lists `x` and `y`. + +## Output + +- `length` returns the number of nodes of `p` and leaves the list unchanged. +- `reverse` reverses `p` in place and returns the new head. +- `append` links `y` after the last node of `x` and returns the head of the concatenation. diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/proof_lib.v b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..ede08a231632b7c278e906a6b3ab6d4d8cf01a4a --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/proof_lib.v @@ -0,0 +1,21 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Local Open Scope sac. + diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_goal.v b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..8cbc53ddfd2a4bd4b5df21295b7d53651b713b79 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_goal.v @@ -0,0 +1,519 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Local Open Scope sac. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_proof. + +(*----- Function length -----*) + +Definition length_safety_wit_1 := +forall (p_pre: Z) (l: (@list Z)) (PreH1 : ((Zlength (l)) <= INT_MAX)) , + ((( &( "n" ) )) # Int |->_) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** (sll p_pre l ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition length_safety_wit_2 := +( +forall (p_pre: Z) (l: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (pnext: Z) (pdata: Z) (n: Z) (p: Z) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : (n = (Zlength (l1)))) (PreH3 : (p <> 0)) (PreH4 : (l2 = (cons (pdata) (l3)))) (PreH5 : ((Zlength (l)) <= INT_MAX)) , + ((( &( "n" ) )) # Int |-> n) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1 ) + ** (sll pnext l3 ) +|-- + “ ((n + 1 ) <= INT_MAX) ” + && “ ((INT_MIN) <= (n + 1 )) ” +) \/ +( +forall (p_pre: Z) (l: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (pnext: Z) (pdata: Z) (n: Z) (p: Z) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : (n = (Zlength (l1)))) (PreH3 : (p <> 0)) (PreH4 : (l2 = (cons (pdata) (l3)))) (PreH5 : ((Zlength (l)) <= INT_MAX)) , + ((( &( "n" ) )) # Int |-> n) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1 ) + ** (sll pnext l3 ) +|-- + “ ((n + 1 ) <= INT_MAX) ” + && “ ((INT_MIN) <= (n + 1 )) ” +). + +Definition length_safety_wit_2_split_goal_1 := +forall (p_pre: Z) (l: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (pnext: Z) (pdata: Z) (n: Z) (p: Z) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : (n = (Zlength (l1)))) (PreH3 : (p <> 0)) (PreH4 : (l2 = (cons (pdata) (l3)))) (PreH5 : ((Zlength (l)) <= INT_MAX)) , + ((( &( "n" ) )) # Int |-> n) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1 ) + ** (sll pnext l3 ) +|-- + “ ((n + 1 ) <= INT_MAX) ” +. + +Definition length_safety_wit_2_split_goal_2 := +forall (p_pre: Z) (l: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) (l3: (@list Z)) (pnext: Z) (pdata: Z) (n: Z) (p: Z) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : (n = (Zlength (l1)))) (PreH3 : (p <> 0)) (PreH4 : (l2 = (cons (pdata) (l3)))) (PreH5 : ((Zlength (l)) <= INT_MAX)) , + ((( &( "n" ) )) # Int |-> n) + ** ((( &( "p" ) )) # Ptr |-> p) + ** ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1 ) + ** (sll pnext l3 ) +|-- + “ ((INT_MIN) <= (n + 1 )) ” +. + +Definition length_entail_wit_1 := +( +forall (p_pre: Z) (l: (@list Z)) (PreH1 : ((Zlength (l)) <= INT_MAX)) , + (sll p_pre l ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) (l2))) ” + && “ ((Zlength (l)) <= INT_MAX) ” + && “ (0 = (Zlength (l1))) ” + && (sllseg p_pre p_pre l1 ) + ** (sll p_pre l2 ) +) \/ +( +forall (l: (@list Z)) (PreH1 : ((Zlength (l)) <= INT_MAX)) , + TT && emp +|-- + “ (0 = (Zlength ((@nil Z)))) ” + && “ (l = (app ((@nil Z)) (l))) ” + && emp +). + +Definition length_entail_wit_1_split_goal_1 := +forall (l: (@list Z)) (PreH1 : ((Zlength (l)) <= INT_MAX)) , + (0 = (Zlength ((@nil Z)))) +. + +Definition length_entail_wit_1_split_goal_2 := +forall (l: (@list Z)) (PreH1 : ((Zlength (l)) <= INT_MAX)) , + (l = (app ((@nil Z)) (l))) +. + +Definition length_entail_wit_2 := +forall (p_pre: Z) (l: (@list Z)) (p: Z) (n: Z) (l1_2: (@list Z)) (l2_2: (@list Z)) (PreH1 : (l = (app (l1_2) (l2_2)))) (PreH2 : ((Zlength (l)) <= INT_MAX)) (PreH3 : (n = (Zlength (l1_2)))) (PreH4 : (p <> 0)) , + (sllseg p_pre p l1_2 ) + ** (sll p l2_2 ) +|-- + EX (pnext: Z) (pdata: Z) (l3: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) (l2))) ” + && “ (n = (Zlength (l1))) ” + && “ (p <> 0) ” + && “ (l2 = (cons (pdata) (l3))) ” + && “ ((Zlength (l)) <= INT_MAX) ” + && ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1 ) + ** (sll pnext l3 ) +. + +Definition length_entail_wit_3 := +( +forall (p_pre: Z) (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3: (@list Z)) (pnext: Z) (pdata: Z) (n: Z) (p: Z) (PreH1 : (l = (app (l1_2) (l2_2)))) (PreH2 : (n = (Zlength (l1_2)))) (PreH3 : (p <> 0)) (PreH4 : (l2_2 = (cons (pdata) (l3)))) (PreH5 : ((Zlength (l)) <= INT_MAX)) , + ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1_2 ) + ** (sll pnext l3 ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app (l1) (l2))) ” + && “ ((Zlength (l)) <= INT_MAX) ” + && “ ((n + 1 ) = (Zlength (l1))) ” + && (sllseg p_pre pnext l1 ) + ** (sll pnext l2 ) +) \/ +( +forall (p_pre: Z) (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l3: (@list Z)) (pnext: Z) (pdata: Z) (n: Z) (p: Z) (PreH1 : (pdata <= INT_MAX)) (PreH2 : (pdata >= INT_MIN)) (PreH3 : (l = (app (l1_2) (l2_2)))) (PreH4 : (n = (Zlength (l1_2)))) (PreH5 : (p <> 0)) (PreH6 : (l2_2 = (cons (pdata) (l3)))) (PreH7 : ((Zlength (l)) <= INT_MAX)) , + ((&((p) # "list" ->ₛ "data")) # Int |-> pdata) + ** ((&((p) # "list" ->ₛ "next")) # Ptr |-> pnext) + ** (sllseg p_pre p l1_2 ) +|-- + EX (l1: (@list Z)) , + “ (l = (app (l1) (l3))) ” + && “ ((Zlength (l)) <= INT_MAX) ” + && “ ((n + 1 ) = (Zlength (l1))) ” + && (sllseg p_pre pnext l1 ) +). + +Definition length_return_wit_1 := +( +forall (p_pre: Z) (l: (@list Z)) (p: Z) (n: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : ((Zlength (l)) <= INT_MAX)) (PreH3 : (n = (Zlength (l1)))) (PreH4 : (p = 0)) , + (sllseg p_pre p l1 ) + ** (sll p l2 ) +|-- + “ (n = (Zlength (l))) ” + && (sll p_pre l ) +) \/ +( +forall (p_pre: Z) (l: (@list Z)) (p: Z) (n: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : ((Zlength (l)) <= INT_MAX)) (PreH3 : (n = (Zlength (l1)))) (PreH4 : (p = 0)) , + (sllseg p_pre p l1 ) + ** (sll p l2 ) +|-- + “ (n = (Zlength (l))) ” + && (sll p_pre l ) +). + +Definition length_return_wit_1_split_goal_1 := +forall (p_pre: Z) (l: (@list Z)) (p: Z) (n: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : ((Zlength (l)) <= INT_MAX)) (PreH3 : (n = (Zlength (l1)))) (PreH4 : (p = 0)) , + (sllseg p_pre p l1 ) + ** (sll p l2 ) +|-- + “ (n = (Zlength (l))) ” +. + +Definition length_return_wit_1_split_goal_spatial := +forall (p_pre: Z) (l: (@list Z)) (p: Z) (n: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app (l1) (l2)))) (PreH2 : ((Zlength (l)) <= INT_MAX)) (PreH3 : (n = (Zlength (l1)))) (PreH4 : (p = 0)) , + (sllseg p_pre p l1 ) + ** (sll p l2 ) +|-- + (sll p_pre l ) +. + +(*----- Function reverse -----*) + +Definition reverse_safety_wit_1 := +forall (p_pre: Z) (l: (@list Z)) , + ((( &( "w" ) )) # Ptr |->_) + ** ((( &( "p" ) )) # Ptr |-> p_pre) + ** (sll p_pre l ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition reverse_entail_wit_1 := +( +forall (p_pre: Z) (l: (@list Z)) , + (sll p_pre l ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app ((rev (l1))) (l2))) ” + && (sll 0 l1 ) + ** (sll p_pre l2 ) +) \/ +( +forall (l: (@list Z)) , + TT && emp +|-- + “ (l = (app ((rev ((@nil Z)))) (l))) ” + && emp +). + +Definition reverse_entail_wit_1_split_goal_1 := +forall (l: (@list Z)) , + (l = (app ((rev ((@nil Z)))) (l))) +. + +Definition reverse_entail_wit_2 := +forall (l: (@list Z)) (v: Z) (w: Z) (l1_2: (@list Z)) (l2_2: (@list Z)) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) , + (sll w l1_2 ) + ** (sll v l2_2 ) +|-- + EX (vnext: Z) (vdata: Z) (l2_new: (@list Z)) (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app ((rev (l1))) (l2))) ” + && “ (v <> 0) ” + && “ (l2 = (cons (vdata) (l2_new))) ” + && (sll w l1 ) + ** ((&((v) # "list" ->ₛ "data")) # Int |-> vdata) + ** ((&((v) # "list" ->ₛ "next")) # Ptr |-> vnext) + ** (sll vnext l2_new ) +. + +Definition reverse_entail_wit_3 := +( +forall (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l2_new: (@list Z)) (vnext: Z) (vdata: Z) (v: Z) (w: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (vdata) (l2_new)))) , + (sll w l1_2 ) + ** ((&((v) # "list" ->ₛ "data")) # Int |-> vdata) + ** ((&((v) # "list" ->ₛ "next")) # Ptr |-> w) + ** (sll vnext l2_new ) +|-- + EX (l1: (@list Z)) (l2: (@list Z)) , + “ (l = (app ((rev (l1))) (l2))) ” + && (sll v l1 ) + ** (sll vnext l2 ) +) \/ +( +forall (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l2_new: (@list Z)) (vdata: Z) (v: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (vdata) (l2_new)))) , + TT && emp +|-- + “ (l = (app ((rev ((cons (vdata) (l1_2))))) (l2_new))) ” + && emp +). + +Definition reverse_entail_wit_3_split_goal_1 := +forall (l: (@list Z)) (l1_2: (@list Z)) (l2_2: (@list Z)) (l2_new: (@list Z)) (vdata: Z) (v: Z) (PreH1 : (l = (app ((rev (l1_2))) (l2_2)))) (PreH2 : (v <> 0)) (PreH3 : (l2_2 = (cons (vdata) (l2_new)))) , + (l = (app ((rev ((cons (vdata) (l1_2))))) (l2_new))) +. + +Definition reverse_return_wit_1 := +( +forall (l: (@list Z)) (v: Z) (w: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll w l1 ) + ** (sll v l2 ) +|-- + (sll w (rev (l)) ) +) \/ +( +forall (l: (@list Z)) (v: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll v l2 ) +|-- + “ (l1 = (rev (l))) ” + && emp +). + +Definition reverse_return_wit_1_split_goal_1 := +forall (l: (@list Z)) (v: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll v l2 ) +|-- + “ (l1 = (rev (l))) ” +. + +Definition reverse_return_wit_1_split_goal_spatial := +forall (l: (@list Z)) (v: Z) (l1: (@list Z)) (l2: (@list Z)) (PreH1 : (l = (app ((rev (l1))) (l2)))) (PreH2 : (v = 0)) , + (sll v l2 ) +|-- + TT && emp +. + +(*----- Function append -----*) + +Definition append_safety_wit_1 := +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) , + ((( &( "u" ) )) # Ptr |->_) + ** ((( &( "t" ) )) # Ptr |->_) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** (sll x_pre l1 ) + ** (sll y_pre l2 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition append_safety_wit_2 := +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (u: Z) (t_next: Z) (l1a: (@list Z)) (t_data: Z) (t: Z) (l1b: (@list Z)) (PreH1 : ((app (l1a) ((cons (t_data) (l1b)))) = l1)) (PreH2 : (x_pre <> 0)) (PreH3 : (t <> 0)) (PreH4 : (t_next = u)) , + ((( &( "t" ) )) # Ptr |-> t) + ** ((&((t) # "list" ->ₛ "data")) # Int |-> t_data) + ** ((( &( "x" ) )) # Ptr |-> x_pre) + ** ((( &( "y" ) )) # Ptr |-> y_pre) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> t_next) + ** ((( &( "u" ) )) # Ptr |-> u) + ** (sllseg x_pre t l1a ) + ** (sll u l1b ) + ** (sll y_pre l2 ) +|-- + “ (0 <= INT_MAX) ” + && “ ((INT_MIN) <= 0) ” +. + +Definition append_entail_wit_1 := +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (PreH1 : (x_pre <> 0)) , + (sll x_pre l1 ) + ** (sll y_pre l2 ) +|-- + EX (xn: Z) (a: Z) (l1n: (@list Z)) , + “ (x_pre <> 0) ” + && “ (l1 = (cons (a) (l1n))) ” + && ((&((x_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> xn) + ** (sll xn l1n ) + ** (sll y_pre l2 ) +. + +Definition append_entail_wit_2 := +( +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (a: Z) (l1n: (@list Z)) (xn: Z) (PreH1 : (x_pre <> 0)) (PreH2 : (l1 = (cons (a) (l1n)))) , + ((&((x_pre) # "list" ->ₛ "data")) # Int |-> a) + ** ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> xn) + ** (sll xn l1n ) + ** (sll y_pre l2 ) +|-- + EX (t_next: Z) (l1a: (@list Z)) (t_data: Z) (l1b: (@list Z)) , + “ ((app (l1a) ((cons (t_data) (l1b)))) = l1) ” + && “ (x_pre <> 0) ” + && “ (x_pre <> 0) ” + && “ (t_next = xn) ” + && ((&((x_pre) # "list" ->ₛ "data")) # Int |-> t_data) + ** ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> t_next) + ** (sllseg x_pre x_pre l1a ) + ** (sll xn l1b ) + ** (sll y_pre l2 ) +) \/ +( +forall (x_pre: Z) (l1: (@list Z)) (a: Z) (l1n: (@list Z)) (PreH1 : (x_pre <> 0)) (PreH2 : (l1 = (cons (a) (l1n)))) , + TT && emp +|-- + “ ((app ((@nil Z)) (l1)) = l1) ” + && emp +). + +Definition append_entail_wit_2_split_goal_1 := +forall (x_pre: Z) (l1: (@list Z)) (a: Z) (l1n: (@list Z)) (PreH1 : (x_pre <> 0)) (PreH2 : (l1 = (cons (a) (l1n)))) , + ((app ((@nil Z)) (l1)) = l1) +. + +Definition append_entail_wit_3 := +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (u: Z) (t_next_2: Z) (l1a_2: (@list Z)) (t_data_2: Z) (t: Z) (l1b_2: (@list Z)) (PreH1 : (u <> 0)) (PreH2 : ((app (l1a_2) ((cons (t_data_2) (l1b_2)))) = l1)) (PreH3 : (x_pre <> 0)) (PreH4 : (t <> 0)) (PreH5 : (t_next_2 = u)) , + ((&((t) # "list" ->ₛ "data")) # Int |-> t_data_2) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> t_next_2) + ** (sllseg x_pre t l1a_2 ) + ** (sll u l1b_2 ) + ** (sll y_pre l2 ) +|-- + EX (unext: Z) (udata: Z) (l1b_new: (@list Z)) (t_next: Z) (l1a: (@list Z)) (t_data: Z) (l1b: (@list Z)) , + “ ((app (l1a) ((cons (t_data) (l1b)))) = l1) ” + && “ (t <> 0) ” + && “ (t_next = u) ” + && “ (u <> 0) ” + && “ (x_pre <> 0) ” + && “ (l1b = (cons (udata) (l1b_new))) ” + && ((&((t) # "list" ->ₛ "data")) # Int |-> t_data) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> t_next) + ** (sllseg x_pre t l1a ) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> udata) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l1b_new ) + ** (sll y_pre l2 ) +. + +Definition append_entail_wit_4 := +( +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (l1a_2: (@list Z)) (l1b_2: (@list Z)) (l1b_new: (@list Z)) (udata: Z) (unext: Z) (t: Z) (t_data_2: Z) (t_next_2: Z) (u: Z) (PreH1 : ((app (l1a_2) ((cons (t_data_2) (l1b_2)))) = l1)) (PreH2 : (t <> 0)) (PreH3 : (t_next_2 = u)) (PreH4 : (u <> 0)) (PreH5 : (x_pre <> 0)) (PreH6 : (l1b_2 = (cons (udata) (l1b_new)))) , + ((&((t) # "list" ->ₛ "data")) # Int |-> t_data_2) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> t_next_2) + ** (sllseg x_pre t l1a_2 ) + ** ((&((u) # "list" ->ₛ "data")) # Int |-> udata) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> unext) + ** (sll unext l1b_new ) + ** (sll y_pre l2 ) +|-- + EX (t_next: Z) (l1a: (@list Z)) (t_data: Z) (l1b: (@list Z)) , + “ ((app (l1a) ((cons (t_data) (l1b)))) = l1) ” + && “ (x_pre <> 0) ” + && “ (u <> 0) ” + && “ (t_next = unext) ” + && ((&((u) # "list" ->ₛ "data")) # Int |-> t_data) + ** ((&((u) # "list" ->ₛ "next")) # Ptr |-> t_next) + ** (sllseg x_pre u l1a ) + ** (sll unext l1b ) + ** (sll y_pre l2 ) +) \/ +( +forall (x_pre: Z) (l1: (@list Z)) (l1a_2: (@list Z)) (l1b_2: (@list Z)) (l1b_new: (@list Z)) (udata: Z) (t: Z) (t_data_2: Z) (t_next_2: Z) (u: Z) (PreH1 : (t_data_2 <= INT_MAX)) (PreH2 : (t_data_2 >= INT_MIN)) (PreH3 : ((app (l1a_2) ((cons (t_data_2) (l1b_2)))) = l1)) (PreH4 : (t <> 0)) (PreH5 : (t_next_2 = u)) (PreH6 : (u <> 0)) (PreH7 : (x_pre <> 0)) (PreH8 : (l1b_2 = (cons (udata) (l1b_new)))) , + ((&((t) # "list" ->ₛ "data")) # Int |-> t_data_2) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> t_next_2) + ** (sllseg x_pre t l1a_2 ) +|-- + EX (l1a: (@list Z)) , + “ ((app (l1a) ((cons (udata) (l1b_new)))) = l1) ” + && “ (x_pre <> 0) ” + && “ (u <> 0) ” + && (sllseg x_pre u l1a ) +). + +Definition append_return_wit_1 := +( +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (u: Z) (t_next: Z) (l1a: (@list Z)) (t_data: Z) (t: Z) (l1b: (@list Z)) (PreH1 : (u = 0)) (PreH2 : ((app (l1a) ((cons (t_data) (l1b)))) = l1)) (PreH3 : (x_pre <> 0)) (PreH4 : (t <> 0)) (PreH5 : (t_next = u)) , + ((&((t) # "list" ->ₛ "data")) # Int |-> t_data) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> y_pre) + ** (sllseg x_pre t l1a ) + ** (sll u l1b ) + ** (sll y_pre l2 ) +|-- + (sll x_pre (app (l1) (l2)) ) +) \/ +( +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (u: Z) (t_next: Z) (l1a: (@list Z)) (t_data: Z) (t: Z) (l1b: (@list Z)) (PreH1 : (t_data <= INT_MAX)) (PreH2 : (t_data >= INT_MIN)) (PreH3 : (u = 0)) (PreH4 : ((app (l1a) ((cons (t_data) (l1b)))) = l1)) (PreH5 : (x_pre <> 0)) (PreH6 : (t <> 0)) (PreH7 : (t_next = u)) , + ((&((t) # "list" ->ₛ "data")) # Int |-> t_data) + ** ((&((t) # "list" ->ₛ "next")) # Ptr |-> y_pre) + ** (sllseg x_pre t l1a ) + ** (sll u l1b ) + ** (sll y_pre l2 ) +|-- + EX (y: Z) (l0: (@list Z)) (x: Z) , + “ (x_pre <> 0) ” + && “ ((app (l1) (l2)) = (cons (x) (l0))) ” + && (sll y l0 ) + ** ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> y) + ** ((&((x_pre) # "list" ->ₛ "data")) # Int |-> x) +). + +Definition append_return_wit_2 := +( +forall (y_pre: Z) (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (PreH1 : (x_pre = 0)) , + (sll x_pre l1 ) + ** (sll y_pre l2 ) +|-- + (sll y_pre (app (l1) (l2)) ) +) \/ +( +forall (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (PreH1 : (x_pre = 0)) , + (sll x_pre l1 ) +|-- + “ (l2 = (app (l1) (l2))) ” + && emp +). + +Definition append_return_wit_2_split_goal_1 := +forall (x_pre: Z) (l2: (@list Z)) (l1: (@list Z)) (PreH1 : (x_pre = 0)) , + (sll x_pre l1 ) +|-- + “ (l2 = (app (l1) (l2))) ” +. + +Definition append_return_wit_2_split_goal_spatial := +forall (x_pre: Z) (l1: (@list Z)) (PreH1 : (x_pre = 0)) , + (sll x_pre l1 ) +|-- + TT && emp +. + +Module Type VC_Correct. + +Include sll_Strategy_Correct. + +Axiom proof_of_length_safety_wit_1 : length_safety_wit_1. +Axiom proof_of_length_safety_wit_2 : length_safety_wit_2. +Axiom proof_of_length_entail_wit_1 : length_entail_wit_1. +Axiom proof_of_length_entail_wit_2 : length_entail_wit_2. +Axiom proof_of_length_entail_wit_3 : length_entail_wit_3. +Axiom proof_of_length_return_wit_1 : length_return_wit_1. +Axiom proof_of_reverse_safety_wit_1 : reverse_safety_wit_1. +Axiom proof_of_reverse_entail_wit_1 : reverse_entail_wit_1. +Axiom proof_of_reverse_entail_wit_2 : reverse_entail_wit_2. +Axiom proof_of_reverse_entail_wit_3 : reverse_entail_wit_3. +Axiom proof_of_reverse_return_wit_1 : reverse_return_wit_1. +Axiom proof_of_append_safety_wit_1 : append_safety_wit_1. +Axiom proof_of_append_safety_wit_2 : append_safety_wit_2. +Axiom proof_of_append_entail_wit_1 : append_entail_wit_1. +Axiom proof_of_append_entail_wit_2 : append_entail_wit_2. +Axiom proof_of_append_entail_wit_3 : append_entail_wit_3. +Axiom proof_of_append_entail_wit_4 : append_entail_wit_4. +Axiom proof_of_append_return_wit_1 : append_return_wit_1. +Axiom proof_of_append_return_wit_2 : append_return_wit_2. + +End VC_Correct. diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_goal_check.v b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..32aca47b173f9928e98a0bc89672d1f04014edf8 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_goal_check.v @@ -0,0 +1,7 @@ +From PVbench.Data_structures.singly_linked_list.rocq.groundtruth Require Import singly_linked_list_goal singly_linked_list_proof_auto singly_linked_list_proof_manual. + +Module VC_Correctness : VC_Correct. + Include sll_strategy_proof. + Include singly_linked_list_proof_auto. + Include singly_linked_list_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_proof_auto.v b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..b5599461b6a9a01100df4dadb4e3b20b5dbb17e8 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_proof_auto.v @@ -0,0 +1,46 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.singly_linked_list.rocq.groundtruth Require Import singly_linked_list_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Local Open Scope sac. + +Lemma proof_of_length_safety_wit_1 : length_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_length_entail_wit_2 : length_entail_wit_2. +Proof. Admitted. + +Lemma proof_of_reverse_safety_wit_1 : reverse_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_reverse_entail_wit_2 : reverse_entail_wit_2. +Proof. Admitted. + +Lemma proof_of_append_safety_wit_1 : append_safety_wit_1. +Proof. Admitted. + +Lemma proof_of_append_safety_wit_2 : append_safety_wit_2. +Proof. Admitted. + +Lemma proof_of_append_entail_wit_1 : append_entail_wit_1. +Proof. Admitted. + +Lemma proof_of_append_entail_wit_3 : append_entail_wit_3. +Proof. Admitted. + diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_proof_manual.v b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..22cbcd6c1be3e8cccd5a6c16cd31f40e5f98d2d3 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/groundtruth/singly_linked_list_proof_manual.v @@ -0,0 +1,244 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.singly_linked_list.rocq.groundtruth Require Import singly_linked_list_goal. +From PVbench.Data_structures.singly_linked_list.rocq.groundtruth Require Import singly_linked_list_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.singly_linked_list.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_length_safety_wit_2 : length_safety_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + split_pures. + - dump_pre_spatial. + pose proof PreH5 as Hlen. + rewrite PreH1 in Hlen. + rewrite PreH4 in Hlen. + rewrite Zlength_app in Hlen. + rewrite Zlength_cons in Hlen. + rewrite PreH2. + pose proof Zlength_nonneg l1. + pose proof Zlength_nonneg l3. + lia. + - dump_pre_spatial. + rewrite PreH2. + pose proof Zlength_nonneg l1. + lia. +Qed. + +Lemma proof_of_length_entail_wit_1 : length_entail_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists nil l. + split_pure_spatial. + - simpl sllseg. + split_pure_spatial. + + cancel (sll p_pre l). + + dump_pre_spatial. + reflexivity. + - split_pures. + + dump_pre_spatial. + simpl. + reflexivity. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + simpl. + reflexivity. +Qed. + +Lemma proof_of_length_entail_wit_3 : length_entail_wit_3. +Proof. + LLM_pre_process ltac:(int_auto). + subst l2_2. + Exists (l1_2 ++ (pdata :: nil))%list l3. + split_pure_spatial. + - sep_apply (sllseg_len1 p pdata pnext); [ | easy ]. + sep_apply (sllseg_sllseg p_pre p pnext l1_2 (pdata :: nil)%list). + cancel. + - split_pures. + + dump_pre_spatial. + rewrite <- app_assoc. + simpl. + exact PreH1. + + dump_pre_spatial. + exact PreH5. + + dump_pre_spatial. + rewrite PreH2. + rewrite Zlength_app. + rewrite Zlength_cons. + rewrite Zlength_nil. + lia. +Qed. + +Lemma proof_of_length_return_wit_1 : length_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + subst p. + sep_apply (sll_zero 0 l2); [ | reflexivity ]. + Intros_p Hl2. + rewrite Hl2 in PreH1. + rewrite app_nil_r in PreH1. + subst l. + split_pure_spatial. + - apply sllseg_0_sll. + - dump_pre_spatial. + rewrite PreH3. + reflexivity. +Qed. + +Lemma proof_of_reverse_entail_wit_1 : reverse_entail_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists nil l. + split_pure_spatial. + - simpl sll. + split_pure_spatial. + + cancel (sll p_pre l). + + dump_pre_spatial. + reflexivity. + - dump_pre_spatial. + simpl. + reflexivity. +Qed. + +Lemma proof_of_reverse_entail_wit_3 : reverse_entail_wit_3. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists (vdata :: l1_2) l2_new. + split_pure_spatial. + - cancel (sll vnext l2_new). + simpl sll. + Exists w. + split_pure_spatial. + + cancel. + + dump_pre_spatial. + exact PreH2. + - dump_pre_spatial. + subst l2_2. + simpl. + rewrite <- app_assoc. + simpl. + exact PreH1. +Qed. + +Lemma proof_of_reverse_return_wit_1 : reverse_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + sep_apply (sll_zero v l2); [ | tauto ]. + Intros_p Hl2. + rewrite Hl2 in PreH1. + rewrite app_nil_r in PreH1. + subst l. + rewrite rev_involutive. + cancel (sll w l1). +Qed. + +Lemma proof_of_append_entail_wit_2 : append_entail_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + Exists xn. + Exists nil. + Exists a. + Exists l1n. + split_pure_spatial. + - cancel ((&((x_pre) # "list" ->ₛ "data")) # Int |-> a). + cancel ((&((x_pre) # "list" ->ₛ "next")) # Ptr |-> xn). + cancel (sll xn l1n). + cancel (sll y_pre l2). + simpl sllseg. + split_pure_spatial. + + cancel. + + dump_pre_spatial. + reflexivity. + - split_pures. + + dump_pre_spatial. + simpl. + symmetry. + exact PreH2. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma proof_of_append_entail_wit_4 : append_entail_wit_4. +Proof. + LLM_pre_process ltac:(int_auto). + subst t_next_2 l1b_2. + Exists unext. + Exists (l1a_2 ++ (t_data_2 :: nil))%list. + Exists udata. + Exists l1b_new. + split_pure_spatial. + - sep_apply (sllseg_len1 t t_data_2 u); [ | tauto ]. + sep_apply (sllseg_sllseg x_pre). + cancel. + - split_pures. + + dump_pre_spatial. + rewrite <- app_assoc. + simpl. + exact PreH1. + + dump_pre_spatial. + exact PreH5. + + dump_pre_spatial. + exact PreH4. + + dump_pre_spatial. + reflexivity. +Qed. + +Lemma proof_of_append_return_wit_2 : append_return_wit_2. +Proof. + left. + LLM_pre_process ltac:(int_auto). + rewrite PreH1. + sep_apply (sll_zero 0 l1); [ | reflexivity ]. + Intros_p Hl1. + rewrite Hl1 in *. + subst l1. + simpl. + cancel (sll y_pre l2). +Qed. + +Lemma proof_of_append_return_wit_1 : append_return_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + subst t_next. + sep_apply (sll_zero u l1b); [ | tauto ]. + Intros_p Hl1b. + rewrite Hl1b in *. + sep_apply (sllseg_len1 t t_data y_pre); [ | tauto ]. + sep_apply (sllseg_sll t y_pre (t_data :: nil)%list l2). + sep_apply (sllseg_sll x_pre t l1a (t_data :: l2)). + subst l1. + rewrite <- app_assoc. + simpl. + cancel. +Qed. diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/solution_annotated.c b/benchmarks/Data_structures/singly_linked_list/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..920d583d03abeb1663f157dfe077b1b31fc0a1e0 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/solution_annotated.c @@ -0,0 +1,111 @@ +#include "sll_def.h" + +int length(struct list *p) +/*@ With (l: list Z) + Require sll(p, l) && Zlength(l) <= 2147483647 + Ensure __return == Zlength(l) && sll(p@pre, l) +*/ +{ + int n = 0; + /*@ Inv Assert + exists l1 l2, + l == app(l1, l2) && + Zlength(l) <= 2147483647 && + n == Zlength(l1) && + sllseg(p@pre, p, l1) * sll(p, l2) + */ + while (p) { + /*@ Assert exists l1 l2 l3 pnext pdata, + l == app(l1, l2) && + n == Zlength(l1) && + p != 0 && + l2 == cons(pdata, l3) && + Zlength(l) <= 2147483647 && + store(&(p -> data), pdata) * + store(&(p -> next), pnext) * + sllseg(p@pre, p, l1) * sll(pnext, l3) + */ + n++; + p = p -> next; + } + return n; +} + +struct list *reverse(struct list *p) +/*@ With (l: list Z) + Require sll(p, l) + Ensure sll(__return, rev(l)) +*/ +{ + struct list * w = (void *) 0, * v = p; + /*@ Inv Assert + exists l1 l2, + p == p@pre && + l == app(rev(l1), l2) && + sll(w, l1) * sll(v, l2) + */ + while (v) { + /*@ Assert exists l1 l2 l2_new vnext vdata, + p == p@pre && + l == app(rev(l1), l2) && + v != 0 && + l2 == cons(vdata, l2_new) && + sll(w, l1) * + store(&(v -> data), vdata) * + store(&(v -> next), vnext) * + sll(vnext, l2_new) + */ + struct list * t = v -> next; + v -> next = w; + w = v; + v = t; + } + return w; +} + +struct list *append(struct list *x, struct list *y) +/*@ With l1 l2 + Require sll(x, l1) * sll(y, l2) + Ensure sll(__return, app(l1, l2)) +*/ +{ + struct list *t, *u; + if (x == (void *)0) { + return y; + } else { + /*@ Assert exists a l1n xn, + x != 0 && x == x@pre && y == y@pre && + l1 == cons(a, l1n) && + has_ptr_permission(&t) * has_ptr_permission(&u) * + store(&(x -> data), a) * + store(&(x -> next), xn) * + sll(xn, l1n) * sll(y, l2) + */ + t = x; + u = t -> next; + /*@ Inv Assert + exists l1a l1b, + app(l1a, cons(t -> data, l1b)) == l1 && + x == x@pre && y == y@pre && x != 0 && + t != 0 && t -> next == u && + sllseg(x, t, l1a) * + sll(u, l1b) * sll(y, l2) + */ + while (u != (void *)0) { + /*@ Assert exists l1a l1b l1b_new udata unext, + app(l1a, cons(t -> data, l1b)) == l1 && + t != 0 && t -> next == u && + u != 0 && x == x@pre && y == y@pre && x != 0 && + l1b == cons(udata, l1b_new) && + sllseg(x, t, l1a) * + store(&(u -> data), udata) * + store(&(u -> next), unext) * + sll(unext, l1b_new) * sll(y, l2) + */ + t = u; + u = t -> next; + } + t -> next = y; + return x; + } +} diff --git a/benchmarks/Data_structures/singly_linked_list/rocq/solution_spec.c b/benchmarks/Data_structures/singly_linked_list/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..8574072b235d2792914c00fa1aeee597651414cd --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/rocq/solution_spec.c @@ -0,0 +1,55 @@ +#include "sll_def.h" + +int length(struct list *p) +/*@ With (l: list Z) + Require sll(p, l) && Zlength(l) <= 2147483647 + Ensure __return == Zlength(l) && sll(p@pre, l) +*/ +{ + int n = 0; + + while (p) { + n++; + p = p -> next; + } + return n; +} + +struct list *reverse(struct list *p) +/*@ With (l: list Z) + Require sll(p, l) + Ensure sll(__return, rev(l)) +*/ +{ + struct list * w = (void *) 0, * v = p; + + while (v) { + struct list * t = v -> next; + v -> next = w; + w = v; + v = t; + } + return w; +} + +struct list *append(struct list *x, struct list *y) +/*@ With l1 l2 + Require sll(x, l1) * sll(y, l2) + Ensure sll(__return, app(l1, l2)) +*/ +{ + struct list *t, *u; + if (x == (void *)0) { + return y; + } else { + t = x; + u = t -> next; + + while (u != (void *)0) { + t = u; + u = t -> next; + } + t -> next = y; + return x; + } +} diff --git a/benchmarks/Data_structures/singly_linked_list/solution.c b/benchmarks/Data_structures/singly_linked_list/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..89ae288dadf0ff64f84372f6705f5d7503fc60a7 --- /dev/null +++ b/benchmarks/Data_structures/singly_linked_list/solution.c @@ -0,0 +1,43 @@ +#include "sll_def.h" + +int length(struct list *p) +{ + int n = 0; + + while (p) { + n++; + p = p -> next; + } + return n; +} + +struct list *reverse(struct list *p) +{ + struct list * w = (void *) 0, * v = p; + + while (v) { + struct list * t = v -> next; + v -> next = w; + w = v; + v = t; + } + return w; +} + +struct list *append(struct list *x, struct list *y) +{ + struct list *t, *u; + if (x == (void *)0) { + return y; + } else { + t = x; + u = t -> next; + + while (u != (void *)0) { + t = u; + u = t -> next; + } + t -> next = y; + return x; + } +} diff --git a/benchmarks/Data_structures/sll_queue/manifest.json b/benchmarks/Data_structures/sll_queue/manifest.json new file mode 100644 index 0000000000000000000000000000000000000000..c56acb138457c3014b254cc7a603ea1d894f9221 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/manifest.json @@ -0,0 +1,19 @@ +{ + "id": "sll_queue", + "source": { + "dataset": "classical_data_structure", + "problem_id": "sll_queue", + "title": "Queue on a Singly Linked List", + "tags": [ + "data structures", + "queue", + "linked list" + ] + }, + "stratification": { + "band": "unclassified", + "output_mode": "CONSTRUCT", + "interactive": false, + "multi_test": false + } +} diff --git a/benchmarks/Data_structures/sll_queue/problem.md b/benchmarks/Data_structures/sll_queue/problem.md new file mode 100644 index 0000000000000000000000000000000000000000..2d23e5f50088db6c4c5ae830038497dd7135e349 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/problem.md @@ -0,0 +1,26 @@ +# Queue on a Singly Linked List + +## Description + +Maintain a first-in first-out queue of integers stored in a singly linked list with head and tail pointers, supporting creation, insertion at the back and removal from the front. + +## Input + +List nodes have this type: + +```c +struct list { + int data; + struct list *next; +}; +``` + +- `init_empty_queue` takes no arguments. +- `enqueue` receives a queue `q` and an integer `x`. +- `dequeue` receives a non-empty queue `q`. + +## Output + +- `init_empty_queue` returns a new empty queue. +- `enqueue` appends `x` at the back of `q`. +- `dequeue` removes the element at the front of `q` and returns it. diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/proof_lib.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/proof_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..d7b23a22d080c17234dd4834842831402637ba2c --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/proof_lib.v @@ -0,0 +1,22 @@ +(* Supporting lemmas for the manual proof. *) +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string. +Local Open Scope list. +Import naive_C_Rules. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +Local Open Scope sac. + diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_goal.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..2a6400d95bd1b31ae362c2c3146f1175d7a5270c --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_goal.v @@ -0,0 +1,264 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +Local Open Scope sac. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_strategy_proof. +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_store_strategy_goal. +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_store_strategy_proof. + +(*----- Function enqueue -----*) + +Definition enqueue_entail_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) , + (store_queue q_pre l ) +|-- + EX (v: Z) (u: Z) (qhead: Z) (qtail: Z) , + “ (qtail <> 0) ” + && ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qhead qtail l ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) , + (store_queue q_pre l ) +|-- + EX (v: Z) (u: Z) (qhead: Z) (qtail: Z) , + “ (qtail <> 0) ” + && ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qhead qtail l ) +). + +Definition enqueue_return_wit_1 := +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval_data: Z) (retval_next: Z) (retval: Z) (PreH1 : (retval <> 0)) (PreH2 : (retval_next = 0)) (PreH3 : (retval_data = 0)) (PreH4 : (qtail <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> retval_next) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> retval_data) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> retval) + ** (sllseg qhead qtail l ) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +) \/ +( +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval_data: Z) (retval_next: Z) (retval: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (retval_data <= INT_MAX)) (PreH3 : (x_pre >= INT_MIN)) (PreH4 : (retval_data >= INT_MIN)) (PreH5 : (retval <> 0)) (PreH6 : (retval_next = 0)) (PreH7 : (retval_data = 0)) (PreH8 : (qtail <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> retval_next) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> retval_data) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> retval) + ** (sllseg qhead qtail l ) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +). + +Definition enqueue_return_wit_1_split_goal_spatial := +forall (x_pre: Z) (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (retval_data: Z) (retval_next: Z) (retval: Z) (PreH1 : (x_pre <= INT_MAX)) (PreH2 : (retval_data <= INT_MAX)) (PreH3 : (x_pre >= INT_MIN)) (PreH4 : (retval_data >= INT_MIN)) (PreH5 : (retval <> 0)) (PreH6 : (retval_next = 0)) (PreH7 : (retval_data = 0)) (PreH8 : (qtail <> 0)) , + ((&((retval) # "list" ->ₛ "next")) # Ptr |-> retval_next) + ** ((&((retval) # "list" ->ₛ "data")) # Int |-> retval_data) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> retval) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> x_pre) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> retval) + ** (sllseg qhead qtail l ) +|-- + (store_queue q_pre (app (l) ((cons (x_pre) ((@nil Z))))) ) +. + +Definition enqueue_partial_solve_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (u: Z) (v: Z) (PreH1 : (qtail <> 0)) , + ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qhead qtail l ) +|-- + “ (qtail <> 0) ” + && ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qhead qtail l ) +. + +(*----- Function dequeue -----*) + +Definition dequeue_entail_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) , + (store_queue q_pre (cons (x) (l)) ) +|-- + EX (v: Z) (u: Z) (qheadnext: Z) (qtail: Z) (qhead: Z) , + “ (qhead <> 0) ” + && “ (qtail <> 0) ” + && ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) , + (store_queue q_pre (cons (x) (l)) ) +|-- + EX (v: Z) (u: Z) (qheadnext: Z) (qtail: Z) (qhead: Z) , + “ (qhead <> 0) ” + && “ (qtail <> 0) ” + && ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qhead) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +). + +Definition dequeue_return_wit_1 := +( +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (u: Z) (v: Z) (qheadnext: Z) (PreH1 : (qhead <> 0)) (PreH2 : (qtail <> 0)) , + ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +|-- + “ (x = x) ” + && (store_queue q_pre l ) +) \/ +( +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (u: Z) (v: Z) (qheadnext: Z) (PreH1 : (u <= INT_MAX)) (PreH2 : (u >= INT_MIN)) (PreH3 : (qhead <> 0)) (PreH4 : (qtail <> 0)) , + ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +|-- + (store_queue q_pre l ) +). + +Definition dequeue_return_wit_1_split_goal_spatial := +forall (q_pre: Z) (l: (@list Z)) (qhead: Z) (qtail: Z) (u: Z) (v: Z) (qheadnext: Z) (PreH1 : (u <= INT_MAX)) (PreH2 : (u >= INT_MIN)) (PreH3 : (qhead <> 0)) (PreH4 : (qtail <> 0)) , + ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +|-- + (store_queue q_pre l ) +. + +Definition dequeue_partial_solve_wit_1 := +forall (q_pre: Z) (l: (@list Z)) (x: Z) (qhead: Z) (qtail: Z) (u: Z) (v: Z) (qheadnext: Z) (PreH1 : (qhead <> 0)) (PreH2 : (qtail <> 0)) , + ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +|-- + “ (qhead <> 0) ” + && “ (qtail <> 0) ” + && ((&((qhead) # "list" ->ₛ "next")) # Ptr |-> qheadnext) + ** ((&((qhead) # "list" ->ₛ "data")) # Int |-> x) + ** ((&((q_pre) # "queue" ->ₛ "head")) # Ptr |-> qheadnext) + ** ((&((q_pre) # "queue" ->ₛ "tail")) # Ptr |-> qtail) + ** ((&((qtail) # "list" ->ₛ "data")) # Int |-> u) + ** ((&((qtail) # "list" ->ₛ "next")) # Ptr |-> v) + ** (sllseg qheadnext qtail l ) +. + +(*----- Function init_empty_queue -----*) + +Definition init_empty_queue_return_wit_1 := +( +forall (retval_tail: Z) (retval_head: Z) (retval: Z) (retval_data: Z) (retval_next: Z) (retval_2: Z) (PreH1 : (retval_2 <> 0)) (PreH2 : (retval_next = 0)) (PreH3 : (retval_data = 0)) (PreH4 : (retval <> 0)) (PreH5 : (retval_head = 0)) (PreH6 : (retval_tail = 0)) , + ((&((retval_2) # "list" ->ₛ "next")) # Ptr |-> retval_next) + ** ((&((retval_2) # "list" ->ₛ "data")) # Int |-> retval_data) + ** ((&((retval) # "queue" ->ₛ "head")) # Ptr |-> retval_2) + ** ((&((retval) # "queue" ->ₛ "tail")) # Ptr |-> retval_2) +|-- + (store_queue retval (@nil Z) ) +) \/ +( +forall (retval_tail: Z) (retval_head: Z) (retval: Z) (retval_data: Z) (retval_next: Z) (retval_2: Z) (PreH1 : (retval_data <= INT_MAX)) (PreH2 : (retval_data >= INT_MIN)) (PreH3 : (retval_2 <> 0)) (PreH4 : (retval_next = 0)) (PreH5 : (retval_data = 0)) (PreH6 : (retval <> 0)) (PreH7 : (retval_head = 0)) (PreH8 : (retval_tail = 0)) , + ((&((retval_2) # "list" ->ₛ "next")) # Ptr |-> retval_next) + ** ((&((retval_2) # "list" ->ₛ "data")) # Int |-> retval_data) + ** ((&((retval) # "queue" ->ₛ "head")) # Ptr |-> retval_2) + ** ((&((retval) # "queue" ->ₛ "tail")) # Ptr |-> retval_2) +|-- + (store_queue retval (@nil Z) ) +). + +Definition init_empty_queue_return_wit_1_split_goal_spatial := +forall (retval_tail: Z) (retval_head: Z) (retval: Z) (retval_data: Z) (retval_next: Z) (retval_2: Z) (PreH1 : (retval_data <= INT_MAX)) (PreH2 : (retval_data >= INT_MIN)) (PreH3 : (retval_2 <> 0)) (PreH4 : (retval_next = 0)) (PreH5 : (retval_data = 0)) (PreH6 : (retval <> 0)) (PreH7 : (retval_head = 0)) (PreH8 : (retval_tail = 0)) , + ((&((retval_2) # "list" ->ₛ "next")) # Ptr |-> retval_next) + ** ((&((retval_2) # "list" ->ₛ "data")) # Int |-> retval_data) + ** ((&((retval) # "queue" ->ₛ "head")) # Ptr |-> retval_2) + ** ((&((retval) # "queue" ->ₛ "tail")) # Ptr |-> retval_2) +|-- + (store_queue retval (@nil Z) ) +. + +Definition init_empty_queue_partial_solve_wit_1 := + TT && emp +|-- + TT && emp +. + +Definition init_empty_queue_partial_solve_wit_2 := +forall (retval_tail: Z) (retval_head: Z) (retval: Z) (PreH1 : (retval <> 0)) (PreH2 : (retval_head = 0)) (PreH3 : (retval_tail = 0)) , + ((&((retval) # "queue" ->ₛ "head")) # Ptr |-> retval_head) + ** ((&((retval) # "queue" ->ₛ "tail")) # Ptr |-> retval_tail) +|-- + “ (retval <> 0) ” + && “ (retval_head = 0) ” + && “ (retval_tail = 0) ” + && ((&((retval) # "queue" ->ₛ "head")) # Ptr |-> retval_head) + ** ((&((retval) # "queue" ->ₛ "tail")) # Ptr |-> retval_tail) +. + +Module Type VC_Correct. + +Include sll_Strategy_Correct. +Include sll_queue_store_Strategy_Correct. + +Axiom proof_of_enqueue_entail_wit_1 : enqueue_entail_wit_1. +Axiom proof_of_enqueue_return_wit_1 : enqueue_return_wit_1. +Axiom proof_of_enqueue_partial_solve_wit_1 : enqueue_partial_solve_wit_1. +Axiom proof_of_dequeue_entail_wit_1 : dequeue_entail_wit_1. +Axiom proof_of_dequeue_return_wit_1 : dequeue_return_wit_1. +Axiom proof_of_dequeue_partial_solve_wit_1 : dequeue_partial_solve_wit_1. +Axiom proof_of_init_empty_queue_return_wit_1 : init_empty_queue_return_wit_1. +Axiom proof_of_init_empty_queue_partial_solve_wit_1 : init_empty_queue_partial_solve_wit_1. +Axiom proof_of_init_empty_queue_partial_solve_wit_2 : init_empty_queue_partial_solve_wit_2. + +End VC_Correct. diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_goal_check.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..ddeaef750bf009904f5ab11c19edff4c1e172b88 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_goal_check.v @@ -0,0 +1,8 @@ +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_goal sll_queue_proof_auto sll_queue_proof_manual. + +Module VC_Correctness : VC_Correct. + Include sll_strategy_proof. + Include sll_queue_store_strategy_proof. + Include sll_queue_proof_auto. + Include sll_queue_proof_manual. +End VC_Correctness. diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_proof_auto.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_proof_auto.v new file mode 100644 index 0000000000000000000000000000000000000000..bfc7f78cb161091fee1fc9e8af6a3c9c985827d6 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_proof_auto.v @@ -0,0 +1,35 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_goal. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +Local Open Scope sac. + +Lemma proof_of_enqueue_partial_solve_wit_1 : enqueue_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_dequeue_partial_solve_wit_1 : dequeue_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_init_empty_queue_partial_solve_wit_1 : init_empty_queue_partial_solve_wit_1. +Proof. Admitted. + +Lemma proof_of_init_empty_queue_partial_solve_wit_2 : init_empty_queue_partial_solve_wit_2. +Proof. Admitted. + diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_proof_manual.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_proof_manual.v new file mode 100644 index 0000000000000000000000000000000000000000..a47a7e9bb9fbaa381c7457f739b0816882abbe59 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_proof_manual.v @@ -0,0 +1,117 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Strings.String. +Require Import Coq.Strings.Ascii. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Coq.Sorting.Permutation. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_goal. +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_proof_auto. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Local Open Scope string_scope. +Local Open Scope list. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.groundtruth.proof_lib. +Local Open Scope sac. + + +Lemma proof_of_enqueue_entail_wit_1 : enqueue_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Intros qhead qtail u v. + Exists v. + Exists u. + Exists qhead. + Exists qtail. + split_pure_spatial. + - cancel. + cancel. + cancel. + - dump_pre_spatial. + exact H. +Qed. + +Lemma proof_of_enqueue_return_wit_1 : enqueue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + sep_apply (sllseg_len1 qtail x_pre retval); [ | tauto ]. + sep_apply (sllseg_sllseg qhead qtail retval l (x_pre :: nil)%list). + Exists qhead retval. + Exists retval_data retval_next. + split_pure_spatial. + - cancel. + cancel. + - dump_pre_spatial. + exact PreH1. +Qed. + +Lemma proof_of_dequeue_entail_wit_1 : dequeue_entail_wit_1. +Proof. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Intros qhead qtail u v. + simpl sllseg. + Intros qheadnext. + Exists v. + Exists u. + Exists qheadnext. + Exists qtail. + Exists qhead. + split_pure_spatial. + - cancel. + cancel. + cancel. + cancel. + - split_pures. + + dump_pre_spatial. + exact H0. + + dump_pre_spatial. + exact H. +Qed. + +Lemma proof_of_dequeue_return_wit_1 : dequeue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Exists qheadnext qtail u v. + split_pure_spatial. + - cancel. + cancel. + cancel. + - split_pures. + + dump_pre_spatial. + reflexivity. + + dump_pre_spatial. + exact PreH2. +Qed. + +Lemma proof_of_init_empty_queue_return_wit_1 : init_empty_queue_return_wit_1. +Proof. + left. + LLM_pre_process ltac:(int_auto). + unfold store_queue. + Exists retval_2 retval_2 retval_data retval_next. + simpl sllseg. + split_pure_spatial. + - cancel. + - split_pures. + + dump_pre_spatial. + exact PreH1. + + dump_pre_spatial. + reflexivity. +Qed. diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_goal.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_goal.v new file mode 100644 index 0000000000000000000000000000000000000000..f2b129ffab9a7fbee345645fefa04de9be88ad52 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_goal.v @@ -0,0 +1,56 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +Require Import Coq.micromega.Psatz. +From SimpleC.SL Require Import SeparationLogic. +Import naive_C_Rules. +Require Import SimpleC.EE.QCP_demos_LLM.sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Definition sll_queue_store_strategy0 := + forall (p : Z) (l0 : (@list Z)), + TT && + emp ** + ((store_queue p l0)) + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list Z)), + TT && + (“ (l0 = l1) ”) && + emp -* + TT && + emp ** + ((store_queue p l1)) + ). + +Definition sll_queue_store_strategy1 := + TT && + emp + |-- + ( + TT && + emp + ) ** ( + ALL (l1 : (@list Z)) (l2 : (@list Z)) (x2 : Z) (x1 : Z), + TT && + (“ (x1 = x2) ”) && + (“ (l1 = l2) ”) && + emp -* + TT && + (“ ((@cons Z x1 l1) = (@cons Z x2 l2)) ”) && + emp + ). + +Module Type sll_queue_store_Strategy_Correct. + + Axiom sll_queue_store_strategy0_correctness : sll_queue_store_strategy0. + Axiom sll_queue_store_strategy1_correctness : sll_queue_store_strategy1. + +End sll_queue_store_Strategy_Correct. diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_goal_check.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_goal_check.v new file mode 100644 index 0000000000000000000000000000000000000000..71d01d4f477091f04b1f7befe45ee88ac11aeaf5 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_goal_check.v @@ -0,0 +1,5 @@ +From PVbench.Data_structures.sll_queue.rocq.groundtruth Require Import sll_queue_store_strategy_goal sll_queue_store_strategy_proof. + +Module sll_queue_store_Strategy_Correctness : sll_queue_store_Strategy_Correct. + Include sll_queue_store_strategy_proof. +End sll_queue_store_Strategy_Correctness. diff --git a/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_proof.v b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_proof.v new file mode 100644 index 0000000000000000000000000000000000000000..8c40b63b352ffc751dda1c20059657152fd3d14a --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/groundtruth/sll_queue_store_strategy_proof.v @@ -0,0 +1,35 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Strings.String. +From SimpleC.SL Require Import SeparationLogic. +Require Import PVbench.Data_structures.sll_queue.rocq.groundtruth.sll_queue_store_strategy_goal. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib. +Require Import PVbench.Data_structures.sll_queue.rocq.groundtruth.proof_lib. +Import naive_C_Rules. +Local Open Scope Z_scope. +Local Open Scope sac. +Local Open Scope string. + +Lemma sll_queue_store_strategy0_correctness : sll_queue_store_strategy0. +Proof. + pre_process_default. + Intros_p H. + subst l1. + cancel. +Qed. + +Lemma sll_queue_store_strategy1_correctness : sll_queue_store_strategy1. +Proof. + pre_process_default. + Intros_p H. + Intros_p H0. + subst x2 l2. + split_pure_spatial. + 2: { + dump_pre_spatial. + reflexivity. + } + cancel. +Qed. diff --git a/benchmarks/Data_structures/sll_queue/rocq/sll_queue_store.strategies b/benchmarks/Data_structures/sll_queue/rocq/sll_queue_store.strategies new file mode 100644 index 0000000000000000000000000000000000000000..bd17d3ba57468fd04628110b7c16756d80b7bc08 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/sll_queue_store.strategies @@ -0,0 +1,22 @@ +//test curent rules +//max rule id:30 + +#include "sll_def.h" +#include "sll_queue_store_def.h" + + + +id : 0 +priority : core(2) +left : store_queue(?p, ?l0) at 0 +right : store_queue(p, ?l1) at 1 +action : left_erase(0); + right_erase(1); + right_add(l0 == l1); + +id : 1 +priority : core(2) +right: cons{Z}(?x1, ?l1) == cons{Z}(?x2, ?l2) at 0 +action : right_erase(0); + right_add(x1 == x2); + right_add(l1 == l2); diff --git a/benchmarks/Data_structures/sll_queue/rocq/sll_queue_store_def.h b/benchmarks/Data_structures/sll_queue/rocq/sll_queue_store_def.h new file mode 100644 index 0000000000000000000000000000000000000000..19e70a9be22fb15ecfe3e4a5b16be9b6354a389b --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/sll_queue_store_def.h @@ -0,0 +1,9 @@ +struct queue { + struct list * head; + struct list * tail; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib */ + +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) + */ diff --git a/benchmarks/Data_structures/sll_queue/rocq/solution_annotated.c b/benchmarks/Data_structures/sll_queue/rocq/solution_annotated.c new file mode 100644 index 0000000000000000000000000000000000000000..f22d7ea79ca7bc79974ea0f27cc77ff25cba8b93 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/solution_annotated.c @@ -0,0 +1,97 @@ +#include "sll_def.h" +struct queue { + struct list * head; + struct list * tail; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib */ +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) */ +/*@ include strategies "sll_queue_store.strategies" */ + +struct list * malloc_list_cell() + /*@ Require emp + Ensure __return != 0 && + __return -> next == 0 && + __return -> data == 0 + */ + ; + +void free_list_cell(struct list * p) + /*@ Require exists x y, p -> next == x && p -> data == y && emp + Ensure emp + */ + ; + +struct queue * malloc_queue_cell() + /*@ Require emp + Ensure __return != 0 && + __return -> head == 0 && + __return -> tail == 0 + */ + ; + +void free_queue_cell(struct queue * p) + /*@ Require exists x y, p -> head == x && p -> tail == y && emp + Ensure emp + */ + ; + +void enqueue(struct queue * q, int x) +/*@ With l + Require store_queue(q, l) + Ensure store_queue(q, app(l, cons(x, nil))) + */ +{ + /*@ Assert exists qhead qtail u v, + q == q@pre && x == x@pre && + qtail != 0 && + store(&(q -> head), qhead) * + store(&(q -> tail), qtail) * + store(&(qtail -> data), u) * + store(&(qtail -> next), v) * + sllseg(qhead, qtail, l) + */ + struct list * p; + p = malloc_list_cell(); + q -> tail -> data = x; + q -> tail -> next = p; + q -> tail = p; +} + +int dequeue(struct queue * q) +/*@ With x l + Require store_queue(q, cons(x, l)) + Ensure __return == x && store_queue(q, l) + */ +{ + /*@ Assert exists qhead qtail u v qheadnext, + q == q@pre && + qhead != 0 && qtail != 0 && + store(&(q -> head), qhead) * + store(&(q -> tail), qtail) * + store(&(qhead -> data), x) * + store(&(qhead -> next), qheadnext) * + store(&(qtail -> data), u) * + store(&(qtail -> next), v) * + sllseg(qheadnext, qtail, l) + */ + int x0; + struct list * p; + p = q -> head; + x0 = p -> data; + q -> head = p -> next; + free_list_cell(p); + return x0; +} + +struct queue * init_empty_queue() +/*@ Require emp + Ensure store_queue(__return, nil) + */ +{ + struct queue * q; + q = malloc_queue_cell(); + q -> head = malloc_list_cell(); + q -> tail = q -> head; + return q; +} diff --git a/benchmarks/Data_structures/sll_queue/rocq/solution_spec.c b/benchmarks/Data_structures/sll_queue/rocq/solution_spec.c new file mode 100644 index 0000000000000000000000000000000000000000..a69186d92bad17e1c5220aba2c340153e72f51e6 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/solution_spec.c @@ -0,0 +1,60 @@ +#include "sll_def.h" +struct queue { + struct list * head; + struct list * tail; +}; + +/*@ Import Coq Require Import PVbench.Data_structures.sll_queue.rocq.spec_lib */ +/*@ Extern Coq (store_queue : Z -> list Z -> Assertion) */ + +struct list * malloc_list_cell() +; + +void free_list_cell(struct list * p) +; + +struct queue * malloc_queue_cell() +; + +void free_queue_cell(struct queue * p) +; + +void enqueue(struct queue * q, int x) +/*@ With l + Require store_queue(q, l) + Ensure store_queue(q, app(l, cons(x, nil))) + */ +{ + struct list * p; + p = malloc_list_cell(); + q -> tail -> data = x; + q -> tail -> next = p; + q -> tail = p; +} + +int dequeue(struct queue * q) +/*@ With x l + Require store_queue(q, cons(x, l)) + Ensure __return == x && store_queue(q, l) + */ +{ + int x0; + struct list * p; + p = q -> head; + x0 = p -> data; + q -> head = p -> next; + free_list_cell(p); + return x0; +} + +struct queue * init_empty_queue() +/*@ Require emp + Ensure store_queue(__return, nil) + */ +{ + struct queue * q; + q = malloc_queue_cell(); + q -> head = malloc_list_cell(); + q -> tail = q -> head; + return q; +} diff --git a/benchmarks/Data_structures/sll_queue/rocq/spec_lib.v b/benchmarks/Data_structures/sll_queue/rocq/spec_lib.v new file mode 100644 index 0000000000000000000000000000000000000000..6d40ab9c43e0761ee7ba6d8a8145ccb11db88802 --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/rocq/spec_lib.v @@ -0,0 +1,31 @@ +Require Import Coq.ZArith.ZArith. +Require Import Coq.Bool.Bool. +Require Import Coq.Lists.List. +Require Import Coq.Classes.RelationClasses. +Require Import Coq.Classes.Morphisms. +Require Import Coq.micromega.Psatz. +Require Import Permutation. +Require Import String. +From AUXLib Require Import int_auto Axioms Feq Idents ListLib VMap. +Require Import SetsClass.SetsClass. Import SetsNotation. +From SimpleC.SL Require Import Mem SeparationLogic. +Require Import Logic.LogicGenerator.demo932.Interface. +Local Open Scope Z_scope. +Local Open Scope sets. +Import ListNotations. +Local Open Scope list. +Require Import String. +Local Open Scope string. +From SimpleC.EE.QCP_demos_LLM Require Import sll_lib. + +Import naive_C_Rules. +Local Open Scope sac. + +Definition store_queue (x: addr) (l: list Z): Assertion := + EX (h t: addr) (u: Z) (v: addr), + “ t <> 0 ” && + &(x # "queue" ->ₛ "head") # Ptr |-> h ** + &(x # "queue" ->ₛ "tail") # Ptr |-> t ** + sllseg h t l ** + &(t # "list" ->ₛ "data") # Int |-> u ** + &(t # "list" ->ₛ "next") # Ptr |-> v. diff --git a/benchmarks/Data_structures/sll_queue/solution.c b/benchmarks/Data_structures/sll_queue/solution.c new file mode 100644 index 0000000000000000000000000000000000000000..b4f9f3001b6640be0460216fdf688e8cd70528fa --- /dev/null +++ b/benchmarks/Data_structures/sll_queue/solution.c @@ -0,0 +1,46 @@ +#include "sll_def.h" +struct queue { + struct list * head; + struct list * tail; +}; + +struct list * malloc_list_cell() +; + +void free_list_cell(struct list * p) +; + +struct queue * malloc_queue_cell() +; + +void free_queue_cell(struct queue * p) +; + +void enqueue(struct queue * q, int x) +{ + struct list * p; + p = malloc_list_cell(); + q -> tail -> data = x; + q -> tail -> next = p; + q -> tail = p; +} + +int dequeue(struct queue * q) +{ + int x0; + struct list * p; + p = q -> head; + x0 = p -> data; + q -> head = p -> next; + free_list_cell(p); + return x0; +} + +struct queue * init_empty_queue() +{ + struct queue * q; + q = malloc_queue_cell(); + q -> head = malloc_list_cell(); + q -> tail = q -> head; + return q; +} diff --git a/docs/ROCQ_COVERAGE.md b/docs/ROCQ_COVERAGE.md index d8989702df29e20468c9732fd8071f057c85527c..b3f0a111b5802a7a27b4ef2ee3ffa83986269e41 100644 --- a/docs/ROCQ_COVERAGE.md +++ b/docs/ROCQ_COVERAGE.md @@ -4,7 +4,7 @@ The Rocq (Coq/QCP) version of PV-Bench provides formal specifications, program a generated verification goals for C program verification, covering classic algorithms, Codeforces problems, data structures and engineering code. -The `main` branch carries **215 Rocq cases**: 74 algorithms, 128 Codeforces problems, 5 data structures and 8 engineering cases. Codeforces ratings range from **800 to 2800**. +The `main` branch carries **223 Rocq cases**: 77 algorithms, 128 Codeforces problems, 10 data structures and 8 engineering cases. Codeforces ratings range from **800 to 2800**. Each case's Rocq files live in a `rocq/` directory next to `lean/`: `solution_spec.c` with the function contract, `solution_annotated.c` with the verification annotations, the specification @@ -17,11 +17,11 @@ built locally and not committed. For dependency configuration and build instruct | Category | Cases | Content | | --- | --- | --- | -| Algorithms (`Algorithms/`) | 74 | sorting, number theory, dynamic programming, greedy methods, sequence processing, graph algorithms and computational geometry | +| Algorithms (`Algorithms/`) | 77 | sorting, number theory, dynamic programming, greedy methods, sequence processing, graph algorithms and computational geometry | | Competitive problems (`Codeforces/`) | 128 | constructive, math, string, game, graph and optimization problems | -| Data structures (`Data_structures/`) | 5 | array stack, binary indexed tree and three priority-queue interfaces | +| Data structures (`Data_structures/`) | 10 | array stack, binary indexed tree, three priority-queue interfaces, singly linked lists and three linked-list queues | | Engineering (`Engineering/`) | 8 | MiniSat dynamic vectors and C string / memory routines | -| Total | 215 | | +| Total | 223 | | Cases are counted per independent implementation. Different implementations of the same algorithm are counted separately — for example five quicksort partition schemes, four Prim implementations @@ -42,23 +42,23 @@ therefore requires the data-structure case as well — the two are not independe Beyond these, many cases include shared C definitions that come with QCP rather than with this repository (`QCP_examples/QCP_demos_LLM/` and `QCP_examples/stdlib/`): `string.h` (29 cases), -`array2_ext_def.h` (24), `safeexec_def.h` (14), `array2_def.h` (14), `graph_matrix_def.h` (12), +`array2_ext_def.h` (24), `safeexec_def.h` (13), `array2_def.h` (14), `graph_matrix_def.h` (12), `int_ptr_array2_def.h` (8) and `sll_def.h` (3). They provide array, matrix, list, string and monadic-execution representations, and must be on the include path for a case to be checked. -## Algorithms (74) +## Algorithms (77) | Primary category | Cases | | --- | --- | -| Sorting and discretization | 12 | -| Number theory and modular arithmetic | 11 | +| Sorting and discretization | 14 | +| Number theory and modular arithmetic | 13 | | Dynamic programming | 22 | | Greedy, binary search and two pointers | 7 | | Sequences, strings and range queries | 6 | | Computational geometry | 2 | -| Graph algorithms | 14 | +| Graph algorithms | 13 | -### Sorting and discretization (12) +### Sorting and discretization (14) | Problem / implementation | Case directory | Content | | --- | --- | --- | @@ -73,14 +73,18 @@ monadic-execution representations, and must be on the include path for a case to | Quicksort: Hoare swap partition | [quicksort_hoare_swap_index](../benchmarks/Algorithms/quicksort_hoare_swap_index/rocq/) | two-way scan and swap | | Quicksort: Hoare swap partition, variant 2 | [quicksort_hoare_swap_index2](../benchmarks/Algorithms/quicksort_hoare_swap_index2/rocq/) | another swap-partition implementation | | Quicksort: Lomuto partition | [quicksort_lomuto_index](../benchmarks/Algorithms/quicksort_lomuto_index/rocq/) | scanning partition placing the pivot | +| Insertion sort on a singly linked list | [sll_insertion_sort](../benchmarks/Algorithms/sll_insertion_sort/rocq/) | sorted prefix list, node relinking and a permutation of the input | +| Merge sort on a singly linked list | [sll_merge_sort](../benchmarks/Algorithms/sll_merge_sort/rocq/) | split, merge and recursion verified against a monadic merge-sort program, from which the sorted-permutation contract is derived | | Selection sort | [selection_sort](../benchmarks/Algorithms/selection_sort/rocq/) | picks the minimum each round | -### Number theory and modular arithmetic (11) +### Number theory and modular arithmetic (13) | Problem / implementation | Case directory | Content | | --- | --- | --- | | Chinese remainder theorem | [chinese_remainder_theorem](../benchmarks/Algorithms/chinese_remainder_theorem/rocq/) | congruence system with pairwise coprime moduli; P1495 | | Inverse via Euler's theorem | [euler_theorem_inverse](../benchmarks/Algorithms/euler_theorem_inverse/rocq/) | coprimality, Euler's totient and modular power | +| Euclidean gcd | [gcd](../benchmarks/Algorithms/gcd/rocq/) | recursive Euclid on signed integers, with `gcd(x, 0) = abs(x)` | +| Extended Euclidean algorithm | [exgcd](../benchmarks/Algorithms/exgcd/rocq/) | gcd with Bézout coefficients; the body is verified against a stronger contract with coefficient bounds, from which the public one is derived. It implements the interface that `modular_inverse` and both Chinese-remainder cases call | | Extended Chinese remainder theorem | [extended_chinese_remainder_theorem](../benchmarks/Algorithms/extended_chinese_remainder_theorem/rocq/) | consistent congruence system with non-coprime moduli; P4777 | | Prime factorization | [integer_divide](../benchmarks/Algorithms/integer_divide/rocq/) | prime factors with multiplicity in non-decreasing order | | Batch modular inverses | [linear_modular_inverse](../benchmarks/Algorithms/linear_modular_inverse/rocq/) | linear recurrence for a prime modulus; P3811 | @@ -148,7 +152,7 @@ monadic-execution representations, and must be on the include path for a case to | Convex hull with floating-point coordinates | [convex_hull_float](../benchmarks/Algorithms/convex_hull_float/rocq/) | cross-product orientation, stack construction and floating-point comparison | | Polar-angle sort of planar points | [sort_point](../benchmarks/Algorithms/sort_point/rocq/) | half-planes, cross products, distances and permutation of a point array | -### Graph algorithms (14) +### Graph algorithms (13) | Problem / implementation | Case directory | Content | | --- | --- | --- | @@ -164,7 +168,6 @@ monadic-execution representations, and must be on the include path for a case to | Kruskal minimum spanning tree | [kruskal_union_find](../benchmarks/Algorithms/kruskal_union_find/rocq/) | edge sorting and union-find merging; reuses a `union_find` structure kept outside this repository | | Prim on an adjacency matrix | [prim_adjacency_matrix](../benchmarks/Algorithms/prim_adjacency_matrix/rocq/) | nearest-vertex maintenance and spanning-tree cost | | Prim returning the tree matrix | [prim_adjacency_matrix_return_matrix](../benchmarks/Algorithms/prim_adjacency_matrix_return_matrix/rocq/) | builds and returns the spanning tree as a matrix | -| Prim on a forward star | [prim_forward_star](../benchmarks/Algorithms/prim_forward_star/rocq/) | forward-star graph and vertex-by-vertex growth | | Heap-based Prim on a forward star | [prim_forward_star_heap](../benchmarks/Algorithms/prim_forward_star_heap/rocq/) | priority queue over candidate edges; reuses `priority_queue_decrease_key` | ## Codeforces problems (128) @@ -350,7 +353,7 @@ Problem tags are multi-label; the table lists tags occurring at least five times | [1750/F — Majority](../benchmarks/Codeforces/examples_shard01/P093_1750F_majority/rocq/) | 2700 | H2 | combinatorics, dp, math, strings | | [1436/F — Sum Over Subsets](../benchmarks/Codeforces/examples_shard01/P096_1436F_sum_over_subsets/rocq/) | 2800 | VH | combinatorics, math, number theory | -## Data structures (5) +## Data structures (10) | Case | Case directory | Content | | --- | --- | --- | @@ -358,6 +361,11 @@ Problem tags are multi-label; the table lists tags occurring at least five times | Array-Based Priority Queue | [priority_queue](../benchmarks/Data_structures/priority_queue/rocq/) | build, sift, pop and heapsort | | Priority Queue with Decrease-Key | [priority_queue_decrease_key](../benchmarks/Data_structures/priority_queue_decrease_key/rocq/) | position back-mapping, insert, delete and decrease-key | | Indexed Priority Queue | [priority_queue_index](../benchmarks/Data_structures/priority_queue_index/rocq/) | key–data correspondence and heap operations | +| Singly Linked List Operations | [singly_linked_list](../benchmarks/Data_structures/singly_linked_list/rocq/) | length, in-place reversal and concatenation | +| Generic Singly Linked List Reversal | [polymorphic_sll](../benchmarks/Data_structures/polymorphic_sll/rocq/) | reversal parametric in the representation of each node payload | +| Queue on a Singly Linked List | [sll_queue](../benchmarks/Data_structures/sll_queue/rocq/) | sentinel tail node, creation, enqueue and dequeue | +| Queue on a Doubly Linked List | [dll_queue](../benchmarks/Data_structures/dll_queue/rocq/) | head and tail pointers with back links, enqueue and dequeue | +| Queue from Two Stacks | [functional_queue](../benchmarks/Data_structures/functional_queue/rocq/) | front and back stacks, with a reversal when the front is empty | | Array-Based Stack | [stack](../benchmarks/Data_structures/stack/rocq/) | capacity bound, push / pop and bulk construction | ## Engineering (8)