I am trying to write a program in Mathematica that will perform basic uncertainty analysis for me and "show the work," so to speak. One of the pieces of this program will involve taking in an expression and list of variables, say,

myexpr = w == 2 y Cos[x] + z^2
myvaris = {x, y, z, w}

and solving the expressions for the first variable in the list, e.g.

Solve[myexpr, myvaris[[1]]]

which outputs

{{x -> ConditionalExpression[-ArcCos[(w - z^2)/(2*y)] + 2*Pi*C[1], 
     Element[C[1], Integers]]}, 
{x -> ConditionalExpression[ArcCos[(w - z^2)/(2*y)] + 2*Pi*C[1], 
     Element[C[1], Integers]]}}

which is all good and correct. But what I would like to obtain is just something like

{x -> ArcCos[(w - z^2)/(2*y)]}

without all the conditional expression business, because its presence wrecks the form of the output I'd like. In particular, what I want in the end is something I can pass to TeXForm which will go into a StringForm to output a chunk of LaTeX. Is it possible to construct something like this (and if so how), or am I asking a question which cannot be solved in pure generality?

To be clear, I'm not asking how to eliminate the particular occurrences of ConditionalExpression in the output above, but to eliminate all instances of such a ConditionalExpression and arbitrary constants in general, without having to manipulate by hand any intermediate results. I'm not really concerned with the output being reliably correct or complete in the end; I just want the expression that a naive high school algebra student would write down.

  • $\begingroup$ You should use Normal. $\endgroup$
    – corey979
    Feb 13 '17 at 22:08
  • $\begingroup$ Thanks; that's a bit better but still leaves in the arbitrary constants and produces multiple rules. It's easy enough to just call the first rule and forget the rest, but is there a way to set all arbitrary constants to zero? $\endgroup$
    – Diffycue
    Feb 13 '17 at 22:12
  • $\begingroup$ Just saw Corey comment. So I deleted my answer. Normal is the recommended way. $\endgroup$
    – Nasser
    Feb 13 '17 at 22:33

You can set all generated parameters to 0 with:


{{x->-ArcCos[(w-z^2)/(2 y)]},{x->ArcCos[(w-z^2)/(2 y)]}}

  • $\begingroup$ It's probably better to use: Solve[myexpr,myvaris[[1]],GeneratedParameters->C] /. _C->0 instead. $\endgroup$
    – Carl Woll
    Feb 13 '17 at 22:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.