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

learn more… | top users | synonyms

42
votes
2answers
1k views

Head and everything except Head?

I have been working on picking expressions apart using Head and Part and encountered a little mystery. Consider the canonical ...
37
votes
3answers
860 views

Replace inside Held expression

I wish to make functional replacement inside Held expression like this: ...
22
votes
7answers
900 views

How do I get my equation to have the form $(x-a)^2 + (y-b)^2 + (z-c)^2-d = 0$?

I want Mathematica to express the equation $$-11 - 2 x + x^2 - 4 y + y^2 - 6 z + z^2=0$$ in the form $$(x - 1)^2 + (y - 2)^2 + (z - 3)^2 - 25=0$$ How do I tell Mathematica to do that?
20
votes
1answer
319 views

How can I see which transformations Simplify attempts?

The documentation for Simplify[expr] says that it performs a sequence of algebraic and other transformations on expr, and returns the simplest form it finds. How can I see which transformations it ...
18
votes
1answer
513 views

List manipulation to build a functional expression

Since Mathematica deals with Head[a, b] as an expression in this way The first Part of Head[a, b] is ...
17
votes
3answers
576 views

How can I completely ban usage of some functions in output and mandate use of others?

For example, I hate that Mathematica uses Pochhammer symbol in outputs and prefer all the expressions in Gamma function. How can ...
15
votes
1answer
351 views

List of atomic expressions

I was surprised to see Graph objects are atomic. Is there a way (through documentation or programmatically) to find all atomic heads? The ones I know of are: ...
14
votes
3answers
471 views

Comparing Mathematica expressions like diff

I am looking for a way to compare (or "diff") two Mathematica expressions, similarly to how to diff utility can compare two text files and report the differences. Has anyone already written such a ...
14
votes
1answer
271 views

Why is ReplaceAll behaving like this?

I'm learning to use the ReplaceAll function and I found the behavior of which is quite confusing. For Sqrt[f[x, y]] /. f[___] -> u Mathematica returns ...
13
votes
2answers
456 views

How to embed an image into a string?

Note: The bug described in the post is in Mathematica 9, and has been fixed in 10.0. The documentation for String contains the following statements: Strings ...
13
votes
1answer
407 views

Transform an expression into a graph that can be plotted with TreeGraph (not TreeForm)

I would like to plot an expression (like TreeForm does), but using the new TreeGraph functionality. ...
11
votes
3answers
933 views

How can I transfer mathematical expressions between Mathematica and Maple?

Is there a simple way to copy mathematical expressions between Mathematica and Maple (or at least in one direction)? I mean only expressions built from numbers and predefined mathematical functions, ...
11
votes
5answers
258 views

Construct an infix operation from a list

Inspired by this question, if I have a list {a, p, b, q, c} where p and q are binary ...
11
votes
3answers
191 views

How to collect expressions from cells created by Print?

I have a notebook where evaluation of a certain cell produced hundreds of adjacent output cells using Print. I need to create a list containing all expressions from ...
11
votes
2answers
622 views

Displaying a series obtained by evaluating a Taylor series

Description of problem I would like to use Mathematica to display the series obtained by substituting a value for $x$ in a Taylor series expansion. The terms of the series will be rational numbers, ...
11
votes
2answers
603 views

Google Code Jam: Mountain View code review

After participating in Google Code Jam 2012 Round 2, it occurred to me that the Mountain View problem boiled down to solving a set of linear inequalities, which could be done in Mathematica. I've only ...
11
votes
1answer
186 views

What are the default TransformationFunctions used in Simplify and FullSimplify?

If I do Simplify[(c^3 - s^3)^2 - (s^3 + c^3)^2, TransformationFunctions -> Automatic] (i.e. a verbose version of default behaviour), what transformation ...
10
votes
4answers
424 views

Extracting equations from Piecewise expressions

Say I have a PDF: PDF[LogNormalDistribution[1.75, 0.65], x] Calculating it, Mathematica gives me an expression that looks like this: I want to extract the ...
9
votes
2answers
3k views

How to expand tan(x+y) as normal form?

TrigExpand@Tan[x + y] gives $\frac{\sin (x) \cos (y)}{\cos (x) \cos (y)-\sin (x) \sin (y)}+\frac{\cos (x) \sin(y)}{\cos (x) \cos (y)-\sin (x) \sin (y)}$ but I ...
9
votes
2answers
200 views

How to do algebra on summations of variable expressions?

Is there any easy, general way to handle algebra on variable Sums? For examples, Gaussian Mixtures or Fourier Series: ...
9
votes
3answers
726 views

Pattern matching a pattern with patterns

Confusing title, I know. But the question is, if we have two patterns which have the same general structure but different names used in the patterns and different names: ...
9
votes
1answer
128 views

What are the scoping rules for function parameters shadowing System` symbols?

Here are some very contrived code snippets, highly unlikely to appear in real code, but still I am curious why they behave like this: ...
8
votes
4answers
758 views

Extracting variables from an expression

I'm looking for a way to extract a list of variables from an expression, for example with an input like: ...
8
votes
3answers
606 views

How to extract expression from ConditionalExpression

p1 := y /. {First[Solve[x^2 + y^2 + x == 1, y, Reals]]} ...
8
votes
2answers
184 views

How to reduce the number of operations needed to evaluate an expression? [duplicate]

For some numerical calculations in C++ I have, for example, this complicated expression to evaluate. Given as Mathematica input, in its original form it is ...
8
votes
2answers
191 views

Keep Mathematica from simplifying functions with a specified Head

I want to run Simplify and/or Refine on various expressions, but keep it from touching anything that contains a specific ...
8
votes
1answer
833 views

How do I expand a sum?

I have a problem with Mathematica's symbolic manipulations. As an example, consider the following expression: $$\sum _{i=1}^n -2 x_i \left(-a x_i-b+y_i\right)=0$$ How do I get Mathematica to expand ...
8
votes
2answers
191 views

The most external subexpression with given pattern

Suppose there is a deep expression with several instances of some _f. I want to get the most external case of _f from it (I also ...
8
votes
1answer
103 views

How to get a list of all expressions in a notebook matching a certain pattern?

Suppose I have a Mathematica notebook saved to a certain location on disk. Given a pattern I need to get the list of all expressions matching this pattern that appear in input, output or print cells ...
8
votes
0answers
198 views

How to convert a notebook cell to a string retaining all formatting, colorization of identifiers etc?

I have an opened Mathematica notebook containing several cells. Suppose, I am interested in one of them -- it may contain a complete or incomplete expression (e.g. with syntax errors, highlighted ...
7
votes
4answers
358 views

Counting multiplications (complexity function)

I'm trying to count the number of times multiplication appears in an expression (for the purpose of constructing a ComplexityFunction that would help me simplify a terrible algebraic expression for ...
7
votes
3answers
134 views

Thread over uneven (ragged) expressions with full functionality?

There are a number of questions on this site about "threading" including several relating to uneven (ragged) lists. However, none that I could find deal with the full functionality of ...
7
votes
2answers
399 views

How to automatically get rid of trig functions in an expression?

I have a large expression containing many terms like this: Sin[1/2 ArcTan[(2 Log[5])/(Log[5]^2 - 2)]] where a trig function is invoked on a rational multiple ...
7
votes
1answer
92 views

Need a generalization of RootApproximant to recognize linear combinations over algebraic numbers

RootApproximant does a very good job when I need to recognize an algebraic number and when enough of its digits are known (or even when an unlimited number of ...
6
votes
6answers
147 views

Trying to write out the prime factorization of a number with CenterDot and Superscript

I am trying to use CenterDot and Superscript, in conjunction with Apply to write out the prime factorization of any given integer. Everything works well UNLESS the prime factorization of the number ...
6
votes
4answers
150 views

Expression manipulation: Explode sums and products? [duplicate]

I wonder if the functionality exists to explode a sum, or product? What I mean by that is the following. Imagine, you have input data data = a + b c - d e f ; Is ...
6
votes
2answers
121 views

Partial result of aborted evaluation of FullSimplify

When FullSimplify invoked on a large expression, it can run for hours. If I do not have time to wait, and abort the evaluation, I get no result, although, ...
6
votes
2answers
283 views

How to get the matrix coefficient from a QuadraticForm expression in a very fast way?

As we know, QuadraticFormDistribution is the distribution of z.a.z + b.z + c for a real-valued p x p symmetric positive definite ...
6
votes
3answers
283 views

Threading Distribute[]

I wish to use Distribute[p.(q+r)+m] to get p.q+p.r+m. However, Distribute apparently does not thread through all parts of the ...
6
votes
1answer
231 views

Summa package problem

I need to use the features of the Summa package but it doesn't work in Mathematica 9. It gives the error Cannot open Utilities`FilterOptions` My question is: ...
6
votes
2answers
115 views

Why is ToRadicals[] not able to handle all cases? Is there a workaround?

The documentation for the function ToRadicals says: ♦ There are some cases in which expressions involving radicals can in principle be given, but ...
6
votes
1answer
129 views

Is it possible to disable assumptions used by FullSimplify for zero testing [closed]

Sometimes when I invoke FullSimplify on a large expression, I get a series of messages like this: ...
6
votes
0answers
164 views

Using FunctionExpand to evaluate symbolic derivatives

Some symbolic derivatives of certain special function are not expanded automatically, but FunctionExpand often helps to get a derivative-free closed form ...
5
votes
4answers
209 views

Concatenating strings, unevaluated expressions and evaluated expressions/values

Maybe this is something very simple to some of you. Anyway, I think this can be useful to many others like me. I would like to build an output that involves strings, unevaluated expressions and ...
5
votes
5answers
173 views

Is there an analogue of the Variables command for general expressions?

The command Variables[poly] gives me a list of all variables that appear in the expression poly, which involved sums, ...
5
votes
2answers
193 views

Passing list of options to Plot

I'm looking for a way to create a variable that I can use to hold all of the graphics directives for, say, a plot command. For example, I have 8 plots with variations on the following: ...
5
votes
1answer
80 views

Why is NHoldFirst not propagated to symbolic derivatives?

I encountered a nasty problem that N cannot evaluate expressions containing a symbolic Derivative of a multi-parameter function ...
5
votes
1answer
83 views

MapIndexed stops at levelspec 1 if only the index is passed?

If the function passed to MapIndexed references the first (or data) argument, the following performs as expected: ...
5
votes
2answers
227 views

How can I retrieve the point coordinates from a LOG Plot after the data points were manually moved?

I'm having problems with getting coordinates out ofa ListLogLogPlot I basically plotted a list, then selected data points on the graph, moved these points around, ...