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
2 answers

Writing a Factorial function with Lists

While I believe I have found a sound algorithm for my function (Factorial) I'm very confused as to why it loops infinitely. Here's my code : declare fun{Fact N} local M=1 in %I suppose it loops from here?? local FactT in …
user3078046
  • 31
  • 1
  • 7
0
votes
2 answers

Improving the Efficiency Of This Code With Tracking Variable?

I have written the below code outline, basically to sum an array (a) where each element is multiplied by a value x^i: y = a(0) i = 0 {y = sum from i=0 to (n-1) a(i) * x^i AND 0 <= n <= a.length} //Invariant while (i < (n-1)) {y = sum from i=0 to…
Rome_Leader
  • 2,518
  • 9
  • 42
  • 73
0
votes
1 answer

Always Valid Entities

I'm interested to see how supporters of the "Always-Valid" entity approach (vs isValid method later) would suggest modelling a object with collections. I really like the idea behind this approach, but I am having difficulty with implementing it as…
Milambardo
  • 330
  • 2
  • 14
0
votes
2 answers

OCL define invariant

If I have to define an invariant to state that the age of a person requesting a loan should be greater than 18 for the attached class diagram would this be context Person inv: age > 18 or context Person inv: self.age > 18 and what is the…
CompilerSaysNo
  • 415
  • 3
  • 14
0
votes
1 answer

Bad result on shape recognition using invariant moments

My project is shape recognition of leaf. I use Invariant Moments to feature extraction and City Block Distance to compute the distance between test image and image in database. Bust the result i get is very bad. I can say the recognition is only get…
gussurya_w
  • 93
  • 5
  • 14
0
votes
1 answer

how to omit program points in Daikon invariant detector?

I am using Daikon (likely program invariant detector) to generate invariants for a simple java class with different methods. I wanted to omit few methods from this class which I achieved through the following command: java daikon.Chicory…
Dr. Mian
  • 3,334
  • 10
  • 45
  • 69
0
votes
1 answer

Domain Driven Design - Order of child of entites with respect to parent entity

I have two aggregates Parent and Child, say. A Parent can have many Childs (Children). A Child can only belong to one Parent. I need to keep track of a sort order of the Child entities so that when you get the Child entities for a Parent the list is…
0
votes
1 answer

Scala anonymous function genric variance issues

I'm on the road to learn Scala and I'm having a hard time understanding contravariants, covariants, invariance, etc. From Why doesn't the example compile, aka how does (co-, contra-, and in-) variance work? I have learned how functions can be…
Miles
  • 1
  • 1
0
votes
1 answer

Class invariants within code

I am wondering if there is a definitive procedure in determining invariant for a specific class or does it change on a case by case basis? Obviously it depends on certain variables and require statements but my question is, Is there some sort of…
Jim
  • 482
  • 1
  • 5
  • 20
0
votes
1 answer

Compilers Exam Explanation

I am preparing for a Compilers exam and I found the following two questions in past papers that I don't know how to answer: 1. Array bounds checking requires code to check each array subscript to ensure it falls within the array's declared range.…
Sorin Cioban
  • 2,237
  • 6
  • 30
  • 36
0
votes
0 answers

Code Contracts- Invariants are not rewritten

I am using VS2010 Ultimate with Code Contracts. After getting unexpected runtime behavior, I reviewed the source code in reflector and realized that my invariants are not being compiled. The generated __ContractsRuntime class only contains…
smartcaveman
  • 41,281
  • 29
  • 127
  • 212
0
votes
1 answer

OCL Requirement: Invariant for possible range of attribute values

So I have the following Object structure: Class Node RSSI: int I need to write a OCL invariant for the requirement that the the RSSI values of all Node objects do not differ by more than 2. I tried to solve it with an iterate expression but since…
gaussd
  • 899
  • 6
  • 15
  • 28
0
votes
1 answer

How to compute radon transform with invariant properties

I try to work the R transformation that, according with what is written in the scientific article "Recognition of Human Home Activities via Depth Silhouettes and R Transformation for Smart Homes", is computed in this way: where In Matlab I get…
Mario Lepore
  • 307
  • 2
  • 8
  • 18
0
votes
1 answer

OCL constraint using Ecore classifiers - Unknow type exception

I'm developing an Ecore model with some invariants defined in OCL, using the OCLinEcore editor. In my model, some elements have references to EClassifier; in some OCL constraints, I need to check if the EClassifier referred to is an EDataType or an…
Luc Touraille
  • 79,925
  • 15
  • 92
  • 137
0
votes
1 answer

Loops and Invariants?

I'm trying to swap the values of array b and to store a value in k so that the postcondition b [0...h] <= 9 and b[k+1..] > 9 is true. I have this so far: for ( int b = 0; k!= b.length; k = k+1 ) { int p = k+1; for ( int h= k+1; h !=…
1 2 3
14
15