sage - 如何从字符串创建多项式
问题描述
我想从字符串创建布尔多项式。目前我通过使用隐式定义的变量来定义多项式:
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: 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
推荐阅读
- batch-file - 为什么错误:不支持输入重定向,立即退出进程
- javascript - 找不到 React HTML 元素参考宽度和高度
- android - 使用协程在 Room 中的 ViewModel 中显示 LiveData
- scala - Spark - 从外部表创建 DataFrame
- java - 使用 Avro 序列化程序初始化 Kafka Producer 时出错:java.lang.NoClassDefFoundError
- react-native - 屏幕和标题在反应导航中闪烁
- angular - 在 Angular 中动态导入的组件中插入输入
- python - 访问python字典中最近的一年
- javascript - Javascript中的抽象语法树递归怎么样?
- intellij-idea - 当 IntelliJ 启动时,我总是需要重新导入我的 Maven 依赖项