本文整理汇总了Python中sympy.printing.conventions.split_super_sub函数的典型用法代码示例。如果您正苦于以下问题:Python split_super_sub函数的具体用法?Python split_super_sub怎么用?Python split_super_sub使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了split_super_sub函数的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: pretty_symbol
def pretty_symbol(symb_name, bold_name=False):
"""return pretty representation of a symbol"""
# let's split symb_name into symbol + index
# UC: beta1
# UC: f_beta
if not _use_unicode:
return symb_name
name, sups, subs = split_super_sub(symb_name)
def translate(s, bold_name) :
if bold_name:
gG = greek_bold_unicode.get(s)
else:
gG = greek_unicode.get(s)
if gG is not None:
return gG
for key in sorted(modifier_dict.keys(), key=lambda k:len(k), reverse=True) :
if s.lower().endswith(key) and len(s)>len(key):
return modifier_dict[key](translate(s[:-len(key)], bold_name))
if bold_name:
return ''.join([bold_unicode[c] for c in s])
return s
name = translate(name, bold_name)
# Let's prettify sups/subs. If it fails at one of them, pretty sups/subs are
# not used at all.
def pretty_list(l, mapping):
result = []
for s in l:
pretty = mapping.get(s)
if pretty is None:
try: # match by separate characters
pretty = ''.join([mapping[c] for c in s])
except (TypeError, KeyError):
return None
result.append(pretty)
return result
pretty_sups = pretty_list(sups, sup)
if pretty_sups is not None:
pretty_subs = pretty_list(subs, sub)
else:
pretty_subs = None
# glue the results into one string
if pretty_subs is None: # nice formatting of sups/subs did not work
if subs:
name += '_'+'_'.join([translate(s, bold_name) for s in subs])
if sups:
name += '__'+'__'.join([translate(s, bold_name) for s in sups])
return name
else:
sups_result = ' '.join(pretty_sups)
subs_result = ' '.join(pretty_subs)
return ''.join([name, sups_result, subs_result])
开发者ID:asmeurer,项目名称:sympy,代码行数:59,代码来源:pretty_symbology.py
示例2: pretty_symbol
def pretty_symbol(symb_name):
"""return pretty representation of a symbol"""
# let's split symb_name into symbol + index
# UC: beta1
# UC: f_beta
if not _use_unicode:
return symb_name
name, sups, subs = split_super_sub(symb_name)
# let's prettify name
gG = greek.get(name.lower())
if gG is not None:
if name.islower():
greek_name = greek.get(name.lower())[0]
else:
greek_name = greek.get(name.lower())[1]
# some letters may not be available
if greek_name is not None:
name = greek_name
# Let's prettify sups/subs. If it fails at one of them, pretty sups/subs are
# not used at all.
def pretty_list(l, mapping):
result = []
for s in l:
pretty = mapping.get(s)
if pretty is None:
try: # match by separate characters
pretty = ''.join([mapping[c] for c in s])
except KeyError:
return None
result.append(pretty)
return result
pretty_sups = pretty_list(sups, sup)
if pretty_sups is not None:
pretty_subs = pretty_list(subs, sub)
else:
pretty_subs = None
# glue the results into one string
if pretty_subs is None: # nice formatting of sups/subs did not work
if len(sups) > 0:
sups_result = '^' + '^'.join(sups)
else:
sups_result = ''
if len(subs) > 0:
subs_result = '_' + '_'.join(subs)
else:
subs_result = ''
else:
sups_result = ' '.join(pretty_sups)
subs_result = ' '.join(pretty_subs)
return ''.join([name, sups_result, subs_result])
开发者ID:arunenigma,项目名称:sympy,代码行数:58,代码来源:pretty_symbology.py
示例3: _print_Symbol
def _print_Symbol(self, sym):
x = self.dom.createElement('mi')
def join(items):
if len(items) > 1:
mrow = self.dom.createElement('mrow')
for i, item in enumerate(items):
if i > 0:
mo = self.dom.createElement('mo')
mo.appendChild(self.dom.createTextNode(" "))
mrow.appendChild(mo)
mi = self.dom.createElement('mi')
mi.appendChild(self.dom.createTextNode(item))
mrow.appendChild(mi)
return mrow
else:
mi = self.dom.createElement('mi')
mi.appendChild(self.dom.createTextNode(items[0]))
return mi
# translate name, supers and subs to unicode characters
def translate(s):
if s in greek_unicode:
return greek_unicode.get(s)
else:
return s
name, supers, subs = split_super_sub(sym.name)
name = translate(name)
supers = [translate(sup) for sup in supers]
subs = [translate(sub) for sub in subs]
mname = self.dom.createElement('mi')
mname.appendChild(self.dom.createTextNode(name))
if len(supers) == 0:
if len(subs) == 0:
x.appendChild(self.dom.createTextNode(name))
else:
msub = self.dom.createElement('msub')
msub.appendChild(mname)
msub.appendChild(join(subs))
x.appendChild(msub)
else:
if len(subs) == 0:
msup = self.dom.createElement('msup')
msup.appendChild(mname)
msup.appendChild(join(supers))
x.appendChild(msup)
else:
msubsup = self.dom.createElement('msubsup')
msubsup.appendChild(mname)
msubsup.appendChild(join(subs))
msubsup.appendChild(join(supers))
x.appendChild(msubsup)
return x
开发者ID:cklb,项目名称:sympy,代码行数:55,代码来源:mathml.py
示例4: _print_Symbol
def _print_Symbol(self, sym, style='plain'):
def join(items):
if len(items) > 1:
mrow = self.dom.createElement('mrow')
for i, item in enumerate(items):
if i > 0:
mo = self.dom.createElement('mo')
mo.appendChild(self.dom.createTextNode(" "))
mrow.appendChild(mo)
mi = self.dom.createElement('mi')
mi.appendChild(self.dom.createTextNode(item))
mrow.appendChild(mi)
return mrow
else:
mi = self.dom.createElement('mi')
mi.appendChild(self.dom.createTextNode(items[0]))
return mi
# translate name, supers and subs to unicode characters
def translate(s):
if s in greek_unicode:
return greek_unicode.get(s)
else:
return s
name, supers, subs = split_super_sub(sym.name)
name = translate(name)
supers = [translate(sup) for sup in supers]
subs = [translate(sub) for sub in subs]
mname = self.dom.createElement('mi')
mname.appendChild(self.dom.createTextNode(name))
if len(supers) == 0:
if len(subs) == 0:
x = mname
else:
x = self.dom.createElement('msub')
x.appendChild(mname)
x.appendChild(join(subs))
else:
if len(subs) == 0:
x = self.dom.createElement('msup')
x.appendChild(mname)
x.appendChild(join(supers))
else:
x = self.dom.createElement('msubsup')
x.appendChild(mname)
x.appendChild(join(subs))
x.appendChild(join(supers))
# Set bold font?
if style == 'bold':
x.setAttribute('mathvariant', 'bold')
return x
开发者ID:gamechanger98,项目名称:sympy,代码行数:53,代码来源:mathml.py
示例5: str_symbol
def str_symbol(name_str):
(name, supers, subs) = split_super_sub(name_str)
# translate name, supers and subs to tex keywords
greek = set(['alpha', 'beta', 'gamma', 'delta', 'epsilon', 'zeta',
'eta', 'theta', 'iota', 'kappa', 'lambda', 'mu', 'nu',
'xi', 'omicron', 'pi', 'rho', 'sigma', 'tau', 'upsilon',
'phi', 'chi', 'psi', 'omega'])
greek_translated = {'lamda': 'lambda', 'Lamda': 'Lambda'}
other = set(['aleph', 'beth', 'daleth', 'gimel', 'ell', 'eth',
'hbar', 'hslash', 'mho'])
def translate(s):
tmp = s.lower()
if tmp in greek or tmp in other:
return "\\" + s
if s in greek_translated:
return "\\" + greek_translated[s]
else:
return s
name = translate(name)
if supers != []:
supers = list(map(translate, supers))
if subs != []:
subs = list(map(translate, subs))
# glue all items together:
if len(supers) > 0:
name += "^{%s}" % " ".join(supers)
if len(subs) > 0:
name += "_{%s}" % " ".join(subs)
return name
开发者ID:HeinerKirchhoffer,项目名称:sympy,代码行数:38,代码来源:printing.py
示例6: test_super_sub
def test_super_sub():
assert split_super_sub("beta_13_2") == ("beta", [], ["13","2"])
assert split_super_sub("beta_132_20") == ("beta", [], ["132","20"])
assert split_super_sub("beta_13") == ("beta", [], ["13"])
assert split_super_sub("x_a_b") == ("x", [], ["a","b"])
assert split_super_sub("x_1_2_3") == ("x", [], ["1","2","3"])
assert split_super_sub("x_a_b1") == ("x", [], ["a","b1"])
assert split_super_sub("x_a_1") == ("x", [], ["a","1"])
assert split_super_sub("x_1_a") == ("x", [], ["1","a"])
assert split_super_sub("x_1^aa") == ("x", ["aa"], ["1"])
assert split_super_sub("x_1__aa") == ("x", ["aa"], ["1"])
assert split_super_sub("x_11^a") == ("x", ["a"], ["11"])
assert split_super_sub("x_11__a") == ("x", ["a"], ["11"])
assert split_super_sub("x_a_b_c_d") == ("x", [], ["a","b","c","d"])
assert split_super_sub("x_a_b^c^d") == ("x", ["c","d"], ["a","b"])
assert split_super_sub("x_a_b__c__d") == ("x", ["c","d"], ["a","b"])
assert split_super_sub("x_a^b_c^d") == ("x", ["b","d"], ["a","c"])
assert split_super_sub("x_a__b_c__d") == ("x", ["b","d"], ["a","c"])
assert split_super_sub("x^a^b_c_d") == ("x", ["a","b"], ["c","d"])
assert split_super_sub("x__a__b_c_d") == ("x", ["a","b"], ["c","d"])
assert split_super_sub("x^a^b^c^d") == ("x", ["a","b","c","d"], [])
assert split_super_sub("x__a__b__c__d") == ("x", ["a","b","c","d"], [])
assert split_super_sub("alpha_11") == ("alpha", [], ["11"])
assert split_super_sub("alpha_11_11") == ("alpha", [], ["11","11"])
开发者ID:aeberspaecher,项目名称:sympy,代码行数:24,代码来源:test_conventions.py
示例7: _print_Function
def _print_Function(self, expr, exp=None):
from sympy.physics.vector.functions import dynamicsymbols
func = expr.func.__name__
t = dynamicsymbols._t
if hasattr(self, '_print_' + func):
return getattr(self, '_print_' + func)(expr, exp)
elif isinstance(type(expr), UndefinedFunction) and (expr.args == (t,)):
name, supers, subs = split_super_sub(func)
name = translate(name)
supers = [translate(sup) for sup in supers]
subs = [translate(sub) for sub in subs]
if len(supers) != 0:
supers = r"^{%s}" % "".join(supers)
else:
supers = r""
if len(subs) != 0:
subs = r"_{%s}" % "".join(subs)
else:
subs = r""
if exp:
supers += r"^{%s}" % self._print(exp)
return r"%s" % (name + supers + subs)
else:
args = [str(self._print(arg)) for arg in expr.args]
# How inverse trig functions should be displayed, formats are:
# abbreviated: asin, full: arcsin, power: sin^-1
inv_trig_style = self._settings['inv_trig_style']
# If we are dealing with a power-style inverse trig function
inv_trig_power_case = False
# If it is applicable to fold the argument brackets
can_fold_brackets = self._settings['fold_func_brackets'] and \
len(args) == 1 and \
not self._needs_function_brackets(expr.args[0])
inv_trig_table = ["asin", "acos", "atan", "acot"]
# If the function is an inverse trig function, handle the style
if func in inv_trig_table:
if inv_trig_style == "abbreviated":
func = func
elif inv_trig_style == "full":
func = "arc" + func[1:]
elif inv_trig_style == "power":
func = func[1:]
inv_trig_power_case = True
# Can never fold brackets if we're raised to a power
if exp is not None:
can_fold_brackets = False
if inv_trig_power_case:
name = r"\operatorname{%s}^{-1}" % func
elif exp is not None:
name = r"\operatorname{%s}^{%s}" % (func, exp)
else:
name = r"\operatorname{%s}" % func
if can_fold_brackets:
name += r"%s"
else:
name += r"\left(%s\right)"
if inv_trig_power_case and exp is not None:
name += r"^{%s}" % exp
return name % ",".join(args)
开发者ID:AkshaySiramdas,项目名称:sympy,代码行数:72,代码来源:printing.py
示例8: str_symbol
def str_symbol(name_str):
(name, supers, subs) = split_super_sub(name_str)
# translate name, supers and subs to tex keywords
greek = set(
[
"alpha",
"beta",
"gamma",
"delta",
"epsilon",
"zeta",
"eta",
"theta",
"iota",
"kappa",
"lambda",
"mu",
"nu",
"xi",
"omicron",
"pi",
"rho",
"sigma",
"tau",
"upsilon",
"phi",
"chi",
"psi",
"omega",
]
)
greek_translated = {"lamda": "lambda", "Lamda": "Lambda"}
other = set(["aleph", "beth", "daleth", "gimel", "ell", "eth", "hbar", "hslash", "mho"])
def translate(s):
tmp = s.lower()
if tmp in greek or tmp in other:
return "\\" + s
if s in greek_translated:
return "\\" + greek_translated[s]
else:
return s
name = translate(name)
if supers != []:
supers = list(map(translate, supers))
if subs != []:
subs = list(map(translate, subs))
# glue all items together:
if len(supers) > 0:
name += "^{%s}" % " ".join(supers)
if len(subs) > 0:
name += "_{%s}" % " ".join(subs)
return name
开发者ID:ngaurav,项目名称:sympy,代码行数:61,代码来源:printing.py
注:本文中的sympy.printing.conventions.split_super_sub函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论