# computer-algebra-systems

##### Force evaluate index expression before passing to sum()

Question I want to write an (somehow) enhanced sum function which takes a number of indices at once, but I cannot understand how to get it work. Here is what I currently have: (%i1) nsum(indexes, expr) := if indexes = [] then expr else nsum(rest(indexes), sum(expr, first(indexes),1, N)) $ (%i2) nsum([i,j], i+j), nouns; sum: index must be a symbol; found intosym(first(indexes)) #0: nsum(indexes=[k,j],expr=k+j) I think this could be fixed by forcing Maxima expand first(indexes) into a symbol before passing to sum function. I tried ''(...) and ev(..., nouns), but without any success. Answer1

2021-09-23 09:43:33 分类:技术分享 symbolic-math quote maxima computer-algebra-systems

##### Sympy: Drop higher order terms in polynomial

Question Using Sympy, say we have an expression f, which is a polynomial of the Symbol "x" (and of potentially other symbols). I would like to know what if there is an efficient way to drop all terms in f of order greater than some integer n. As a special case I have a very complicated function but i want to only keep terms up to 2nd order in x. What's the efficient way to do this? The obvious, not-very-efficient way to do it would be for each m less than n, take m derivatives and set x to 0 to obtain the coefficient of x^m. We obtain each coefficient this way then reconstruct the polynomial

2021-09-01 07:25:23 分类:技术分享 python sympy symbolic-math computer-algebra-systems polynomials

##### Haskell library like SymPy? [closed]

Question Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 6 years ago. Improve this question I need to manipulate expressions like 1 + sqrt(3) and do basic arithmetic like addition, subtraction, and division. I'd like the result to be in some sort of canonical form so that it can be used as a key in a map. Turning 1 + sqrt(3) into a float is not feasible due to roundoff problems. I used SymPy for this task in Python. Is there an equivalent native

2021-06-22 21:12:37 分类:技术分享 haskell symbolic-math computer-algebra-systems

##### How to do function composition in Sympy?

Question I want to do something like h = f(g(x)) and be able to differentiate h, like h.diff(x). For just one function like h = cos(x) this is in fact possible and the documentation makes it clear. But for function compositions it is not so clear. If you have done this, kindly show me an example or link me to the relevant document. (If Sympy can't do this, do you know of any other packages that does this, even if it is non-python) thank you. Answer1 It seems that function composition works as you would expect in sympy: import sympy h = sympy.cos('x') g = sympy.sin(h) g Out[245]: sin(cos(x)) Or

2021-06-01 15:54:38 分类:技术分享 python sympy computer-algebra-systems

##### Multivariate Taylor approximation in sympy

Question I aim to write a multidimensional Taylor approximation using sympy, which uses as many builtin code as possible, computes the truncated Taylor approximation of a given function of two variables returns the result without the Big-O-remainder term, as e.g. in sin(x)=x - x**3/6 + O(x**4). Here is what I tryed so far: Approach 1 Naively, one could just combine the series command twice for each variable, which unfortunately does not work, as this example shows for the function sin(x*cos(y)): sp.sin(x*sp.cos(y)).series(x,x0=0,n=3).series(y,x0=0,n=3) >>> NotImplementedError: not sure of

2021-05-25 02:59:34 分类:技术分享 python sympy computer-algebra-systems symbolic-computation

##### Dealing with piecewise equations returned by sympy integrate

Question In sympy I have an integral which returns a Piecewise object, e.g. In [2]: from sympy.abc import x,y,z In [3]: test = exp(-x**2/z**2) In [4]: itest = integrate(test,(x,0,oo)) In [5]: itest Out[5]: ⎧ ___ ⎪ ╲╱ π ⋅z │ ⎛ 1 ⎞│ π ⎪ ─────── for │periodic_argument⎜──────────────, ∞⎟│ ≤ ─ ⎪ 2 │ ⎜ 2 ⎟│ 2 ⎪ │ ⎝polar_lift (z) ⎠│ ⎪ ⎪∞ ⎪⌠ ⎨⎮ 2 ⎪⎮ -x ⎪⎮ ─── ⎪⎮ 2 ⎪⎮ z ⎪⎮ ℯ dx otherwise ⎪⌡ ⎪0 ⎩ I would like to extract just the first branch of this piecewise equation, in other words, I would like to be able to do something like itest.parts(0)to extract simply sqrt(pi)*z/2. I can't seem to find any way

2021-05-18 06:59:43 分类:技术分享 python sympy symbolic-math computer-algebra-systems symbolic-computation

##### Sign of a symbolic algebraic expression

Question Is there any algorithm that can find the sign of an arbitrary symbolic algebraic expression given in a "Tree - Form"? I know that a general algorithm doesn't exist because the zero recognizion problem is undecidable for an arbitrary expression, but how should I approach the problem of finding the sign of an expression? (how is this done in computer algebra?) For example: sign(sqrt(2)-1) = ? Answer1 Evaluate the function value You need function evaluator engine for that (it is not that hard to code) there is no way to evaluate sign only if you want to support +,- operations !!! All my

2021-04-29 16:02:23 分类:技术分享 algorithm algebra computer-algebra-systems