4
$\begingroup$

I am trying to reduce some equations and get the final simplified answer. But there are two issues.

This is just an example to show what my problem is. There are lots of similar samples with the same issue for me.

Reduce[((x >= xP && Mod[x, Abs[1]] == Mod[xP, Abs[1]] && x >= xP &&
     t == tP && z + 2*x*t == zP + 2*xP*tP)) && Not[(xP != 10)], {t,
  xP, zP}]

And this the (copy/pasted) output:

C[1] \[Element] Integers && C[1] >= 10 && x == C[1] && t == tP &&
 xP == 10 && zP == -20 tP + 2 t x + z
  1. How do I get rid of these constants? c1 is an integer, c>=10 and x==c1, so I expect to just see x>=10. I think there must some other functions to give us a nicer output.
  2. Why doesn't it replace t and tP? I don't want to see t==tP. We expect only replacement.
$\endgroup$
3
  • 1
    $\begingroup$ Re (2): By specifying {t, xP, zP} for the variables, you ask for a solution for t. To get rid of it, mark it for elimination: Reduce[.., {xP, zP}, {t}]. Re (1): I'm not sure what will work in general. Reduce is parametrizing the solution set in terms of the integer parameter C[1]. It's designed this way. You could replace it thus: {xP, zP}, {t}] /. C[1] -> x. I'm not sure that works in all your problems, since it's based on knowing the output of Reduce. $\endgroup$
    – Michael E2
    Commented Apr 6, 2021 at 22:08
  • $\begingroup$ @MichaelE2 Thanks that was great, but now the output is this : x [Element] Integers && x >= 10 && xP == 10 && zP == -20 tP + 2 tP x + z . Is there anyway not to see "X IS INTEGER"? thanks again $\endgroup$
    – Azzurro94
    Commented Apr 6, 2021 at 22:14
  • 1
    $\begingroup$ Simplify[result, Element[x, Integers]] is one way, which may do other simplifications. Another is result /. _Element -> True, which would remove all domain specifications. I think x might have to be an integer though. $\endgroup$
    – Michael E2
    Commented Apr 6, 2021 at 22:22

2 Answers 2

6
$\begingroup$

This will get the desired result:

sol = Solve[((x >= xP && Mod[x, Abs[1]] == Mod[xP, Abs[1]] && 
    x >= xP && t == tP && z + 2*x*t == zP + 2*xP*tP)) && Not[xP != 10], 
  {xP, zP}, {tP}, MaxExtraConditions -> All];
Normal@sol

(*  {{xP -> 10, zP -> -20 t + 2 t x + z}}  *)

Or to keep the conditions but eliminate the parameters C[]:

Simplify[sol,
 TransformationFunctions -> {Automatic,
   (# /. ce_ConditionalExpression :> (ce /. 
         First@Solve[Last@ce, Cases[Last@ce, _C, Infinity], Reals]) &)}
 ]

Appendix

The OP indicates that the solution in my comment is preferred, so in keeping with SE philosophy, I will include in my answer. The reception of Bob's answer led me to think the OP didn't mind whether the output was in Solve or Reduce form, so I opted above for Solve. Besides, Normal@Solve[..] seems so simple.

Simplify[
 Reduce[((x >= xP && Mod[x, Abs[1]] == Mod[xP, Abs[1]] && x >= xP && 
       t == tP && z + 2*x*t == zP + 2*xP*tP)) && Not[(xP != 10)],
  {xP, zP}, {tP (* or t *)}
  ] /. C[1] -> x,
 x \[Element] Integers]

(*  x >= 10 && xP == 10 && 2 t (-10 + x) + z == zP  *)

I personally was somewhat dissatisfied with this solution because the replacement C[1] -> x is predicted to work only after carefully inspecting the output of Reduce. So an approach that focussed narrowly on "just an example" seems to lack sufficient robustness. The Solve approach in the second solution above, which constructs the replacement C[1] -> x, seems more robust. Probably it could be broken by carefully thinking about what would break it; however, it will work on a wider class of problems than than the narrower class that C[1] -> x fixes. But perhaps the OP's problems all belong to that narrower class.

$\endgroup$
3
  • $\begingroup$ To me the best answer is the one you mentioned in comments because it does not show "if x ......" and i want to reduce, because solve gives me these conditions in the output.( in this answer, the results is shown as somehow conditioned answer ) by the way thanks both answer is good. $\endgroup$
    – Azzurro94
    Commented Apr 8, 2021 at 16:36
  • $\begingroup$ Could you show me a link to a good document that i can learn from? i didn't find in the wolfram website such a deep instructions $\endgroup$
    – Azzurro94
    Commented Apr 8, 2021 at 17:35
  • $\begingroup$ @Azzurro94 You're welcome. I don't have a good reference/tutorial for symbolic equation solving in Mathematica, unfortunately. What I know is built from experience and goes back to before Mathematica, when I studied computer algebra and computational algebraic geometry. $\endgroup$
    – Michael E2
    Commented Apr 8, 2021 at 19:36
4
$\begingroup$
Clear["Global`*"]

Add the condition Element[x, Integers] to Reduce

sol =
  Reduce[((x >= xP && Mod[x, Abs[1]] == Mod[xP, Abs[1]] && x >= xP && 
       t == tP && z + 2*x*t == zP + 2*xP*tP)) && Not[(xP != 10)] && 
    Element[x, Integers], {xP, zP}, {t}, Reals];

Convert to a ConditionalExpression

sol2 = ConditionalExpression[
  ToRules[And @@ Cases[sol, eq_Equal, 1]] // Simplify, 
  And@@Cases[sol, _?(FreeQ[#, Equal] &), 1]]

enter image description here

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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