Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Some operations on complement bitsets are wrong #5480

Open
hiiamboris opened this issue Feb 13, 2024 · 3 comments
Open

Some operations on complement bitsets are wrong #5480

hiiamboris opened this issue Feb 13, 2024 · 3 comments
Assignees
Labels
type.review Ticket describes a possible improvement.

Comments

@hiiamboris
Copy link
Collaborator

Describe the bug

Using helper func for visualization:
base2: func [bs] [s: copy {} repeat i 24 [append s pick "10" on = find bs i - 1] insert skip insert skip s 8 "." 8 "." s]

command result expected ok?
base2 c1: charset [0 - 15] "11111111.11111111.00000000" "11111111.11111111.00000000"
base2 c2: charset [not 1 - 6] "10000001.11111111.11111111" "10000001.11111111.11111111"
base2 exclude c1 c2 "01111110.11111111.11111111" "01111110.00000000.00000000"
base2 exclude c2 c1 "00000000.00000000.11111111" "00000000.00000000.11111111"
base2 union c1 c2 "11111111.11111111.11111111" "11111111.11111111.11111111"
base2 c1 or c2 "11111111.11111111.11111111" "11111111.11111111.11111111"
base2 intersect c1 c2 "10000001.00000000.11111111" "10000001.11111111.00000000"
base2 c1 and c2 "10000001.11111111.11111111" "10000001.11111111.00000000"
base2 difference c1 c2 "01111110.11111111.11111111" "01111110.00000000.11111111"
base2 c1 xor c2 "01111110.11111111.11111111" "01111110.00000000.11111111"

To reproduce

base2 c1: charset [0 - 15]
base2 c2: charset [not 1 - 6]
base2 exclude c1 c2
base2 exclude c2 c1
base2 union c1 c2
base2 c1 or c2
base2 intersect c1 c2
base2 c1 and c2
base2 difference c1 c2
base2 c1 xor c2

Platform version

Red 0.6.4 for Windows built 13-Feb-2024/15:12:43+03:00  commit #f519e8a
@hiiamboris hiiamboris added the type.bug Ticket describes an abnormal behavior, not conforming to the specs or expectation. label Feb 13, 2024
@qtxie
Copy link
Contributor

qtxie commented Feb 14, 2024

The length of the bitset should be taken into account.

>> c1
==  make bitset! #{FFFF}      ;-- "11111111.11111111"
>> c2
== make bitset! [not #{7E}]   ;-- "10000001"
>> length? c1
== 16
>> length? c2
== 8
>> c3: c1 and c2
== make bitset! [not #{7E}]   ;-- "10000001"
>> length? c3
== 8

c1 and c2 is correct.

@hiiamboris
Copy link
Collaborator Author

No it's not correct. Length is just an internal implementation detail. Implementation should not drive the design. Design should drive the implementation.

@hiiamboris
Copy link
Collaborator Author

hiiamboris commented Feb 14, 2024

General rules for bitsets should be:

  1. Result length should equal the longest operand's length, and may be zero:
    >> (charset []) or (charset [not]) 
    == make bitset! [not #{FF}]     ;) length was extended leading to wrong result! expected [not #{}]
    
  2. Negation flag may be freely set by binary operations depending on whether the trail should be set or not, e.g.:
    >> (charset [not]) and (charset [])
    == make bitset! [not #{}]       ;) expected empty set, got full set!
    >> (charset [not]) and (charset [not]) 
    == make bitset! #{}             ;) expected full set, got empty set!
    

Current builds of Red, R3 and Ren-C I have all fail the bitset math. @Oldes @hostilefork FYI.

@dockimbel dockimbel added type.review Ticket describes a possible improvement. and removed type.bug Ticket describes an abnormal behavior, not conforming to the specs or expectation. labels Feb 16, 2024
@dockimbel dockimbel changed the title Bitsets operations are completely wrong Some negative bitsets operations are wrong Feb 25, 2024
@dockimbel dockimbel changed the title Some negative bitsets operations are wrong Some complement bitsets operations are wrong Feb 25, 2024
@dockimbel dockimbel changed the title Some complement bitsets operations are wrong Some operations on complement bitsets are wrong Feb 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type.review Ticket describes a possible improvement.
Projects
None yet
Development

No branches or pull requests

3 participants