how to add all parentheses in symbolic logic expression

10 Ansichten (letzte 30 Tage)
Pedro Pablo Mitidieri
Pedro Pablo Mitidieri am 27 Jan. 2023
Beantwortet: Piyush am 22 Feb. 2023
Hello,
I am working on matlab 2020b and I have a relatively long logic phrase, an example would be:
a & b & c & (d & e & f | g & h & j) & (k | p)
The computation is done first on the & and later on the |, if I understood correctly.
This logic phrase is obtained after running :
simplify(evalin(symengine, someLogicPhrase))
My issue is that this phrase is used by some users and I would like to add parentheses when the logic phrases between | are long. I would change the previous one to something like this:
a & b & c & ( (d & e & f) | (g & h & j)) & (k | p)
Where there are new parentheses that will make it more user-friendly in my case.
Is there any easy way to do it using the symbolic toolbox? or any other.
Thank you in advance,
  1 Kommentar
Dyuman Joshi
Dyuman Joshi am 27 Jan. 2023
If I am understanding this correct, you want to modify a symbolic expression?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Piyush
Piyush am 22 Feb. 2023
When you have long logic phrase, you may use newlines to improve readability. Place operators at the end of a line, rather than at the beginning of a line.
You can use extra newlines when it helps with readability, e.g.
if (c > 30 && // is cost per unit must be high?
d > 40) { // and distance travelled high?
// code
}
Generally, Use of parentheses is an indicator that standard operator precedence rules are not in use, for example, "a = b * (c + d)" indicates to the reader that standard operator precedence is not in use.

Kategorien

Mehr zu Symbolic Math Toolbox finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by