[BUG] Logical AND
|
01-26-2014, 04:10 PM
Post: #1
|
|||
|
|||
[BUG] Logical AND
Hi,
Could not find any report of this elsewhere If you are in Home View 3 AND 2 returns 1 However if you are in CAS 3 AND 2 returns 2 If you try 3 and 2, it still returns 2 and the and is changed to AND on the line The other logical operators seems to behave as expected. Cheers, Terje |
|||
01-26-2014, 04:27 PM
(This post was last modified: 01-26-2014 04:27 PM by Tim Wessman.)
Post: #2
|
|||
|
|||
RE: [BUG] Logical AND
I beleive it is doing a bitwise and here by design. You are comparing two integers after all.
TW Although I work for HP, the views and opinions I post here are my own. |
|||
01-26-2014, 04:45 PM
Post: #3
|
|||
|
|||
RE: [BUG] Logical AND
(01-26-2014 04:27 PM)Tim Wessman Wrote: I beleive it is doing a bitwise and here by design. You are comparing two integers after all. Hi, I may be mistaken but shouldn't then a bitwise 5 AND 3 become 1 rather than 3 on the calculator? The result is in any event the same if you use 3. AND 2. In Home view there seems to be no such bitwise manipulation Also the help screen on the calculator uses 3 AND 2 -> 1 as an example... Cheers, Terje |
|||
01-26-2014, 04:59 PM
Post: #4
|
|||
|
|||
RE: [BUG] Logical AND
In Home it turn to bitwise with binary integer
#2 AND #3 is bitwise It is undocumented. It overlap with BITAND() Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
01-26-2014, 05:01 PM
Post: #5
|
|||
|
|||
RE: [BUG] Logical AND
EXPR("3 AND 2") always return 1. Something funny is happening in the CAS, it always returns the last digit.
My website: ried.cl |
|||
01-26-2014, 05:15 PM
Post: #6
|
|||
|
|||
RE: [BUG] Logical AND
Yep, for (x and y) CAS returns (x!=0)*y
i.e. 0 and y returns 0 while x and y returns y for any x<>0 |
|||
01-26-2014, 05:16 PM
Post: #7
|
|||
|
|||
RE: [BUG] Logical AND
Prime have 2 heads: Home and CAS
So using a CAS function in Home get you some CAS behavior in Home. And the same function can exist in both, simply Home will be uppercase and CAS will be lowercase. Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
01-26-2014, 06:56 PM
(This post was last modified: 01-26-2014 06:57 PM by Tugdual.)
Post: #8
|
|||
|
|||
RE: [BUG] Logical AND
(01-26-2014 05:16 PM)patrice Wrote: Prime have 2 heads: Home and CASCAS makes it uppercase after you press enter. Documentation is the same in both cases. What the heck is the advantage of the CAS implementation? Doesn't make much sense to me. Definitely a bug. |
|||
01-26-2014, 07:49 PM
(This post was last modified: 01-26-2014 07:51 PM by Tim Wessman.)
Post: #9
|
|||
|
|||
RE: [BUG] Logical AND
Quote:I may be mistaken but shouldn't then a bitwise 5 AND 3 become 1 rather than 3 on the calculator? The result is in any event the same if you use 3. AND 2 Well I thought it was doing a bitwise, but you are right. Just seems to be returning the second item. Maybe bernard can enlighten. :-? TW Although I work for HP, the views and opinions I post here are my own. |
|||
01-27-2014, 09:20 AM
(This post was last modified: 01-27-2014 09:21 AM by parisse.)
Post: #10
|
|||
|
|||
RE: [BUG] Logical AND
a and b returns 0 if a is zero and b otherwise for integers. Returning b is easier than returning 1 because it works for other types (e.g. if b is a variable name or a symbolic expression). For more precision, here is the source code from gen.cc
Code:
|
|||
01-27-2014, 06:37 PM
Post: #11
|
|||
|
|||
RE: [BUG] Logical AND
Can you please fix that to 1:true and 0:false?
|
|||
01-27-2014, 06:42 PM
Post: #12
|
|||
|
|||
RE: [BUG] Logical AND
==0 for False and <>0 for True is not worse than ==1 for False
Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
01-27-2014, 10:53 PM
Post: #13
|
|||
|
|||
RE: [BUG] Logical AND
In some occasions, I like to do arithmetic with tests. Something like (a==b)*c+d with the test returning 1 or 0 is very convenient.
|
|||
01-27-2014, 11:15 PM
Post: #14
|
|||
|
|||
RE: [BUG] Logical AND
(01-27-2014 10:53 PM)Tugdual Wrote: In some occasions, I like to do arithmetic with tests. Something like (a==b)*c+d with the test returning 1 or 0 is very convenient.Then test ((a<>0)==(b<>0))*(c<>0)+(d<>0) Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
01-27-2014, 11:59 PM
Post: #15
|
|||
|
|||
RE: [BUG] Logical AND
(01-27-2014 11:53 PM)Han Wrote: Just use AND as opposed to and (lower case). The uppercase version does not have this behavior and will evaluate to either a 0 or a 1, or produce an error otherwise (if I'm not mistaken). This goes for both Home and CAS view. In this case I think you may be mistaken. If you refer to my initial post, I tried both upper- and lowercase and, both with the same result. In CAS mode the lowercase and is changed to uppercase after the command is executed. Cheers, Terje |
|||
01-28-2014, 12:02 AM
(This post was last modified: 01-28-2014 12:04 AM by Han.)
Post: #16
|
|||
|
|||
RE: [BUG] Logical AND
(01-27-2014 09:20 AM)parisse Wrote: a and b returns 0 if a is zero and b otherwise for integers. Returning b is easier than returning 1 because it works for other types (e.g. if b is a variable name or a symbolic expression). For more precision, here is the source code from gen.cc Is there some convention that xcas/giac is following by returning the second argument if the first argument is non-zero in an AND operation? This is the first time I've seen a non-bitwise AND operation return something other than the operation unevaluated, 0, or 1 (or some variation of the values 0 and 1) on atomic arguments. Graph 3D | QPI | SolveSys |
|||
01-28-2014, 06:03 AM
Post: #17
|
|||
|
|||
RE: [BUG] Logical AND
(01-27-2014 11:59 PM)Terje Vallestad Wrote:(01-27-2014 11:53 PM)Han Wrote: Just use AND as opposed to and (lower case). The uppercase version does not have this behavior and will evaluate to either a 0 or a 1, or produce an error otherwise (if I'm not mistaken). This goes for both Home and CAS view. Believe it or not (this is SO bizarre), you can use this mixed-case syntax in CAS only: And(x,y) It returns 0 or 1, as you wanted. If Textbook Display is off, it will nicely be displayed in the history as "And", the way you typed it. (That's true for most commands when Textbook Display is off). If Textbook Display is on, it will annoyingly be displayed as "AND" but it will still act like "And", the way you want it to. If the "Change apparent integers into exact integers" CAS setting is turned off, then it will return the reals 0. and 1. instead of the integers 0 and 1, as shown below, but that shouldn't matter. <0|ɸ|0> -Joe- |
|||
01-28-2014, 07:32 AM
Post: #18
|
|||
|
|||
RE: [BUG] Logical AND
There is a reason not to return 1, if you run say 2 && a, where a is symbolic, it's better to return a than 1 since if a is 0 the answer is correct. What I can do is change to 1 (or 0) if the second argument is a float or complex or integer.
|
|||
01-30-2014, 01:49 PM
Post: #19
|
|||
|
|||
RE: [BUG] Logical AND
I am beginning to realize that the AND, OR, and NOT from the Shift+6 menu are more meant for Boolean tests (true vs false) - while BITAND, BITOR, and BITNOT are for Boolean operations.
|
|||
02-01-2014, 07:57 PM
Post: #20
|
|||
|
|||
RE: [BUG] Logical AND
Hi Eddie,
(01-30-2014 01:49 PM)Eddie W. Shore Wrote: I am beginning to realize that the AND, OR, and NOT from the Shift+6 menu are more meant for Boolean tests (true vs false) - while BITAND, BITOR, and BITNOT are for Boolean operations.I don't know if it is a usage or not, but I call "Boolean" operations done at integer value level, and "bitwise" operations done at bit level. AND, OR and NOT are said to be Boolean. BITAND, BITOR, BITNOT and BITXOR are said to be bitwise (operations done at bit level. So: 3 OR 5 => 1, Boolean as expected BITOR(3,5) => 7, bitwise as expected but #3 OR #5 => #7, bitwise not as expected BITOR(#3,#5) => #7, bitwise as expected in order to get OR to act Boolean, one have to resort to: (#3 <> #0) OR '#5 <> #0) Unfortunate behavior! Patrice “Everything should be made as simple as possible, but no simpler.” Albert Einstein |
|||
« Next Oldest | Next Newest »
|
User(s) browsing this thread: 6 Guest(s)