Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Latest commit

 

History

History
History
47 lines (43 loc) · 1.31 KB

File metadata and controls

47 lines (43 loc) · 1.31 KB
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
package symjava.symbolic;
public class SymPrinting {
public static int getPrecedence(Expr expr) {
if(expr instanceof Sum)
return 5;
else if(expr instanceof Add || expr instanceof Subtract)
return 10;
if(expr instanceof Multiply || expr instanceof Divide || expr instanceof Negate)
return 20;
if( expr instanceof Reciprocal )
return 25;
if(expr instanceof Pow)
return 30;
if(expr instanceof Func) {
Func f = (Func)expr;
if(f.isAbstract())
return 90;
else
return getPrecedence(f.getExpr());
}
if(expr instanceof Symbol || expr instanceof Symbols || expr instanceof SymReal<?>)
return 100;
return 1000; //default to atomic
}
public static String addParenthsesIfNeeded(Expr toMe, Expr forOperation) {
if(getPrecedence(toMe) < getPrecedence(forOperation))
return "(" + toMe.toString() + ")";
return toMe.toString();
}
public static String addParenthsesIfNeeded2(Expr toMe, Expr forOperation) {
if(getPrecedence(toMe) <= getPrecedence(forOperation))
return "(" + toMe.toString() + ")";
return toMe.toString();
}
public static String join(Expr[] exprs,String deliminator) {
StringBuilder sb = new StringBuilder();
for(Expr e : exprs) {
sb.append(e.toString());
sb.append(deliminator);
}
return sb.substring(0, sb.length()-deliminator.length());
}
}
Morty Proxy This is a proxified and sanitized view of the page, visit original site.