Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

C generation with Mathematica #1

Closed
wants to merge 9 commits into from
Closed
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions khp.md
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ Main symbolic execution semantics
```{.k}
module KHP
imports KHP-SYNTAX
imports MAP
imports COLLECTIONS
imports WOLFRAMLANGUAGE
imports K-IO

Expand All @@ -95,15 +95,12 @@ module KHP
syntax KItem ::= "#processMode" "(" Mode ")"
| "#synthesizeConstraints"

syntax Ids ::= ".Ids"
| Id
| Ids "," Ids [right]

configuration <k> #processMode($MODE) ~> $PGM:Pgm </k>
<pgmVars> .Ids </pgmVars>
<state> .Map </state>
<evolutionConditions> .Set </evolutionConditions>
<counter> 0 </counter>
<constraintVars> SetItem(String2Id("t_post")) </constraintVars>

rule #processMode(#regular) ~> P:Pgm => P
rule #processMode(#constraintSynthesis) ~> P:Pgm => P ~> #synthesizeConstraints
Expand All @@ -129,6 +126,7 @@ For each variable, the state is bound to a logical Variable of sort `Real`.
(.Set => SetItem(#appendStrToPgmVar(X, "_i") == #VarReal(#prependStrToPgmVar("VAR_", X))))
...
</evolutionConditions>
<constraintVars> ... .Set => (SetItem(#prependStrToPgmVar("VAR_", X)) SetItem(#appendStrToPgmVar(X, "_i"))) ... </constraintVars>

rule vars .VarDecls ; S:Stmts => S
syntax FullFormExpression ::= "#toWolframExpression" "(" BExp ")" [function]
Expand Down Expand Up @@ -383,10 +381,17 @@ Mechanism to handle storing evolution conditions

syntax KItem ::= "#wolfram.quantifierElimination" "(" FullFormExpression ")" [function]

rule #wolfram.quantifierElimination( WLFRAMEXPR )
syntax Ids ::= "List2Ids" "(" List ")" [function]
rule List2Ids(.List) => .Ids
rule List2Ids(ListItem(I:Id) L:List) => I , List2Ids(L)

rule <k> #wolfram.quantifierElimination( WLFRAMEXPR )
mickyabir marked this conversation as resolved.
Show resolved Hide resolved
=> #system("wolframscript -c" +String "\""
//+String #toWolframExpressionString(Compile[ { List2Ids(Set2List(Vars)) } , WLFRAMEXPR ])
+String #toWolframExpressionString(Resolve[ WLFRAMEXPR, Reals ])
+String "\"")
+String "\"") <k>
//<constraintVars> Vars </constraintVars>


rule <k> #processFinalStateConstraints ~> #constraints(WLFRAMEXPR)
=> #wolfram.quantifierElimination(WLFRAMEXPR) </k>
Expand Down
16 changes: 16 additions & 0 deletions wolframlanguage.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,18 @@ module WOLFRAMLANGUAGE-SYNTAX
imports ID
imports STRING

syntax Ids ::= ".Ids"
| Id
| Ids "," Ids [right]

syntax VariableExpressions ::= "{" Ids "}"

syntax FullFormExpression ::= Id
| Real
| "True" [token]
| "Reals" [token]
| Operator "[" FullFormExpressions "]"
| Operator "[" VariableExpressions "," FullFormExpressions "]"

syntax FullFormExpressions ::= List{FullFormExpression, ","}

Expand All @@ -30,9 +37,12 @@ module WOLFRAMLANGUAGE-SYNTAX
| "Implies" [token]
| "ForAll" [token]
| "Resolve" [token]
| "Export" [token]
| "Compile" [token]

syntax String ::= "Operator2String" "(" Operator ")" [function, hook(STRING.token2string)]
| "#toWolframExpressionString" "(" FullFormExpression ")" [function]
| "#toWolframExpressionString" "(" VariableExpressions ")" [function]
| "#toWolframExpressionStringAux" "(" FullFormExpressions ")" [function]

endmodule
Expand All @@ -44,6 +54,8 @@ module WOLFRAMLANGUAGE
rule #toWolframExpressionString(REAL:Real) => Real2String(REAL)
rule #toWolframExpressionString(True) => "True"
rule #toWolframExpressionString(Reals) => "Reals"
//rule #toWolframExpressionString({ E:FullFormExpressions }) => "{" +String #toWolframExpressionStringAux(E) +String "}"
rule #toWolframExpressionString({ I:Id , Rest:Ids }) => "{" +String Id2String(I) +String #toWolframExpressionString(Rest) +String "}"

rule #toWolframExpressionStringAux(E1:FullFormExpression , E2:FullFormExpressions)
=> #toWolframExpressionString(E1) +String ", " +String #toWolframExpressionStringAux(E2)
Expand All @@ -55,6 +67,10 @@ module WOLFRAMLANGUAGE
=> Operator2String(OP)
+String "[" +String #toWolframExpressionStringAux(EXPRS) +String "]"

rule #toWolframExpressionString(OP:Operator [ VARS:VariableExpressions , EXPRS:FullFormExpressions ])
=> Operator2String(OP)
+String "[" +String #toWolframExpressionString(VARS) +String #toWolframExpressionStringAux(EXPRS) +String "]"

endmodule

```