Zulip Chat Archive

Stream: maths

Topic: Algebraic structure on Bool


Wrenna Robson (Jul 17 2023 at 15:44):

I feel like I'm missing something obvious, but do we have + and * and the corresponding algebraic structures defined on Bool?

Wrenna Robson (Jul 17 2023 at 15:44):

I've just encountered this in the context of finding that Fin n -> Bool doesn't seem to have a 0.

Kyle Miller (Jul 17 2023 at 15:47):

Bool is a boolean algebra and uses ⊥/⊔/⊓/⊤ rather than 0/+/*/1. I'm not sure if there's a Bool-like that uses algebraic notation.

Wrenna Robson (Jul 17 2023 at 15:49):

Well, that's not the end of the world, I can use that notation instead as the Pi type inherits it. Though it feels to me like the kind of thing where having both might be desirable - I don't know if it creates too many issues, mind.

Wrenna Robson (Jul 17 2023 at 15:49):

In particular, I would use + to mean xor, not or.

Kyle Miller (Jul 17 2023 at 15:50):

Oh, if you want + to mean xor, then you can use Fin 2

Wrenna Robson (Jul 17 2023 at 15:53):

Right.

Wrenna Robson (Jul 17 2023 at 15:53):

It's just that (in another thread, not sure how to link) people were talking about defining bitvectors as Fin n -> Bool.

Wrenna Robson (Jul 17 2023 at 15:54):

I think that in any scenario where you care about bitvectors, you probably want + to mean xor. But you also probably want "or" and "and" as operations.

Eric Wieser (Jul 17 2023 at 15:56):

Whether you pick X = Bool or X = Fin 2, note that using Fin n -> X for bit vectors means you get and () and or () for free.

Kyle Miller (Jul 17 2023 at 15:56):

Mathlib has a ∆ b notation for symmetric differences at least (which is xor for bool)

Kyle Miller (Jul 17 2023 at 15:56):

https://leanprover-community.github.io/mathlib4_docs/Mathlib/Order/SymmDiff.html

Eric Wieser (Jul 17 2023 at 15:56):

Presumably it works just fine for Fin n -> X too

Kyle Miller (Jul 17 2023 at 15:57):

Yeah: docs#Pi.symmDiff_def

Reid Barton (Jul 17 2023 at 16:02):

In SMT-LIB "addition of bitvectors" means addition modulo 2^n.
I will grant that "bitvector" seems like an inappropriate word choice, but it's what they use.

Reid Barton (Jul 17 2023 at 16:02):

This certainly doesn't affect Bool itself and probably also not Fin n -> Bool, but it is a counterexample in practice to

Wrenna Robson said:

I think that in any scenario where you care about bitvectors, you probably want + to mean xor.

Eric Wieser (Jul 17 2023 at 16:03):

I think there's tension here between the Fin (2^n) representation (where + is obviously addition) and the Fin n -> Fin 2 representation (where + is xor)

Eric Wieser (Jul 17 2023 at 16:04):

Maybe trying to create a BitVector that claims to be both of these and muddies the water about what the operations mean is a mistake

Notification Bot (Jul 17 2023 at 16:55):

This topic was moved here from #mathlib4 > Algebraic structure on Bool by Heather Macbeth.

Yaël Dillies (Jul 17 2023 at 18:23):

docs3#bool.boolean_ring


Last updated: Dec 20 2023 at 11:08 UTC