kmath icon indicating copy to clipboard operation
kmath copied to clipboard

No floored division and modulo operations in IntRing, ShortRing, ByteRing and LongRing

Open CommanderTvis opened this issue 5 years ago • 5 comments

There are no div and mod operations in integer typed rings. They have some use cases in basic arithmetics, so I think, integer algebra is inconsistent without them.

CommanderTvis avatar Jun 11 '20 18:06 CommanderTvis

I'm not sure how faithful kmath about algebra abstractions. But rings don't have division. You'll get field if you want to add division.

Also while it's possible to define Field for word32/word64. Its division is completely different from usual rounded down division.

Shimuuar avatar Jun 11 '20 19:06 Shimuuar

Those operations are not a part of Ring definition. We can add them if it is possible to implement them relying only on basic arithmetic operations. Otherwise, they could be added to short and int rings directly (but it does not make a lot of sense since ints and shorts already have them).

altavir avatar Jun 11 '20 19:06 altavir

Those operations are not a part of Ring definition. We can add them if it is possible to implement them relying only on basic arithmetic operations. Otherwise, they could be added to short and int rings directly (but it does not make a lot of sense since ints and shorts already have them).

It does. For example, for adv-expr Expressions API: binaryOperation("mod", a, b). Without algebra-supported operations, mod and div are simply unaccessible.

CommanderTvis avatar Jun 12 '20 08:06 CommanderTvis

@Shimuuar Ring does not have division. It has only multiplication.

altavir avatar Jun 12 '20 10:06 altavir

@Shimuuar Ring does not have division. It has only multiplication.

I suggest introducing new interface, something like:

interface DivisionWithRemainder<T> : RingOperations<T> {
  fun mod(T, T): T
  fun div(T, T): T
}

CommanderTvis avatar Jun 13 '20 16:06 CommanderTvis