Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improve solve_right for some inexact rings #29729

Open
mwageringel opened this issue May 23, 2020 · 15 comments
Open

improve solve_right for some inexact rings #29729

mwageringel opened this issue May 23, 2020 · 15 comments

Comments

@mwageringel
Copy link

Since #12406, the check keyword to solve_right is ignored over all inexact rings. As discussed on sage-devel, this is a bit too drastic, as the solution can be checked for correctness in some cases.

Over SR, we can check if all entries are exact and then check whether the solution is correct. This was done in #33159.

Over ball and interval fields, we can check the error bounds to determine whether the result is valid.

sage: matrix(RIF, [[2/3, 1], [2/5, 3/5]]).solve_right(vector(RIF, [1, 1]))  # this solution is acceptable
([-infinity .. +infinity], [-infinity .. +infinity])
sage: matrix(RIF, [[0]]).solve_right(vector(RIF, [1]))  # this is not
(0)

CC: @aghitza @nbruin

Component: linear algebra

Branch/Commit: u/mjo/ticket/29729 @ 22efbc6

Issue created by migration from https://trac.sagemath.org/ticket/29729

@orlitzky
Copy link
Contributor

comment:1

Here's a proof-of-concept (not well tested) for SR.


New commits:

adeb978Trac #29729: add special case to solve_right() for symbolic systems.

@orlitzky
Copy link
Contributor

Branch: u/mjo/ticket/29729

@orlitzky
Copy link
Contributor

Commit: adeb978

@orlitzky
Copy link
Contributor

comment:2

The SR proof-of-concept passes a ptestlong, at least.

As for the ball/interval fields: half of the problem with RBF is that we have a dedicated implementation of _solve_right_nonsingular_square for complex ball matrices, but not for RBF ones. Thus we miss out on the work that the arb library has already done for these systems. Compare:

sage: A = matrix(RBF, [[2/3, 1], [2/5, 3/5]])
sage: b = vector(RBF, [1, 1])
sage: A.solve_right(b)
(nan, nan)

sage: A = A.change_ring(CBF)
sage: b = b.change_ring(CBF)
sage: A.solve_right(b)
...
ValueError: unable to invert this matrix

(Note: we should catch that exception and turn it into a NotFullRankError).

For the generic interval solve/check, as a first approximation, maybe we could multiply A*x and check that each component thereof intersects the corresponding component (interval) of b. That's as opposed to the default "check" implementation using literal equality that would fail. This needs an expert opinion as my understanding of interval systems is only wikipedia-deep.

@orlitzky
Copy link
Contributor

comment:3

It might also be a good idea to factor out the solution check into a separate method, that way we don't have to override all of _solve_right_general for interval matrices just to replace the strict-equality check.

@mwageringel
Copy link
Author

comment:4

Replying to @orlitzky:

(Note: we should catch that exception and turn it into a NotFullRankError).

The NotFullRankError is currently only used internally for control flow, so we should only raise it if we want _solve_right_general to be tried when _solve_right_nonsingular_square fails, in the case of CBF.

For the generic interval solve/check, as a first approximation, maybe we could multiply A*x and check that each component thereof intersects the corresponding component (interval) of b. That's as opposed to the default "check" implementation using literal equality that would fail. This needs an expert opinion as my understanding of interval systems is only wikipedia-deep.

The literal equality check seemingly works with ball/interval arithmetics. Though, this is probably just a coincidence. If vector equality is implemented by checking whether not any entries are different (as opposed to all entries being equal), for ball fields this means it is checked that no entries are disjoint balls, hence they must intersect.

sage: A = matrix(RBF, [[2/3, 1], [2/5, 3/5]])
sage: b = vector(RBF, [1, 1])
sage: x = A.solve_right(b)
sage: A * x == b
True

However, it would be more correct to check that every entry of b, as a ball/interval, is fully contained in the corresponding entry of A * x:

sage: all(u in v for u, v in zip(b, A*x))
True

I am not very familiar with interval arithmetics either, though.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2020

Branch pushed to git repo; I updated commit sha1. New commits:

22efbc6Trac #29729: new subclass for RealBallField matrices.

@sagetrac-git
Copy link
Mannequin

sagetrac-git mannequin commented May 30, 2020

Changed commit from adeb978 to 22efbc6

@orlitzky
Copy link
Contributor

comment:6

That last commit should fix the square/nonsingular issue but probably needs some polish.

@orlitzky
Copy link
Contributor

comment:7

Replying to @mwageringel:

The NotFullRankError is currently only used internally for control flow, so we should only raise it if we want _solve_right_general to be tried when _solve_right_nonsingular_square fails, in the case of CBF.

If we can make check=True work, I think that's what we want. I'm imagining a square system with exact real entries (like powers of two) and then some extra redundant rows tacked onto the end. If the generic solver can eliminate those junk rows and if check=True can make sure we don't wind up with a wrong answer... well first we need to make check=True work, and then I can just try it.

The literal equality check seemingly works with ball/interval arithmetics. Though, this is probably just a coincidence...
However, it would be more correct to check that every entry of b, as a ball/interval, is fully contained in the corresponding entry of A * x:

From what I gather, a solution to an interval system Ax = b should be an interval vector x such that for all x in x, there exists some A in A and b in b with Ax = b. So I don't think either suggestion is quite right; mine because Ax can wind up being larger than necessary, and thus too lenient if we intersect it with b. Yours I would imagine is too strict: if everything is nonnegative, we should be able to pair up the left endpoints of x with the left endpoints of A and b and not insist that the right endpoints of A and b work (for the left endpoints of x) as well.

@mwageringel
Copy link
Author

comment:8

Replying to @orlitzky:

From what I gather, a solution to an interval system Ax = b should be an interval vector x such that for all x in x, there exists some A in A and b in b with Ax = b.

This does not seem quite right to me, as then x could always be shrinkened to just a single point, thus reducing the error to 0.

In my naive understanding, as we do not know the exact values of A and b, the solution x of the system Ax = b should satisfy:

∀ *A*∈**A** ∀ *b*∈**b** ∃ *x*∈**x** such that *Ax* = *b*.

Given x and A, let me denote the product by y = Ax. Then y should contain the set

{ *y*∈ℝ<sup>n</sup> | ∃ *A*∈**A** ∃ *x*∈**x** : *Ax* = *y* }.

(In particular, this means that ∀ AAxxyy such that Ax = y.)

Since A is non-empty, we can fix an arbitrary AA. Now, given any bb, we find an xx satisfying Ax=b, and so by.

Therefore, under the above assumptions, it would be a necessary condition that b is contained in y.

@mwageringel
Copy link
Author

comment:9

Replying to @mwageringel:

In my naive understanding, as we do not know the exact values of A and b, the solution x of the system Ax = b should satisfy:

∀ *A*∈**A** ∀ *b*∈**b** ∃ *x*∈**x** such that *Ax* = *b*.

Come to think of it, this will never hold if A has more rows than columns (and not everything is exact), as then A and b can easily be chosen such that no solution exists.

@orlitzky
Copy link
Contributor

orlitzky commented Jun 2, 2020

comment:10

It looks like all of these definitions of a solution that we've been making up are valid in different contexts (see e.g. Interval linear systems as a necessary step in fuzzy linear systems by Lodwick and Dubois). However, since RBF is documented to be implemented with Arb and since square systems will be solved by Arb, we should probably use the same interpretation of "solution" that Arb uses. So far I've been unable to figure out what that is. I may have to ask on the mailing list.

@mkoeppe mkoeppe modified the milestones: sage-9.2, sage-9.3 Oct 24, 2020
@mkoeppe
Copy link
Contributor

mkoeppe commented Apr 7, 2021

comment:12

Sage development has entered the release candidate phase for 9.3. Setting a new milestone for this ticket based on a cursory review.

@mkoeppe mkoeppe modified the milestones: sage-9.3, sage-9.4 Apr 7, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.4, sage-9.5 Aug 10, 2021
@mkoeppe mkoeppe modified the milestones: sage-9.5, sage-9.6 Dec 18, 2021
@orlitzky

This comment has been minimized.

@mkoeppe mkoeppe modified the milestones: sage-9.6, sage-9.7 May 3, 2022
@mkoeppe mkoeppe removed this from the sage-9.7 milestone Sep 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants