@ -142,8 +142,9 @@ let%test_module "normalization" =
normalize ( x < y ) ;
normalize ( x < y ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && true ( no linear ) && { [ x + - y ] < 0 } , pruned = true ( no atoms ) ,
known = true ( no var = var ) && true ( no linear ) && true ( no term_eqs ) && { [ x + - y ] < 0 } ,
both = true ( no var = var ) && true ( no linear ) && { [ x + - y ] < 0 } | } ]
pruned = true ( no atoms ) ,
both = true ( no var = var ) && true ( no linear ) && true ( no term_eqs ) && { [ x + - y ] < 0 } | } ]
let % expect_test _ =
let % expect_test _ =
normalize ( x + i 1 - i 1 < x ) ;
normalize ( x + i 1 - i 1 < x ) ;
@ -175,8 +176,9 @@ let%test_module "normalization" =
normalize ( of_binop Eq x y = i 0 && x = i 0 && y = i 1 ) ;
normalize ( of_binop Eq x y = i 0 && x = i 0 && y = i 1 ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && x = 0 ∧ y = 1 ∧ v6 = 0 && true ( no atoms ) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && x = 0 ∧ y = 1 ∧ v6 = 0 && true ( no term_eqs ) && true ( no atoms ) ,
both = true ( no var = var ) && x = 0 ∧ y = 1 ∧ v6 = 0 && true ( no atoms ) | } ]
pruned = true ( no atoms ) ,
both = true ( no var = var ) && x = 0 ∧ y = 1 ∧ v6 = 0 && true ( no term_eqs ) && true ( no atoms ) | } ]
let % expect_test _ =
let % expect_test _ =
normalize ( x = i 0 && x < i 0 ) ;
normalize ( x = i 0 && x < i 0 ) ;
@ -194,12 +196,16 @@ let%test_module "normalization" =
&&
&&
x = - v6 + v8 - 1 ∧ v7 = v8 - 1 ∧ v10 = 0
x = - v6 + v8 - 1 ∧ v7 = v8 - 1 ∧ v10 = 0
&&
&&
true ( no term_eqs )
&&
{ 0 = [ v9 ] ÷ [ w ] } ∧ { [ v6 ] = [ v ] × [ y ] } ∧ { [ v9 ] = [ z ] × [ v8 ] } ,
{ 0 = [ v9 ] ÷ [ w ] } ∧ { [ v6 ] = [ v ] × [ y ] } ∧ { [ v9 ] = [ z ] × [ v8 ] } ,
pruned = true ( no atoms ) ,
pruned = true ( no atoms ) ,
both = true ( no var = var )
both = true ( no var = var )
&&
&&
x = - v6 + v8 - 1 ∧ v7 = v8 - 1 ∧ v10 = 0
x = - v6 + v8 - 1 ∧ v7 = v8 - 1 ∧ v10 = 0
&&
&&
true ( no term_eqs )
&&
{ 0 = [ v9 ] ÷ [ w ] } ∧ { [ v6 ] = [ v ] × [ y ] } ∧ { [ v9 ] = [ z ] × [ v8 ] } | } ]
{ 0 = [ v9 ] ÷ [ w ] } ∧ { [ v6 ] = [ v ] × [ y ] } ∧ { [ v9 ] = [ z ] × [ v8 ] } | } ]
(* check that this becomes all linear equalities *)
(* check that this becomes all linear equalities *)
@ -211,12 +217,16 @@ let%test_module "normalization" =
&&
&&
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ v7 = - 1 ∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ v7 = - 1 ∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
&&
&&
true ( no term_eqs )
&&
true ( no atoms ) ,
true ( no atoms ) ,
pruned = true ( no atoms ) ,
pruned = true ( no atoms ) ,
both = true ( no var = var )
both = true ( no var = var )
&&
&&
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ v7 = - 1 ∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ v7 = - 1 ∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
&&
&&
true ( no term_eqs )
&&
true ( no atoms ) | } ]
true ( no atoms ) | } ]
(* check that this becomes all linear equalities thanks to constant propagation *)
(* check that this becomes all linear equalities thanks to constant propagation *)
@ -229,6 +239,8 @@ let%test_module "normalization" =
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ z = 12 ∧ w = 7 ∧ v = 3 ∧ v7 = - 1
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ z = 12 ∧ w = 7 ∧ v = 3 ∧ v7 = - 1
∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
&&
&&
true ( no term_eqs )
&&
true ( no atoms ) ,
true ( no atoms ) ,
pruned = true ( no atoms ) ,
pruned = true ( no atoms ) ,
both = true ( no var = var )
both = true ( no var = var )
@ -236,6 +248,8 @@ let%test_module "normalization" =
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ z = 12 ∧ w = 7 ∧ v = 3 ∧ v7 = - 1
x = - v6 - 1 ∧ y = 1 / 3 · v6 ∧ z = 12 ∧ w = 7 ∧ v = 3 ∧ v7 = - 1
∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
∧ v8 = 0 ∧ v9 = 0 ∧ v10 = 0
&&
&&
true ( no term_eqs )
&&
true ( no atoms ) | } ]
true ( no atoms ) | } ]
end )
end )
@ -245,37 +259,38 @@ let%test_module "variable elimination" =
simplify ~ keep : [ x_var ; y_var ] ( x = y ) ;
simplify ~ keep : [ x_var ; y_var ] ( x = y ) ;
[ % expect
[ % expect
{ |
{ |
known = x = y && true ( no linear ) && true ( no atoms) , pruned = true ( no atoms ) ,
known = x = y && true ( no linear ) && true ( no term_eqs) && true ( no atoms) , pruned = true ( no atoms ) ,
both = x = y && true ( no linear ) && true ( no atoms) | } ]
both = x = y && true ( no linear ) && true ( no term_eqs) && true ( no atoms) | } ]
let % expect_test _ =
let % expect_test _ =
simplify ~ keep : [ x_var ] ( x = i 0 && y = i 1 && z = i 2 && w = i 3 ) ;
simplify ~ keep : [ x_var ] ( x = i 0 && y = i 1 && z = i 2 && w = i 3 ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && x = 0 && true ( no atoms) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && x = 0 && true ( no term_eqs) && true ( no atoms) , pruned = true ( no atoms ) ,
both = true ( no var = var ) && x = 0 && true ( no atoms) | } ]
both = true ( no var = var ) && x = 0 && true ( no term_eqs) && true ( no atoms) | } ]
let % expect_test _ =
let % expect_test _ =
simplify ~ keep : [ x_var ] ( x = y + i 1 && x = i 0 ) ;
simplify ~ keep : [ x_var ] ( x = y + i 1 && x = i 0 ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && x = 0 && true ( no atoms) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && x = 0 && true ( no term_eqs) && true ( no atoms) , pruned = true ( no atoms ) ,
both = true ( no var = var ) && x = 0 && true ( no atoms) | } ]
both = true ( no var = var ) && x = 0 && true ( no term_eqs) && true ( no atoms) | } ]
let % expect_test _ =
let % expect_test _ =
simplify ~ keep : [ y_var ] ( x = y + i 1 && x = i 0 ) ;
simplify ~ keep : [ y_var ] ( x = y + i 1 && x = i 0 ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && y = - 1 && true ( no atoms) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && y = - 1 && true ( no term_eqs) && true ( no atoms) , pruned = true ( no atoms ) ,
both = true ( no var = var ) && y = - 1 && true ( no atoms) | } ]
both = true ( no var = var ) && y = - 1 && true ( no term_eqs) && true ( no atoms) | } ]
(* should keep most of this or realize that [w = z] hence this boils down to [z+1 = 0] *)
(* should keep most of this or realize that [w = z] hence this boils down to [z+1 = 0] *)
let % expect_test _ =
let % expect_test _ =
simplify ~ keep : [ y_var ; z_var ] ( x = y + z && w = x - y && v = w + i 1 && v = i 0 ) ;
simplify ~ keep : [ y_var ; z_var ] ( x = y + z && w = x - y && v = w + i 1 && v = i 0 ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && x = y - 1 ∧ z = - 1 && true ( no atoms ) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && x = y - 1 ∧ z = - 1 && true ( no term_eqs ) && true ( no atoms ) ,
both = true ( no var = var ) && x = y - 1 ∧ z = - 1 && true ( no atoms ) | } ]
pruned = true ( no atoms ) ,
both = true ( no var = var ) && x = y - 1 ∧ z = - 1 && true ( no term_eqs ) && true ( no atoms ) | } ]
let % expect_test _ =
let % expect_test _ =
simplify ~ keep : [ x_var ; y_var ] ( x = y + z && w + x + y = i 0 && v = w + i 1 ) ;
simplify ~ keep : [ x_var ; y_var ] ( x = y + z && w + x + y = i 0 && v = w + i 1 ) ;
@ -285,20 +300,24 @@ let%test_module "variable elimination" =
&&
&&
x = - v + v7 + 1 ∧ y = - v7 ∧ z = - v + 2 · v7 + 1 ∧ w = v - 1
x = - v + v7 + 1 ∧ y = - v7 ∧ z = - v + 2 · v7 + 1 ∧ w = v - 1
&&
&&
true ( no term_eqs )
&&
true ( no atoms ) ,
true ( no atoms ) ,
pruned = true ( no atoms ) ,
pruned = true ( no atoms ) ,
both = true ( no var = var )
both = true ( no var = var )
&&
&&
x = - v + v7 + 1 ∧ y = - v7 ∧ z = - v + 2 · v7 + 1 ∧ w = v - 1
x = - v + v7 + 1 ∧ y = - v7 ∧ z = - v + 2 · v7 + 1 ∧ w = v - 1
&&
&&
true ( no term_eqs )
&&
true ( no atoms ) | } ]
true ( no atoms ) | } ]
let % expect_test _ =
let % expect_test _ =
simplify ~ keep : [ x_var ; y_var ] ( x = y + i 4 && x = w && y = z ) ;
simplify ~ keep : [ x_var ; y_var ] ( x = y + i 4 && x = w && y = z ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && x = y + 4 && true ( no atoms) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && x = y + 4 && true ( no term_eqs) && true ( no atoms ) ,
both= true ( no var = var ) && x = y + 4 && true ( no atoms ) | } ]
pruned= true ( no atoms ) , both= true ( no var = var ) && x = y + 4 && true ( no term_eqs ) && true ( no atoms ) | } ]
end )
end )
let % test_module " non-linear simplifications " =
let % test_module " non-linear simplifications " =
@ -307,21 +326,33 @@ let%test_module "non-linear simplifications" =
simplify ~ keep : [ w_var ] ( ( ( i 0 / ( x * z ) ) & v ) * v mod y = w ) ;
simplify ~ keep : [ w_var ] ( ( ( i 0 / ( x * z ) ) & v ) * v mod y = w ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && w = 0 && true ( no atoms) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && w = 0 && true ( no term_eqs) && true ( no atoms) , pruned = true ( no atoms ) ,
both = true ( no var = var ) && w = 0 && true ( no atoms) | } ]
both = true ( no var = var ) && w = 0 && true ( no term_eqs) && true ( no atoms) | } ]
let % expect_test " constant propagation: bitshift " =
let % expect_test " constant propagation: bitshift " =
simplify ~ keep : [ x_var ] ( of_binop Shiftlt ( of_binop Shiftrt ( i 0b111 ) ( i 2 ) ) ( i 2 ) = x ) ;
simplify ~ keep : [ x_var ] ( of_binop Shiftlt ( of_binop Shiftrt ( i 0b111 ) ( i 2 ) ) ( i 2 ) = x ) ;
[ % expect
[ % expect
{ |
{ |
known = true ( no var = var ) && x = 4 && true ( no atoms) , pruned = true ( no atoms ) ,
known = true ( no var = var ) && x = 4 && true ( no term_eqs) && true ( no atoms) , pruned = true ( no atoms ) ,
both = true ( no var = var ) && x = 4 && true ( no atoms) | } ]
both = true ( no var = var ) && x = 4 && true ( no term_eqs) && true ( no atoms) | } ]
let % expect_test " non-linear becomes linear " =
let % expect_test " non-linear becomes linear " =
normalize ( w = ( i 2 * z ) - i 3 && z = x * y && y = i 2 ) ;
normalize ( w = ( i 2 * z ) - i 3 && z = x * y && y = i 2 ) ;
[ % expect
[ % expect
{ |
{ |
known = z = v8 ∧ w = v7 && x = 1 / 4 · v6 ∧ y = 2 ∧ z = 1 / 2 · v6 ∧ w = v6 - 3 && true ( no atoms ) ,
known = z = v8 ∧ w = v7
&&
x = 1 / 4 · v6 ∧ y = 2 ∧ z = 1 / 2 · v6 ∧ w = v6 - 3
&&
true ( no term_eqs )
&&
true ( no atoms ) ,
pruned = true ( no atoms ) ,
pruned = true ( no atoms ) ,
both = z = v8 ∧ w = v7 && x = 1 / 4 · v6 ∧ y = 2 ∧ z = 1 / 2 · v6 ∧ w = v6 - 3 && true ( no atoms ) | } ]
both = z = v8 ∧ w = v7
&&
x = 1 / 4 · v6 ∧ y = 2 ∧ z = 1 / 2 · v6 ∧ w = v6 - 3
&&
true ( no term_eqs )
&&
true ( no atoms ) | } ]
end )
end )