Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: Add definition taclets for binaryAnd, binaryOr, and binaryXOr #3174

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

ChristianHein
Copy link
Contributor

Until now, KeY could only evaluate the functions binaryAnd, binaryOr, and
binaryXOr for literal values or in cases where a special case taclet exists
(see file "binaryLemmas.key"). For general reasoning, this is insufficient.
This pull request adds new definition taclets for these functions using a new
helper function bitAt to extract individual bits from unbounded JavaDL ints.

Overview of the taclets added:

  • Bit extraction helper function bitAt
  • binaryAndDef, binaryAndIntDef, binaryAndLongDef
  • binaryOrDef, binaryOrIntDef, binaryOrLongDef
  • binaryXOrDef, binaryXOrIntDef, binaryXOrLongDef

Using the bitAt function, we define binaryAnd, binaryOr, and binaryXOr
mathematically as bounded sums over all positional values of the result,
depending on the results of the bit operations on the input parameters.
We include three variants of each function definition: One general one where
the user must specify the maximum sign bit index of the two parameters; one for
Java int parameters (sign bit index 31); and one for Java long parameters
(sign-bit index 63). Each taclet opens another proof branch in
which it must be proven that the parameters of the function lie within the
valid range dictated by the sign bit index (e.g. inRangeInt(left) & inRangeInt(right)for the Javaint` versions).


Discussion Points

  • The general definition taclets (e.g. binaryOrDef) force the user to specify the index of the sign bit. The disadvantage of this approach is that these taclets are not useful for proving properties of the bitwise functions which are independent of bit width, e.g., \forall int a; \forall int b; (binaryOr(a, b) = binaryOr(b, a)).
  • @WolframPfeifer and I have discussed whether it would be better if these taclets did not define the binaryX functions, but instead defined the XJint/XJlong functions. At the moment, these latter functions are simply intermediate functions which are translated into binaryX. It seems that the binaryX functions are supposed to be treated as fundamental "mathematical" bitwise functions, although they assume two's complement representation which is not mathematically based. The XJint/XJlong functions clearly encode Java integer semantics into the meaning of the function in their name, thus might be the better "abstraction level" at which to define these functions.

The `bitAt` returns the value of a single bit (0 or 1) from an unbounded
JavaDL int, assuming two's complement representation. For negative
indices, the result is zero.

Introduced for definitions of `binaryAnd`, `binaryOr`, and `binaryXOr`
in a later commit. Developed as part of my bachelor's thesis "Handling
Bitwise Operations in Deductive Program Verification: Case Study
java.util.BitSet with KeY" (2023).
Until now, KeY could only evaluate the functions `binaryAnd`,
`binaryOr`, and `binaryXOr` for literal values or in cases where a
special case taclet exists (see file "binaryLemmas.key"). For general
reasoning, this is insufficient. This commit adds the following new
definitions for these functions in KeY:
- binaryAndDef, binaryAndIntDef, binaryAndLongDef
- binaryOrDef, binaryOrIntDef, binaryOrLongDef
- binaryXOrDef, binaryXOrIntDef, binaryXOrLongDef

Using the `bitAt` helper function to refer to individual bits in the
bitwise representation of input parameters, this commit defines the
`binaryAnd`, `binaryOr`, and `binaryXOr` functions mathematically as a
bounded sum over all positional values of the result, depending on the
result of the bit operations on the input parameters. The signed bit has
a negative positional value because of two's complement representation.
Bitwise operations are emulated mathematically, e.g., using
multiplication for AND.

This commit includes three variants of each function definition: One
general one where the user must specify the maximum sign bit index of
the two parameters; one for Java `int` parameters (sign bit index 31);
and one for Java `long` parameters (sign-bit index 63). Each taclet
additionally opens another proof branch in which it must be proven that
the parameters of the function lie within the valid range dictated by
the sign bit index (e.g.  `inRangeInt(left) & `inRangeInt(right)` for
the Java `int` versions).

These taclets were developed as part of my bachelor's thesis "Handling
Bitwise Operations in Deductive Program Verification: Case Study
java.util.BitSet with KeY" (2023).
@ChristianHein ChristianHein changed the title Add definition taclets for binaryAnd, binaryOr, and binaryXOr Draft: Add definition taclets for binaryAnd, binaryOr, and binaryXOr Jun 19, 2023
@codecov
Copy link

codecov bot commented Jun 19, 2023

Codecov Report

Merging #3174 (d607320) into main (edd76a2) will increase coverage by 0.00%.
The diff coverage is n/a.

@@            Coverage Diff            @@
##               main    #3174   +/-   ##
=========================================
  Coverage     31.54%   31.54%           
- Complexity    16774    16776    +2     
=========================================
  Files          2374     2374           
  Lines        150964   150964           
  Branches      24053    24053           
=========================================
+ Hits          47625    47627    +2     
  Misses        97547    97547           
+ Partials       5792     5790    -2     

see 2 files with indirect coverage changes

📣 We’re building smart automated test selection to slash your CI/CD build times. Learn more

@github-actions
Copy link

Thank you for your contribution.

The test artifacts are available on Artiweb.
The newest artifact is here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants