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
FSeq question #85
Comments
Hi Andrzej, Your intuition is correct. The problem here is that the
int len = 6;
var l = Zen.Symbolic<FSeq<byte>>(depth: 10); // give the max size here
var idx = Zen.Symbolic<BigInteger>();
var sol = Zen.And(
l.Length() == (BigInteger)len,
l.At(idx) == Option.Some<byte>(1),
l.At(idx + BigInteger.One) == Option.Some<byte>(2)).Solve();
int len = 30;
var l = Zen.Symbolic<Seq<byte>>();
var idx = Zen.Symbolic<BigInteger>();
var sol = Zen.And(
idx >= BigInteger.Zero, // have to add constraints on the index since Nth can return any value if out of bounds
idx < (BigInteger)(len - 1),
l.Length() == (BigInteger)len,
l.Nth(idx) == 1,
l.Nth(idx + BigInteger.One) == 2).Solve(); In terms of having every element of the sequence depend on other values, there is not a super clean way to do that since the sequence length is variable. If you really want to you can write recursive functions (like this), but I wouldn't recommend it. If you are okay with modeling a sequence that has a fixed length, you could look at the var a = Zen.Symbolic<Array<byte, _10>>();
Zen<byte>[] array = a.ToArray();
var constraints = new List<Zen<bool>>();
for (int i = 0; i < array.Length; i++)
{
constraints.Add(array[i] == (byte)(i + 1));
}
var sol = Zen.And(constraints).Solve();
Console.WriteLine(sol.Get(a)); Result is: |
Thank you for the detailed answer, this helps :-) |
Hello,
While trying to find a way to specify sequences like "the value of the element is the index+1" or "the value of the element is the sum of the 2 previous elements", I've encountered the below behavior, where a solution will be found for sequence len=5, but not for len=6:
I assume I must be doing something wrong, or that there must be some parameter like search depth/iterations, that needs adjusting to make this work?
Also, if you have hints for implementing the above mentioned sequences, it will be greatly appreciated ;-)
Best regards,
Andrzej
The text was updated successfully, but these errors were encountered: