how to add all parentheses in symbolic logic expression

7 visualizaciones (últimos 30 días)
Pedro Pablo Mitidieri
Pedro Pablo Mitidieri el 27 de En. de 2023
Respondida: Piyush el 22 de Feb. de 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 comentario
Dyuman Joshi
Dyuman Joshi el 27 de En. de 2023
If I am understanding this correct, you want to modify a symbolic expression?

Iniciar sesión para comentar.

Respuestas (1)

Piyush
Piyush el 22 de Feb. de 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.

Categorías

Más información sobre Symbolic Math Toolbox en Help Center y File Exchange.

Productos


Versión

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by