How important is it for elements of code to be algebraic structures?

How important is it for elements of code to be algebraic structures?

For example:
I store some data in a list-type structure, adding two lists gives another list to its a groupoid. Since the addition of lists is associative and the empty list is the identity element its actually a monoid.

Now I can do the following:
1) Overload negation to mean remove a matching entry from the end of the list
2) (This is usually not implemented in a list) If nothing can be removed, let the list remember it sothat it will remove an entry once its added.

Now the list has inverses, so its a Group. Further I can now let the list sort itself when a new element is added, thus now its an Abelian group.

Now There are two options, I can either leave it with the properties of a group, or I can force the list to contain only unique elements, then it becomes an Abelian Semigroup where each element is Idempotent.

A drawback to this might be that the structure is too limiting to accommodate some elements of code, but I can see this making it easier to reason about your code since everything obeys familiar mathematical theorems.

So should code be mathematical structures?

Good luck asking real questions on a designated shitpost evaluation and processing station

Have you been reading Elements of Programming?

...

no, Typeclassopedia

I posted this on /g/, and the consensus was that only math autists care about this, and in has no practical applications, like Haskel.

another example:

take a list of elements [x], and a parser f x -> y that changes each entry to another type y. If all possible values of x are X, then all possible lists of x is the power set P(X) (assuming its sorted and all elements are idempotent). f can be though of as a homomorphism, and if any entry in the list [x] that cant be parsed evaluates to the empty string and f([]) = [] then the kernel of f is the elements that cant be parsed. We can thus form the quotient group P(X)/ker(f) which is all possible lists that can be parsed.

Now validation of the original list is easy, just check if it is in P(X)/ker(f) abd you know it can be parsed.

>elements of code
What?

are you a dotnetter? in that case 'snippets' of code

Seems like you had enough information of the state of things before you even asked the questions.
Besides, take care of your notation, what you write is hardly to be understood

>are you a dotnetter?
What?

I know its possible, i just dont know if its a good idea

Theoretically an optimizing compiler can take advantage of such algebraic structures, but we've yet to see such a compiler implementation.

Also monads in haskell (which are monoids in the category of endofunctors) unify a vast number of constructs under the same programming pattern which makes reasoning about them easier.

>abelian groups not being before ring

what a shit graph

>caring what /g/ thinks

>abelian field

>add measure
>get measurable space
No. You add a measure to a measurable space to get a measure space.

>So should code be mathematical structures?

My response would be why not? Just by overloading operators so that objects can be composed immediately helps with making the code much shorter and easier to read, specially if you have a large operation.

Like if you want to stick together 3 lists. You would have
list4 = list1 * list2 * list3
instead of
list4=list1.add(list2).add(list3) or any equivalent implementation like
list4=list1.add(list2,list3)

Which are longer and denser implementations that do the literal same thing.

Another advantage is analyzing your code. If your program is just an algebra machine then you can study your objects via algebraic expressions, the same way we study the properties of real numbers via algebraic expressions... and we already know how useful that has been for the study of real numbers.

im guessing he calls division rings fields and field abelian fields.

Put do we even know of a triple field?

You certainly can, but why should you?

Also, that image is pretty fucked up overall now that I've looked into it more.

This image has been posted on sci hundereds of times, and i think its the first time people have found anything wrong with it.

>why should you
because if you know add() forms a abelian group then in say a dictionary, then you know that
x.add(y).add(z) = x.add(y.add(z)) = z.add(x) .add(y)
without having to care about the internals of add()

Oh boy, that's not a claim you should be making.
>"Abelian" is an adjective for groups, but not other structures. "Commutative" is most often used instead.
>"Equivalence classes for pairs" comes after the integers. How the hell do you think we construct the integers from the naturals?
>Algebras come after algebraic structures.
>Measurable spaces are incorrectly placed as a consequence of measures. No mention of sigma Algebras is given. Measurable spaces do not come after algebras.
>Algebras somehow follow from rings.
>A commutative field with ordering and least upper bound is NOT necessarily the reals and is NOT sufficient to define the reals.
>Lie Algebras and Lie Groups are totally unconnected.
Shall I go on?

im not saying its not wrong, just that no one has catched the errors on sci before that i remember

"good idea" is a normative concept. What's the goal?

If you can stop time/aging and have each programmer always motivated to work an indefinite amount of time to code, then humans should invest a could of years to develope a ridiculously strongly typed language and have each program be developed in year-long projects (you can stop time after all, and the people are magically motivated). If you can form an elite group capable of the whole math canon and introduce a technocratic voting register on how a program should be implemented - then I think this is a good idea.
In practice, in the capitalistic world we live in and with our finite life span, and where kids won't take more than 4 years of programming before they are hired to develope sensitive code that has to be prototyped quickly, you need a wide variety of languages with this and that advantage, and such very strong systems are just a niche. A niche that arguable should be larger, but there is just too much effort to get into the abstraction, especially if you have to wage your employees away. Besides, most people don't see aesthetics in those complicated frameworks, at least as long as they haven't spent time learning it.

>▶"good idea" is a normative concept. What's the goal?
good idea for programmers who know algebra to implement it in the language they are working in, like say C#.

There are probably too many diverging classes relevant in practice and the ones that make for mathematically often studied structures are merely one example of those many