1
$\begingroup$

Is it possible to make Mathematica FullSimplify all expressions automatically? I am performing symbolic computations and I am trying to avoid writing FullSimplify around every line of code.

UPDATE:

In light of some of the comments, I thought it would be worthwhile to provide more context regarding the application I had in mind.

It is a common situation while manipulating well-behaved functions, such as symbolic polynomials of several variables, that one is interested in performing standard, simple yet potentially lengthy computations. These could include taking derivatives and cross products, normalizing, or forming and inverting matrices. Some of these operations involve square roots and absolute values, which do not simplify when the variables are symbolic. Multiple layers of these processes can produce very long formulas, obscuring patterns that would otherwise be evident.

The goal is to use Mathematica to experiment with different combinations of operations, observe the resulting formulas and adjust, without having to constantly specify simplification and assumptions. From the comments, it seems that a good way of doing this would be:

$Post=FullSimplify;

$Assumptions=...;

...work space...

$Post=.;

$Assumptions=True;

What would be the correct way of adding TimeConstrained to $Post at the beginning? As @Nasser suggested this is a good idea if one is worried about FullSimplify taking too long.

2nd UPDATE:

From @Domen: $Post = FullSimplify[#, TimeConstraint -> 30] &;.

$\endgroup$
9
  • 3
    $\begingroup$ $Post = FullSimplify; $\endgroup$
    – Domen
    Dec 25, 2022 at 20:12
  • 8
    $\begingroup$ Be careful doing FullSimplify after each command. FullSimplify could easily end up taking very very long time since it tries many things, and your code will end up taking hrs to finish depending how long it is. I normally put TimeConstrained on it if I have to use it. $\endgroup$
    – Nasser
    Dec 25, 2022 at 20:22
  • 5
    $\begingroup$ Often, to be fully effective, FullSimplify needs to be provided with appropriate assumptions. $\endgroup$
    – Bob Hanlon
    Dec 25, 2022 at 21:32
  • 1
    $\begingroup$ To add options to FullSimplify use $Post = FullSimplify[#, TimeConstraint -> 30] &; $\endgroup$
    – Domen
    Dec 27, 2022 at 14:09
  • 1
    $\begingroup$ Block[{$Post = ... }, ...] does not do anything because $Post would only be applied after the block has exited. Are you aware that you can type // FullSimplify directly at the end of an output, which is quite quick to do? That might be the best solution for you. I assume that by now you have tried out $Post = FullSimplify and discovered why it's not a practically workable solution. $\endgroup$
    – Szabolcs
    Dec 27, 2022 at 14:51

1 Answer 1

2
$\begingroup$

Will it solve your difficulty if you introduce a short version of its name, like fS?

For example,

fS[x_, ass__ : Automatic] := FullSimplify[x, Assumptions -> ass] 

Its use requires then much less typing. For example, this is with no assumptions:

(1/a - 1/(b + c))/(
  1/a + 1/(
   b + c))*(1 + (b^2 + c^2 - a^2)/(2*b*c))/((a - b - c)/(a*b*c)) // fS

(* 1/2 a (a - b - c)  *)

or with the assumptions:

(Sqrt[Sqrt[m] - Sqrt[(m^2 - 9)/m]] + Sqrt[
    Sqrt[m] + Sqrt[(m^2 - 9)/m]])^2*Power[m^2/4, (4)^-1] //fS[#, m > 0] &

(*  Sqrt[2] (3 + m)  *)

The analogous short-cut you might make also with the Simplifyto avoid using FullSimplifyeverywhere.

Hope this helps. Have fun!

$\endgroup$
3
  • 3
    $\begingroup$ You seem to underestimate the @Nasser's comment. $\endgroup$ Dec 26, 2022 at 21:26
  • $\begingroup$ It was not my intention. Let me edit my comment. $\endgroup$
    – mmen
    Dec 27, 2022 at 10:17
  • $\begingroup$ I think @Domen ‘s suggestion using $Post is really straight forward, and useful for prototyping. One only has to be careful about when to use it as as @Nasser and @kirma have warned. @Bob Hanlon, note that it can also be combined with $Assumptions for a very effective use. $\endgroup$
    – mmen
    Dec 27, 2022 at 10:22

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.