Skip to content

Commit

Permalink
add integration test for newtypes
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Kent committed Mar 17, 2022
1 parent b488b4c commit ad7b218
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 7 deletions.
6 changes: 0 additions & 6 deletions examples/misc/cryptol_newtype.cry

This file was deleted.

1 change: 0 additions & 1 deletion examples/misc/cryptol_newtype.saw

This file was deleted.

40 changes: 40 additions & 0 deletions intTests/test_newtype/complex.cry
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// This is a development of rational complex numbers

type Int = Integer

// Complex rational numbers in rectangular coordinates
newtype CplxInt =
{ real : Int, imag : Int }

embedQ : Int -> CplxInt
embedQ x = CplxInt{ real = x, imag = 0 }

cplxAdd : CplxInt -> CplxInt -> CplxInt
cplxAdd x y = CplxInt { real = r, imag = i }
where
r = x.real + y.real
i = x.imag + y.imag

cplxMul : CplxInt -> CplxInt -> CplxInt
cplxMul x y = CplxInt { real = r, imag = i }
where
r = x.real * y.real - x.imag * y.imag
i = x.real * y.imag + x.imag * y.real

cplxEq : CplxInt -> CplxInt -> Bit
cplxEq x y = (x.real == y.real) && (x.imag == y.imag)

cplxAddAssoc : CplxInt -> CplxInt -> CplxInt -> Bit
cplxAddAssoc x y z =
cplxEq (cplxAdd (cplxAdd x y) z)
(cplxAdd x (cplxAdd y z))

cplxMulAssoc : CplxInt -> CplxInt -> CplxInt -> Bit
cplxMulAssoc x y z =
cplxEq (cplxMul (cplxMul x y) z)
(cplxMul x (cplxMul y z))

cplxMulDistrib : CplxInt -> CplxInt -> CplxInt -> Bit
cplxMulDistrib x y z =
cplxEq (cplxMul x (cplxAdd y z))
(cplxAdd (cplxMul x y) (cplxMul x z))
8 changes: 8 additions & 0 deletions intTests/test_newtype/test.saw
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import "complex.cry";

prove_print cvc4 {{ \ x y z -> cplxAddAssoc x y z}};

prove_print cvc4 {{ \ x y z -> cplxMulAssoc x y z}};

prove_print cvc4 {{ \ x y z -> cplxMulDistrib x y z}};

0 comments on commit ad7b218

Please sign in to comment.