Comments (4)
I do not have the time to work on this for the 2.1 release, so I'm pushing.
from cryptol.
I did some work on this a while back, and started a Cryptol module stating characteristic properties of a bunch of primitives. Maybe we should finish it.
/*
This module contains logical specifications of all of Cryptol's
primitives, written as checkable properties in Cryptol. Overloaded
primitives are specified for each base instance of the class: For
example, the Arith primitives are specified for bitvectors and integer
types.
Each primitive is specified in terms of earlier ones. We take True,
False, and logical complement as our base primitives, which are left
unspecified.
*/
module PrimSpec where
cons : {n, a} a -> [n]a -> [1+n]a
cons x xs = [x] # xs
/* Logic Bit, Cmp Bit */
infix 5 <==>
(<==>) : Bit -> Bit -> Bit
x <==> y = x == y
property not_Bit_1 = ~ False
property not_Bit_2 = ~ (~ True)
property eq_Bit_1 = True == True
property eq_Bit_2 = ~ (True == False)
property eq_Bit_3 = ~ (False == True)
property eq_Bit_4 = False == False
property ite_Bit_1 x y = (if True then x else y) <==> x
property ite_Bit_2 x y = (if False then x else y) <==> y
property conj_Bit x y = (x && y) <==> (if x then y else False)
property disj_Bit x y = (x || y) <==> (if x then True else y)
property xor_Bit x y = (x ^ y) <==> (if x then ~ y else y)
property zero_Bit = zero <==> False
property le_Bit x y = (x <= y) <==> (if x then y else True)
property lt_Bit x y = (x < y) <==> (if x then False else y)
property ge_Bit x y = (x >= y) <==> (if y then x else True)
property gt_Bit x y = (x > y) <==> (if y then False else x)
property ne_Bit x y = (x != y) <==> ~ (x == (y : Bit))
/* Cmp [n]a */
eq_nil : {a} (Cmp a) => Bit
eq_nil = [] == ([] : [0]a)
eq_cons : {n, a} (Cmp a, fin n) => a -> [n]a -> a -> [n]a -> Bit
eq_cons x xs y ys = (cons x xs == cons y ys) <==> (x == y /\ xs == ys)
le_nil : {a} (Cmp a) => Bit
le_nil = [] <= ([] : [0]a)
le_cons : {n, a} (Cmp a, fin n) => a -> [n]a -> a -> [n]a -> Bit
le_cons x xs y ys = (cons x xs <= cons y ys) <==> (x <= y) /\ (x == y ==> xs <= ys)
/* Arith [n] */
//primitive (+) : {a} (Arith a) => a -> a -> a
//primitive (-) : {a} (Arith a) => a -> a -> a
//primitive (*) : {a} (Arith a) => a -> a -> a
//primitive (/) : {a} (Arith a) => a -> a -> a
//primitive (%) : {a} (Arith a) => a -> a -> a
//primitive (^^) : {a} (Arith a) => a -> a -> a
//primitive lg2 : {a} (Arith a) => a -> a
//primitive negate : {a} (Arith a) => a -> a
inc : {n} (fin n) => [n] -> [n]
inc xs = reverse [ x ^ c | x <- reverse xs | c <- cs ]
where cs = [True] # [ x && c | x <- reverse xs | c <- cs ]
inc_spec : {n} (fin n, n >= 1) => [n] -> Bit
inc_spec x = inc x == x + 1
add_0 : {a} (Arith a, Cmp a, Literal 0 a) => a -> Bit
add_0 x = 0 + x == x
add_S : {a} (Arith a, Cmp a, Literal 1 a) => a -> a -> Bit
add_S x y = (x + 1) + y == (x + y) + 1
mul_0 : {a} (Arith a, Cmp a, Literal 0 a) => a -> Bit
mul_0 x = 0 * x == 0
mul_S : {a} (Arith a, Cmp a, Literal 1 a) => a -> a -> Bit
mul_S x y = (x + 1) * y == x + x * y
sub_spec x y = x - y == x + negate y
/* Sequence primitives */
//primitive (#) : {front, back, a} (fin front) => [front]a -> [back]a -> [front + back] a
append_nil xs = [] # xs == xs
append_cons x xs ys = cons x xs # ys == cons x (xs # ys)
//primitive splitAt : {front, back, a} (fin front) => [front + back]a -> ([front]a, [back]a)
splitAt_nil : {back, a} (fin back, Cmp a) => [back]a -> Bit
splitAt_nil xs = splitAt`{0, back} xs == ([], xs)
splitAt_cons : {front, back, a} (fin front, fin back, Cmp a) => a -> [front + back]a -> Bit
splitAt_cons x xs = splitAt`{1+front, back} (cons x xs) == (cons x xs1, xs2)
where (xs1, xs2) = splitAt`{front, back} xs
//primitive join : {parts, each, a} (fin each) => [parts][each]a
// -> [parts * each]a
join_nil : {each, a} (fin each, Cmp a) => Bit
join_nil = join ([] : [0][each]a) == []
join_cons :
{parts, each, a} (fin parts, fin each, Cmp a) =>
[each]a -> [parts][each]a -> Bit
join_cons xs xss = join (cons xs xss) == xs # join xss
//primitive split : {parts, each, a} (fin each) => [parts * each]a
// -> [parts][each]a
split_nil : {each, a} (fin each, Cmp a) => Bit
split_nil = split`{0} [] == ([] : [0][each]a)
split_cons : {parts, each, a} (fin parts, fin each, Cmp a) => [(1 + parts) * each]a -> Bit
split_cons xs = split`{1+parts} xs == cons xs1 (split xs2)
where (xs1, xs2) = splitAt`{each, parts * each} xs
//primitive reverse : {n, a} (fin n) => [n]a -> [n]a
reverse_nil : {a} (Cmp a) => Bit
reverse_nil = reverse [] == ([] : [0]a)
reverse_cons : {n, a} (fin n, Cmp a) => a -> [n]a -> Bit
reverse_cons x xs = reverse (cons x xs) == reverse xs # [x]
//primitive transpose : {rows, cols, a} [rows][cols]a -> [cols][rows]a
transpose_cons xs xss = transpose (cons xs xss) == [ cons y ys | y <- xs | ys <- xss ]
from cryptol.
Let's add the Cryptol file quoted above to the repo, and continue to add to it.
from cryptol.
Todo: Put the cryptol file with specs for primitives in the lib
directory, alongside Cryptol.cry
. This would let cryptol users (or saw users) to import and refer to the properties in the file.
We should also strive to keep the file up to date whenever we add new primitive functions to cryptol.
Todo: Also add a test to the test suite that runs :check
and :prove
on all the properties in this file at several common bit-widths.
from cryptol.
Related Issues (20)
- Support ghc 9.8 HOT 4
- [Remote API] `ValueError` Exception on `check`, then Hang
- Provide mechanism for collecting all primitives used in a module
- A few typos in the Programming Cryptol book
- Cryptol projects should not stop on error
- The reference manual doesn't describe properties HOT 1
- Add configuration parameters to configuration command
- Make new command for checking properties not REPL specific
- Validation of Properties should create in house data structure rather than std out
- Unify `FullFingerprint` with `FileInfo`
- Define format for the Projects file
- Loading and the projects file
- `mypy --install-types` not freezing dependencies
- Support latest version of `types-requests` HOT 2
- properties in parameterized modules should not be accessible in instantiated modules by `:check` etc.
- Make `coreLint` sanity-check numeric constraint guards
- Regression (`Undefined vairable`) in program that uses submodules, functors, and interfaces HOT 4
- Attach arrays to the SMT theory of arrays in the repl (or in general) HOT 1
- Remove distutils import from cryptol-remote-api HOT 3
- Mention all type class instances in the reference manual HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cryptol.