Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
I
inox
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
LARA
inox
Commits
d087bf60
Commit
d087bf60
authored
13 years ago
by
Ali Sinan Köksal
Browse files
Options
Downloads
Patches
Plain Diff
generation of product methods
parent
2633b157
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
cp-demo/Product.scala
+7
-0
7 additions, 0 deletions
cp-demo/Product.scala
src/cp/Terms.scala
+215
-27
215 additions, 27 deletions
src/cp/Terms.scala
src/cp/Utils.scala
+44
-3
44 additions, 3 deletions
src/cp/Utils.scala
with
266 additions
and
30 deletions
cp-demo/Product.scala
+
7
−
0
View file @
d087bf60
...
@@ -7,6 +7,13 @@ object Product {
...
@@ -7,6 +7,13 @@ object Product {
val
c2
=
((
x
:
Int
)
=>
x
>
41
).
c
val
c2
=
((
x
:
Int
)
=>
x
>
41
).
c
val
c3
=
c1
product1
c2
val
c3
=
c1
product1
c2
val
c4
=
((
a
:
Boolean
,
b
:
Int
)
=>
a
==
b
>
0
).
c
val
c5
=
((
i
:
Int
,
j
:
Int
)
=>
i
>
j
).
c
val
c6
=
c4
product2
c5
println
(
c3
.
solve
)
println
(
c3
.
solve
)
println
(
c6
.
solve
)
}
}
}
}
This diff is collapsed.
Click to expand it.
src/cp/Terms.scala
+
215
−
27
View file @
d087bf60
This diff is collapsed.
Click to expand it.
src/cp/Utils.scala
+
44
−
3
View file @
d087bf60
...
@@ -68,6 +68,45 @@ object Utils {
...
@@ -68,6 +68,45 @@ object Utils {
}
}
}).
flatten
.
mkString
(
"\n\n"
)
}).
flatten
.
mkString
(
"\n\n"
)
val
productMethods
=
(
for
(
otherArity
<-
1
to
(
maxArity
-
arity
))
yield
{
val
productArity
=
arity
+
otherArity
val
thisParams
=
(
1
to
arity
).
map
(
"T"
+
_
)
val
otherParams
=
(
1
to
otherArity
).
map
(
"A"
+
_
)
val
otherParamsString
=
otherParams
.
mkString
(
","
)
val
otherTermParams
=
otherParams
++
Seq
(
"Boolean"
)
val
otherTermParamsString
=
otherTermParams
.
mkString
(
","
)
val
resultParams
=
thisParams
++
otherParams
val
resultTermParams
=
resultParams
++
Seq
(
"Boolean"
)
val
resultTermParamsString
=
resultTermParams
.
mkString
(
","
)
val
scalaFunctionParams
=
resultParams
.
zipWithIndex
.
map
{
case
(
p
,
i
)
=>
"x_%d : %s"
format
(
i
,
p
)
}
val
scalaFunctionParamsString
=
scalaFunctionParams
.
mkString
(
", "
)
val
thisScalaFunctionArgs
=
(
0
until
arity
).
map
(
"x_"
+
_
)
val
thisScalaFunctionArgsString
=
thisScalaFunctionArgs
.
mkString
(
", "
)
val
otherScalaFunctionArgs
=
(
arity
until
productArity
).
map
(
"x_"
+
_
)
val
otherScalaFunctionArgsString
=
otherScalaFunctionArgs
.
mkString
(
", "
)
val
thisApplication
=
"this.scalaFunction(%s)"
format
(
thisScalaFunctionArgsString
)
val
otherApplication
=
"other.scalaFunction(%s)"
format
(
otherScalaFunctionArgsString
)
val
scalaFunction
=
"(%s) => %s && %s"
format
(
scalaFunctionParamsString
,
thisApplication
,
otherApplication
)
val
methodString
=
"""def product%d[%s](other: Term%d[%s])(implicit isBoolean: R =:= Boolean): Term%d[%s] = {
val (newExpr, newTypes) = Terms.product(this, other)
Term%d(this.program, newExpr, if (this.scalaFunction == null || other.scalaFunction == null) null else %s, newTypes, this.converter, this.lVars ++ other.lVars)
}
"""
format
(
otherArity
,
otherParamsString
,
otherArity
,
otherTermParamsString
,
productArity
,
resultTermParamsString
,
productArity
,
scalaFunction
)
methodString
}).
mkString
(
"\n\n"
)
val
(
applyParams
,
applyArgs
)
=
traitArgParams
.
zipWithIndex
.
map
{
case
(
p
,
i
)
=>
(
"x_%d : %s"
format
(
i
,
p
),
"x_%d"
format
(
i
))
}.
unzip
val
(
applyParams
,
applyArgs
)
=
traitArgParams
.
zipWithIndex
.
map
{
case
(
p
,
i
)
=>
(
"x_%d : %s"
format
(
i
,
p
),
"x_%d"
format
(
i
))
}.
unzip
val
evaluatorArgs
=
traitArgParams
.
zipWithIndex
.
map
{
case
(
p
,
i
)
=>
"converter.expr2scala(s(%d)).asInstanceOf[%s]"
format
(
i
,
p
)
}
val
evaluatorArgs
=
traitArgParams
.
zipWithIndex
.
map
{
case
(
p
,
i
)
=>
"converter.expr2scala(s(%d)).asInstanceOf[%s]"
format
(
i
,
p
)
}
...
@@ -90,6 +129,8 @@ object Utils {
...
@@ -90,6 +129,8 @@ object Utils {
%s
%s
%s
%s
%s
}"""
format
(
traitName
,
termClassParamTuple
,
"R"
,
arity
,
traitParams
.
mkString
(
","
),
}"""
format
(
traitName
,
termClassParamTuple
,
"R"
,
arity
,
traitParams
.
mkString
(
","
),
arity
,
traitArgParamsString
,
arity
,
traitArgParamsString
,
...
@@ -97,7 +138,7 @@ object Utils {
...
@@ -97,7 +138,7 @@ object Utils {
termClassParamTuple
,
"R"
,
termClassParamTuple
,
"R"
,
evaluatorArgs
.
mkString
(
","
),
evaluatorArgs
.
mkString
(
","
),
applyParams
.
mkString
(
", "
),
applyArgs
.
mkString
(
", "
),
applyParams
.
mkString
(
", "
),
applyArgs
.
mkString
(
", "
),
indent
(
orMethod
),
indent
(
andMethod
),
indent
(
notMethod
),
indent
(
minimizingMethod
),
indent
(
lazySolveMethod
),
indent
(
composeMethods
))
indent
(
orMethod
),
indent
(
andMethod
),
indent
(
notMethod
),
indent
(
minimizingMethod
),
indent
(
lazySolveMethod
),
indent
(
composeMethods
)
,
indent
(
productMethods
)
)
termTraitString
termTraitString
}
}
...
@@ -169,11 +210,11 @@ object Utils {
...
@@ -169,11 +210,11 @@ object Utils {
booleanTerms
=
"type Constraint[T] = Term[T,Boolean]"
::
booleanTerms
booleanTerms
=
"type Constraint[T] = Term[T,Boolean]"
::
booleanTerms
intTerms
=
"type IntTerm[T] = Term[T,Int]"
::
intTerms
intTerms
=
"type IntTerm[T] = Term[T,Int]"
::
intTerms
for
(
arity
<-
1
to
maxArity
)
{
for
(
arity
<-
0
to
maxArity
)
{
val
params
=
(
1
to
arity
)
map
(
"T"
+
_
)
val
params
=
(
1
to
arity
)
map
(
"T"
+
_
)
val
paramWithBooleanString
=
(
params
++
Seq
(
"Boolean"
)).
mkString
(
"["
,
","
,
"]"
)
val
paramWithBooleanString
=
(
params
++
Seq
(
"Boolean"
)).
mkString
(
"["
,
","
,
"]"
)
val
paramWithIntString
=
(
params
++
Seq
(
"Int"
)).
mkString
(
"["
,
","
,
"]"
)
val
paramWithIntString
=
(
params
++
Seq
(
"Int"
)).
mkString
(
"["
,
","
,
"]"
)
val
paramString
=
params
.
mkString
(
"["
,
","
,
"]"
)
val
paramString
=
if
(
arity
==
0
)
""
else
params
.
mkString
(
"["
,
","
,
"]"
)
val
boolType
=
"type Constraint%d%s = Term%d%s"
format
(
arity
,
paramString
,
arity
,
paramWithBooleanString
)
val
boolType
=
"type Constraint%d%s = Term%d%s"
format
(
arity
,
paramString
,
arity
,
paramWithBooleanString
)
val
intType
=
"type IntTerm%d%s = Term%d%s"
format
(
arity
,
paramString
,
arity
,
paramWithIntString
)
val
intType
=
"type IntTerm%d%s = Term%d%s"
format
(
arity
,
paramString
,
arity
,
paramWithIntString
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment