equality

Returning NotImplemented from __eq__

▼魔方 西西 提交于 2020-08-19 06:08:46
问题 What's the result of returning NotImplemented from __eq__ special method in python 3 (well 3.5 if it matters)? The documentation isn't clear; the only relevant text I found only vaguely refers to "some other fallback": When NotImplemented is returned, the interpreter will then try the reflected operation on the other type, or some other fallback, depending on the operator. If all attempted operations return NotImplemented , the interpreter will raise an appropriate exception. See Implementing

Returning NotImplemented from __eq__

风格不统一 提交于 2020-08-19 06:08:08
问题 What's the result of returning NotImplemented from __eq__ special method in python 3 (well 3.5 if it matters)? The documentation isn't clear; the only relevant text I found only vaguely refers to "some other fallback": When NotImplemented is returned, the interpreter will then try the reflected operation on the other type, or some other fallback, depending on the operator. If all attempted operations return NotImplemented , the interpreter will raise an appropriate exception. See Implementing

Test for equality to the default value

可紊 提交于 2020-07-31 07:50:17
问题 The following doesn't compile: public void MyMethod<T>(T value) { if (value == default(T)) { // do stuff } } Error: Operator '==' cannot be applied to operands of type 'T' and 'T' I can't use value == null because T may be a struct. I can't use value.Equals(default(T)) because value may be null . What is the proper way to test for equality to the default value? 回答1: To avoid boxing for struct / Nullable<T> , I would use: if (EqualityComparer<T>.Default.Equals(value,default(T))) { // do stuff

Why are arrays equal to their corresponding strings?

你。 提交于 2020-06-23 03:33:23
问题 Why is an array evaluated to true when it is compared to its corresponding string? var a = [1,2,3]; var b = '1,2,3'; console.log(a==b);// true Variable a stores the memory address of the array it is assigned. Then how is a memory address equal to corresponding string of that array. 回答1: Well in case of "==", array is converted to toString and then compared due to loose comparison, so it equates to true. So what happens is this: var a = [1,2,3]; var b = '1,2,3'; a == b //is same as a.toString(

Why is the output different in both cases comparing floats

本秂侑毒 提交于 2020-06-17 08:03:32
问题 PYTHON PROGRAM : a = 0.2 if a == 0.2: print('*') OUTPUT : * C PROGRAM : #include <stdio.h> int main(void) { float a = 0.2; if(a == 0.2) { puts("*"); } } OUTPUT : Why is the output different in both cases? Is there a difference between the working of == operator? 回答1: It is because the types float and double have different width reserved for the mantissa. The type double can represent a floating number more precisely. In this case that matters as 0.2 can't be represented exactly and has a very

How to solve goals with invalid type equalities in Coq?

时光怂恿深爱的人放手 提交于 2020-06-14 05:04:30
问题 My proof scripts are giving me stupid type equalities like nat = bool or nat = list unit which I need to use to solve contradictory goals. In normal math, this would be trivial. Given sets bool := { true, false } and nat := { 0, 1, 2, ... } I know that true ∈ bool , but true ∉ nat , hence bool ≠ nat . In Coq, I don't even know how to state that true :̸ nat . Question Is there a way to show that these equalities are false? Or maybe, is it impossible? (Ed.: Removed long list of failed attemts,

How to solve goals with invalid type equalities in Coq?

烂漫一生 提交于 2020-06-14 05:03:11
问题 My proof scripts are giving me stupid type equalities like nat = bool or nat = list unit which I need to use to solve contradictory goals. In normal math, this would be trivial. Given sets bool := { true, false } and nat := { 0, 1, 2, ... } I know that true ∈ bool , but true ∉ nat , hence bool ≠ nat . In Coq, I don't even know how to state that true :̸ nat . Question Is there a way to show that these equalities are false? Or maybe, is it impossible? (Ed.: Removed long list of failed attemts,

Strict Equality (===) versus Shallow Equality Checks in React-Redux

白昼怎懂夜的黑 提交于 2020-05-23 08:48:45
问题 I'm studying how Hooks APIs provided by React-Redux-v.7.1 works, and saw it mentioned in Equality Comparisons and Updates (https://react-redux.js.org/api/hooks#equality-comparisons-and-updates) that: " As of v7.1.0-alpha.5, the default comparison is a strict === reference comparison. This is different than connect() , which uses shallow equality checks on the results of mapState calls to determine if re-rendering is needed. This has several implications on how you should use useSelector() . "

How to explicitly use an induction principle in coq?

三世轮回 提交于 2020-05-16 22:06:15
问题 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.

How to explicitly use an induction principle in coq?

我的梦境 提交于 2020-05-16 22:05:20
问题 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.