Although both behaviors may be reasonable, I don't like the fact that each 
line of the following code gives a completely different result depending on 
whether F = RR (returns a result that may be garbage, without warning) or F 
= RDF (gives an error, even though there may be a valid solution).  My own 
preference for default behavior (for F = RR, at least, which is where I 
think a naive user is likely to be working) is intermediate between these 
two, and is what I think MATLAB does: return a result but give a warning. 

sage: matrix(F, [[0]]).solve_right(vector(F, [0]))
sage: matrix(F, [[0]]).solve_right(vector(F, [1]))

Along these lines, I note that the code for 
`Matrix_generic_dense.solve_right` has

try:
    X = self._solve_right_nonsingular_square(C, check_rank=True)
except NotFullRankError:
    X = self._solve_right_general(C, check=check)

It seems to me that the except clause would be a good place to put a 
warning message over inexact rings. However, I know nothing about numerical 
analysis (and not much about sage), so I am certainly not giving an expert 
opinion on anything in this discussion, just the viewpoint of this sage 
user, and I apologize if it is noise.

On Saturday, May 23, 2020 at 12:30:56 PM UTC-6, Markus Wageringel wrote:
>
> Indeed, instead of ignoring the `check` keyword altogether over inexact 
> fields, it would be useful to verify the solution when that is possible, 
> such as for exact input over SR and for ball and intervall fields. I have 
> opened #29729 <https://trac.sagemath.org/ticket/29729> for this. For 
> general inexact rings though, the result cannot be verified, so it would 
> not make sense to do the check by default.
>
>
> Am Samstag, 23. Mai 2020 07:15:45 UTC+2 schrieb Dave Morris:
>>
>> From the documentation at 
>> https://www.mathworks.com/help/matlab/ref/mldivide.html, it appears to 
>> me that MATLAB gives a warning: "Warning: Matrix is close to singular or 
>> badly scaled. Results may be inaccurate."  That seems to me to be a better 
>> default behavior than what sage is doing now, but I think it would make 
>> sense to let users choose to turn off the warning (and maybe also let them 
>> upgrade it to an error).
>>
>
>  The generic implementation of `solve_right` does not provide this. I 
> would suggest to use a type that has a specialized implementation for this, 
> such as RDF, CDF, CBF. For example over RDF and CDF, a warning is issued if 
> the input is ill-conditioned and an error is raised if the matrix is 
> singular, which is a reasonable behavior:
>
> sage: matrix(RDF, [[2/3, 1], [0.4, 0.6]]).solve_right(vector(RDF, [1, 1]))
> /Applications/SageMath/src/bin/sage-ipython:1: LinAlgWarning: Ill-conditioned 
> matrix (rcond=2.77556e-17): result may not be accurate.
>   #!/usr/bin/env sage-python
> (5404319552844596.0, -3602879701896396.0)
> sage: matrix(RDF, [[0]]).solve_right(vector(RDF, [1]))
> ...
> LinAlgError: Matrix is singular.
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"sage-devel" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to sage-devel+unsubscr...@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/sage-devel/748c6d4f-bb2d-4c44-92c5-ddffbb02b475%40googlegroups.com.

Reply via email to