homomorphy_term (Application os ts r) = t'
      where ts' = map free_term ts
            Qual_op_name op_name ot op_r = os
            Op_type _ ar co ot_r = ot
            op_name' = mkFreeName op_name
            ar' = map mkFreeName ar
            co' = mkFreeName co
            ot' = Op_type Total ar' co' ot_r
            os' = Qual_op_name op_name' ot' op_r
            t = Application os' ts' r
            ot_hom = Op_type Partial [co'] co nullRange
            name_hom = mkQualOp homId ot_hom
            t' = mkAppl name_hom [t]
homomorphy_term (Application os ts r) = t'
      where ts' = map free_term ts
            Qual_op_name op_name ot op_r = os
            Op_type _ ar co ot_r = ot
            op_name' = mkFreeName op_name
            ar' = map mkFreeName ar
            co' = mkFreeName co
            ot' = Op_type Total ar' co' ot_r
            os' = Qual_op_name op_name' ot' op_r
            t = Application os' ts' r
            ot_hom = Op_type Partial [co'] co nullRange
            name_hom = mkQualOp homId ot_hom
            t' = mkAppl name_hom [t]
homomorphy_term (Application os ts r) = t'
      where ts' = map free_term ts
            Qual_op_name op_name ot op_r = os
            Op_type _ ar co ot_r = ot
            op_name' = mkFreeName op_name
            ar' = map mkFreeName ar
            co' = mkFreeName co
            ot' = Op_type Total ar' co' ot_r
            os' = Qual_op_name op_name' ot' op_r
            t = Application os' ts' r
            ot_hom = Op_type Partial [co'] co nullRange
            name_hom = mkQualOp homId ot_hom
            t' = mkAppl name_hom [t]