bugGNU Octave - Bugs: bug #51748, [octave forge] (symbolic) vpa...

 
 

bug #51748: [octave forge] (symbolic) vpa producing strange results

Submitter:  Luis Mendo <lmendo>
Submitted:  Mon 14 Aug 2017 09:59:26 AM UTC
   
 
Category:  Octave Package Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Inaccurate Result
Status:  Fixed Assigned to:  None
Originator Name:  Luis Mendo Open/Closed:  * Closed
Release:  * 4.2.1 Operating System:  * Any
Fixed Release:  None Planned Release:  None
* Mandatory Fields

Add a New Comment Rich Markup
   

Jump to the original submission

Tue 03 Jul 2018 06:05:09 AM UTC, comment #12: 

Yes, I think we can close this.

Colin Macdonald <cbm>
Thu 01 Feb 2018 02:21:36 AM UTC, comment #11: 

The original motivating example here now shows


>> vpa('(5^.5)^4',30)
warning: string expression involving decimals is dangerous, see "help vpa"
warning: called from
    vpa at line 119 column 7
ans = (sym) 25.0000000000000000000000000000


This is both a better answer and an appropriate warning suggesting that you don't do this. Can we consider this issue resolved?

Mike Miller <mtmiller>
Group Member
Mon 09 Oct 2017 09:00:20 PM UTC, comment #10: 

I posted this upstream https://github.com/sympy/sympy/issues/13425

As I said below, I don't really think there is a bug here.  Its more like: there is something you should not be doing (putting floats into vpa and expected more than 15 digits accuracy) but in some very specific cases (integer powers of two), we can nonetheless recover accuracy.

A better fix might be to have vpa look for decimal points in strings and raise a warning (like the rat warning in sym).

Colin Macdonald <cbm>
Sun 08 Oct 2017 10:45:15 PM UTC, comment #9: 

I'll do it and post the link back here...

Colin Macdonald <cbm>
Sun 08 Oct 2017 08:07:09 PM UTC, comment #8: 

I had looked briefly at the list of open issues on SymPy but I wasn't able to find one similar to this that is open or that had been reported. Colin, do you want to raise this with SymPy? If not I can do it.

Mike Miller <mtmiller>
Group Member
Sun 08 Oct 2017 05:07:22 PM UTC, comment #7: 

Mike: No, I haven't. I don't really feel I'm suited for that, due to my very limited Python/SymPy knowledge

Luis Mendo <lmendo>
Sun 08 Oct 2017 04:09:49 PM UTC, comment #6: 

Luis - have you discussed this with SymPy yet?

Mike Miller <mtmiller>
Group Member
Mon 14 Aug 2017 11:10:20 PM UTC, comment #5: 

This one is not wrong:

print(N((5**.5)**4, 30))


There python has done a floating point computation which we then ask to magically convert to 30 digits accuracy. That aint gonna happen: the computation was already done in lower precision.


The case with the string is less obvious:

print(N('(5^.5)^4', 30))


This depends on exactly what SymPy promises for string input to N.  I'm not sure what is promised (docs don't say you're supposed to pass strings to N at all) but what is done currently in practice is pass the input to `sympify` which will evaluate that expression (that is compute a double precision floating point).

Interestingly, one can do this:

&amp;amp;gt;&amp;amp;gt;&amp;amp;gt; N(sympify('(5^.5)^4', evaluate=False), 30)
25.0000000000000000000000000000

I'm not sure that would be a good change for SymPy or not: but as Mike as said, that's a discussion for upstream.

Colin Macdonald <cbm>
Mon 14 Aug 2017 03:56:14 PM UTC, comment #4: 

Yeah, sorry, I thought there was a difference between Octave's and Sympy's results, but actually they are the same (and wrong)

Luis Mendo <lmendo>
Mon 14 Aug 2017 03:43:25 PM UTC, comment #3: 

So this looks like something you may want to get improved in SymPy? Please link to a SymPy issue tracker if so, or we can mark this as won't fix.

Mike Miller <mtmiller>
Group Member
Mon 14 Aug 2017 01:09:43 PM UTC, comment #2: 

Sympy version with strings also gives wrong results (sorry for so many messages). So Octave does the same as Sympy.


from sympy import *
print(N('(5^.5)^4', 30))


gives


25.0000000000000035527136788005


Luis Mendo <lmendo>
Mon 14 Aug 2017 01:00:27 PM UTC, comment #1: 

Sorry, I forgot the relevant Sympy case. It works the same as Octave:


from sympy import *
print(N((5**.5)**4, 30))


gives


25.0000000000000035527136788005


Luis Mendo <lmendo>
Mon 14 Aug 2017 09:59:26 AM UTC, original submission:  

Running these statements in Octave


vpa('5^2',30)
vpa('sqrt(5)^4',30)
vpa('.5',30)
vpa('(5^.5)^4',30)


produces the following results, the fourth of which is not correct:


ans = (sym) 25.0000000000000000000000000000
ans = (sym) 25.0000000000000000000000000000
ans = (sym) 0.500000000000000000000000000000
ans = (sym) 25.0000000000000035527136788005


This is strange, specially considering that .5 is represented exactly as a float (see third statement).

For reference, SymPy produces the correct result:


from sympy import *
print(N(sqrt(5)**4, 30))
print(N(5**2, 30))


gives


25.0000000000000000000000000000
25.0000000000000000000000000000


Luis Mendo <lmendo>

 

(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 cbm (Posted a comment)
  • -email is unavailable- added by mtmiller (Posted a comment)
  • -email is unavailable- added by jwe (Updated the item)
  • -email is unavailable- added by andy1978 (Updated the item)
  • -email is unavailable- added by lmendo (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.

     

    Follow 11 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-07-06 andy1978 StatusReady For Test Fixed
        Open/ClosedOpen Closed
    2018-07-02 jwe Summary[octave-forge] (symbolic) vpa producing strange results [octave forge] (symbolic) vpa producing strange results
    2018-02-01 mtmiller StatusNeed Info Ready For Test
    2017-08-14 mtmiller CategoryOctave Function Octave Package
        StatusNone Need Info
    2017-08-14 andy1978 CategoryOctave Package Octave Function
        Summary[octave forge] (symbolic) vpa producing strange results [octave-forge] (symbolic) vpa producing strange results
    2017-08-14 jwe CategoryOctave Function Octave Package
        Summary[octave-forge] (symbolic) vpa producing strange results [octave forge] (symbolic) vpa producing strange results
    2017-08-14 andy1978 Summaryvpa producing strange results [octave-forge] (symbolic) vpa producing strange results

    Back to the top

    Powered by Savane 3.13-02a9.
    Corresponding source code