alcides / aeon

Aeon programming language
https://alcides.github.io/aeon/
8 stars 3 forks source link

RefinedType to Metahandler Union #66

Closed eduardo-imadeira closed 3 months ago

eduardo-imadeira commented 3 months ago

Test : https://github.com/alcides/aeon/blob/03604a59f1dc8172d7c3840ed8b904dd0e886744/tests/intervals_test.py#L83

For example, from this refined type {g:Int | (g > 0 && g < 10) || (g > 20 && g < 30)}, the sympy expresion would be: ((g > 0) & (g < 10)) | ((g > 20) & (g < 30)) then transforming this sympy expression into a list of Relational objects we would get : [g > 0, g < 10, g > 20, g < 30] I would expect that when I use this list of Relational objects as input of the sympy function reduce_rational_inequalities to get the object : Union(Interval(0, 10), Interval(20, 30)) , but instead I am getting an EmptySetobject (https://github.com/alcides/aeon/blob/03604a59f1dc8172d7c3840ed8b904dd0e886744/aeon/synthesis_grammar/grammar.py#L180)

alcides commented 3 months ago

I'll take a look at this later. @pcanelas, do you have idea about this?

alcides commented 3 months ago

Just a though:

If the list of relational objects is [g > 0, g < 10, g > 20, g < 30], you are loosing the OR. And indeed, there is no value that is smaller than 10 AND greater than 20.

After obtaining the sympy expression, you have to convert each (recursive) argument of OR into an interval.

The following pseudo-code should work. You are just missing the split step.

rt = "{g:Int | (g > 0 && g < 10) || (g > 20 && g < 30)}"
sympy_expr = convert_to_sympy(rt)
interval_exprs = split("|", sympy_expr) # this needs to be a recursive function
intervals = map(reduce_rational_inequalities, interval_exprs)
metahandlers = map( interval_to_mh, intervals)
final_metahandler = fold(Union, meta handlers)