how to add all parentheses in symbolic logic expression

조회 수: 3 (최근 30일)
Pedro Pablo Mitidieri
Pedro Pablo Mitidieri 2023년 1월 27일
답변: Piyush 2023년 2월 22일
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
Dyuman Joshi
Dyuman Joshi 2023년 1월 27일
If I am understanding this correct, you want to modify a symbolic expression?

댓글을 달려면 로그인하십시오.

답변 (1개)

Piyush
Piyush 2023년 2월 22일
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.

카테고리

Help CenterFile Exchange에서 Symbolic Math Toolbox에 대해 자세히 알아보기

제품


릴리스

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by