CliMA / Impero.jl

A symbolic language for equation specification
Apache License 2.0
15 stars 1 forks source link

playing around with nary operators again #25

Open leios opened 3 years ago

leios commented 3 years ago

I was just getting used to Impero dev again (trying to turn it into a general symbolic equation tool). I completely forgot what I was trying to do with nary operators before, but now I have something that works a bit, but returns the following:

julia> @wrapper P=nothing A=nothing B=nothing C=nothing

julia> +([P,A])
+(P,A,0)

I gotta be honest. I don't know where the 0 is coming from. It's also in the * operator, which obviously makes everything fail. Any ideas?

Maybe it's best to just remove nary operators and move on?

sandreza commented 3 years ago

O.o The zero confuses me

sandreza commented 3 years ago

@leios Oh wait, found it: https://github.com/CliMA/Impero.jl/blob/master/src/abstract_core.jl#L64

I think there was a reason for adding the zero previously right?

leios commented 3 years ago

Ah, ok. I vaguely remember now. Sorry, that was my bad.

The 0 is the neutral element of addition. I should also have a 1 to deal with the neutral element of multiplication (but, uh... cough, cough). This would just help dealing with potentially empty sets, but I think it can be entirely removed without consequence. Let me do that today.

leios commented 3 years ago

I fixed the Base.show issue. I honestly don't remember what I was thinking when I did that!

I do want to ask about what we want to do with these operators in the future. When adding a bunch of numbers together in Julia, it's kinda nary anyway:

julia> x = 1;

julia> dump(:(x+x+x))
Expr
  head: Symbol call
  args: Array{Any}((4,))
    1: Symbol +
    2: Symbol x
    3: Symbol x
    4: Symbol x

As a note: I think the LLVM code does things slightly differently. It seems like it turns everything into binary operators.

I could try to find a way to extend the + and * operators to all be nary... This might help with certain optimizations in the future, but I am not sure where I actually need to go with this PR right now so I might work on other things for the next few days and come back to this later this week!