千里马:如何用符号代替普通子表达式 [英] Maxima: how to replace common subexpressions with symbols

查看:100
本文介绍了千里马:如何用符号代替普通子表达式的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个表达式(实际上我的要复杂得多,数千个字符)

Suppose I have an expression like (actually mine is much more complex, thousands of characters)

expr:a+b*c+b*c*d;

并且我想用符号替换内部子表达式(用于避免重新计算常见子表达式),例如用k代替b*c:

and I want to replace an internal sub-expression with a symbol (useful to avoid recomputation of common subexpressions), say k in place of b*c:

subst(b*c=k,expr);

返回

k+b*c*d+a

我如何使Maxima计算正确的"替代值以便返回(除简化之外,在这里)

How I can make Maxima calculate the "right" substitution so to return (apart from obviuos simplification, here)

k+k*d+a

?

推荐答案

看看letletsimp.例如:

(%i2) expr : a + b*c + b*c*d;
(%o2) b*c*d+b*c+a
(%i3) let (b*c, k);
(%o3) b*c --> k
(%i4) letsimp (expr);
(%o4) d*k+k+a

letsimpsubsttellsimpdefrule的不同之处在于,这些其他函数仅进行形式上的替换,即替换与某种模式完全相同的子表达式.

letsimp differs from subst and tellsimp or defrule in that those other functions make only formal substitutions, i.e., replacing subexpressions which are exactly the same as some pattern.

这篇关于千里马:如何用符号代替普通子表达式的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆