230 questions
1 vote
1 answer
73 views
Adding constraints to deriving declarations
I have this datatype newtype Dimension a b = MkDimension b Whenever it is properly formatted (e.g. satisfies the format constraint), I want to derive a set of classes. I do not want a Dimension which ...
0 votes
1 answer
44 views
Multi-Head Self Attention in Transformer is permutation-invariant or equivariant how to see it in practice?
I read that a function f is equivariant if f(P(x)) = P(f(x)) where P is a permutation So to check what means equivariant and permutation invariant I wrote the following code import torch import torch....
2 votes
0 answers
144 views
Is it possible to create true sentinel values in Rust?
Say I have some simple struct, eg: struct SomeStruct { things: Vec<usize> recent_thing: Option<usize> } I'm trying to assert some invariant on this struct. For example, maybe we want ...
0 votes
1 answer
68 views
DDD. Correct class hierarchy and ensuring invariants
I wonder how to build correct hierarchy and where to cover invariants. There are following entities: Faculty, Course, Student, Teacher. Faculty consists of Courses. Course cannot exist without Faculty....
0 votes
0 answers
47 views
Can invariants span across multiple aggregate roots?
I've got a bit of a theoretical question surrounding DDD and aggregates. It really boils down to this: Yes, we all know that within an aggregate everything must stay consistent. But does that mean ...
0 votes
2 answers
70 views
Why is this Dafny Method not holding when it should?
method search(a: array<int>) returns (i : int) requires a.Length > 1 && a[0] == a[a.Length-1] ensures 0 <= i < a.Length-1 && a[i] >= a[i + 1] { i := ......; ...
0 votes
1 answer
64 views
About Dafny loop invariant errors
The following code is the answer I came up with for the following problem. However, there are two main errors. By the way, this problem is problem 17 in Chapter 13 of the book "PROGRAM PROOFS&...
0 votes
1 answer
52 views
How can an AA-Tree always have 2 children per non-leaf node for arbitrary total-element counts?
I've been reading up on AA-Trees. One of their invariants is that every non-leaf node has two children. How can that work whenever the total element count happens to not be one less than a power of ...
4 votes
0 answers
66 views
Why are non-type template parameters limited to structural types? [duplicate]
When using non-type template parameters, the non-type parameter must be 'structural' per the C++ standard. Classes with private data members are not structural. However, sometimes it is convenient to ...
0 votes
1 answer
165 views
Why do I get "closeparen expected" error in Dafny?
I am struggling with Dafny's syntax, and I get an error that I don't know how to deal with. Here is the code: function pow(base: int, exp: nat): int { if exp == 0 then 1 else base * pow(base, exp -...
1 vote
0 answers
46 views
How to Use Stateful Fuzzing in Foundry to Verify Conditions for Emitting Events?
I have a contract in which I am emitting an event when a certain condition is met enum Type { One, Two } function _someFunc() internal { ... if (someVar != 0) { emit Abstain(Type.One) } ...
-1 votes
1 answer
106 views
Typed builder pattern: bypassing invariants runtime
I would like to determine if there is a way to follow the type state pattern but allow invariants if there is an alternative. Suppose I have a builder pattern for a wrapper struct around a trait. ...
1 vote
1 answer
188 views
Seeking Patterns to Address Concurrent Update Challenges in a Domain-Driven Design Context
Our development team is currently exploring effective patterns to handle situations where concurrent updates might lead to data inconsistencies. We adhere to Domain-Driven Design (DDD) principles, ...
0 votes
1 answer
82 views
Non-aggregate initialization
I need to implement an AutoDocs class that will contain information about the license plate number and driver's full name. It is necessary to implement the class with the following invariants: the ...
1 vote
1 answer
486 views
Dafny Method to find Max fails to verify
I'm working on a Dafny program that finds the maximum element in a sequence of integers. The method Strictmax should return the maximum element and its index. If the maximum element is not unique, the ...