Giter Club home page Giter Club logo

Comments (20)

thofma avatar thofma commented on June 3, 2024

What to do you mean by "now"? I did not observe a change to divrem in julia.

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

I actually have no memory of writing this (though clearly I did).

But I assume divrem is defined as per rem, i.e. the % operator in C, which does not give the positive modulus, as we define it in Nemo. Therefore if you have negative values, divrem with Nemo ZZ will give a different answer than if you use BigInt's in Julia. This means AA will give a different answer to Nemo.

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

I cannot follow. They give the same answer. Do you have an example?

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

I guess what I mean is, when we type divrem, we currently mean Euclidean division. But Julia does not give that. Therefore, we should instead use divmod in Nemo and make it return the right thing, instead of what Julia (and apparently Nemo), currently return.

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

I don't see the problem. We currently have divrem(x, y) = div(x, y), rem(x, y) for Int, BigInt and fmpz. What we return is a valid Euclidean divsion. I don't see the point of changing rem and introducing yet another function for division.

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

Sorry, yes there would be not change to rem.

Currently mod(2, 5) and mod(-3, 5) return the same result.

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

I think we have been bitten by this before (divrem not yielding something positive as the second argument) and I see how divmod would help with this. I would like to hear what @fieker thinks.

So the proposal is to introduce divmod, which would be the same as divrem for polynomial rings, but would always return a positive remainder for integers.

from abstractalgebra.jl.

fieker avatar fieker commented on June 3, 2024

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

I just did some more testing and searching and here is what I found out.

  1. Let's first look at %, mod and rem. There is no way we can be consistent with julia:
  • julias mod is not the same as our mod: mod(x, y) will always have the same sign as y, that is,
    mod(1, -2) = -1. On the other hand, for fmpz mod(x, y) is always positive.
  • % is just an alias for rem.
  1. More worrying is the following: Very often one needs a div(x, y) such that x - div(x, y) * y = mod(x, y). Think for example of reduction of a row in the Hermite form algorithm. At the moment, div(x, y) and divrem(x, y) won't give you such a division. Consequently you will find something like https://github.com/thofma/Hecke.jl/blob/c3e395397d4a5d890446b40ef477e85870fab793/src/Sparse/HNF.jl#L369-L374

I don't see a clear way forward. I don't mind too much about 1), but 2) is very annoying.

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

fieker avatar fieker commented on June 3, 2024

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

from abstractalgebra.jl.

thofma avatar thofma commented on June 3, 2024

No, it is not true that julias mod and rem are the same.

julia> rem(3, -2)
1

julia> mod(3, -2)
-1

Same for BigInt.

from abstractalgebra.jl.

wbhart avatar wbhart commented on June 3, 2024

The original ticket here is no longer valid. And we are basically doing this optimally, with our own internal hacked versions of div and divrem defined in terms of mod not rem. It's not possible to do better without breaking HNF and ResidueRing/Field.

from abstractalgebra.jl.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.