This problem can be seen clearly if we use *Matrix_generic_dense* as element class for matrix space.
On Tuesday, March 26, 2024 at 9:42:45 PM UTC+5:30 Animesh Shree wrote: > I was going through this code and got error. But I could not understand > why this is the case. > > > > > sage: T = TropicalSemiring(QQ) > sage: T(1) > 1 > sage: T(2) > 2 > sage: T(-2) > -2 > sage: -T(2) > --------------------------------------------------------------------------- > ArithmeticError Traceback (most recent call last) > Cell In[26], line 1 > ----> 1 -T(Integer(2)) > > File ~/sage/src/sage/rings/semirings/tropical_semiring.pyx:278, in > sage.rings.semirings.tropical_semiring.TropicalSemiringElement.__neg__() > 276 if self._val is None: > 277 return self > --> 278 raise ArithmeticError("cannot negate any non-infinite element") > 279 > 280 cpdef _mul_(left, right) noexcept: > > ArithmeticError: cannot negate any non-infinite element > sage: > > > It looks like starting with T(-2) and reaching to -2 from T(2) by > comparing with zero(+Inf) are different things. > T(-2) = -2 > T(2) -T(2) = T.zero(+inf) = T(2) + (-T(2)) > > My doubt is : if we cannot negate the elements, then how can we compute > the determinant of a Matrix over Tropical Semiring. > For example in 2x2 matrix : [[a,b], [c,d]] the determinant should be ad - > bc > But can it be expressed as ad + (-bc) -->> min ( add(a,d), -1*add(b,c) )? > > In fact we connot even do matrix subtraction directly. > What can be done in these cases?? > On Thursday, March 21, 2024 at 8:48:26 PM UTC+5:30 Animesh Shree wrote: > >> Hello Sir, >> >> I have submitted my proposal. >> Please review it and let me know necessary updates and improvements. >> >> I want to verify soundness of my approach and extend the proposal for >> Multivariate Polynomials. >> >> Thank You >> Animesh Shree >> On Tuesday, March 12, 2024 at 12:26:38 AM UTC+5:30 tcscrims wrote: >> >>> Mathematically speaking, you can always weaken axioms. However, there >>> are some extra advantages that additive groups have that commutative >>> semirings don't have (mainly 0, the additive identity). >>> >>> That being said, there isn't anything prevent you from constructing the >>> appropriate categories. It would be good to have a more specific use-case >>> in mind, but that isn't necessary. However, one should be careful with the >>> name because it would conflict with what "most" people would call an >>> algebra (which is why we have MagmaticAlgebras). >>> >>> Best, >>> Travis >>> >>> >>> On Tuesday, March 12, 2024 at 2:57:29 AM UTC+9 anime...@iiits.in wrote: >>> >>>> Hello Sir, >>>> >>>> I was going through "Algebras" and I had a doubt. >>>> Does MagmaticAlgebra and AssociativeAlgebra have to be implemented over >>>> Ring only? >>>> I went through internet and google uses rings to define those algebras, >>>> but the axioms that those algebra follow (Unital, Associative) are also >>>> preserved by commutative semirings. >>>> Would it be good to define MagmaticAlgebra and AssociativeAlgebra over >>>> other objects that follow those axioms too or come-up with alternative >>>> Algebra? >>>> >>> -- You received this message because you are subscribed to the Google Groups "sage-gsoc" group. To unsubscribe from this group and stop receiving emails from it, send an email to sage-gsoc+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/sage-gsoc/79a222b3-2d35-4309-81ba-9c4f68f51247n%40googlegroups.com.
sage: T = TropicalSemiring(QQ) sage: m = MatrixSpace(T, 2); m Full MatrixSpace of 2 by 2 dense matrices over Tropical semiring over Rational Field sage: m.element_class <class 'sage.matrix.matrix_generic_dense.Matrix_generic_dense'> sage: sage: sage: sage: sage: ele = m.an_element() sage: ele [6/5 6/5] [6/5 6/5] sage: ele2 = m([[1,2],[3,4]]) sage: ele2 [1 2] [3 4] sage: ele + ele2 [ 1 6/5] [6/5 6/5] sage: sage: sage: sage: sage: ele - ele2 # =============================================== Error 1 of 2 =============================================== --------------------------------------------------------------------------- ArithmeticError Traceback (most recent call last) Cell In[27], line 1 ----> 1 ele - ele2 File ~/sage/src/sage/structure/element.pyx:1345, in sage.structure.element.Element.__sub__() 1343 cdef int cl = classify_elements(left, right) 1344 if HAVE_SAME_PARENT(cl): -> 1345 return (<Element>left)._sub_(right) 1346 if BOTH_ARE_ELEMENT(cl): 1347 return coercion_model.bin_op(left, right, sub) File ~/sage/src/sage/matrix/matrix_generic_dense.pyx:255, in sage.matrix.matrix_generic_dense.Matrix_generic_dense._sub_() 253 res._entries = [None]*(self._nrows*self._ncols) 254 for k in range(self._nrows*self._ncols): --> 255 res._entries[k] = self._entries[k] - other._entries[k] 256 return res 257 File ~/sage/src/sage/structure/element.pyx:1345, in sage.structure.element.Element.__sub__() 1343 cdef int cl = classify_elements(left, right) 1344 if HAVE_SAME_PARENT(cl): -> 1345 return (<Element>left)._sub_(right) 1346 if BOTH_ARE_ELEMENT(cl): 1347 return coercion_model.bin_op(left, right, sub) File ~/sage/src/sage/structure/element.pyx:1382, in sage.structure.element.Element._sub_() 1380 raise bin_op_exception('-', self, other) 1381 else: -> 1382 return python_op(other) 1383 1384 def __neg__(self): File ~/sage/src/sage/categories/additive_magmas.py:826, in AdditiveMagmas.AdditiveUnital.ElementMethods._sub_(left, right) 807 def _sub_(left, right): 808 r""" 809 Default implementation of difference. 810 (...) 824 (0, 0) 825 """ --> 826 return left + (-right) File ~/sage/src/sage/rings/semirings/tropical_semiring.pyx:278, in sage.rings.semirings.tropical_semiring.TropicalSemiringElement.__neg__() 276 if self._val is None: 277 return self --> 278 raise ArithmeticError("cannot negate any non-infinite element") 279 280 cpdef _mul_(left, right) noexcept: ArithmeticError: cannot negate any non-infinite element sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: sage: ele.determinant() # =============================================== Error 2 of 2 =============================================== --------------------------------------------------------------------------- ArithmeticError Traceback (most recent call last) Cell In[28], line 1 ----> 1 ele.determinant() File ~/sage/src/sage/matrix/matrix2.pyx:2130, in sage.matrix.matrix2.Matrix.determinant() 2128 d = self.get_unsafe(0, 0) 2129 elif n == 2: -> 2130 d = self.get_unsafe(0, 0)*self.get_unsafe(1, 1) - self.get_unsafe(1, 0)*self.get_unsafe(0, 1) 2131 elif n == 3: 2132 d = self.get_unsafe(0, 0) * (self.get_unsafe(1, 1)*self.get_unsafe(2, 2) - self.get_unsafe(1, 2)*self.get_unsafe(2, 1)) \ File ~/sage/src/sage/structure/element.pyx:1345, in sage.structure.element.Element.__sub__() 1343 cdef int cl = classify_elements(left, right) 1344 if HAVE_SAME_PARENT(cl): -> 1345 return (<Element>left)._sub_(right) 1346 if BOTH_ARE_ELEMENT(cl): 1347 return coercion_model.bin_op(left, right, sub) File ~/sage/src/sage/structure/element.pyx:1382, in sage.structure.element.Element._sub_() 1380 raise bin_op_exception('-', self, other) 1381 else: -> 1382 return python_op(other) 1383 1384 def __neg__(self): File ~/sage/src/sage/categories/additive_magmas.py:826, in AdditiveMagmas.AdditiveUnital.ElementMethods._sub_(left, right) 807 def _sub_(left, right): 808 r""" 809 Default implementation of difference. 810 (...) 824 (0, 0) 825 """ --> 826 return left + (-right) File ~/sage/src/sage/rings/semirings/tropical_semiring.pyx:278, in sage.rings.semirings.tropical_semiring.TropicalSemiringElement.__neg__() 276 if self._val is None: 277 return self --> 278 raise ArithmeticError("cannot negate any non-infinite element") 279 280 cpdef _mul_(left, right) noexcept: ArithmeticError: cannot negate any non-infinite element