bugGNU Octave - Bugs: bug #65032, [Octave Forge] (Symbolic) @sym/qr...

 
 

bug #65032: [Octave Forge] (Symbolic) @sym/qr outputs q1 of q=[q1 q2]

Submitter:  Liang Tang <lt1234>
Submitted:  Thu 14 Dec 2023 01:51:27 PM UTC
   
 
Category:  Octave Forge Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Matlab Compatibility
Status:  None Assigned to:  None
Originator Name:  lt1234 Open/Closed:  * Open
Release:  * 8.2.0 Operating System:  * Microsoft Windows
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Thu 14 Dec 2023 03:52:05 PM UTC, comment #1: 

Maybe consider reporting to the developers of the symbolic package:
https://github.com/gnu-octave/symbolic/issues

I don't think Octave can do anything to change the behavior of the symbolic package in that respect.

Markus M├╝tzel <mmuetzel>
Group administrator
Thu 14 Dec 2023 01:51:27 PM UTC, original submission:  

Hi,

There is no Octave compatibility option for me to pick for reporting.  Therefore I picked the matlab compatibility instead. 

@sym/qr clearly documents the differences of @sym/qr compared to Octave/qr. [q r]=@sym/qr(A) behaves the same as Octave [q r] = qr(A, 'econ').  There is no input argument for @sym/qr to force @sym/qr to output the full q=[q1 q2].  Effectively, for numeric variables, @sym/qr output is a subset of Octave qr. 

By reading the documentation, matlab qr and matlab symbolic qr appear to be equivalent in syntax. It is also known that Octave/qr and Matlab/qr are compatible. That leaves @sym/qr inconsistent in definition and output, i.e., same inputs but different (or subset of) results.

@sym/qr returns the q equivalent to the q of qr with 'econ' argument. There is no option to output the full q matrix. 
sympy 1.12 documentation page 1330 states the same limitation.  So the 'econ' limitation is at sympy, not the symbolic package. 

sympy recommends post process the symbolic q1 of the q=[q1 q2] for the full q.  There are three items to note:

(1) sympy recommends Gram-Schmidt but I can not identify the availability of symbolic Gram-Schmidt in the symbolic package.  I think Gram-Schmidt is a method of sympy matrix object,
similar to a method of an Octave class.  Since I have not found any mean to access the GS method in @sym, with a m file, only numeric values from @sym/qr can be processed. 
(2) The null space of the input matrix A to qr is not unique.  Therefore the q2 of q=[q1 q2] from Octave/qr may not be reproduced.  In addition, I think both Octave and Matlab qr are built-in.  It is unclear to me for what a user can do. 
(3) Knowing the matrix null space is not unique, we also find null of @sym and null of Octave produce different results.  I may be able to replace Octave q2 with Octave null(A).  But the same cannot be done for @sym.  Mathematically both codes are correct but output values are different.   It is about compatibility, not incorrect results.   
      
I would like you to consider the following.  Thanks.   

(A) @sym/syntax: delete this option  -- Method on @sym: [Q, R] = qr (M). 
(B) @sym/syntax: modify this option  -- Method on @sym: R = qr (M), replaced with  @sym: R = qr (M, 0)
(C) Documentation:  If you agree with the deletion/modification, please update the text accordingly.   Give workaround for the full q if possible.
(D) Investigate the feasibility to implement the @sym/qr [Q, R] = qr (M) according to the definition of Octave [Q, R] = qr (M).


Example: 

% sym qr

ver('symbolic')
pkg load symbolic

% @sym/qr outputs q1 

A=sym('A'); A=[sym(1/sqrt(2)) 1/sqrt(2) 0]';
[q_s, r_s]=qr(A);

double(q_s), double(q_s)*double(q_s)',  double(q_s)'*double(q_s)

% Octave qr (full q)

[q r ]= qr([1/sqrt(2) 1/sqrt(2) 0]');

q, q*q' 

% Octave qr + econ = @sym/qr

[q_e r_e ]= qr([1/sqrt(2) 1/sqrt(2) 0]', 'econ');

q_e, q_e*q_e',  q_e'*q_e

%  @sym q1 + modified GS, per sympy

[q_G, r_G] = mgson([q(:,1)'; 1 2 3; 4 5 6]') ; % mgson (modofied GS) downloaded from github for demo purpose

%{
q_G = ...
  [-0.7071  -0.1622   0.6882;
   -0.7071   0.1622  -0.6882;
         0   0.9733   0.2294];
%}

q_G, q_G*q_G'

% this shows the difference for null (same null space uniqueness discussion)

[q r]=qr([1 2 3]'); q(:, 2:end), null([1 2 3]), null([sym('1') sym('2') sym('3')])
 

   

Liang Tang <lt1234>

 

(Note: upload size limit is set to 16384 kB, after insertion of the required escape characters.)

Attach Files:
   
   
Comment:
   

No files currently attached

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by mmuetzel (Posted a comment)
  • -email is unavailable- added by lt1234 (Submitted the item)
  •  

    There are 0 votes so far. Votes easily highlight which items people would like to see resolved in priority, independently of the priority of the item set by tracker managers.

    Only group members can vote.

     

    No changes have been made to this item

    Back to the top

    Powered by Savane 3.12.
    Corresponding source code