Skip to content

Commit f619fad

Browse files
Merge pull request #34 from judovana/0.1.9-release
0.1.9 release
2 parents a8b8dc7 + f64e1e9 commit f619fad

File tree

4 files changed

+76
-9
lines changed

4 files changed

+76
-9
lines changed

README.md

Lines changed: 70 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,7 @@
3333
* [Editing a Matrix example](#editing-a-matrix-example)
3434
* [12. Finding the characteristic polynomial of a Matrix](#12-finding-the-characteristic-polynomial-of-a-matrix)
3535
* [Logical Calculus](#logical-calculus)
36+
* [Expanding Calculus](#expanding-calculus)
3637
* [TO BE CONTINUED](#to-be-continued)
3738

3839

@@ -48,7 +49,7 @@ If you need to access this library via Maven Central, do:
4849
<dependency>
4950
<groupId>com.github.gbenroscience</groupId>
5051
<artifactId>parser-ng</artifactId>
51-
<version>0.1.8</version>
52+
<version>0.1.9</version>
5253
</dependency>
5354
5455

@@ -726,8 +727,10 @@ This would give:
726727
## Logical Calculus
727728

728729
The logical expressions in math engine have theirs intentional limitations. Thus allmighty logical expression parser was added around individually evaluated Mathematical expressions which results can be later compared, and logically grouped. The simplest way to evaluate an logical expression in ParserNG is to use the <code>LogicalExpression</code> class.
729-
<code>LogicalExpression</code> is the class responsible for basic comaprsions and logica expression parsing and evaluation. It calls <code>MathExpression</code> to ech of its basic non-logical parts
730-
730+
<code>LogicalExpression</code> is the class responsible for basic comaprsions and logica expression parsing and evaluation. It calls <code>MathExpression</code> to ech of its basic non-logical parts. The default <code>MathExpression</code> can be repalced by any custom implementation of <code>Solvable</code>, but it is only for highly specialized usages. Highlight, where MathExpression is using <code>()</code> for mathematical bracketing, LogicalExpression - as () can be part of underlying comapred mathematical expressiosn uses <code>[]</code> brackets.<br>
731+
<br>
732+
In CLI, you can use -l/-L/--logic switch to work with LogicalExpression. Although it is fully compatible with MathExpression you may face unknown issue<br>
733+
<br>
731734
Do:<br>
732735
`LogicalExpression expr = new LogicalExpression("[1+1 < (2+0)*1 impl [ [5 == 6 || 33<(22-20)*2 ]xor [ [ 5-3 < 2 or 7*(5+2)<=5 ] and 1+1 == 2]]] eq [ true && false ] ");`
733736
<br>
@@ -827,7 +830,7 @@ to: true eq false
827830
is: false
828831
false
829832
```
830-
Note, that logical parsser supports only dual operators, so where true|false|true is valid, 1<2<3 is invalid!
833+
Note, that logical parsser's comparsions supports only dual operators, so where true|false|true is valid, 1<2<3 is invalid!
831834
Thus: [1<2]<3 is necessary and even [[true|false]|true]is recomeded to be used, For 1<2<3 exception is thrown.
832835
Single letter can logical operands can be used in row. So eg | have same meaning as ||. But also unluckily also eg < is same as <<
833836
Negation can be done by single ! strictly close attached to [; eg ![true] is ... false. Some spaces like ! [ are actually ok to
@@ -836,6 +839,69 @@ But much less for [r=3;r<r+1 || [r<5]]", which fails and must be declared as "[r
836839
To avoid this, you can declare all in first dummy expression: "[r=3;r<1] || [r<r+1 || [r<5]]" which ensure theirs allocation ahead of time and do not affect the rest
837840
If you modify the variables, in the subseqet calls, results maybe funny. Use verbose mode to debug order
838841

842+
## Expanding Calculus
843+
Very often an expressions, or CLI is called above known, huge (generated) array of values. Such can be processed via <code>ExpandingExpression</code>. Unlike other Expressins, this one have List<String> as aditional parameters, where each member is a number. THose numbers can thenbe accessed as L0, L1...Ln. Size of the list is held in special MN variable. The index can be calucalted dynamically, like L{MN/2} - in example of four items, will expand to L2. Although `{}` and `MN` notations are powerfull, the main power is in *slices*:
844+
```
845+
Instead of numbers, you can use literalls L0, L1...L99, which you can then call by:
846+
Ln - vlaue of Nth number
847+
L2..L4 - will expand to values of L2,L3,L4 - order is hnoured
848+
L2.. - will expand to values of L2,L3,..Ln-1,Ln
849+
..L5 - will expand to values of L0,L1...L4,L5
850+
where ..L5 or L2.. are order sensitive, the L{MN}..L0 or L0..L{MN} is not. But requires dynamic index evaluation
851+
When used as standalone, VALUES_PNG xor VALUES_IPNG are used to pass in the space separated numbers (the I is inverted order)
852+
Assume VALUES_PNG='5 9 3 8', then it is the same as VALUES_IPNG='8 3 9 5'; BUt be aware, with I the L.. and ..L are a bit oposite then expected
853+
L0 then expand to 8; L2.. expands to 9,3,8; ' ..L2 expands to 5,9
854+
L2..L4 expands to 9,5; L4..L2 expands to 5,9
855+
```
856+
ExpandingExpression calls <code>LogicalExpression</code> inside, and yet again the underlying Math evaluator is - defaulting as <code>MathExpression</code> can be repalced by any custom implementation of <code>Solvable</code>. Highlight, where MathExpression is using <code>()</code> for mathematical bracketing, LogicalExpression ses <code>[]</code> brackets. The dynamic indexes in <code>ExpandingExpression</code> uses are wrapped in `{}` <br>
857+
<br>
858+
In CLI, you can use -e/-E/--expanding switch to work with Expanding expressions. The array of numbers goes in via VALUES_PNG xor VALUES_IPNG variable. Although it is fully compatible with MathExpression and LogicalExpression you may face unknown issue<br>
859+
<br>
860+
Example:<br>
861+
```
862+
VALUES_PNG="1 8 5 2" java -jar target/parser-ng-0.1.9.jar -e "avg(..L{MN/2})*1.1-MN < L0 | (L1+L{MN-1})*1.3 + MN< L0" -v
863+
avg(..L{MN/2})*1.1-MN < L0 | (L1+L{MN-1})*1.3 + MN< L0
864+
Expression : avg(..L{MN/2})*1.1-MN <L0 | (L1+L{MN-1})*1.3 + MN<L0
865+
Upon : 1,8,5,2
866+
As : Ln...L1,L0
867+
MN = 4
868+
L indexes brackets: avg(..L{4/2})*1.1-4 < L0 | (L1+L{4-1})*1.3 + 4< L0
869+
Expression : 4/2
870+
Expanded as: 4/2
871+
is: 2.0
872+
4/2 = 2 (2.0)
873+
to: avg(..L 2 )*1.1-4 < L0 | (L1+L{4-1})*1.3 + 4< L0
874+
Expression : 4-1
875+
Expanded as: 4-1
876+
is: 3.0
877+
4-1 = 3 (3.0)
878+
to: avg(..L 2 )*1.1-4 < L0 | (L1+L 3 )*1.3 + 4< L0
879+
Expanded as: avg(1,8 )*1.1-4 < 2 | (5+1 )*1.3 + 4< 2
880+
avg(1,8 )*1.1-4 < 2 | (5+1 )*1.3 + 4< 2
881+
brackets: avg(1,8 )*1.1-4 < 2 | (5+1 )*1.3 + 4< 2
882+
evaluating logical: avg(1,8 )*1.1-4 < 2 | (5+1 )*1.3 + 4< 2
883+
evaluating comparison: avg(1,8 )*1.1-4 < 2
884+
evaluating math: avg(1,8 )*1.1-4
885+
is: 0.9500000000000002
886+
evaluating math: 2
887+
is: 2
888+
... 0.9500000000000002 < 2
889+
is: true
890+
evaluating comparison: (5+1 )*1.3 + 4< 2
891+
evaluating math: (5+1 )*1.3 + 4
892+
is: 11.8
893+
evaluating math: 2
894+
is: 2
895+
... 11.8 < 2
896+
is: false
897+
... true | false
898+
is: true
899+
true
900+
is: true
901+
true
902+
```
903+
904+
See [jenkins-report-generic-chart-column](https://github.com/judovana/jenkins-report-generic-chart-column#most-common-expressions) as real-world user of `ExpandingParser`
839905

840906
## TO BE CONTINUED
841907
And much more!

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>com.github.gbenroscience</groupId>
55
<artifactId>parser-ng</artifactId>
6-
<version>0.1.8</version>
6+
<version>0.1.9</version>
77
<packaging>jar</packaging>
88

99
<name>ParserNG</name>

src/main/java/math/Main.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ public static void setExpandable(boolean expandable) {
248248

249249
public static String getVersion() {
250250
//todo, read from pom. See JRD how we did it
251-
return "0.1.8";
251+
return "0.1.9";
252252
}
253253

254254
public static MultiSwitch getLogcalSwitch() {

src/main/java/parser/ExpandingExpression.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,11 @@ public static String getHelp() {
9898
//longterm todo, repalce this static help by better help using delegated help methods from logical parser
9999
return "This is abstraction which allows to set with slices, rows and subset of immutable known numbers." + "\n" +
100100
"Instead of numbers, you can use literalls L0, L1...L99, which you can then call by:" + "\n" +
101-
"Ln - vlaue of Nth number" + "\n" +
101+
"Ln - vlaue of Nth number, or in Slices" + "\n" +
102102
"L2..L4 - will expand to values of L2,L3,L4 - order is hnoured" + "\n" +
103103
"L2.. - will expand to values of L2,L3,..Ln-1,Ln" + "\n" +
104104
"..L5 - will expand to values of L0,L1...L4,L5" + "\n" +
105+
"where ..L5 or L2.. are order sensitive, the L{MN}..L0 or L0..L{MN} is not. But requires dynamic index evaluation." + "\n" +
105106
"When used as standalone, " + VALUES_PNG + " xor " + VALUES_IPNG + " are used to pass in the space separated numbers (the I is inverted order)" + "\n" +
106107
"Assume " + VALUES_PNG + "='5 9 3 8', then it is the same as " + VALUES_IPNG + "='8 3 9 5'; BUt be aware, with I the L.. and ..L are a bit oposite then expected" + "\n" +
107108
"L0 then expand to 8; L2.. expands to 9,3,8; ' ..L2 expands to 5,9 " + "\n" +
@@ -113,12 +114,12 @@ public static String getHelp() {
113114
"MN = 4\n" +
114115
"Expanded as: avg(60,20,80)*1.1-4 < 70 | 80*1.3 + 4< 70\n" +
115116
"...indeed\n" +
116-
"Dynamic calculation of L's indexes\n" +
117+
"Dynamic calculation of L's indexes:\n" +
117118
"Sometimes, Lx, as number is not enough, and you need to calcualte it dynamically. To do so, you can use L{}\n" +
118119
"Inisde {} can be mathematical formula (including Ls, MN. or even nested {}, which will evaluate itself as number, which will be used as Lx. Eg:\n" +
119120
"'avg(..L{MN/2}) < avg(L{MN/2}..)' will go to 'avg(..L1) < avg(L1..)' will go on 1 2 3 to 'avg(1,2 ) < avg(2,3) will go to 1.5<2.5 ... true'\n" +
120121
"For fun try eg: VALUES_PNG='1 2 3' on 'avg(..L{L{MN/2}}) < avg(L{L{MN/2}}..)'\n" +
121-
"This parser by default uses LogicalExpression interpreter, but should work directly in" + "\n" +
122+
"This parser by default uses LogicalExpression interpreter, but should work directly on simple Logical or Math expressions. The LogicalExpression class canbe repalced if needed." + "\n" +
122123
"In verbose mode, the expanded expression is always printed";
123124

124125
}

0 commit comments

Comments
 (0)