当前你的浏览器版本过低,网站已在兼容模式下运行,兼容模式仅提供最小功能支持,网站样式可能显示不正常。
请尽快升级浏览器以体验网站在线编辑、在线运行等功能。

建议使用的浏览器:

谷歌Chrome 火狐Firefox Opera浏览器 微软Edge浏览器 QQ浏览器 360浏览器 傲游浏览器

1467:Symbolic Derivation

题目描述
Write a program that performs symbolic derivation f'(x) = df(x)/dx of a given function f(x). The function f(x) is defined by an expression which may contain the following operations: + (addition), - (subtraction), * (multiplication), / (division), and ln (natural logarithm). Besides, the operands may be the variable x and numerical constants. The expression may contain arbitrarily nested sub-expressions in parentheses ( ). The expression is given in a usual, infix form, such as:
(2*ln(x+1.7)-x*x)/((-7)+3.2*x*x)+(x+3*x)*x

Numerical constants have the form d.d, with an optional sign (+ or -), where the number of digits both in integer and decimal parts are arbitrary. The input expression is guaranteed to be correct (no syntax error can occur).

The output expression should be written in infix form. It should not be optimized for human reading. This means, it can contain redundancies, such as 0*x, 1*x, 0+x, etc. The derivation should be performed using the following rules:

1. The operators * and / are of higher priority than the operators + and -. Parentheses may change the priorities as usually.

2. The operators +, -, *, and / are left-associative, meaning that they group from left to right:
a*b*c = (a*b)*c, a/b/c = (a/b)/c, a/b*c = (a/b)*c, etc.

3. The rules for derivation are:
(a + b)' = a' + b'

(a - b)' = a' - b'
(a * b)' = (a' * b + a * b')
(a / b)' = (a' * b - a * b') / b^2 Note: use b^2 and not (b*b) for presentation
ln(a)' = (a')/(a)
x' = 1
const' = 0


4. While producing the symbolic derivation, use parentheses for output strictly as stated in the previous rule. Do not perform presentation optimizations, such as 0*a = 0, 1*a = a, etc.
输入解释
The input is a textual file which has one f(x) definition per line. The input lines do not have blanks.
输出解释
The output should contain lines with corresponding symbolic derivations f’=df/dx, one line for each f. The strings representing f(x) and f ’(x) are guaranteed to have no more than 100 characters.
输入样例
x*x/x
-45.78*x+x
-2.45*x*x+ln(x-3)
输出样例
((1*x+x*1)*x-x*x*1)/x^2
(0*x-45.78*1)+1
((0*x-2.45*1)*x-2.45*x*1)+(1-0)/(x-3)

该题目是Virtual Judge题目,来自 北京大学POJ

源链接: POJ-1467

最后修改于 2020-10-29T06:04:55+00:00 由爬虫自动更新

共提交 0

通过率 --%
时间上限 内存上限
1000 10000