Questions tagged [commutativity]

In mathematics, a binary operation is commutative if changing the order of the operands does not change the result. It is a fundamental property of many binary operations, and many mathematical proofs depend on it. The name is needed because there are operations, such as division and subtraction, that do not have it (for example, "3 − 5 ≠ 5 − 3"); such operations are not commutative, and so are referred to as noncommutative operations. The idea that simple operations such as the multiplication and addition of numbers are commutative, was for many years implicitly assumed.

Source: https://en.wikipedia.org/wiki/Commutative_property

61 questions
1
vote
3 answers

Why is multiplication not always commutative in Ruby?

If x is a non-integer, I get this result: x = "a" x * 6 #=> aaaaaa 6 * x #=> TypeError: String can't be coerced into Fixnum whereas if x is an integer: x = 6 x * 6 #=> 36 6 * x #=> 36 It's strange that the operand order in multiplication matters…
roppo
  • 57
  • 7
1
vote
1 answer

Associativity and commutativity of inner joins sql

Let us say I have this schema. Boats _____ bid bname Reserves ________ sid bid date Sailors _______ sid sname I know that inner joins are supposed to be both associative and commutative, but I cannot really understand why. Given the query: SELECT…
user3903214
  • 203
  • 1
  • 9
1
vote
1 answer

Does Z3 have a feature for facilitating the matching of subformulas in chains of associative / commutative operators?

Let's say I have a user-defined commutative and associative operator op. The code below is invalid because I'm using op with more than two arguments. Let's suppose for a moment that it is valid and that it means "the way op is applied is…
simon1505475
  • 675
  • 3
  • 9
1
vote
3 answers

Commutativity of disjunction in Prolog

I've just started learning Prolog and I encountered a problem that I don't understand. When I ask: ?- fail; true. Prolog answers: true Which is something I expected. But, if I ask: ?- true; fail. Prolog answers: true ; false. ..and I don't…
1
vote
2 answers

How to optimize conditional sub-selects that involve inner joins?

I have got an SQL query (MS SQL 2008) that I would like to optimize speed-wise. It has got the following structure (only in reality there are 10 different when-cases in the case statement). The important bits are the sub selects in the case…
0
votes
2 answers

Ordering of keys in dictionaries using SymPy

I have the following problem with my code. I start off with a polynomial (f = 3x+2y+xy), and want to store the coefficients and variables in separate lists (I want to be able to change this polynomial f, so don't want to predetermine which variables…
Lauren S
  • 27
  • 4
0
votes
2 answers

Map a list to a value with non commutative function in haskell

Hello I have a function foo (Int -> Int -> Int) in haskell and I want to map each element of a list [1..y] to a value x which I would usually do like this: map (foo x) [1..y] the problem is my function is not commutative so what I actually want to…
CoffeeKid
  • 123
  • 5
0
votes
1 answer

JavaScript commutative behavior for function call. Needed pointers for what exactly happens behind scenes

I have following code and want to check commutative property with impure functions. Can anyone explain why the first two console log print 3, 3 and why the direct function call print 3 and -3? var multi = 1; const f = x =>{ multi = -multi; …
0
votes
1 answer

Force SymPy symbols to not commute with matrices

I'm using SymPy to solve a linear system of equations of matrices. However, I'm not using SymPy's MatrixSymbol object because it doesn't seem to play nice with solve_linear_system. So instead I'm just using normal symbols with commutative=False,…
0
votes
0 answers

Avoiding commutative duplicates in MongoDB

Background I am using a MongoDB database to build a medical application, where drug information is stored. There are a few collections in this database, and one of them is for pairwise drug interactions. The data provided to me is on a per drug…
Chthonic Project
  • 8,216
  • 1
  • 43
  • 92
0
votes
1 answer

Does the order of inputs matter in MATLAB functions?

I have a function called f(x,y), which returns 1 when both x = -1 and y = 1, and 0 otherwise. I want to apply it on every pair of the same column elements of a matrix. I want to know if I have to repeat it the other way? or does it work the same…
Free Soul
  • 81
  • 1
  • 2
  • 9
0
votes
1 answer

non-commutative combination of two byte arrays

If I want to combine two numbers (Int,Long,...) n1,n2in a non-commutative way, p*n1 + n2 where p is an arbitrary prime seems reasonable enough a choice. As many hashing options return a byte array, though, I am now trying to substitute the numbers…
User1291
  • 7,664
  • 8
  • 51
  • 108
0
votes
2 answers

Is there a way to use commutative encryption in php?

I have used the encrypt and decrypt functions from this answer to implement message passing using Three-pass protocol with the Blowfish cipher. And I tried using commutative ecryption/decryption. That is, $tmp = encrypt($input, $key1); $tmp =…
Xpleria
  • 5,472
  • 5
  • 52
  • 66
0
votes
2 answers

Solving equations with an associative and commutative operator

Consider a goal like this in Isabelle (and don’t worry about ccProd and ccFromList): ccProd {x} (set xs) ⊔ (ccProd {x} (set ys) ⊔ (ccFromList xs ⊔ (ccFromList ys ⊔ ccProd (set xs) (set ys)))) = ccProd {x} (set xs) ⊔ (ccFromList xs ⊔ (ccFromList ys ⊔…
Joachim Breitner
  • 25,395
  • 6
  • 78
  • 139
0
votes
1 answer

invalid subscript: physics and commutators in maple17

I tried the following based on the first example in the maple 17 help for "Physics[Commutator]". anybody know what's wrong? with(Physics); Setup(mathematicalnotation = true); e1:=[Z[1],Z[2]][-]; Error, invalid subscript …
juggler
  • 319
  • 1
  • 5
  • 16