math behind "Category"

14 views
Skip to first unread message

Qian Yun

unread,
Aug 7, 2026, 8:53:46 AM (6 days ago) Aug 7
to fricas-devel
I have been thinking of the math behind "Category",
i.e. the various "has" and "Join" relations,
for a long time.

It does not have a tight relationship with "category theory".
Only recently it occurred to me that it should be
"universal algebra":
https://en.wikipedia.org/wiki/Universal_algebra

- Qian

Kurt Pagani

unread,
Aug 7, 2026, 10:06:48 AM (6 days ago) Aug 7
to fricas...@googlegroups.com


On 07/08/2026 14:53, Qian Yun wrote:
> I have been thinking of the math behind "Category",
> i.e. the various "has" and "Join" relations,
> for a long time.

I've been running for many years (just for fun as it's free) a simple
python app giving synonyms (using NLTK):
https://nilqed.pythonanywhere.com/

-> Category

a collection of things sharing a common attribute

a general concept that marks divisions or coordinations in a conceptual
scheme

--
Sounds reasonable (?).

>
> It does not have a tight relationship with "category theory".

Ask Gemini ;)

"""
One point

2. Conceptual Differences: Internal vs. External
While they both look at structure, they approach mathematics from
opposite directions:

Universal Algebra is "Internal": It looks inside the object. It defines
a group by looking at its elements and checking if \(x \cdot x^{-1} = e\).

Category Theory is "External": It looks outside the object. It defines a
group by how it maps to other groups. It doesn't care about elements; it
cares about arrows.
"""

> Only recently it occurred to me that it should be
> "universal algebra":
> https://en.wikipedia.org/wiki/Universal_algebra

and "it" concludes:

"""
From a computer science perspective, the relationship between universal
algebra and category theory provides the mathematical foundation for
modern programming languages, data types, and system semantics.In short:
Universal algebra gives us the tools to define what data structures are
(syntax and operations), while category theory gives us the tools to
define how they behave and compose (semantics and transformations).
""">
> - Qian
>

Martin Baker

unread,
Aug 7, 2026, 10:32:33 AM (6 days ago) Aug 7
to fricas...@googlegroups.com
Yes, I can see how a FriCAS domain is internal because it has a
representation and a FriCAS category is external because it does not.
That is only defined upto isomorphism by the functions into and out of it.
However I think its unfortunate that FriCAS cannot use category
theoretic structures such as Monads in the same way that functional
languages like Haskell and Idris can.

Waldek Hebisch

unread,
Aug 7, 2026, 5:33:33 PM (6 days ago) Aug 7
to fricas...@googlegroups.com
There are many possible approaches. I think that rather simple
approach is most useful. Namely, categories define abstact
interface, that is set of available operations (including
their signatures). There is interface inheritance, done
via "Join": given category may inherit from other categories,
then it posseses all properties of those categories. In
effect there is inheritance DAG, category directly inherits
from categories mentioned in its definition (that is from its
parents), but also inherits all categories and signatures
from its parents. "has" for named categories is explained
in FriCAS book: this is decided by assertion, that is category
'A has B' if and only if B appears in inheritance chain.

There are some twists. The above rule is related to "name
equivalence" of types. In FriCAS there are also unnamed
categories which use "structural equivalence". Unnamed
category U may be viewed as set of categories and signatures.
Category A has unnamed category U if and only if it has
all categories and signatures appearing in definition of U.

Concerning domains, one can associate a category with each
domain. For domain D you can think of it as 'typeOf(D)'.
Internally, part of domain definition before '== add ...'
part is compiled as a category, this category determines
interface of the domain.

The above is actually quite close to handling of types in
typical programming languages. In FriCAS interesting part
is that types have parameters. Parameters alone create
only modest complication, basically to answer 'A has B' you
need to be able to determine if any ancestor of A is equal
to B. "Name equivalence" means that we need to compare names
of constructors, if names are different then clearly we do not
have equality. FriCAS has no overloading for constructors,
so if names match, then also number of arguments matches and
to decide equality we need to compare arguments.

In FriCAS some exports are conditional. That actually requires
answer to some tricky questions. Consider:

A : Category == with
if % has B then C
if % has C then B

What we get asking 'A has B'? I did not check if this is implemented
correctly, but official answer is 'no'. Similar things appeared
earlier trying to define semantics of programming languages via
recursive equations and the approach which works reasonably well
is to take "minimal fixpoint". There is restriction: a cycle
of dependences can not contain negation. So

A : Category == with
if not(% has B) then C
if % has C then B

is illegal.

--
Waldek Hebisch

Qian Yun

unread,
Aug 7, 2026, 7:57:37 PM (6 days ago) Aug 7
to fricas...@googlegroups.com
On 8/7/26 10:32 PM, Martin Baker wrote:
> Yes, I can see how a FriCAS domain is internal because it has a
> representation and a FriCAS category is external because it does not.
> That is only defined upto isomorphism by the functions into and out of it.
> However I think its unfortunate that FriCAS cannot use category
> theoretic structures such as Monads in the same way that functional
> languages like Haskell and Idris can.

Monad is just a monoid in the category of endofunctors...
Jokes aside, Monad (such as Maybe) can be easily implemented
in FriCAS, there were some lengthy discussion about it in the past,
but Waldek prefers Union("failed", ...) over Maybe.

- Qian

Martin Baker

unread,
Aug 8, 2026, 3:32:58 AM (6 days ago) Aug 8
to fricas...@googlegroups.com
Yes but as I pointed out in this thread in 2017:
https://groups.google.com/g/fricas-devel/c/56BSvqutzro/m/0JAPWA0CAgAJ

If you define a monad as an endofunctor with two natural transformations:

M M X -> M X
X -> M X

You can do this in functional languages and then implement specific
cases of it:
In the maybe instance:

Maybe Maybe X -> Maybe X
X -> Maybe X

In the list instance:

List List X -> List X
X -> List X

and so on, I don't believe you can do this sort of thing in FriCAS.

Functional languages have whole libraries of category theoretic
structures. I don't think you could do that sort of thing in FriCAS?

Qian Yun

unread,
Aug 8, 2026, 4:26:23 AM (6 days ago) Aug 8
to fricas...@googlegroups.com
On 8/8/26 3:32 PM, Martin Baker wrote:
> Yes but as I pointed out in this thread in 2017:
> https://groups.google.com/g/fricas-devel/c/56BSvqutzro/m/0JAPWA0CAgAJ
>
> If you define a monad as an endofunctor with two natural transformations:
>
> M M X -> M X
> X -> M X
>

Yes, fricas can only implement the equivalent form:

(M X, X -> M X) -> M X
X -> M X

But it is not enough to get "M M X -> M X".

Only combining

M a -> (a -> M b) -> M b
(Let a <- M X and b <- X)
can do it.

- Qian

Reply all
Reply to author
Forward
0 new messages