Specy / rooc

A language for compiling formal mathematical models into static models which are transformed to be solved
https://rooc.specy.app
MIT License
4 stars 0 forks source link

sum/min/max/avg as both blocks and scoped blocks #2

Closed Specy closed 10 months ago

Specy commented 10 months ago

I could turn the sum/min/max/avg as both blocks and scoped blocks. But the syntax might become a little confusing, perhaps i could add a special syntax to clearly distinguish between scoped and unscoped blocks? currently scoped blocks are the kind where

sum(i in 0..5) { exp } 

will be converted into a sum of the expressions inside of it, and this will also add the values of the scope to the block in the exp. at the same time there is:

min { x_1, x_2, x_3 }

which currently has no way to specify the scope, so it must be manually written out. an example of this could be trying to calculate the average of a row in a matrix

min 1
s.t. 
     sum(row in M) { avg { ??? }  } <= 3
where 
    M = [
        [1,2,3],
        [4,5,6]
    ]

i could turn this into:

 sum(row in M) { avg(el in row){  el  }  } <= 3

but then would this look ugly syntax wise? the min/max/avg blocks make sense to be both scoped and unscoped, but for example the sum block doesn't make sense to be

Specy commented 10 months ago

I added the min/max/avg blocks in 57c7d49, they seem to be fine for now, i won't be adding the sum as a non scoped block

Need to choose what to do with them still so i'll keep this issue open