Stack Exchange Network

Stack Exchange network consists of 175 Q&A communities including Stack Overflow, the largest, most trusted online community for developers to learn, share their knowledge, and build their careers.

Visit Stack Exchange

Questions tagged [expression-manipulation]

How to manipulate expressions structurally, not necessarily complying with the rules of algebra.

0
votes
0answers
16 views

Manipulating expressions containing complex exponentials and double integrals

Given that I have Integrate[Integrate[Exp[I w (x-u+v)]f[u, v] , u], v] $\int\left( \int e^{iw(x-u+v)} f[u, v] du\right) dv$ First, I want to first extract ...
4
votes
3answers
185 views

How is Sequence[Range[5], 3, 2] // Partition@# & parsed?

For learning purposes, I want to rewrite the following Partition@Sequence[Range[5],3,2] {{1,2,3},{3,4,5}} into another one ...
1
vote
2answers
48 views

Convert String in Expression to Integer

I have reviewed many string replacement Q&A but I have been unable to apply them to this case (MWE): ...
1
vote
2answers
40 views

Collect term in a distributive way

Consider P = x (a2 b2 v^a2-1+a3 b3 v^a3-1+d1+d2-2 y)-(y-d1)(y-d2)-x I would like to collect terms in (x,y,z) in a distributive way, that is to get an expression ...
0
votes
0answers
11 views

Transform String to Expression [duplicate]

I have a variable postVector and another called CHKpostVector. Both are global variables. Only the variable ...
1
vote
0answers
43 views

Do replacement only on certain specific forms

If I want to replace, say, a with a1 + a2 in an expression, I can write ...
0
votes
1answer
20 views

Extract terms containing a specific symbol from an expression

I would like to be able to extract terms that contain either a symbol or a small expression from a larger one. Example (with a somewhat complicated function to give the idea of what I am after): <...
3
votes
0answers
79 views

Select certain term containing some patterns and confusing pattern Alternatives in FreeQ

I am considering a function termsContain[func_,list_] which select in an expression func the terms containing the ones in the ...
1
vote
2answers
45 views

Question about replace command

I want to replace the common part in the equation by different value. Here is my equation ...
18
votes
4answers
2k views

Cleanest way to take a[b[c]] to a[b][c]

As indicated in the title I'm looking for the fastest way to transform a[b[c]] into a[b][c], and the natural generalization to ...
0
votes
1answer
33 views

Expression replacement with variable exponents

I have an expression that consists of a large sum of variables of powers like: X[1]^(2p) X[2]^2 + X[1]^2 X[2]^(2p) + X1[1]^(1+p) X[2]^(1+p) ... Now I would like ...
5
votes
2answers
191 views

How to find all variables of an expression?

Is there a function that can extract a list of variables in an expression? For example, assume we have an expression x^2+y^3+z This expression has variables x, y ...
4
votes
1answer
93 views

How to bring out all factors recursively except one particular term?

I want to write a function keepOnly[expr_, keep_] Such that keepOnly[f[f2*g[g2*h[h2*keep, h1], g1], f1], keep] becomes ...
0
votes
1answer
26 views

How to save numbers that stand in front of x, y, z in expression in to variables, A,B,C

I have a different plane functions in form: Ax+By+Cz =0 I need a factors A, B, C which stand in front of variables x, y and z. Is there any function in Mathematica to do something like this?
1
vote
1answer
41 views

Extracting parts of symbolic expressions

I've searched around and found things that could help me only in cases that are simpler than the one I had in mind. I would like to extract polynomials from expressions that schematically look like $$...
0
votes
0answers
31 views

Manipulating Equations: Substracting two equations

I was wondering why I fail to substract two equations using thread, while it works properly, as described here for additions. Example: Let a system of equations be given: ...
4
votes
2answers
331 views

Drop 1st element of {#a, #b, #c} &

I pass the following to a function: {#a, #b, #c} & These are keys that are used in a list of associations. There are instances where I want to pass only the ...
0
votes
0answers
43 views

How to stop evaluation of Zeta with even arguments

It could be a duplicate question. However I could not find much after a huge searching. I have a huge expression in mathematica involving many Zetas. I want not to evaluate the even Zetas which ...
1
vote
0answers
47 views

Selecting the 1st and then subsequent elements in an expression [closed]

I'm using a mixture of Span and Part to try and extract the arguments of a function that I need. I'm using a function such as $...
1
vote
1answer
41 views

Factor common terms out of a sum, without changing it otherwise?

I have some expressions, that consist of rather lengthy sums such as ...
2
votes
0answers
58 views

Generating a list of 4-digit integers by simulating four dice being thrown eight times

I simulate throwing four dice and merge their values together to form a 4-digit number. This is done eight times and I want to get a list like this one: ...
3
votes
1answer
46 views

Apply on Message resolves MessageName before applying

I want to make a Message from a List. Message[LibraryFunction::argx, 1, 3] ...
1
vote
2answers
48 views

Define a bilinear function of strings

I have a linear combinations of strings, e.g. combStrings = 0.1 "a" + 0.2 "b" I want to define a function f[] which deals ...
1
vote
2answers
41 views

Move part of expression

What is the best way to take a part of an expression and put it somewhere else in the same expression? Essentially I need to combine a Extract, ...
1
vote
1answer
58 views

Simplifying a Sum of Fractions by Removing Fractions in Denominators

I have a sum of fractions of the form $x1 - \frac{(x2 + x3)}{(x4 + x5)} - \frac{(x6 + \frac{x7}{x13})}{(x8 - x9 - \frac{x10}{(x11 + x12)})}.$ How might I simplify it to remove fractions from the ...
0
votes
3answers
98 views

Replacements within a mathematica expression?

Say I have many expressions of the form $$\text{expr} = \frac{1}{AB(C+D)^n E^m}$$ where $A,B,C,D$ and $E$ are symbols and $n,m$ arbitrary powers. In order to convert between the mathematica output and ...
3
votes
1answer
37 views

InitializationFunction for TemplateObject

Shortly, I want something like this to work: ...
1
vote
3answers
77 views
2
votes
2answers
48 views

Expanding powers in an expression and Hold

Let an expression like -(1/2) + (3 x^5)/2 be given. How can this be turned into -(1/2) + (3 x x x x x)/2? All powers of ...
0
votes
0answers
41 views

How to use === with condition?

I have two expressions, and they are same when k is positive and x is non-zero real number. Below code gives me ...
4
votes
2answers
88 views

Expanding Log[Product[…]]

I'm trying to get the log-likelihood of a Gaussian in the form $$ p(\textbf{x}|u,\sigma^2)=\prod_{n=1}^{N}\mathcal{N}(x_n|\mu,\sigma^2) \quad (1) $$ $$ \ln\ p(\textbf{x}|\mu,\sigma^2)=-\frac{1}{2\...
6
votes
3answers
227 views

How can I delete a random part of an expression?

I have the expression: Times[0.19157500241430547,Power[Plus[0.7235014213631388,k,Times[-1,Power[m,c]]],Times[g,z]]] Also represented as: ...
5
votes
2answers
158 views

Extracting coefficients from sum

I'm having the hardest time working if I have a sum of products, with coefficients out the front, like expr = 1 + 2 a[0] b[1] + 2 a[0] b[1] c[3] + c[6] + 5 d[3, 4] ...
3
votes
2answers
102 views

Handling long expressions

After using Expand on the result of a calculation I get a long expression which is a sum of 8654461 terms (nearly 8.7 million). ...
1
vote
3answers
62 views

Elimination of terms not containing at least one variable from a set

I have an expression with each term therein either containing at least one $n_i \in \left\{ n_1 , n_2 \dots , n_{5} \right\}$ or no $n_i$ at all. I would like to easily eliminate all the terms that ...
3
votes
2answers
135 views

Sums as rational vector dot products with a basis constants vector

I have series of values which, by visual inspection, appear to be sums of certain constants, not divisible by each other, with rational weights. I want to convert these sums to vectors of weights for ...
1
vote
0answers
51 views

Collect/Expand with D

I am new to MMA and have a basic question. I am trying to separate the derivatives of an expression for simplification. E.g. on doing ...
0
votes
2answers
77 views

rewriting negative powers

I often run into the problem that Mathematica refuses to simplify divergent subexpressions as part of a full expression that is manifestly finite. This only happens when a symbolic power is involved. ...
1
vote
3answers
218 views

Collect doesn't work properly

I run Want to write an expression in the form of expr= (b rr^w+ q rr^v +...)/(c rr^n + p rr^m + d rr^s +...) To do that, I write ...
3
votes
4answers
74 views

Splitting Piecewise with vectors to components

I have a piecewise function defined with vectors, e.g. ab = Piecewise[{ {{a1, a2, a3}, 0 < r < 1}, {{b1, b2, b3}, 1 < r < 2} }, {c1, c2, c3}] The ...
6
votes
5answers
239 views

First evaluate in place all subexpressions matching pattern before substituting result

ReplaceAll[expr, {patt1:>rhs1, patt2:>rhs2, …}] works by looking for and making all possible replacements of subexpressions in ...
1
vote
1answer
49 views

Low level built-in function to transpose expression (not array) [closed]

I have an expression like this F[G[1, b], G[3, y], G[4, y], G[5, u]] that I would like to Transpose to obtain ...
3
votes
4answers
183 views

How to separate integers and radicals from a term?

If I have a variable such as r = 1 + Sqrt[2] + Sqrt[13] how can I separate that into two separate variables with the rational and irrational parts? i.e. ...
0
votes
1answer
24 views

Keeping terms separate without combining it especially with multiplied random numbers

Suppose I have an expression where random numbers in exponentials are multiplied and this expression will keep on iterating such that more of such terms will occur. But I need to keep those terms as ...
5
votes
2answers
133 views

How to mark leaves of polynomial based on its position in tree

I've been struggling with this for a few days, and so I thought I might ask this here. Part of the problem lies in the fact that I do not even know the mathematical solution, which runs the risk of ...
1
vote
0answers
110 views

Split expression into nested list of summands, times and dot products

In order to avoid the XY Problem we might have encountered in another question I asked, here I ask a new question with full context: I want to get a list representation of an expanded expression, ...
0
votes
0answers
31 views

Assume Symbolic Elements as Scalars in Distribute

So yesterday I asked about TensorExpand but it turns out that it is way too slow for my needs. I want Mathematica to know that my symbolic variables are scalars, so I don't have the parentheses in my ...
1
vote
1answer
32 views

Assume symbolic elements as reals in TensorExpand

Let's assume that a, b are complex variables, and A[t],B[u], C[t,u] are matrices. ...
1
vote
1answer
40 views

How to force Refine to use a specific form

I have an assumption relating three variables and Simplify (and all functions that use assumptions) seem to take preference on one of these variables. For example: ...
2
votes
0answers
47 views

How does one generically expand the argument of a gamma function? [closed]

I have expressions of the form Gamma[2 (56 + k)] which I would like to convert to Gamma[112 + 2 k] But ...