Hide keyboard shortcuts

Hot-keys on this page

r m x p   toggle line displays

j k   next/prev highlighted chunk

0   (zero) top of page

1   (one) first highlighted chunk

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

45

46

47

48

49

50

51

52

53

54

55

56

57

58

59

60

61

62

63

64

65

66

67

68

69

70

71

72

73

74

75

76

77

78

79

80

81

82

83

84

85

86

87

88

89

90

91

92

93

94

95

96

97

""" 

Substitution Maps 

  

This object wraps Pynac ``exmap`` objects. These encode substitutions 

of symbolic expressions. The main use of this module is to hook into 

Pynac's ``subs()`` methods and pass a wrapper for the substitution map 

back to Python. 

""" 

  

#***************************************************************************** 

# Copyright (C) 2013 Volker Braun <vbraun.name@gmail.com> 

# 

# This program is free software: you can redistribute it and/or modify 

# it under the terms of the GNU General Public License as published by 

# the Free Software Foundation, either version 2 of the License, or 

# (at your option) any later version. 

# http://www.gnu.org/licenses/ 

#***************************************************************************** 

  

  

from sage.libs.pynac.pynac cimport * 

from sage.symbolic.expression cimport Expression, new_Expression_from_GEx 

  

  

cdef class SubstitutionMap(SageObject): 

  

cpdef Expression apply_to(self, Expression expr, unsigned options): 

""" 

Apply the substitution to a symbolic expression 

  

EXAMPLES:: 

 

sage: from sage.symbolic.substitution_map import make_map 

sage: subs = make_map({x:x+1}) 

sage: subs.apply_to(x^2, 0) 

(x + 1)^2 

""" 

return new_Expression_from_GEx(expr._parent,  

expr._gobj.subs_map(self._gmapobj, options)) 

  

def _repr_(self): 

""" 

Return the string representation 

  

EXAMPLES:: 

 

sage: from sage.symbolic.substitution_map import make_map 

sage: make_map({x:x+1}) 

SubsMap 

""" 

return 'SubsMap' # GEx_to_str(&x._gobj) 

  

  

cdef SubstitutionMap new_SubstitutionMap_from_GExMap(const GExMap& smap): 

""" 

Wrap a Pynac object into a Python object 

  

INPUT: 

  

- ``smap`` -- a Pynac ``exmap``. 

  

OUTPUT: 

  

A new Python :class:`SubstitutionMap` 

  

EXAMPLES:: 

  

sage: from sage.symbolic.substitution_map import make_map 

sage: make_map({x:x+1}) 

SubsMap 

""" 

cdef SubstitutionMap result 

result = <SubstitutionMap>SubstitutionMap.__new__(SubstitutionMap) 

result._gmapobj = smap 

return result 

  

  

cpdef SubstitutionMap make_map(subs_dict): 

""" 

Construct a new substitution map 

  

OUTPUT: 

  

A new :class:`SubstitutionMap` for doctesting 

  

EXAMPLES:: 

  

sage: from sage.symbolic.substitution_map import make_map 

sage: make_map({x:x+1}) 

SubsMap 

""" 

cdef GExMap smap 

for k, v in subs_dict.iteritems(): 

smap.insert(make_pair((<Expression>k)._gobj, 

(<Expression>v)._gobj)) 

return new_SubstitutionMap_from_GExMap(smap)