ported qi calc1
ported qi calc2; now using lambda functions