so I have just started to learn cvc4 after I have spent some time learning boolector. With it, it is possible to print the model just using boolector_print_model. Unfortunately the doc page for cvc4 is down at the moment and I cannot understand how to do the same with cvc4 in Java.
Can anyone help to do it please?
For instance, you could help me to see the model for this example.
EDIT: Just to be clear, with the entire model I mean a valid value for each BV or in general variable present within my model.
An example model could be:
(model
...
(define-fun number_6_0_7 () (_ BitVec 8) #x00)
(define-fun number_6_1_7 () (_ BitVec 8) #x00)
(define-fun number_6_2_7 () (_ BitVec 8) #x00)
(define-fun number_6_3_7 () (_ BitVec 8) #x78)
...
)
Thanks a lot
Unlike boolector, CVC4 does not have a mechanism of accessing the entire model in once call via the API. This is because CVC4 allows for much richer types, including data-types, uninterpreted-functions, etc.; which makes model construction more complicated.
Instead, you call the getValue method for each of the input variables you have, and print them yourself. Here's an example:
https://github.com/CVC4/CVC4/blob/e3cd4670a080554e4ae1f2f26ee4353d11f02f6b/examples/api/java/FloatingPointArith.java#L66-L68
Related
Can I get multiple models for a query like the following?
(set-logic LIA)
(set-option :produce-models true)
(declare-const x Int)
(assert (< x 20))
(check-sat)
(get-model)
Instead of just
sat
(
(define-fun x () Int 0)
)
I'd like to get 0, 1, -1, 2, ...
SMTLib language does not have a mechanism to retrieve "all-models." So, if you're bound to be using SMTLib only, you cannot do this; at least not easily.
However, most solvers (definitely including cvc4 and z3) can be scripted from higher-level languages. The idea is to make a check-sat call, and if you get a solution, you add an additional assertion that disallows that model, and query for a new one. See this answer for how to do this in z3, as scripted from Python: Trying to find all solutions to a boolean formula using Z3 in python. You can do the same from C/Java etc.; or use a higher-level binding that provides such a command out-of-the box.
Which random number generator is used in Scratch 1.4 and where can I find its implementaion in the source code? If it is just libc's random(), please point me to the spot where it's called.
Scratch 1.x is written in Squeak Smalltalk. You can get the source code from within Scratch by following these instructions.
The pick random () to () block is defined in Scratch-Objects -> ScriptableScratchMorph (instance) -> other ops -> randomFrom:to:. The basic essential code there is
t5 _ RandomGen next * (t4 - t3) + t3.
Now, what is RandomGen? It turns out that it's defined in Scratch (in the class initialization) as just being a copy of Squeak's Random.
According to the Squeak wiki:
The random-number-generator is a Park-Miller generator, it is implemented in the class Random.
Scratch also calls for a random number in some list blocks, where you can do something with "any" list item. This is implemented in list ops -> lineNum:forList:.
The objective is to make the docco generated documentation for fluentnode (written in Coffee-Script) as easy to read and understand as possible. At the moment I'm struggling with the best way to represent the function names on the left hand side of the help pages you can access at http://o2platform.com/fluentnode/index.html
At the moment I'm exploring three syntax options:
A) #.{function-name} ({params})
B) {ClassName}::{function-name} ({params})
C) {ClassName}#{function-name} ({params})
As an example, the Array's .empty() method, would be represented as:
A) #.empty ()
B) Array::empty ()
C) Array#empty ()
Note that this would be seen inside the file for a particular class (so it would still be obvious on A that this is related to an array)
To see this in action I used these methodologies on three different help files:
A) #.{function-name} ({params}) on Array.html
B) {ClassName}::{function-name} ({params}) on Function.html
C) {ClassName}#{function-name} ({params}) on C) http://o2platform.com/fluentnode/Number.html
Btw: if there are other ways to represent this, please point me to existing docco generated sites which represent those techniques.
(Question also asked here https://github.com/o2platform/fluentnode/issues/31)
I'm going with a variation of option A) which is
#.empty {parmas}
Where I'm not using () in the params which makes it easy to see them
According to sec. 3.9.3 of The SMT-LIBv2 Language and Tools: A Tutorial it is possible to declare a composite sort like this in SMT-LIBv2:
(set-logic QF_UF)
(declare-sort Triple 3)
(declare-fun state () (Triple Bool Bool Bool))
I am using CVC4 and it seems to accept this syntax. But how do I access the elements? I tried the following (and various variations of that and other things I found online):
(assert (_ state 1))
(assert (select 1 state))
But it looks like those operators only work on vectors and arrays. I can't find any example that uses such composite sorts and can't find anything about accessing those elements in the tutorial or the language standard. How is it done? Or did I completely misunderstand what this feature is for?
My application: I want to encode a temporal problem and want to do it in form of a state transition function that converts the old state into a new state, so I can write something like the following when experimenting with the system:
....
(declare-fun initial_state () MyStateSort)
(declare-fun state_after_step_1 () MyStateSort)
(declare-fun state_after_step_2 () MyStateSort)
(assert (= (MyTransitionFunc initial_state) state_after_step_1)
(assert (= (MyTransitionFunc state_after_step_1) state_after_step_2)
This is an answer to my own question. If anyone can post an example for a use-case of a user-defined sort with arity > 0, I'll happily accept that as answer.
After reading the SMT-LIBv2 standard more carefully I am now thinking that sort declarations with arity > 0 only have an application in theory definitions (for declaring sorts like Array), not in user-supplied code. The example in David Cok's Tutorial seems to be misleading, as it suggests that this can be used to declare composite sorts. I have not found any indication of that anywhere else. This includes the complete SMT-LIB benchmark that contains not a single sort declaration with arity > 0.
Instead of "composite sorts" one should use uninterpreted functions to create the equivalent of complex data structures. Example:
(set-logic QF_UF)
(declare-sort CONTAINER_SORT 0)
(declare-fun CONTAINER_MEMBER_1 (CONTAINER_SORT) Bool)
(declare-fun CONTAINER_MEMBER_2 (CONTAINER_SORT) Bool)
(declare-fun INSTANCE_1 () CONTAINER_SORT)
(declare-fun INSTANCE_2 () CONTAINER_SORT)
This will effectively declare the following 4 independent Bool expressions.
(CONTAINER_MEMBER_1 INSTANCE_1)
(CONTAINER_MEMBER_2 INSTANCE_1)
(CONTAINER_MEMBER_1 INSTANCE_2)
(CONTAINER_MEMBER_2 INSTANCE_2)
This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
What does () => mean in C#?
Hi Everybody,
This is my first question in stackoverflow.
I have encounter something as
() => SomeClass.SomeMethod(param1, param2)
This is entirely new to me and I cannot fathom what it is, what we call it, what it does,
how it works etc.
What I am looking for is an explanation for the same with a simple example which can be
understandable easily and I can implement it in my program. It will be nice if I can get
the real time scenario for this implementation.
I am using C#3.0 with dotnet framework 3.5.
Many thanks in advance.
Lambdas page on MSDN is quite helpful with the syntax.
And yes, ()=>GetSomething() is an expression lambda that takes no parameters and returns something. The other lambda flavour is a statement lambda, which is an anonymous function that does not return anything - i.e. a void function.
Both can take any number of parameters, including none.
It's a lambda function I guess. It is the kind of function you define "inline".
For example, in LINQ you can do the following:
myTable.Where(eleme=>elem.qty>=10);
Here you pass the function leme=>elem.qty>=10 as a parameter to the Where method.
I guess in your example, () => SomeClass.SomeMethod(param1, param2) is referring to a function taking no input parameter an returning some value.
This is a lambda that creates an Action delegate.
More info (and example) http://msdn.microsoft.com/en-us/library/system.action.aspx
You can also create an action and pass in parameters with (s) => SomeMethod(s);
Or, you can pass an entire block:
(x) => {
DoSomething(x);
if(x.SomeValue == requiredValue){
x.SomeOtherValue = true;
}
}
For more examples of passing parameters to Action<T> see here