bugGNU Octave - Bugs: bug #53434, isprime.m:missing error,warning...

 
 

bug #53434: isprime.m:missing error,warning for negative numbers

Submitted by:  Dildar Sk <hodor123456>
Submitted on:  Fri 23 Mar 2018 06:33:40 AM UTC  
 
Category:  Octave Function Severity:  3 - Normal
Priority:  5 - Normal Item Group:  Missed Error or Warning
Status:  None Assigned to:  None
Originator Name:  Dildar SK Open/Closed:  Closed
Release:  dev Operating System:  GNU/Linux

Add a New Comment (Rich Markup)
   

You are not logged in

Please log in, so followups can be emailed to you.

 

( Jump to the original submission)

Fri 23 Mar 2018 04:09:32 PM UTC, comment #7: 

Octave generally views itself as a superset of Matlab.  If an Octave function can do everything the equivalent Matlab function does, and also improve on it by operating on a larger input domain, then we choose that course.

It may be of use mostly to number theoreticians, but there is such a thing as "prime" for negative numbers so Octave implemented it.

The situation is not the same for the primes() function.  The implicit definition of primes() is the the list of primes from 1 to the input N.  If N is negative then the list is empty.  And for compatibility with Matlab, Octave does not issue an error that the list is empty, it just returns an empty list.

Rik <rik5>
Project Administrator
Fri 23 Mar 2018 09:10:06 AM UTC, comment #6: 

So,if that the case,
Why primes,list_primes doesn't follow this.
Why do they return empty vector(does not throws warning,error)
when there is a -ve input?

Dildar Sk <hodor123456>
Fri 23 Mar 2018 08:39:04 AM UTC, comment #5: 

To answer your previous question, because (-2+1i)*(-1-2i)=(4+3i), while for 8+3i no such factorization can be found, because if there were two Gaussian integers that have the product 8+3i, their absolute values would need to have the product sqrt(73). However, 73 is a prime number, and as the absolute value of any Gaussian integer is the square root of an integer, one of these factors would need to have an absolute value of 1. Thus 8+3i is prime. Or you just believe the 19-th century number theoreticians.

To answer why it is not following Matlab: browse the source code to look when this has been introduced. I just did this exercise for you, giving the result that you should check the discussion at bug #43041. If this is dear to your heart, you can try to see whether the consensus has changed in the meantime.

Michael Leitner <mleitner>
Fri 23 Mar 2018 08:16:07 AM UTC, comment #4: 

Sorry,I got the implementation now.
But why it's not following MATLAB.
And can we implement enhanced version of a function which
is not available in MATLAB?

Dildar Sk <hodor123456>
Fri 23 Mar 2018 08:06:58 AM UTC, comment #3: 

I dont know why it's following not MATLAB.
Whatever,in case,

>> isprime(4+3i)

ans = 0

>> isprime(8+3i)

ans = 1

Why this inconsistency?

Dildar Sk <hodor123456>
Fri 23 Mar 2018 07:56:44 AM UTC, comment #2: 

Not so fast: didn't you read the documentation of isprime? It is clearly stated that Octave's handling of non-positive values (including not only negative, but also complex) is different from Matlab. So you can now argue that this inconsistency has more drawbacks than advantages, and that the function should be dumbed down to perform as Matlab, to be discussed by the maintainers, but the case is not so clear as you seem to think. By the way, your test seems to miss the case of complex numbers, as these are always larger than zero (which, by the way, is the topic of another discussion, whether it is a good idea to keep this Matlab incompatibility), and also the case of non-scalar inputs (because the semantics of if imply all instead of any for logical matrices). Thus the "contains" in the error message is in fact correct.

Michael Leitner <mleitner>
Fri 23 Mar 2018 06:39:06 AM UTC, comment #1: 

I changed the error,warning message.
Updated the function and updated the test.
Patch attached.

(file #43637)

Dildar Sk <hodor123456>
Fri 23 Mar 2018 06:33:40 AM UTC, original submission:  

When I try on MATLAB,

>> isprime(-12)

Error using isprime (line 19)
All entries of X must be nonnegative integers.

>> isprime(-25)

Error using isprime (line 19)
All entries of X must be nonnegative integers.

But when I try on GNU Octave,

isprime (-12)
ans = 0

>> isprime(-36)

ans = 0

>> isprime(-23)

ans = 1

So,it's escaping error,warnings relative to MATLAB.

Dildar Sk <hodor123456>

 

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

Attach Files:
   
   
Comment:
   

Attached Files
file #43637:  isprime.patch added by hodor123456 (2KiB - text/x-patch)

 

Depends on the following items: None found

Items that depend on this one: None found

 

Carbon-Copy List
  • -email is unavailable- added by rik5 (Posted a comment)
  • -email is unavailable- added by mleitner (Posted a comment)
  • -email is unavailable- added by hodor123456 (Submitted the item)
  •  

    Do you think this task is very important?
    If so, you can add your encouragement to it.
    This task has 0 encouragements so far.

    Only project members can vote.

     

     

     

    Follow 2 latest changes.

    Date Changed by Updated Field Previous Value => Replaced by
    2018-03-23 rik5 Open/ClosedOpen => Closed
    2018-03-23 hodor123456 Attached File- => Added isprime.patch, #43637

    Back to the top


    Powered by Savane 3.5