Replies: 7 comments 5 replies
-
Good morning from China,
I wouldn't change this since the two groups of functions you mentioned are
used differently. On top of that the majority of users only ever touch the
bottom four, so not changing their signature would be beneficial.
…On Sat, Aug 19, 2023, 00:36 Markus Iser ***@***.***> wrote:
IPASIR-2 uses zero-terminated arrays of literals in several places:
- in the classic *learned clause callback* for the exported learned
clause (inherited from IPASIR)
- in the *import clause callback* for the imported learned clause
- in the *notify callback* for the exported assignment
IPASIR-2 even uses zero-terminated arrays of structs:
- in the *options getter* for returning the available options
IPASIR-2 also uses zero-terminated C-style strings:
- in *ipasir2_signature* (inherited from IPASIR)
- as option identifiers
The only exceptions to this pattern where no arrays are used are the
following (all inherited from IPASIR):
- *ipasir2_add* sets clauses literal-wise (zero terminated)
- *ipasir2_assume* accumulates assumptions literal-wise
- *ipasir2_val* to receive the model literal-wise
- *ipasir2_failed* to receive failed assumptions literal-wise
With IPASIR-2 we have the opportunity to make this more homogeneous if the
community wishes for that. That means using arrays in the setters of
clauses (add) and assumptions (assume) and getters of models (val) and
failed assumptions (failed) as well, or only in a subset of those.
Moreover, we could move from zero terminated arrays to arrays with length,
which would imply adding an additional parameter per array and function to
specify the array-length. That would solve some issues, e.g., if models are
returned via array and zero indicates don't care literals (which would
conflict with zero-termination anyway). In any case, I would aim at staying
homogeneous, i.e., either stick to zero-termination or length termination,
but not mix both.
So, shall we open that can of worms or leave everything as it is? :)
—
Reply to this email directly, view it on GitHub
<#30>, or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ACF2LLT2YFWJCOJHG2B4OMDXV6KZTANCNFSM6AAAAAA3VYHO7M>
.
You are receiving this because you are subscribed to this thread.Message
ID: ***@***.***>
|
Beta Was this translation helpful? Give feedback.
-
I agree that it is important to have a consistent data structure for clauses, but I don't think we need to apply that principle to all arrays in IPASIR-2. I'm currently writing a prototype C++ wrapper for IPASIR-2, so some thoughts on clauses: Explicitly passing the size would be a better fit for clauses than zero-termination. For example, it would play nicer with things like However, zero-terminated clauses shouldn't become too much of a problem either. The performance impact (copying clauses to add trailing zeros, and iterating to determine their length) should be tiny even compared to the amount of time needed to learn a clause, especially since the overhead is mostly just linear memory access. But to be on the safe side, we should profile example applications when the interface is stable enough. All in all, I'd welcome switching to pointer+size representation, but sticking with zero-terminated clauses should be viable too. |
Beta Was this translation helpful? Give feedback.
-
As was pointed out to me recently since C++11 there is this 'std::vector::data' which (similar to 'std::string::c_string') would give us an effective and both time and space efficient way to get a continuous C-style array of int's ('int *') from a 'std::vector' (I always used the idiom '&v[0]' before). Therefore I am tempted to suggest we move to 'pointer + size' as this would give an in-place no performance overhead usage for C++ users (which are probably the most common users anyhow). Adding the zero on the C++ side before to obtain a zero terminated int array is awkward in case the C++ users wants to work with the vector of literals afterwards (and also always needs to remember that). An IPASIR C++ wrapper could further simplify that:
|
Beta Was this translation helpful? Give feedback.
-
Remark that |
Beta Was this translation helpful? Give feedback.
-
Okay, so this looks like we have some support for switching to array+length in at least some signatures. Regarding
I recommend to propagate this switch to the other methods. Then
Note that some of the signatures would not even grow, as the parameter |
Beta Was this translation helpful? Give feedback.
-
I agree. For some applications single literal 'failed' and 'model' are more efficient than requiring the SAT solver to produce a full model every time. What about two functions? Also note that I assume we will keep the semantics that the model and the failed information might become invalid as soon we add a new clause (or assumption). Therefore the user needs to copy the whole model in case multiple clauses based on the model are added. So even in that case the user might better use the single literal variant. |
Beta Was this translation helpful? Give feedback.
-
Okay, from your comments I got that we should distinguish setters (add, assume) from getters (val, failed), and that we should either leave the getters as they are, and if necessary rather introduce a second getter (probably not necessary). But for the setters, the change to array+len is less problematic, and so I changed the signatures from literal-wise to array+len: ipasir2_add. I made one additional change: To solve the scoping of assumptions in a more intuitive way, I removed assume() and integrated it into solve(): ipasir2_solve |
Beta Was this translation helpful? Give feedback.
-
IPASIR-2 uses zero-terminated arrays of literals in several places:
IPASIR-2 even uses zero-terminated arrays of structs:
IPASIR-2 also uses zero-terminated C-style strings:
The only exceptions to this pattern where no arrays are used are the following (all inherited from IPASIR):
With IPASIR-2 we have the opportunity to make this more homogeneous if the community wishes for that. That means using arrays in the setters of clauses (add) and assumptions (assume) and getters of models (val) and failed assumptions (failed) as well, or only in a subset of those. Moreover, we could move from zero terminated arrays to arrays with length, which would imply adding an additional parameter per array and function to specify the array-length. That would solve some issues, e.g., if models are returned via array and zero indicates don't care literals (which would conflict with zero-termination anyway). In any case, I would aim at staying homogeneous, i.e., either stick to zero-termination or length termination, but not mix both.
So, shall we open that can of worms or leave everything as it is? :)
Beta Was this translation helpful? Give feedback.
All reactions