Comments (2)
Hi Andrzej,
Your intuition is correct. The problem here is that the FSeq
type will only model sequences up to a certain bounded length. The default was 5
(and recently increased to 8
). So when you ask for a sequence of length 6 it can't find such a sequence because no sequence of length 5 or less can have length 6. There are two ways to solve this.
- You can increase the size of the
FSeq
. Just use thedepth
parameter when creating the sequence:
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();
- You could use the
Seq
type, which does not bound the size of the sequence. However, Z3 may not always give you an answer forSeq
. For example, the following works for me:
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 Array
type, which just gives you direct access to all of the elements. For example:
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:
[1,2,3,4,5,6,7,8,9,10]
from zen.
Thank you for the detailed answer, this helps :-)
from zen.
Related Issues (6)
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 zen.