You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now if I write Int(1) as argument of And it gets actually compiled to the code. It would be nice if the compiler could calculate that an identity element doesn't change the result of the operation.
For example if I want to insert a check depending on the value of some parameter I actually have to change the whole expression.
return core_checks if value == 0 else And(core_checks, other_checks)
should become
return And(core_checks, identity_element if value == 0 else other_checks)
Solution
The compiler should detect identity elements for each operator and simplify them.
Urgency
No urgency at all.
The text was updated successfully, but these errors were encountered:
This would probably require for single argument NaryExpressions to exist, if that's the case it would be great if such change to the API was public. One use case could be And(*[validate(thing) for thing in things]) and wouldn't require a special case for a single element array.
Allowing single argument NaryExpressions sounds reasonable and simple to do. edit: #117 adds this
I also agree that it would be nice if PyTeal could intelligently optimize away constants like the original issue suggests. There are many places this could happen, and identify elements in And and Or are one of them.
Another good place would be equality conditions, since it's pretty common to check if a number is equal to 0 or 1. However, this is a redundant check in TEAL, since 0 and 1 can already be used to represent boolean values. For example, the TEAL code <number-to-check>; int 0; == is equivalent to just <number-to-check>; !.
Problem
Right now if I write
Int(1)
as argument ofAnd
it gets actually compiled to the code. It would be nice if the compiler could calculate that an identity element doesn't change the result of the operation.For example if I want to insert a check depending on the value of some parameter I actually have to change the whole expression.
return core_checks if value == 0 else And(core_checks, other_checks)
should become
return And(core_checks, identity_element if value == 0 else other_checks)
Solution
The compiler should detect identity elements for each operator and simplify them.
Urgency
No urgency at all.
The text was updated successfully, but these errors were encountered: