[viff-devel] Vedr.: Small VIFF language parser
Martin Geisler
mg at daimi.au.dk
Tue Jul 15 07:49:34 PDT 2008
Janus Dam Nielsen <fagidiot at daimi.au.dk> writes:
> Hi again,
>
> Heres the fruit of half a days work :)
>
> Analyzing the expression:
> sint n = (a * y + (1 - a) * x);
>
> Yields the following results:
>
> Final result:
> ((a * y )+ ((1 - a )* x )) cost: 30
> (((a * y )+ x )- (x * a )) cost: 30
> (((a * y )+ x )- (a * x )) cost: 30
> (((a * y )- (a * x ))+ x ) cost: 30
> (((y * a )+ x )- (a * x )) cost: 30
> (((y * a )+ x )- (x * a )) cost: 30
> ((a * y )+ (x - (x * a ))) cost: 30
> (((y * a )- (a * x ))+ x ) cost: 30
> (((y * a )- (x * a ))+ x ) cost: 30
> (((a * y )- (x * a ))+ x ) cost: 30
> ((a * (y - x ))+ x ) cost: 20
>
> And lo and behold the last line reveals that the expression
> a * (y - x )+ x
> has the lowest cost.
That is very cool! :-)
>From the output above it seems that you have taught your analyzer
about the distributive law, that + and * are commutative.
What about a - a == 0, and that 0 * a == 0? I don't know if those
rules will help -- they might just blow up the search space... :-)
--
Martin Geisler
More information about the viff-devel
mailing list