What is the best way to define abstract math?

I want to define Clifford Algebra, something already realized in

But, I don’t think it can be helpful to my project. Because I want its arithmatic structure rather than these types.
It it possible to specify the arithmatic structure between self defined types like MyX, MyY and MyZ like

@group * Pauli begin  # `*` operation, defined on Pauli Group
        MyX == X
        MyY == Y
        MyZ == Z

so that MyX * MyY can return im*MyZ (Since we have im*Z == X * Y in Clifford.jl) ?

Or Is there any examples to define group operations using macros?

Do you mean that you want symbolic computation? In that case, I’m not sure that there’s a good answer in Julia.

It not symbolic computation. Ii is about defining a set of methods (like *, +) on existing types easily.

e.g. defining + operation on a circulant group of N elements. Here, the circulant group is what I mean arithmetic structure

By the way, I am also interested in why symbolic computation is hard for Julia? Could you please give a link or explain a bit? Thanks!

There are several efforts to do symbolic computation in Julia, but it’s a difficult problem. There was a talk at JuliaCon 2018 with a bit of a review.

Julia makes it very easy to define methods on your types; see the docs.
I’m not sure what you mean by a “circulant group of N elements”. Is the following what you have in mind?

julia> struct Mod{N}

julia> import Base: +

julia> x = Mod{10}(5)

julia> y = Mod{10}(6)

julia> +(x::Mod{N}, y::Mod{N}) where {N} = Mod{N}( (x.i + y.i) % N )
+ (generic function with 181 methods)

julia> x + y

Sorry for my misleading description, what I mean is more general finite group like

ulia> abstract type CircElem end
julia> struct One <: CircElem end
julia> struct Two <: CircElem end
julia> struct Three <: CircElem end

julia> +(::One, ::Two) = Three()
+ (generic function with 1 method)
julia> +(::Two, ::Two) = One()
+ (generic function with 2 methods)

Now I have some existing codes like

julia> struct MyOne end
julia> struct MyTwo end
julia> struct MyThree end

julia> # can I copy the definition of + from CircElem ?

PS: I want to define arithmetics in the first place, so these relations be reused (i.e. type independent relations)!

Using the type system for run-time computation like this is probably not a great idea. It’s still fairly unclear to me what you’re try to get here. Do you want something that defines algebraic operations for you?

1 Like

Thanks for your suggestion.

Clifford.jl also uses type system to define finite groups.
By doing this, Pauli operators can be used in function dispatch.

Also thanks @dpsanders, now I think it is indeed related to symbolic computation. Although the author of JuliaCon talk http://juliacon.org/2018/talks_workshops/41/ states that Julia is suited for symbolic programing, his repo is dependent on SymPy (very inefficient in my opinion).

I will try to figure out by my self.