Can I create a Smart Group programatically?
There's an example of creating a smart-group in v4.6's CRM_Contact_Form_Task::createHiddenGroup() which calls CRM_Contact_BAO_Group::createHiddenSmartGroup(). It should show the relevant fields/data-structures. There are a few details which would need to be adapted if used in another context:


In CRM_Contact_Form_Task::createHiddenGroup(), it just passes through some existing formValues. This data-structure is a big array defining the search parameters. You can inspect example records in civicrm_saved_search to see what this looks like. I believe this corresponds to advanced-search/CRM_Contact_BAO_Query, but you'd need to investigate.
In CRM_Contact_BAO_Group::createHiddenSmartGroup(), the title is hard-coded.
In CRM_Contact_BAO_Group::createHiddenSmartGroup(), the is_hidden field defaults to 1.