首页 > 解决方案 > 如何从字符串创建多项式

问题描述

我想从字符串创建布尔多项式。目前我通过使用隐式定义的变量来定义多项式:

R = BooleanPolynomialRing(names=["a", "b", "c"], order=TermOrder("lex"))
R.inject_variables()

f = 1 + a*b
g = a*b*(1+c)

我想用字符串f和.g"1 + a*b""a*b*(1+c)"

标签: sage

解决方案


多项式环可以接受字符串并将它们转换为多项式。

sage: R = BooleanPolynomialRing(names=["a", "b", "c"], order=TermOrder("lex"))
sage: R.inject_variables()
Defining a, b, c

sage: f = R("1 + a*b")
sage: f
a*b + 1

sage: g = R("a*b*(1+c)")
sage: g
a*b*c + a*b

推荐阅读