%% Rewrite Expression Using Abbreviations
% Solve the following equation. The solutions are very long expressions. To display the solutions, remove the semicolon at the end of the solve command.

syms a b c d x
solutions = solve(a*x^3 + b*x^2 + c*x + d == 0, x, 'MaxDegree', 3);

% These long expressions have common subexpressions. To shorten the expressions, abbreviate the common subexpression by using subexpr. If you do not specify the variable to use for abbreviations as the second input argument of subexpr, then subexpr uses the variable sigma.

[r, sigma] = subexpr(solutions)

%
% Copyright 2018 The MathWorks, Inc.