-
Notifications
You must be signed in to change notification settings - Fork 73
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add power operator a^b, equivalent to pow(a,b).
For parsing, operator precedence is immediatey below * and /, and ^ is right associative (a^b^c = a^(b^c)). This is implemented as another case of ExpressionBinaryOp.
- Loading branch information
1 parent
65e6872
commit 9dcd92f
Showing
28 changed files
with
1,489 additions
and
984 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
dtmc | ||
|
||
module die | ||
|
||
// local state | ||
s : [0..7] init 0; | ||
// value of the die | ||
d : [0..6] init 0; | ||
|
||
[] s=0 -> 0.5 : (s'=1) + 0.5 : (s'=2); | ||
[] s=1 -> 0.5 : (s'=3) + 0.5 : (s'=4); | ||
[] s=2 -> 0.5 : (s'=5) + 0.5 : (s'=6); | ||
[] s=3 -> 0.5 : (s'=1) + 0.5 : (s'=7) & (d'=1); | ||
[] s=4 -> 0.5 : (s'=7) & (d'=2) + 0.5 : (s'=7) & (d'=3); | ||
[] s=5 -> 0.5 : (s'=7) & (d'=4) + 0.5 : (s'=7) & (d'=5); | ||
[] s=6 -> 0.5 : (s'=2) + 0.5 : (s'=7) & (d'=6); | ||
[] s=7 -> (s'=7); | ||
|
||
endmodule | ||
|
||
rewards "coin_flips" | ||
[] s<7 : 1; | ||
endrewards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
// Some tests of pow(), in each case: | ||
// * occurring in a constant (so Expression evaluation) | ||
// * occurring in a constant property (so probably model checking) | ||
// * occurring in a state-dependent property (so model checking, various engines) | ||
|
||
// RESULT: 1 | ||
"one": s+1; | ||
|
||
// RESULT: 1 | ||
"one_s": round(1+P=?[F<=1 d=6]); | ||
|
||
// RESULT: 1 | ||
"one_m": round(P=?[F true]); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 8 | ||
cPow1; const int cPow1 = pow(2,3); | ||
|
||
// RESULT: 8 | ||
pow(2,3); | ||
|
||
// RESULT: 8 | ||
pow(2*"one", d+3); | ||
|
||
// RESULT: 8 | ||
pow(2*"one_s", d+3); | ||
|
||
// RESULT: 8 | ||
pow(2*"one_m", d+3); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 1/4 | ||
cPow2; const double cPow2 = pow(0.5, 2); | ||
|
||
// RESULT: 1/4 | ||
pow(0.5, 2); | ||
|
||
// RESULT: 1/4 | ||
pow(0.5*"one", d+2); | ||
|
||
// RESULT: 1/4 | ||
pow(0.5*"one_s", d+2); | ||
|
||
// RESULT: 1/4 | ||
pow(0.5*"one_m", d+2); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 1/2 | ||
cPow3; const double cPow3 = pow(2, -1.0); | ||
|
||
// RESULT: 1/2 | ||
pow(2, -1.0); | ||
|
||
// RESULT: 1/2 | ||
pow(2*"one", d-1.0); | ||
|
||
// RESULT: 1/2 | ||
pow(2*"one_s", d-1.0); | ||
|
||
// RESULT: 1/2 | ||
pow(2*"one_m", d-1.0); | ||
|
||
// ------------------------- | ||
|
||
// Don't test errors for now - not done properly for symbolic/param | ||
|
||
// RESULT: Error | ||
//cPow4; const double cPow4 = pow(2,-1); | ||
|
||
// RESULT: Error:negative | ||
//pow(2, -1); | ||
|
||
// RESULT: Error:negative | ||
//pow(2*"one", d-1); | ||
|
||
// RESULT: Error:negative | ||
//pow(2*"one_s", d-1); | ||
|
||
// RESULT: Error:negative | ||
//pow(2*"one_m", d-1); | ||
|
||
// ------------------------- |
5 changes: 5 additions & 0 deletions
5
prism-tests/functionality/language/func_power.prism.props.args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
-ex | ||
-exact | ||
-h | ||
-m | ||
-s |
32 changes: 32 additions & 0 deletions
32
prism-tests/functionality/language/func_power.prism.root.props
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Some tests of pow(), in each case: | ||
// * occurring in a constant (so Expression evaluation) | ||
// * occurring in a constant property (so probably model checking) | ||
// * occurring in a state-dependent property (so model checking, various engines) | ||
|
||
// RESULT: 1 | ||
"one": s+1; | ||
|
||
// RESULT: 1 | ||
"one_s": round(1+P=?[F<=1 d=6]); | ||
|
||
// RESULT: 1 | ||
"one_m": round(P=?[F true]); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 1/2 | ||
cPow4; const double cPow4 = pow(1/4, 1/2); | ||
|
||
// RESULT: 1/2 | ||
pow(1/4, 1/2); | ||
|
||
// RESULT: 1/2 | ||
pow(1/4*"one", d+1/2); | ||
|
||
// RESULT: 1/2 | ||
pow(1/4*"one_s", d+1/2); | ||
|
||
// RESULT: 1/2 | ||
pow(1/4*"one_m", d+1/2); | ||
|
||
// ------------------------- |
4 changes: 4 additions & 0 deletions
4
prism-tests/functionality/language/func_power.prism.root.props.args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-ex | ||
# -exact # no evaluation of roots as rationals | ||
-h | ||
-m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
dtmc | ||
|
||
module die | ||
|
||
// local state | ||
s : [0..7] init 0; | ||
// value of the die | ||
d : [0..6] init 0; | ||
|
||
[] s=0 -> 0.5 : (s'=1) + 0.5 : (s'=2); | ||
[] s=1 -> 0.5 : (s'=3) + 0.5 : (s'=4); | ||
[] s=2 -> 0.5 : (s'=5) + 0.5 : (s'=6); | ||
[] s=3 -> 0.5 : (s'=1) + 0.5 : (s'=7) & (d'=1); | ||
[] s=4 -> 0.5 : (s'=7) & (d'=2) + 0.5 : (s'=7) & (d'=3); | ||
[] s=5 -> 0.5 : (s'=7) & (d'=4) + 0.5 : (s'=7) & (d'=5); | ||
[] s=6 -> 0.5 : (s'=2) + 0.5 : (s'=7) & (d'=6); | ||
[] s=7 -> (s'=7); | ||
|
||
endmodule | ||
|
||
rewards "coin_flips" | ||
[] s<7 : 1; | ||
endrewards |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// Some tests of power operator, in each case: | ||
// * occurring in a constant (so Expression evaluation) | ||
// * occurring in a constant property (so probably model checking) | ||
// * occurring in a state-dependent property (so model checking, various engines) | ||
|
||
// RESULT: 1 | ||
"one": s+1; | ||
|
||
// RESULT: 1 | ||
"one_s": round(1+P=?[F<=1 d=6]); | ||
|
||
// RESULT: 1 | ||
"one_m": round(P=?[F true]); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 8 | ||
cPow1; const int cPow1 = 2^3; | ||
|
||
// RESULT: 8 | ||
2^3; | ||
|
||
// RESULT: 8 | ||
(2*"one")^(d+3); | ||
|
||
// RESULT: 8 | ||
(2*"one_s")^(d+3); | ||
|
||
// RESULT: 8 | ||
(2*"one_m")^(d+3); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 1/4 | ||
cPow2; const double cPow2 = 0.5^2; | ||
|
||
// RESULT: 1/4 | ||
0.5^2; | ||
|
||
// RESULT: 1/4 | ||
(0.5*"one")^(d+2); | ||
|
||
// RESULT: 1/4 | ||
(0.5*"one_s")^(d+2); | ||
|
||
// RESULT: 1/4 | ||
(0.5*"one_m")^(d+2); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 1/2 | ||
cPow3; const double cPow3 = 2^-1.0; | ||
|
||
// RESULT: 1/2 | ||
2^-1.0; | ||
|
||
// RESULT: 1/2 | ||
(2*"one")^(d-1.0); | ||
|
||
// RESULT: 1/2 | ||
(2*"one_s")^(d-1.0); | ||
|
||
// RESULT: 1/2 | ||
(2*"one_m")^(d-1.0); | ||
|
||
// ------------------------- | ||
|
||
// Don't test errors for now - not done properly for symbolic/param | ||
|
||
// RESULT: Error | ||
//cPow4; const double cPow4 = 2^-1; | ||
//cPow4; const double cPow4 = pow(2,-1); | ||
|
||
// RESULT: Error:negative | ||
//2^-1; | ||
|
||
// RESULT: Error:negative | ||
//(2*"one")^(d-1); | ||
|
||
// RESULT: Error:negative | ||
//(2*"one_s")^(d-1); | ||
|
||
// RESULT: Error:negative | ||
//(2*"one_m")^(d-1); | ||
|
||
// ------------------------- |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-ex | ||
-exact | ||
-h | ||
-m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
// Some tests of power operator, in each case: | ||
// * occurring in a constant (so Expression evaluation) | ||
// * occurring in a constant property (so probably model checking) | ||
// * occurring in a state-dependent property (so model checking, various engines) | ||
|
||
// RESULT: 1 | ||
"one": s+1; | ||
|
||
// RESULT: 1 | ||
"one_s": round(1+P=?[F<=1 d=6]); | ||
|
||
// RESULT: 1 | ||
"one_m": round(P=?[F true]); | ||
|
||
// ------------------------- | ||
|
||
// RESULT: 1/2 | ||
cPow4; const double cPow4 = (1/4)^(1/2); | ||
|
||
// RESULT: 1/2 | ||
(1/4)^(1/2); | ||
|
||
// RESULT: 1/2 | ||
(1/4*"one")^(d+1/2); | ||
|
||
// RESULT: 1/2 | ||
(1/4*"one_s")^(d+1/2); | ||
|
||
// RESULT: 1/2 | ||
(1/4*"one_m")^(d+1/2); | ||
|
||
// ------------------------- |
4 changes: 4 additions & 0 deletions
4
prism-tests/functionality/language/power.prism.root.props.args
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
-ex | ||
# -exact # no evaluation of roots as rationals | ||
-h | ||
-m |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.