6 ms·
Here's an example of a recent tool that automatically generates code from a declarative specification written in linear integer arithmetic with operations on se
by nano_o 14y ago
Here's an example of a recent tool that automatically generates code from a declarative specification written in linear integer arithmetic with operations on sets: http://lara.epfl.ch/w/comfusy http://lara.epfl.ch/w/comfusy.
There is a plugin available for the Scala (2.7.7) compiler.
Assuming you want to break a number of seconds contained in variable secnum into hours, minutes, and seconds, you would write something like this:
val secnum: Int = Console.readInt
val (hours, minutes, seconds) = choose((h: Int, m: Int, s: Int) => (
h * 3600 + m * 60 + s == secnum
&& 0 <= m
&& m < 60
&& 0 <= s
&& s < 60
) )
Code that computes the hours, minutes, and seconds will be generated at compile time (it's not interpreted).
- tluyben2 14y agoVery interesting, thanks for that.
- dxbydt 14y agoThis is super interesting but I am really curious about its performance assuming they dont just bruteforce it to exhaust all combinationss. Tons of portfolio optimization problems can be specified very succinctly just like above but the actual computation can be quite tricky. If you had to break up a hundred dollars to invest in google amazon and rest in a riskfree interest bearing bond the optimal constraints look just like the choose function above...so i can declaratively write out the sharpe but maximizing the sharpe is fairly nontrivial. I am going to check this out right now.
- tluyben2 14y agoIt's such a shame though that this kind of research usually stops when the author is done with his/her thesis. A lot of worthwhile papers and software are out there and together probably enough to create a small revolution in software development, but the problems are very hard and usually it's not even concrete enough to define the problem that well. So it would need a lot of these researchers combined to do something great; besides maybe DARPA, I don't see much interest in that at the moment unfortunately.
- nano_o 14y agoI think it's much better than brute force search. The example above produces the following code: val (hours, minutes, seconds) = { val loc1 = secnum div 3600 val num2 = secnum + ((−3600) ∗ loc1) val loc2 = min(num2 div 60, 59) val loc3 = secnum + ((−3600) ∗ loc1) + (−60 ∗ loc2) (loc1, loc2, loc3) } Note that it works for constraints expressed in (parameterized) linear arithmetic and with operations on sets (like taking cardinality, union, intersection...).