圣人数学:如何在符号表达式中组合或扩展指数



如何在 sage 中组合或扩展表达式中的指数?换句话说,我怎样才能让圣人将表达式从(a**b)**c重写为a**(b*c),反之亦然?

例子:

sage: var('x y')
(x, y)
sage: assume(x, 'rational')
sage: assume(y, 'rational')
sage: combine_exponents( (x^2)^y )
x^(2*y)
sage: assume(x > 0)
sage: expand_exponents( x^(1/3*y) )
(x^y)^(1/3)

我已经尝试过:

sage: b = x^(2*y)
sage: a = (x^2)^y
sage: bool(a == b)
True
sage: a
(x^2)^y
sage: simplify(a)
(x^2)^y
sage: expand(a)
(x^2)^y
sage: b
x^(2*y)
sage: expand(b)
x^(2*y)

更新:

simplify_exp(Codelion的答案)可以从(a**b)**c转换为a**(b*c),但不是相反。有没有可能让圣人也扩展指数?

  1. 从圣人6.5开始,将a转化为b,使用方法 canonicalize_radical .

    sage: a.canonicalize_radical()
    x^(2*y)
    

    注意这四种方法simplify_expexp_simplifysimplify_radicalradical_simplify,具有相同的效果,正在被弃用以支持canonicalize_radical.请参阅Sage trac票证#11912。

  2. 不知道有没有内置函数将b转化为a.

    你可以像这样定义自己的函数:

    def power_step(expr, step=None):
        a, b = SR.var('a'), SR.var('b')
        if str(expr.operator()) == str((a^b).operator()):
            aa, mm = expr.operands()
            if step is None:
                if str(mm.operator()) == str((a*b).operator()):
                    bb = mm.operands().pop()
                    return (aa^bb)^(mm/bb)
                else:
                    return expr
            return (aa^step)^(mm/step)
        else:
            if step is None: return expr
            else: return (expr^step)^(1/step)
    

    然后,您可以将电源分解为步骤:

    sage: x, y = var('x y')
    sage: power_step(x^(2*y),y)
    (x^y)^2
    sage: power_step(x^(2*y),2)
    (x^2)^y
    

    请注意,如果您不指定步骤,它不会总是选择显示的第一个

    sage: power_step(2^(x*y))
    (2^y)^x
    sage: power_step(x^(2*y))
    (x^2)^y
    
您可以使用

simplify_exp()函数。因此,对于您的示例,请执行以下操作:

sage: a.simplify_exp()
x^(2*y)

最新更新