Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
# examples how we can use factor to reduce number of imageset :
# current master branch
In [110]: solveset(4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1) # ------------ eq(1)
Out[110]:
7⋅π ⎫ ⎧ 11⋅π ⎫ ⎧ 5⋅π ⎫ ⎧ 3⋅π ⎫ ⎧ 7⋅π ⎫ ⎧ π ⎫
2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ──── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π +| n ∊ ℤ⎬
6 ⎭ ⎩ 6 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4
In [123]: solveset((4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1).rewrite(exp))
Out[123]:
5⋅π ⎫ ⎧ π ⎫ ⎧ 3⋅π ⎫ ⎧ π ⎫ ⎧ 3⋅π ⎫ ⎧ π ⎫
2⋅n⋅π - ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π -| n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π +| n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π - ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π -| n ∊ ℤ⎬
6 ⎭ ⎩ 6 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4
# first factor the trig eq
In [112]: fact = factor_list(4*sin(x)**3 + 2*sin(x)**2 - 2*sin(x) - 1) # ------- eq(1) factors
In [113]: fact
Out[113]:
⎛ ⎡ ⎛ 2 ⎞⎤⎞
1, ⎣(2⋅sin(x) + 1, 1), ⎝2⋅sin (x) - 1, 1⎠⎦⎠
# see the factors exp form(factor them also to remove extra exp)
In [114]: factor((2*sin(x) + 1).rewrite(exp)) # -------eq(1), factor (1)
Out[114]:
2⋅ⅈ⋅x ⅈ⋅x ⎞ -ⅈ⋅x
-⎝ⅈ⋅ℯ -- ⅈ⎠⋅ℯ
In [115]: factor((2*sin(x)**2 - 1).rewrite(exp)) # -------eq(1), factor (2)
Out[115]:
4⋅ⅈ⋅x ⎞ -2⋅ⅈ⋅x
-⎝ℯ + 1⎠⋅ℯ
──────────────────────
2
# both outer exp will not give any solution
In [116]: solveset(exp(-I*x)) # --------- outside bracket - factor (1)
Out[116]: ∅
In [117]: solveset(exp(-2*I*x)) # --------- outside bracket - factor (2)
Out[117]: ∅
# these both will contribute in soln
In [118]: solveset(I*exp(2*I*x) - exp(I*x) - I) # --------- inside bracket - factor (1)
Out[118]:
5⋅π ⎫ ⎧ π ⎫
2⋅n⋅π - ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π -| n ∊ ℤ⎬
6 ⎭ ⎩ 6
In [122]: solveset(exp(4*I*x) + 1) # --------- inside bracket - factor (2)
Out[122]:
⎧n⋅π π ⎫
⎨─── +| n ∊ ℤ⎬
2 4
# now compare if we direclty solve the trig factor
# this looks same as above
In [120]: solveset(2*sin(x) + 1) # ---------current branch solves without factoring, so soln is similar - factor (1)
Out[120]:
7⋅π ⎫ ⎧ 11⋅π ⎫
2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ──── | n ∊ ℤ⎬
6 ⎭ ⎩ 6
# but this contains many imageset that is reduced above
In [121]: solveset(2*sin(x)**2 - 1) # ---------current branch solves without factoring, so soln is larger than Out[122] - factor (2)
Out[121]:
5⋅π ⎫ ⎧ 3⋅π ⎫ ⎧ 7⋅π ⎫ ⎧ π ⎫
2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π + ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π +| n ∊ ℤ⎬
4 ⎭ ⎩ 4 ⎭ ⎩ 4 ⎭ ⎩ 4
# so overall we have (if we use factor correctly, less imagesets we get)
# so ans from factor(1) and factor(2) is here(which is simpler than current master) :
5⋅π ⎫ ⎧ π ⎫
2⋅n⋅π - ─── | n ∊ ℤ⎬ ∪ ⎨2⋅n⋅π -| n ∊ ℤ⎬ ∪
6 ⎭ ⎩ 6
⎧n⋅π π ⎫
⎨─── +| n ∊ ℤ⎬
2 4
# =============================
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment