Skip to content

physiCS-is-computer-science/SimpleFunctionSymbolOperation

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

42 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

 # 邓老师,我是计算机类7班吴梦奇,此项目功能为:对数学函数进行 简单的符号/数值 计算(仅允许 +-*/^() 符号)
 # 该项目由 CMake 构建生成,并由 git 进行项目管理,其中通过 CMakeLists.txt文件 描述项目生成规则,.gitignore文件 指定不跟踪 ./bin文件夹 与 ./build文件夹
 # 其满足基本的错误检测,包括字符串处理、token词法分析、树分析,并主要通过 wrongPrint()和wrongPrintT() 函数抛出错误
 # 当函数过于复杂时同样会抛出错误并停止运算,然而受我水平所限,只有树分析过程才能检查函数复杂度,因此该过程中的错误抛出比较简陋
 # 受我水平所限,最终输出的中缀表达式(一阶导函数)可能比较笨拙
 # 文本末有一附录,记录程序主要测试用例,其中不通过的用例附在结尾处(通过数学软件 Mathematica 逐个验证,准确性基本可以保证)
 # 
 # 以下内容为规范与方向(由于时间所限,带有 * 的模块暂时不支持)


1.仅支持单函数、单变量的 符号/数值 计算(如多项式、指数),变量只允许为字符 'x'。具体计算涉及的模块如下
    (1) 求导
    (2) 积分
    (3) 化简
    (4) 函数间四则运算*


2.项目结构
    (1) main.c 操纵整个程序流程
    (2) 字符串处理模块
    (3) 词法分析模块
    (4) 求导模块
    (5) 积分模块
    (6) 化简模块
    (7) 函数间四则运算模块*
    (8) 必要零件模块
    (9) 屏幕输出模块


3.规范
    严格控制函数、变量作用域与存储期,用多少给多少
    尽量不用全局变量,需要长期保存的变量作用域限定为主、次函数内,调用时传递


4.操作界面与方式
    (1) 操作界面为Windows的 exe 窗口,操作方式为程序引导输入字符或字符串,点击按钮 Calculete 计算
    (2) CMD/PowerShell 窗口输出 运行日志 或 抛出错误

    例: 1.diff(x + 1) 表示对 x + 1 求导一次
        2.diff(x^2 + x - 1, 3) 表示对 x^2 + x - 1 求导一次,并将 3 带入导函数得到导数
        3.inte(x^2) 表示对 x^2 求定积分一次
        4.inte(x^2, 1, 5) 表示对该函数求不定积分一次,第2参数为积分下限,第3参数为积分上限


5.实现
    (1) 输入 命令关键字() 字符串并处理,例:diff(f, num) / inte(f, left, right)
    (2) 处理 命令中作为参数的函数表达式f 并拆解为 Token单元 存储入数组 
    (3) 使用 Token单元 构建抽象表达式树
    (4) 执行功能函数并化简
    (5) 将得到的 结果树 转化为 中缀表达式,输出


6.祝我好运


# 附录:
求导模块中,以下为大部分测试用例:
1. diff(3) = 0
2. diff(x) = 1
3. diff(2*x) = 2
4. diff(x+1) = 1
5. diff(x-1) = 1
6. diff(3*x+2) = 3
7. diff(x^100) = 100*x^99
8. diff(x^2) = 2*x
9. diff(2*x^3) = 6*x^2
10. diff(x^2+x) = 2*x+1
11. diff((x+1)^2) = 2*(x+1)
12. diff(x^2+2*x+1) = 2*x+2
13. diff(1/x) = -1/x^2
14. diff(1/(x^2)) = -2/x^3
15. diff((x+1)/x) = -1/x^2
16. diff(x/(x+1)) = 1/(x+1)^2
17. diff((x^2+1)/x) = 1-1/x^2
18. diff((x^3-2*x+1)^4) = 4*(x^3-2*x+1)^3*(3*x^2-2)
19. diff(1/(x-1)) = -1/(x-1)^2
20. diff((2*x+1)^3) = 6*(2*x+1)^2
21. diff(x^(1/2)) = 1/(2*x^(1/2))
22. diff(x^3+2*x^2-5*x+7) = 3*x^2+4*x-5
23. diff((x^2+3*x)^2) = 2*(x^2+3x)(2*x+3)
24. diff((x+1)*(x-1)) = 2*x
25. diff(x*(x+1)*(x-1)) = 3*x^2-1
26. diff((x^2+1)/(x^2-1)) = -4*x/(x^2-1)^2
27. diff(1/(x^3+x)) = -(3*x^2+1)/(x^3+x)^2
28. diff((x^4+3*x^2+1)^(1/2)) = (4*x^3+6*x)/(2*(x^4+3*x^2+1)^(1/2))
29. diff(x^2/(x+1)) = (x^2+2*x)/(x+1)^2
30. diff((x-1)^3*x^2) = (x-1)^2*x(5x-2)
31. diff((x^2-1)/(x^2+1)) = 4*x/(x^2+1)^2
32. diff(((x+1)^2+1)^3) = 6*(x+1)*((x+1)^2+1)^2
33. diff((x/(x+1))^2) = 2*x/(x+1)^3
34. diff((x^2+1)^(3/2)) = 3*x*(x^2+1)^(1/2)
35. diff((x^3-1)/(x^2+1)) = (x^4+3*x^2+2*x)/(x^2+1)^2
36. diff(x*(x-1)*(x-2)) = 3*x^2-6*x+2
37. diff((x^2-4)^5) = 10*x*(x^2-4)^4
38. diff((x+1)/(x^2+1)) = (-x^2-2*x+1)/(x^2+1)^2
39. diff(1/(x^2-4)^2) = -4*x/(x^2-4)^3
40. diff((x-1)^4*(x+1)^3) = (x-1)^3*(x+1)^2(7x+1)
41. diff((x^2+3*x+2)/(x^2-3*x+2)) = (-6*x^2+12)/(x^2-3*x+2)^2
42. diff(x^(-2)) = -2/x^3
43. diff(x^(3/2)) = 3/2*x^(1/2)
44. diff((x^2+1)^(-1)) = -2*x/(x^2+1)^2
45. diff((1+x^4)^(1/4)) = x^3/(1+x^4)^(3/4)
46. diff(x^2/(x+1)) = (x^2+2*x)/(x+1)^2
47. diff((x^3+2*x)^5) = 5*(x^3+2x)^4(3*x^2+2)
48. diff(3*x^4-2*x^3+x^2-5) = 12*x^3-6*x^2+2*x
49. diff((x-1)/(x^2-1)) = -1/(x+1)^2
50. diff((x^5-3*x^3+2*x+1)^10) = 10*(x^5-3*x^3+2*x+1)^9*(5*x^4-9*x^2+2)
51. diff((x^2+1)*(x^3-1)*(x+2)) = (x^2+1)*(x^3-1)+3*x^2*(x^2+1)*(x+2)+2*x*(x^3-1)*(x+2)
52. diff(x^(1/3)) = 1/(3*x^(2/3))
53. diff((x^2+1)^(1/3)) = (2*x)/(3*(x^2+1)^(2/3))
54. diff(x^(-1/2)) = -1/(2*x^(3/2))
55. diff((x^3+8)^(1/3)) = x^2/(x^3+8)^(2/3)
56. diff((x+1)^(5/2)) = 5/2*(x+1)^(3/2)
57. diff(x^(-3)) = -3/x^4
58. diff((x^2-1)^(-2)) = -4*x/(x^2-1)^3
59. diff((x+1)^(-1/2)) = -1/(2*(x+1)^(3/2))
60. diff((x^2+4)^(-1/2)) = -x/((x^2+4)^(3/2))
61. diff(x^(-5)+x^(-3)+x^(-1)) = -5/x^6-3/x^4-1/x^2
62. diff((1/(x+1))^3) = -3/(x+1)^4
63. diff((x/(x-1))^2) = -2*x/(x-1)^3
64. diff(((x^2+1)/(x^2-1))^2) = -8*x*(x^2+1)/(x^2-1)^3
65. diff((x+1)^2/(x-1)^2) = -4*(x+1)/(x-1)^3
66. diff((x^2-1)^(1/2)/x) = 1/(x^2*(x^2-1)^(1/2))
67. diff(x^2*(1-x)^3) = x*(1-x)^2*(2-5*x)
68. diff((x^3+1)^(2/3)) = 2*x^2/(x^3+1)^(1/3)
69. diff((x+1/x)^2) = 2*x-2/x^3
70. diff((x^2+2*x+1)/(x+1)) = 1
71. diff((x^2-4)/(x-2)) = 1
72. diff((x^3-8)/(x-2)) = 2*(x+1)
73. diff(x/(1+(x)^(1/2))) = (1+0.5*x^(1/2))/(1+x^(1/2))^2
74. diff((1+(x)^(1/2))^3) = 3*(1+x^(1/2))^2/(2*x^(1/2))
75. diff((x^3+x^(1/2))^2) = 2*(x^3+x^(1/2))*(3*x^2+1/(2*x^(1/2)))
76. diff((x^2+1)/(x^(1/2)+1)) = (2*x*(x^(1/2)+1)-(x^2+1)/(2*x^(1/2)))/(x^(1/2)+1)^2
77. diff((x^2+3)^4) = 8*x*(x^2+3)^3
78. diff((x^3-4*x)^3) = 3*(x^3-4x)^2(3*x^2-4)
79. diff((x+1)^2/(x-1)^2) = -4*(x+1)/(x-1)^3
80. diff((x^2+1)^(1/2)*(x+1)) = (2*x^2+x+1)/(x^2+1)^(1/2)
81. diff((x^4+1)^(1/4)+(x^4+1)^(3/4)) = x^3/(x^4+1)^(3/4)+3*x^3/(x^4+1)^(1/4)
82. diff(x^2*(x^3+1)^5) = x*(x^3+1)^4(17x^3+2)
83. diff((x^2-1)/x^3) = -1/x^2+3/x^4
84. diff((x+1)^(1/2)*(x-1)^(1/2)) = x/((x^2-1)^(1/2))
85. diff((x^2+2*x+1)^(1/2)) = (x+1)/((x+1)^2)^(1/2)
86. diff((x^3+3*x^2+3*x+1)^(1/3)) = 1
87. diff(x*(x+1)^(1/2)) = (3*x+2)/(2*(x+1)^(1/2))
88. diff((x^2+1)/x^(1/2)) = 3/2*x^(1/2)-1/(2*x^(3/2))
89. diff((x-1)/(x*(x+1))) = (-x^2+2*x+1)/(x^2*(x+1)^2)
90. diff((x^4+1)^(1/2)/x^2) = -2/(x^3*(x^4+1)^(1/2))
91. diff((x+1)^3*(x+2)^4) = (x+1)^2*(x+2)^3(7x+10)
92. diff(x^2/(x^2+4)^(1/2)) = (x^3+8*x)/((x^2+4)^(3/2))
93. diff((x^2+1)^2*(x^3-1)) = (x^2+1)*(7*x^4+3*x^2-4*x)
94. diff((x-1)^5/(x+1)^3) = 2*(x+4)*(x-1)^4/(x+1)^4
95. diff(x*x^(1/2)*x^(1/4)) = 7/4*x^(3/4)
96. diff((x^2-1)^(1/2)*(x^2+1)^(1/2)) = 2*x^3/((x^4-1)^(1/2))
97. diff(((x^2+1)^3+1)^2) = 12*x*(x^2+1)^2*((x^2+1)^3+1)
98. diff((x-1)^2*(x-2)^3*(x-3)^4) = (x-1)*(x-2)^2*(x-3)^3(9x^2-34*x+29)
99. diff((x^2+2*x+2)^50) = 100*(x+1)*(x^2+2*x+2)^49
100. diff(((x^2+1)^(1/2)+x)^2) = 2*((x^2+1)^(1/2)+x)^2/(x^2+1)^(1/2)

其中不通过的有:
67. diff(x^2*(1-x)^3)

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published