Zulip Chat Archive
Stream: Is there code for X?
Topic: Bit operation typeclasses
Wrenna Robson (Dec 10 2025 at 12:56):
I am trying to describe in general the following behaviour for some type α:
- I have instances
AndOp αandXorOp α. - There exists some
0such thatx &&& 0 = 0andx ^^^ 0 = x. - There exists some
1such thatx &&& 1 = x. x ^^^ (x ^^^ y) = yandy ^^^ (x ^^^ y) = x.- This means that given some
b : Bool, andx y : α, I can mapbto either 0 or 1 (in the obvious way), call thatb'and then I have thatx ^^^ ((x ^^^ y) &&& b)' = bif b then y else xandy ^^^ ((x ^^^ y) &&& b)= bif b then x else y`.
Wrenna Robson (Dec 10 2025 at 12:57):
The context for this is that we think of the map from b to b' as "bit extension`, and assuming we can do that in context time, this essentially describes a type on which we can do "branchless swaps".
Wrenna Robson (Dec 10 2025 at 12:58):
Possibly this bit extension map should also be part of the type!
Aaron Liu (Dec 10 2025 at 19:59):
Wrenna Robson said:
- This means that given some
b : Bool, andx y : α, I can mapbto either 0 or 1 (in the obvious way), call thatb'and then I have thatx ^^^ ((x ^^^ y) &&& b' = bif b then y else xandy ^^^ ((x ^^^ y) &&& b' = bif b then x else y.
you seem to have some mismatched parens
Wrenna Robson (Dec 10 2025 at 20:00):
Think that's fixed it
Last updated: Dec 20 2025 at 21:32 UTC