AbstractAlgebra.jl icon indicating copy to clipboard operation
AbstractAlgebra.jl copied to clipboard

support for derivations?

Open tthsqe12 opened this issue 4 years ago • 9 comments

Suppose we construct something like this

julia> using AbstractAlgebra

julia> R, (a, b, c) = QQ["a", "b", "c"]; F = FractionField(R)
Fraction field of Multivariate Polynomial Ring in a, b, c over Rationals

julia> S, x = F["x"]
(Univariate Polynomial Ring in x over Fraction field of Multivariate Polynomial Ring in a, b, c over Rationals, x)

julia> matrix(S, [a//b*x 1; 1 0])
[a//b*x   1]
[     1   0]

now suppose I would like to differentiate this wrt b and get the answer [-a//b^2*x 0; 0 0]. It is currently not possible to do this directly, right?

How about a Derivation type that can be passed as a second argument to derivative so that you would call something like derivative(ans, Derivation(R, a)) to get the thing that we all would want.

derivative(::RingElem, ::Derivation) would have to be supported by each ring (or an error message by default). How would a ring R support it? It would check if R is the base ring of the derivation and handle it directly, or else pass it on the base ring of R via the derivation rules.

I am bring this up because these kind of ad hoc derivatives are not sustainable in my opinion: https://github.com/Nemocas/AbstractAlgebra.jl/blob/master/src/generic/Fraction.jl#L670

tthsqe12 avatar Mar 16 '21 12:03 tthsqe12

On Tue, Mar 16, 2021 at 05:22:41AM -0700, tthsqe12 wrote:

Suppose we construct something like this

julia> using AbstractAlgebra

julia> R, (a, b, c) = QQ["a", "b", "c"]; F = FractionField(R)
Fraction field of Multivariate Polynomial Ring in a, b, c over Rationals

julia> S, x = F["x"]
(Univariate Polynomial Ring in x over Fraction field of Multivariate Polynomial Ring in a, b, c over Rationals, x)

julia> matrix(S, [a//b*x 1; 1 0])
[a//b*x   1]
[     1   0]

now suppose I would like to differentiate this wrt b and get the answer [-a//b^2*x 0; 0 0]. It is currently not possible to do this directly, right? map_entries(x->derivative(x, b), ans) should do the job.

The question is two-fold

  • do we wat derivations (and differentials and such): yes
  • how do we want to extend them to matrices?

How about a Derivation type that can be passed as a second argument to derivative so that you would call something like derivative(ans, Derivation(R, a)) to get the thing that we all would want.

derivative(::RingElem, ::Derivation) would have to be supported by each ring (or an error message by default). How would a ring R support it? It would check if R is the base ring of the derivation and handle it directly, or else pass it on the base ring of R via the derivation rules.

I am bring this up because these kind of ad hoc derivatives are not sustainable: https://github.com/Nemocas/AbstractAlgebra.jl/blob/master/src/generic/Fraction.jl#L670

-- You are receiving this because you are subscribed to this thread. Reply to this email directly or view it on GitHub: https://github.com/Nemocas/AbstractAlgebra.jl/issues/800

fieker avatar Mar 16 '21 12:03 fieker

julia> map_entries(x->derivative(x, b), ans)
ERROR: MethodError: no method matching derivative(::AbstractAlgebra.Generic.Poly{AbstractAlgebra.Generic.Frac{AbstractAlgebra.Generic.MPoly{Rational{BigInt}}}}, ::AbstractAlgebra.Generic.MPoly{Rational{BigInt}})

tthsqe12 avatar Mar 16 '21 12:03 tthsqe12

On Tue, Mar 16, 2021 at 05:57:37AM -0700, tthsqe12 wrote:

julia> map_entries(x->derivative(x, b), ans)
ERROR: MethodError: no method matching derivative(::AbstractAlgebra.Generic.Poly{AbstractAlgebra.Generic.Frac{AbstractAlgebra.Generic.MPoly{Rational{BigInt}}}}, ::AbstractAlgebra.Generic.MPoly{Rational{BigInt}})

Sorry - I missed the poly ring. What is the definition if extenion of derivations?


-- 
You are receiving this because you commented.
Reply to this email directly or view it on GitHub:
https://github.com/Nemocas/AbstractAlgebra.jl/issues/800#issuecomment-800235810

fieker avatar Mar 16 '21 13:03 fieker

Maybe the derivation constructor needs a bit more sophistication. Maybe @raulepure has some ideas?

tthsqe12 avatar Mar 16 '21 13:03 tthsqe12

@tthsqe12 does want to call derivation on the coefficients of the polynomials, so something like

map_entries(f -> map_coeffs(z -> derivative(z, b), f), mat)

In a polynomial ring F[x], there is only one derivation, namely the one using x. I don't think we want to treat F[x] as a multivariate polynomial ring if F happens to be a polynomial ring (or something similar).

thofma avatar Mar 16 '21 14:03 thofma

@thofma since my point is getting obfuscated I will avoid the use of the word derivation from now on.

julia> R, (a, b, c) = QQ["a", "b", "c"]; S, x = PolynomialRing(R, "x"); F = FractionField(S);
julia> f = (a*x+b)//(c*x+a)
julia> derivative(f)
(a^2 - b*c)//(c^2*x^2 + 2*a*c*x + a^2)
julia> derivative(f, x)
ERROR: MethodError
julia> derivative(f, a)
ERROR: MethodError

It is the intention to never have these derivatives work because "there is only one derivation"?

tthsqe12 avatar Mar 16 '21 14:03 tthsqe12

In this setup one has to specify which derivation one wants, i.e. over which base field. In the example above one should be able to differentiate with respect to a, b, or c too.

raulepure avatar Mar 16 '21 16:03 raulepure

Why was your point getting obfuscated? This is just about having a nice way to turn maps on F to maps on F[x] by applying it to each coefficient. This is what map_coefficients is doing. Then you want to turn a map on F into a map on matrices over F by applying the map to each entry. This is what map_entries is doing. I don't see why derivatives are special. But of course we can try to make them special.

thofma avatar Mar 17 '21 09:03 thofma

Take my last example so that we don't have the map_entries confusion. Currently in order to do derivative(f,a), we are foisting the following error prone mess on users:

julia> (map_coeffs(p->derivative(p,a), numerator(f))*denominator(f)-map_coeffs(p->derivative(p,a), denominator(f))*numerator(f))//denominator(f)^2
(c*x^2 - b)//(c^2*x^2 + 2*a*c*x + a^2)

I know we don't have any complaint from users, but can't imagine anyone being satisfied with this.

tthsqe12 avatar Mar 17 '21 11:03 tthsqe12