Questions in category: 符号运算 (Symbolic operations)
软件 >> Calculator >> 符号运算

1. solve()函数应用于多项式方程

Posted by haifeng on 2023-02-12 14:37:31 last update 2023-02-12 16:01:22 | Answers (0) | 收藏


已知多项式 $x^{13}+x+90$ 能够被 $x^2-x+a$ 整除, 其中 $a$ 是整数, 求 $a$.

问题见于 已知多项式 x^13+x+90 能够被 x^2-x+a 整除,其中 a 是整数,求 a - 基础数学 - 数学中国 - Powered by Discuz! (mathchina.com)

我们扩充了 Calculator 的 solve() 函数的功能, 使之对多项式方程也能处理. 

首先进入 polyn 模式

>> :mode=polyn

然后输入下面的代码, solve 的语法是 solve(equation,x,minValue,maxValue), 其中变量 x 的范围是  $x\in [minValue, maxValue)$.

根据题设, $90$ 能被 $a$  整除, 因此, 搜索的范围可设定在 $[-90,90]$.

>> solve((x^13+x+90)mod(x^2-x+a)==0,a, -90, 90)

 

 

2. 求 Jacobi 符号 $\bigl(\frac{853}{1409}\bigr)$

Posted by haifeng on 2023-02-02 17:57:24 last update 2023-02-02 18:02:06 | Answers (0) | 收藏


求 Jacobi 符号 $\bigl(\frac{853}{1409}\bigr)$

 

>> Jacobi(853,1409,show)
in> Jacobi(853,1409,show)

(556|853) = (139|853)

(6|19) = (2|19)(3|19)
(2|19) = -1

(3|19) = -(19|3) = -(1|3) = -1
(19|139) = -(139|19) = -(6|19) = -1
(139|853) = (853|139) = (19|139) = -1
(853|1409) = (1409|853) = (556|853) = -1
-------
result> -1

------------------------

 

从上面的结果, 可以整理得

(853|1409) = (1409|853) = (556|853)= (139|853) = (853|139) = (19|139) =  -(139|19) = -(6|19)

= -(2|19)(3|19) = -(-1)(3|19) = (3|19) = -(19|3) = -(1|3) = -1

\[
\begin{split}
\bigl(\frac{853}{1409}\bigr) &= \bigl(\frac{1409}{853}\bigr) = \bigl(\frac{556}{853}\bigr) = \bigl(\frac{139}{853}\bigr) = \bigl(\frac{853}{139}\bigr) = \bigl(\frac{19}{139}\bigr) =  -\bigl(\frac{139}{19}\bigr) = -\bigl(\frac{6}{19}\bigr)\\
&= -\bigl(\frac{2}{19}\bigr)\bigl(\frac{3}{19}\bigr) = -(-1)\bigl(\frac{3}{19}\bigr) = \bigl(\frac{3}{19}\bigr) = -\bigl(\frac{19}{3}\bigr) = -\bigl(\frac{1}{3}\bigr) = -1
\end{split}
\]

 

3. [Calculator] 计算 $(x+1)^8\cdot(x^4-8x^3-12x^2-8x-2)$.

Posted by haifeng on 2023-01-03 17:07:16 last update 2023-01-03 17:08:36 | Answers (0) | 收藏


[Calculator] 计算 $(x+1)^8\cdot(x^4-8x^3-12x^2-8x-2)$.

 

符号运算 - 开发应用 - 数学研发论坛 - Powered by Discuz! (emath.ac.cn)

 

 

>> (x+1)^8*(x^4-8x^3-12x^2-8x-2)
in> (x+1)^8*(x^4-8x^3-12x^2-8x-2)

out> x^12-48x^10-272x^9-780x^8-1416x^7-1764x^6-1560x^5-987x^4-440x^3-132x^2-24x^1-2

------------------------

 

 

4. 多项式的加法

Posted by haifeng on 2022-11-28 22:02:15 last update 2022-11-28 22:02:15 | Answers (0) | 收藏


如果使用单链表存储多项式, 则在进行多项式的加法时, 应事先降幂排列.

例如下面的 polyn.exe 测试程序, 可以输入多个参数, 若要执行 $2x^3-x^2+8$ 加上 $4x^4-3x^3+6x+9$, 则可以输入

polyn.exe "2x^3-x^2+8" "4x^4-3x^3+6x+9"

这里已经降幂排列.

D:\work\cs\c++\datastruct\Polynomial\polyn_vc\polyn\Debug>polyn.exe "2x^3-x^2+8" "4x^4-3x^3+6x+9"
argv[1] is 2x^3-x^2+8
        2x^3-1x^2+8x^0

argv[2] is 4x^4-3x^3+6x+9
        4x^4-3x^3+6x^1+9x^0


---------
add 2x^3-x^2+8 and 4x^4-3x^3+6x+9
2x^3-1x^2+8x^0
4x^4-3x^3+6x^1+9x^0
[1] p2-> 4x^4
[2] p1=p2 -1x^3
[3] p1-> -1x^2
[4] p2-> 6x^1
[5] p1=p2 17x^0

------
4x^4-1x^3-1x^2+6x^1+17x^0

 

如果输入的多项式并非已降幂排列, 则 add 程序的算法要么改进, 要么改进多项式存储的数据结构, 比如改为线索树存储.

D:\work\cs\c++\datastruct\Polynomial\polyn_vc\polyn\Debug>polyn.exe "2x^3-x^2+8" "4x^4+6x-3x^3+9"
argv[1] is 2x^3-x^2+8
        2x^3-1x^2+8x^0

argv[2] is 4x^4+6x-3x^3+9
        4x^4+6x^1-3x^3+9x^0


---------
add 2x^3-x^2+8 and 4x^4+6x-3x^3+9
2x^3-1x^2+8x^0
4x^4+6x^1-3x^3+9x^0
[1] p2-> 4x^4
[2] p1-> 2x^3
[3] p1-> -1x^2
[4] p2-> 6x^1
[5] p2-> -3x^3
[6] p1=p2 17x^0

------
4x^4+2x^3-1x^2+6x^1-3x^3+17x^0

 

5. [Bug] Calculator 中的计算bug

Posted by haifeng on 2022-09-14 20:16:40 last update 2022-09-14 20:35:29 | Answers (0) | 收藏


>> (1000*x+100*y)%99
in> (1000*x+100*y)%99

out> 1010475858

 

 

>> (1000*x+100*y)mod99
in> (1000*x+100*y)@99

out> 71

 

 

>> (1000*120+100*121)
in> (1000*120+100*121)

out> 132100

------------------------


>> 132100%99
in> 132100%99

out> 1334

------------------------


>> (1000*120+100*121)%99
in> (1000*120+100*121)%99

out> 13.08050302

------------------------


>> (1)%(2)
in> (1)%(2)

out> 50

------------------------


>> (1)%(1)
in> (1)%(1)

out> 100

------------------------

>> (2)%(1)
in> (2)%(1)

out> 100

------------------------


>> (3)%(1)
in> (3)%(1)

out> 100

------------------------


>> (n)%(1)
in> (n)%(1)

out> n

------------------------

 

6. 记录 Calculator 的 BUG

Posted by haifeng on 2020-12-18 21:12:47 last update 2020-12-28 14:16:47 | Answers (0) | 收藏


[BUG]2020-12-18

>> a/b+c/d-c/d
in> a/b+c/d-c/d

out> (a*d+b*c*d-b*d*c)|(b*d*d)

正确的, 应该是 (a*d*d+b*c*d-b*d*c)|(b*d*d)

通过化简, 应该仍是 a/b 

 


>> (1+3a)/3+3/1
in> (1+3a)/3+3/1

out> a=1; b=1; c=3a; d=1
a=+3a; b=3; c=3; d=1
a+9

这里第二步, a=1+3a, 而不是 +3a


>> (a+3a)/3+3/1
in> (a+3a)/3+3/1

out> a=a; b=1; c=3a; d=1
a=a+3a; b=3; c=3; d=1
(a+3a+9)|3

------------------------


>> (2+3a)/3+3/1
in> (2+3a)/3+3/1

out> a=2; b=1; c=3a; d=1
a=2+3a; b=3; c=3; d=1
a+2+9


以上已解决

[BUG]2020-12-21

>> (1+3a)/3*(3/1)
in> (1+3a)/3*(3/1)

out> (3+9a))|3


>> (1+3a/3)*(a/1)
in> (1+3a/3)*(a/1)

out> 3a/1
3/1
3a/1
3/1
(3a+3a)*a/3
((3a+3a)*a)|3


[+(a +b +c) ]*[+d ]
_tmp = (a*d
_tmp = b*d
(a*d+b*d+c)*d/1
(a*d+b*d+c)*d


Bug 的原因在于这里是按 + 来分割的. 没有考虑 ( ) 的作用.

Remark: 以上 Bugs 都已经解决。2020-12-24

 

不过还有一点小问题:
 

>> ((3+a)*2-3(a-b)/c)*8
in> ((3+a)*2-3(a-b)/c)*8

out> a*2*8-8(3*a+3*b)/c+48

------------------------


>> :mode=fraction
Switch into fraction calculating mode.
e.g., 1/2+1/3 will return 5/6

>> ((3+a)*2-3(a-b)/c)*8
in> ((3+a)*2-3(a-b)/c)*8

out> 8(2(3+a)*c-3(a-b))|c

------------------------


>> :expand=on
Expand on. In fraction calculation mode,
e.g., (a+b)*(c+d) will return a*c+a*d+b*c+b*d.

>> ((3+a)*2-3(a-b)/c)*8
in> ((3+a)*2-3(a-b)/c)*8

out> 8(2(3+a)*c-3(a-b))|c
 ==> 8*2*a*c+8*6*c-8*3*a+8*3*b|


------------------------

[BUG] 2020-12-25,  无法识别 solve() 函数

>> solve(x^2==25,x,1,10)
in> solve(x^2~25,x,1,10)
cmd> solv
>> function solv() is not defined.

已解决 12-25


>> (a+3)-(b-4)
in> (a+3)-(b-4)

out> a-b7

应该返回 a-b+7.  已经解决.


在 numerical 模式(:mode=numerical)下

>> (((a+2)+3)-4)/4
in> (((a+2)+3)-4)/4

out> a1/4

分数计算模式下(:mode=fraction),  应该返回 a+1|4

已经解决  on  2020-12-26


>> (1+3a)/3*(3/1)
in> (1+3a)/3*(3/1)

out> 3(1+3*a)|3
 ==> 3*3*a+3|3


------------------------


>>  3*3*a+3
in> 3*3*a+3

out> (9*a+3)
 ==> 9*a+3

需要两次化简


>> 3*(a-(b*3-4)+d)/c
in> 3*(a-(b*3-4)+d)/c

out> 3(a-b*3-4+d)|c
 ==> 3*a-3*b*3+3*d-12|

BUG  2020-12-26


>> ((3+a)*2-3(a-(2b-3)+5)/c)*8
in> ((3+a)*2-3(a-(2b-3)+5)/c)*8

out> 8(c*2(3+a)-(3(a-2b-3+5)))|c
 ==> 16c*a+48c-24a+48b-48|c

BUG  2020-12-26

正确的应该是 16c*a+48c-24a+48b-192|c


>>  1-(a-3)/a
in> 1-(a-3)/a

out> -(a+3)/a+1

BUG  2020-12-26

正确的应该是  -(a-3)/a+1

已解决.


>> x(x-1)(x-3)
in> x(x-1)(x-3)
>> function x() is not defined.

>> 2(x-1)(x-3)
in> 2(x-1)(x-3)

out> (x-1)*(x-3)

------------------------


>> (x-1)(x-3)*2
in> (x-1)(x-3)*2

out> 2(x-3)

------------------------

>> (x-1)2*(x-3)
in> (x-1)2*(x-3)

out> 2x-6

这个不算是BUG, 这里的输入有误, (x-1)后面如果是数, 需要添加*

------------------------


>> ()2*(x-3)
in> ()2*(x-3)

out> 2x-6

这个也不算是BUG.

------------------------

已解决

>> (x-1)(x+2)
in> (x-1)*(x+2)

out> x*x+2x-x-2

------------------------