Vector/matrix equations

29 views
Skip to first unread message

Emmanuel Charpentier

unread,
Jun 25, 2024, 3:08:59 AM (8 days ago) Jun 25
to sage-devel

Inspired by this ask.sagemath question :

sage: V=vector(var("v", n=2)) sage: W=vector(var("w", n=2)) sage: V==W False

This is expected from a (Python) programmer’s point of view, but the mathematician could expect something like :

sage: from _operator import eq sage: vector(map(eq, V, W)) (v0 == w0, v1 == w1)

Similarly,

sage: A=matrix(var("a", n=4), nrows=2) sage: B=matrix(var("b", n=4), nrows=2) sage: A==B False

where

sage: matrix(map(lambda u, v:map(eq, u, v), A, B)) [a0 == b0 a1 == b1] [a2 == b2 a3 == b3]

could be expected.

Are there (good or bad) reasons not to implement such vector/matrix equalities ?

Emmanuel Charpentier

unread,
Jun 25, 2024, 3:17:48 AM (8 days ago) Jun 25
to sage-devel

FWIW, “the competition” implements this :

Wolfram Language 14.0.0 Engine for Linux x86 (64-bit) Copyright 1988-2023 Wolfram Research, Inc. In[1]:= A={{a0, a1}, {a2, a3}} Out[1]= {{a0, a1}, {a2, a3}} In[2]:= B={{b0, b1}, {b2, b3}} Out[2]= {{b0, b1}, {b2, b3}} In[3]:= A==B Out[3]= {{a0, a1}, {a2, a3}} == {{b0, b1}, {b2, b3}} In[4]:= Flatten[A] Out[4]= {a0, a1, a2, a3} In[5]:= Solve[A==B, Flatten[B]] Out[5]= {{b0 -> a0, b1 -> a1, b2 -> a2, b3 -> a3}}
Reply all
Reply to author
Forward
0 new messages