Reputation: 106351
Are there any languages that perform compile-time optimisation using arbitrary logic programming?
I'm looking for an example of a language that will enable you to do something like:
is-idempotent?
f(f(x))
is equal to f(x)
if the is-idempotent?
function is true for f
is-idempotent?
for various functions (possibly indirectly, e.g. implied by other logic statements)Upvotes: 5
Views: 160
Reputation: 95354
I think what you want is a program transformation system.
These can let you define rules to apply to source code, e.g., algrebraic laws to optimize code.
What you will discover is that there is a variety of problems. The first is handling scoping rules and side effects in langauges. The second is sequencing of the transformations; the order in which they are applied often produces radically different results.
Upvotes: 2