Changeset 7809:8bbea9681c82
Legend:
- Unmodified
- Added
- Removed
-
sage/rings/polynomial/multi_polynomial_libsingular.pyx
r7549 r7809 2601 2601 y + z 2602 2602 2603 sage: f.subs(x=1/y) 2604 (y^2 + y + 1)/y 2605 sage: f.subs({x:1/y}) 2606 (y^2 + y + 1)/y 2607 2603 2608 TESTS: 2604 2609 sage: P.<x,y,z> = QQ[] … … 2613 2618 2614 2619 """ 2615 cdef int mi, i, need_map 2620 cdef int mi, i, need_map, try_symbolic 2616 2621 2617 2622 cdef MPolynomialRing_libsingular parent = <MPolynomialRing_libsingular>self._parent … … 2627 2632 cdef ideal *res_id 2628 2633 need_map = 0 2634 try_symbolic = 0 2629 2635 2630 2636 if fixed is not None: … … 2641 2647 else: 2642 2648 raise TypeError, "keys do not match self's parent" 2643 v = parent._coerce_c(v) 2649 try: 2650 v = parent._coerce_c(v) 2651 except TypeError: 2652 try_symbolic = 1 2653 break 2644 2654 _f = (<MPolynomial_libsingular>v)._poly 2645 2655 if _f == NULL or pNext(_f) == NULL: … … 2649 2659 to_id.m[mi-1] = p_Copy(_f, _ring) 2650 2660 2651 gd = parent.gens_dict() 2661 if not try_symbolic: 2662 gd = parent.gens_dict() 2663 for m,v in kw.iteritems(): 2664 m = gd[m] 2665 for i from 0 < i <= _ring.N: 2666 if p_GetExp((<MPolynomial_libsingular>m)._poly, i, _ring) != 0: 2667 mi = i 2668 break 2669 if i > _ring.N: 2670 raise TypeError, "key does not match" 2671 try: 2672 v = parent._coerce_c(v) 2673 except TypeError: 2674 try_symbolic = 1 2675 break 2676 _f = (<MPolynomial_libsingular>v)._poly 2677 if _f == NULL or pNext(_f) == NULL: 2678 _p = pSubst(_p, mi, _f) 2679 else: 2680 if to_id.m[mi-1] != NULL: 2681 p_Delete(&to_id.m[mi-1],_ring) 2682 to_id.m[mi-1] = p_Copy(_f, _ring) 2683 need_map = 1 2684 2685 if need_map: 2686 for mi from 0 <= mi < _ring.N: 2687 if to_id.m[mi] == NULL: 2688 to_id.m[mi] = p_ISet(1,_ring) 2689 p_SetExp(to_id.m[mi], mi+1, 1, _ring) 2690 p_Setm(to_id.m[mi], _ring) 2691 2692 from_id=idInit(1,1) 2693 from_id.m[0] = _p 2694 2695 res_id = fast_map(from_id, _ring, to_id, _ring) 2696 _p = res_id.m[0] 2697 2698 from_id.m[0] = NULL 2699 res_id.m[0] = NULL 2700 2701 id_Delete(&from_id, _ring) 2702 id_Delete(&res_id, _ring) 2703 2704 id_Delete(&to_id, _ring) 2705 2706 if not try_symbolic: 2707 return co.new_MP(parent,_p) 2708 2709 # now as everything else failed, try to do it symbolically as in call 2710 2711 g = list(parent.gens()) 2712 2713 if fixed is not None: 2714 for m,v in fixed.iteritems(): 2715 if PY_TYPE_CHECK(m,int) or PY_TYPE_CHECK(m,Integer): 2716 mi = m+1 2717 elif PY_TYPE_CHECK(m,MPolynomial_libsingular) and <MPolynomialRing_libsingular>m.parent() is parent: 2718 for i from 0 < i <= _ring.N: 2719 if p_GetExp((<MPolynomial_libsingular>m)._poly, i, _ring) != 0: 2720 mi = i 2721 break 2722 if i > _ring.N: 2723 raise TypeError, "key does not match" 2724 else: 2725 raise TypeError, "keys do not match self's parent" 2726 2727 g[mi-1] = v 2728 2652 2729 for m,v in kw.iteritems(): 2653 2730 m = gd[m] … … 2658 2735 if i > _ring.N: 2659 2736 raise TypeError, "key does not match" 2660 v = parent._coerce_c(v) 2661 _f = (<MPolynomial_libsingular>v)._poly 2662 if _f == NULL or pNext(_f) == NULL: 2663 _p = pSubst(_p, mi, _f) 2664 else: 2665 if to_id.m[mi-1] != NULL: 2666 p_Delete(&to_id.m[mi-1],_ring) 2667 to_id.m[mi-1] = p_Copy(_f, _ring) 2668 need_map = 1 2669 2670 if need_map: 2671 for mi from 0 <= mi < _ring.N: 2672 if to_id.m[mi] == NULL: 2673 to_id.m[mi] = p_ISet(1,_ring) 2674 p_SetExp(to_id.m[mi], mi+1, 1, _ring) 2675 p_Setm(to_id.m[mi], _ring) 2676 2677 from_id=idInit(1,1) 2678 from_id.m[0] = _p 2679 2680 res_id = fast_map(from_id, _ring, to_id, _ring) 2681 _p = res_id.m[0] 2682 2683 from_id.m[0] = NULL 2684 res_id.m[0] = NULL 2685 2686 id_Delete(&from_id, _ring) 2687 id_Delete(&res_id, _ring) 2688 2689 id_Delete(&to_id, _ring) 2690 return co.new_MP(parent,_p) 2737 2738 g[mi-1] = v 2739 2740 return self(*g) 2691 2741 2692 2742 def monomials(self):
Note: See TracChangeset
for help on using the changeset viewer.
