Questions tagged [invariants]

In computer science, a predicate is called an invariant to a sequence of operations provided that: if the predicate is true before starting the sequence, then it is true at the end of the sequence.

In loops, invariants are data structures referenced within the loop that do not change during any iteration. In design-by-contract, invariants are invariants are properties of a class than must be satisfied at the end of any method call that is invoked from outside of the class itself.

References

218 questions
0
votes
1 answer

Invariant of an algorithm

Assume this algorithm which gives the maximal sum of a subarray back. And let a[] be an array of length n. randmax = 0 maximum = 0 for 0 <= i < n randmax = randmax + a_i if randmax > max max = randmax if randmax < 0 randmax =…
regsts
  • 1
0
votes
2 answers

Binary chop: if list[middle] == key case

I'm revising algorithms for my exams and I was trying to solve this exercise but I couldn't come up with a solution. This is the pseudo-code. 1. int search (int [] a, int x) { 2. // Pre: ∃i:Nat (0≤i
user640072
  • 161
  • 2
  • 2
  • 8
0
votes
1 answer

How can I type for Collection?

I have a method look like this. public void some(..., Collection collection) { // WOOT, PECS!!! final Stream stream = getStream(); stream.collect(toCollection(() -> collection)); } And how can I make this method…
Jin Kwon
  • 20,295
  • 14
  • 115
  • 184
0
votes
0 answers

Keypoint orientation in SIFT algorithm?

im currently working on SIFT algorithm. i want to ask how do we rotate 16x16 gradient magnitude in difference for 10 degree because the orientation bin 10 degree difference? and then when we know the maximum gradient orientation example its 200 and…
0
votes
1 answer

Invariant JS parameters are not clear

Why invariant function has this params: function(condition, format, a, b, c, d, e, f) { instead of: function invariant(condition : any, format?: string, ...args : Array < any >) { Can anyone clarify, because for me does not make any…
user3053247
0
votes
1 answer

Invariant sharing with Eiffel's keyword `like`

In Eiffel, it is possible to specify a type with an 'anchored declaration'. I wonder if the relevant invariants in the class also apply to an anchored declaration: class C feature f: INTEGER do ... Do something ... …
g4v3
  • 133
  • 2
  • 10
0
votes
2 answers

Uncaught Invariant Violation: A state mutation was detected between dispatches,

I'm trying to display only a segment of an array of queries that I've mapped from state to the props of my container component (using mapStateToProps). To do this, I use the spread operator, Array.slice, and then iterate over sub-array to create…
C. Hidalgo
  • 1
  • 1
  • 2
0
votes
0 answers

What is the tips for construct invariant for simple program (like interview algorithm)?

I am always wondering how to prove the correctness of a simple program. For example, a interview problem like First Missing Positive. The program looks like this: public class Solution{ public int firstMissingPositive(int[] A){ int i =…
0
votes
0 answers

can not get a type of DBGrid Column, free pascal

I use a free pascal lazarus. I have DBGrid that loads table from DB. I created columns in designer and sqlqueries to these columns. Everything is excellent. But when i need to get type of field i get an error: Project Admin raised exception class…
user2032083
  • 313
  • 2
  • 4
  • 14
0
votes
0 answers

String.ToLowerInvariant not working in lambda expression

When I use ToLowerInvariant or ToUpperInvariant they don't work in lambda expressions. I get an exception: LINQ to Entities does not recognize the method 'System.String ToUpperInvariant()' method, and this method cannot be translated into a store…
Elvin Mammadov
  • 25,329
  • 11
  • 40
  • 82
0
votes
0 answers

UPPAAL: Invariants violated but none have been explicitly set - how to resolve deadlock?

I'd like to learn more about Timed Automata to verify real-time systems. Currently, I'm trying to get myself familiar with a tool called UPPAAL. I drew some simple graphs and added different properties. The entire model is supposed to represent a…
Jim McAdams
  • 1,034
  • 1
  • 14
  • 30
0
votes
1 answer

Clustering algorithm whose results are invariant to data permutation and bootstrap perturbation

I am wondering if there is in the literature a clustering algorithm whose output (partition, dendrogram, soft assignments and so on) is invariant to : permutation in the data points (typically many hierarchical agglomerative clustering are…
0
votes
1 answer

Working out an invariant for a binary search

I need hep working out what the invariant for this code would be. I think there can be multiple invariants but i don't really understand the topic and online resources i have found still dont really help. The code i made for the binary search…
0
votes
0 answers

In Python, how can I enforce a method's input and output invariants in child classes?

Is there a convenient way to enforce a method's input and output invariants, when the method is overridden in a subclass? By enforcing invariants, I mean checking things like: The number of input arguments The types of some/all of the inputs The…
SuperElectric
  • 17,548
  • 10
  • 52
  • 69
0
votes
2 answers

Understanding invariants using Euclid's algorithimn

I'm having issues trying to understand the word "invariant" and "variant" and how it relates to programming in c. It's used a lot in my textbook and its mentioned quite often by my professor but I can't seem to properly understand it even after…