SciProgCentre / kmath

Kotlin mathematics extensions library
656 stars 55 forks source link

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

Open CommanderTvis opened 4 years ago

CommanderTvis commented 4 years ago

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.

Shimuuar commented 4 years ago

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.

altavir commented 4 years ago

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).

CommanderTvis commented 4 years ago

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.

altavir commented 4 years ago

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

CommanderTvis commented 4 years ago

@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
}