typedef g1uintBtwe2
(tk:tk, lb0:int, ub0:int, lb1:int, ub1:int) = [i: int | lb0 <= i; i <= ub0
; lb1 <= i; i <= ub1] g1uint (tk, i)
Should be
typedef g1uintBtwe2
(tk:tk, lb0:int, ub0:int, lb1:int, ub1:int) = [i: int | (lb0 <= i && i <=
ub0) || (lb1 <= i && i <= ub1)] g1uint (tk, i)On Tuesday, October 27, 2015 at 7:21:25 PM UTC-4, Mike Jones wrote:
So to solve I tried to change the constraint to be between numbers. Then
add a conversion function to clamp the data.
However, the constraint on the return value of n73 causes compile
problems. It does not like ‘then 3’, nor ‘else’ x.
I figured that because this takes an int input and returns an int, the
code just has to satisfy the constraint, and simple conditionals would be
solvable. I assume it will treat the 3 or 127 as ints as that is what is
expected to be returned. As far as returning x, it would just have to
figure out that if the extremes are clamped, what is left must be ok.
Eventually I need to pass uint8 into n73 as it comes from the array
reference, but that caused even more constraint failures.
extern fun{} n73 {n: nat | n >= 3 && n <= 127} (x: int): int(n)
implement{} n73 (x) = if x < 3
then 3
else if x > 127
then 127
else x
fun set_n {n0: nat | n0 >= 3 && n0 <= 127} (count: int(n0)): void = let
Another case that does work:
typedef g1uintBtwe2
(tk:tk, lb0:int, ub0:int, lb1:int, ub1:int) = [i: int | lb0 <= i; i <=
ub0; lb1 <= i; i <= ub1] g1uint (tk, i)
typedef uintBtwe2 (lb0:int, ub0:int, lb1:int, ub1:int) = g1uintBtwe2
(uint_kind, lb0, ub0, lb1, ub1)
typedef hex_t = uintBtwe2(0x30, 0x39, 0x41, 0x46)
fun uint82hex (i: uint8) : hex_t = let
val nv = if ((i >= u8(0x30) && i <= u8(0x39)) || (i >= u8(0x41) && i <=
u8(0x46))) then i else u8(0x30)
in
cast{hex_t}(nv)
end
defines a type and uses a case. But because I am calling set_n with a
constraint that has a loop with an extended constraint, I can’t use a
typedef. Is there some way to cast in n73 like cast{n: nat | n >= 3 && n
<= 127}(3) that solves the problem? This would seem like cheating. Your
sort of certifying that the values are within the constraints rather than
let the solver prove it.