Questions tagged [equality]

Equality is a relationship between two or more items or variables or objects that exists if (1) the items are the same item, variable, or object or (2) the items are different items, variables or objects but they have the same value. This tag should generally be used with programming language specific tags as well as other contextual tags such as database system. The post should include as much context about the equality test as is possible.

This tag is typically used for questions concerning how to determine if two objects or variables are either the same object or different objects with the same value. Questions almost always require a programming language tag and other tags for context.

Programming languages represent variables, objects, or other storage containers using different underlying mechanisms for the storage of the values of variables and objects. A test for equality is to compare some characteristic of two variables or objects to determine if the characteristic is the same.

This characteristic is typically either (1) the storage identifier such as a reference handle, memory address, etc. when checking if the two are the same object or (2) the characteristic is the value of the objects retrieved using a storage identifier when checking if the value of the two are the same value.

Different programming languages and different operating environments have differences in how equality is tested and what operators are used to express a test for equality. In some cases various conversions from underlying storage representations may be involved in testing for equality.

See What is the difference between equality and equivalence? as well as Equivalence relation and natural ordering on a class in Java

2095 questions
0
votes
1 answer

How do you do equational reasoning for user defined equational relations with agda-stdlib?

agda-stdlib has facilities for doing equational reasoning for various specific library defined relations (example). It also has a type that identifies equality relations defined here. What is the easiest way for me to get access to the same…
Ace shinigami
  • 1,374
  • 2
  • 12
  • 25
0
votes
1 answer

Why IEqualityComparer doesn't work as expected?

Why EqualityComparer MyEqComp doesn't work? It should left in arr only 2 elements with equal Values - myDic["1"]and myDic["3"] with Value="456". But instead it consists of myDic["1"] and myDic["2"] but their Values are not equal. Function…
NoImagination
  • 178
  • 1
  • 8
0
votes
1 answer

Comparing lists of ints in, while considering two ints not to be equal if repeated

I know this question has been reiterated multiple times, and I think this is straightforward when using lists of reference types. That is also what most questions talk about. When doing this with value types, I can't quite figure it out. What I want…
jokarl
  • 1,913
  • 2
  • 24
  • 52
0
votes
1 answer

Typescript compile error on enum equality check

I created this typescript file to show the problem: enum E { one, two } console.log(E.one) console.log(E.two) let n: E = E.one if (n === E.one) console.log("equal"); if (n === E.two) console.log("equal"); I get compile error from tsc on…
Siavoshkc
  • 346
  • 2
  • 16
0
votes
1 answer

Flutter Dart - Checking equality between two instances of a class

I have defined a class for a complex object containing many attributes. I redefined the equality property in this class : an instance of object is equal to another if on attribute is the same. class CarnetWord { @override bool operator ==(Object…
SylvainJack
  • 1,007
  • 1
  • 8
  • 27
0
votes
1 answer

Enum equalization with other classes

I've created a class that only takes Enums as parameters. I figured I could create a third Enum where I would manually put every option so they have a better naming. The only thing is, I can't test if both my third Enum instance and my class…
FMorschel
  • 799
  • 5
  • 18
0
votes
2 answers

R check equality of one column to rowSums of other columns

I have a dataframe like this: x y x1 y1 x2 y2 x3 y3 1 0 1 0 0 0 0 0 0 0 3 0 0 0 0 0 2 0 0 0 0 0 2 0 1 0 0 0 1 0 0 0 I want to find rows that x=x1+x2+x3 and rows that y=y1+y2+y3. Here is my code to check x=x1+x2+x3: col_x =…
0
votes
3 answers

How to determine if 6 elements are equal in a list with 100 elements

So I have this exercise to do: Write a program to find out how often a streak of six heads or a streak of six tails comes up in a randomly generated list of head and tails and if there is a streak you add to to the variable number_of_streaks I made…
0
votes
0 answers

Why does the eq function in rust give this unexpected result?

In this simple rust program, I want to print They are equal if the input string is lexicographically equal Y. Below is my code: use std::io; fn main() { let mut input: String = String::new(); io::stdin().read_line(&mut input).expect("Could…
Isaac Dzikum
  • 184
  • 9
0
votes
2 answers

CHAI - See if two objects are the same where one attribute has a different order

I have two object arrays: array1 = [ { name: 'Kitty, Hello', otherNames: [ '(1) One', '(2) Two' ] }, { name: 'Cat, Garfield', otherNames: [ '(3) Three' ] } ]; array2 = [ { name: 'Kitty, Hello', otherNames: [ '(2) Two',…
webdesignnoob
  • 381
  • 1
  • 4
  • 13
0
votes
4 answers

all of the condition are working except on the second else-if statement, how to correct this?

I am learning Java and I do not know what makes my code not reading my else-if condition (i == 5) int i; for (i = 1; i <= 5; i++) { int guess = scanner.nextInt(); System.out.println("Attempt: " + i +"/5"); if (guess < numberToGuess)…
0
votes
2 answers

Why is there no error comparing Vector and Array in Rust?

I know that Array and Vector are different types in Rust language, but I wonder why there is no error in comparing the two. // Rust Programming Language fn main() { let vec = vec!["a", "b", "c"]; // Vector let arr = ["a", "b", "c"]; //…
Larynx
  • 398
  • 1
  • 12
0
votes
1 answer

Algorithm to determine if two graphs are the same

Given a graph the root node of which is defined by a Node object: class Node: def __init__(self, val = 0, neighbors = None): self.val = val self.neighbors = neighbors if neighbors is not None else [] def __eq__(self,…
SigKill
  • 87
  • 5
0
votes
1 answer

Equality operator with multiple values in JavaScript

Is there a simple way to compare multiple values to a single value in Javascript ? Like, instead of writing : if (k != 2 && k != 3 && k!= 7 && k!12) Writing something like : if (k != {2,3,7,12})
JS1
  • 631
  • 2
  • 7
  • 23
0
votes
2 answers

Python check for three way equality

How do I check if any 2 of n variables are equal in python. And is there a nice way to do it? This is the situation s = input() D = int(input()) A, B, C = map( lambda x: D % int(x) , s.split()) if A == B == C: ? checks if all are equal …
ttrss
  • 69
  • 5