equality

How to explicitly use an induction principle in coq?

陌路散爱 提交于 2020-05-16 22:05:03
问题 I'm trying to prove symmetry of propositional identity with the induction principal explicitly in Coq, but can't do it with the induction principle like I can in agda. I don't know how to locally declare a variable in Coq, nor do I know how to unfold a definition, as you can see below. How can I get a proof that resembles the agda one below? Inductive Id (A : Type) (x : A) : A -> Type := | refl : Id A x x. (* trivial with induction *) Theorem symId {A} {x y} : Id A x y -> Id A y x. Proof.

Custom equality of types with statically resolved type parameters

笑着哭i 提交于 2020-02-21 23:57:33
问题 How to implement custom equality methods in F# types with statically resolved type parameters? I've tried doing it this way: [<CustomEqualityAttribute>] type Fraction< ^a when ^a: equality and ^a : (static member (*): ^a * ^a -> ^a) > (nominator: ^a, denominator: ^a) = member inline this.Nominator = nominator member inline this.Denominator = denominator member inline this.IsEqualTo(other: Fraction< ^a >) = this.Nominator * other.Denominator = other.Nominator * this.Denominator override inline

How object equality checks work in Javascript? [duplicate]

丶灬走出姿态 提交于 2020-02-07 00:00:27
问题 This question already has answers here : Object comparison in JavaScript [duplicate] (10 answers) How to determine equality for two JavaScript objects? (60 answers) How to determine if Javascript array contains an object with an attribute that equals a given value? (23 answers) indexOf method in an object array? (27 answers) Closed last month . I'm trying to check for the existence of an element of an array using built-in Javascript array function const routes = [ { path: 'users/:id',

Javascript equality operators

允我心安 提交于 2020-01-30 08:32:11
问题 In David Flanagan's Javascript guide, there is a statement: the == operator never attempts to convert its operands to boolean So here I did a little test: var a = false; var b = ""; // empty string a == b; //returns true Looking at Abstract Equality Comparison Algorithm there is a point: e. If Type(x) is Boolean, return true if x and y are both true or both false. Otherwise, return false. How can x and y be both true if y is string data type (without conversion)? 回答1: What happens under the

How to remove duplicates in list of objects without __hash__

蹲街弑〆低调 提交于 2020-01-24 04:10:26
问题 I have a list of custom objects from which I want to remove the duplicates. Normally, you would do this by defining both __eq__ and __hash__ for your objects and then taking the set of the list of objects. I have defined __eq__ , but I can't figure out a good way to implement __hash__ such that it returns the same value for objects that are equal. More specifically, I have a class that is derived from the Tree class from the ete3 toolkit. I have defined two objects to be equal if their

Ruby Set class: equality of sets

前提是你 提交于 2020-01-24 03:59:30
问题 According to the Ruby Set class's documentation, "== Returns true if two sets are equal. The equality of each couple of elements is defined according to Object#eql?. The essence of this can be demonstrated using Date objects, where sets containing different Date objects but with the same date compare to equal: require 'set' d1 = Date.today # => Thu, 30 Sep 2010 puts d1.object_id # => 2211539680 d2 = Date.today + 1 # => Fri, 01 Oct 2010 puts d2.object_id # => 2211522320 set1 = Set.new([d1, d2]

What is the algorithm used by the memberwise equality test in .NET structs?

人走茶凉 提交于 2020-01-22 10:54:08
问题 What is the algorithm used by the memberwise equality test in .NET structs? I would like to know this so that I can use it as the basis for my own algorithm. I am trying to write a recursive memberwise equality test for arbitrary objects (in C#) for testing the logical equality of DTOs. This is considerably easier if the DTOs are structs (since ValueType.Equals does mostly the right thing) but that is not always appropriate. I would also like to override comparison of any IEnumerable objects

Testing for equality between dictionaries in c#

喜欢而已 提交于 2020-01-19 03:13:03
问题 Assuming dictionary keys and values have their equals and hash methods implemented correctly, what is the most succinct and efficient way to test for equality of two dictionaries? In this context two dictionaries are said to be equal if they contain the same set of keys (order not important), and for every such key, they agree on the value. here are some ways i came up with (there are probably many more): public bool Compare1<TKey, TValue>( Dictionary<TKey, TValue> dic1, Dictionary<TKey

Testing for equality between dictionaries in c#

拥有回忆 提交于 2020-01-19 03:09:56
问题 Assuming dictionary keys and values have their equals and hash methods implemented correctly, what is the most succinct and efficient way to test for equality of two dictionaries? In this context two dictionaries are said to be equal if they contain the same set of keys (order not important), and for every such key, they agree on the value. here are some ways i came up with (there are probably many more): public bool Compare1<TKey, TValue>( Dictionary<TKey, TValue> dic1, Dictionary<TKey

Comparing arrays for equality in C++

不问归期 提交于 2020-01-18 15:40:47
问题 Can someone please explain to me why the output from the following code is saying that arrays are not equal ? int main() { int iar1[] = {1,2,3,4,5}; int iar2[] = {1,2,3,4,5}; if (iar1 == iar2) cout << "Arrays are equal."; else cout << "Arrays are not equal."; return 0; } 回答1: if (iar1 == iar2) Here iar1 and iar2 are decaying to pointers to the first elements of the respective arrays. Since they are two distinct arrays, the pointer values are, of course, different and your comparison tests not