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
dc0a2865
Commit
dc0a2865
authored
12 years ago
by
Régis Blanc
Browse files
Options
Downloads
Patches
Plain Diff
optimization that does not introduce variables when the modulo is smaller than B - A
parent
acd77b90
Branches
Branches containing commit
Tags
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/main/scala/leon/synthesis/rules/IntegerInequalities.scala
+23
-8
23 additions, 8 deletions
...main/scala/leon/synthesis/rules/IntegerInequalities.scala
with
23 additions
and
8 deletions
src/main/scala/leon/synthesis/rules/IntegerInequalities.scala
+
23
−
8
View file @
dc0a2865
...
@@ -43,6 +43,7 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
...
@@ -43,6 +43,7 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
val
otherVars
:
List
[
Identifier
]
=
problem
.
xs
.
filterNot
(
_
==
processedVar
)
val
otherVars
:
List
[
Identifier
]
=
problem
.
xs
.
filterNot
(
_
==
processedVar
)
val
normalizedLhs
:
List
[
List
[
Expr
]]
=
lhsSides
.
map
(
linearArithmeticForm
(
_
,
Array
(
processedVar
)).
toList
)
val
normalizedLhs
:
List
[
List
[
Expr
]]
=
lhsSides
.
map
(
linearArithmeticForm
(
_
,
Array
(
processedVar
)).
toList
)
var
upperBounds
:
List
[(
Expr
,
Int
)]
=
Nil
// (t, c) means c*x <= t
var
upperBounds
:
List
[(
Expr
,
Int
)]
=
Nil
// (t, c) means c*x <= t
var
lowerBounds
:
List
[(
Expr
,
Int
)]
=
Nil
// (t, c) means t <= c*x
var
lowerBounds
:
List
[(
Expr
,
Int
)]
=
Nil
// (t, c) means t <= c*x
...
@@ -54,15 +55,30 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
...
@@ -54,15 +55,30 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
case
err
=>
sys
.
error
(
"unexpected from normal form: "
+
err
)
case
err
=>
sys
.
error
(
"unexpected from normal form: "
+
err
)
}
}
//optimization when coef = 1
val
L
=
if
(
upperBounds
.
isEmpty
&&
lowerBounds
.
isEmpty
)
-
1
else
lcm
((
upperBounds
:::
lowerBounds
).
map
(
_
.
_2
))
println
(
"LCM: "
+
L
)
//optimization when coef = 1 and when ub - lb is a constant greater than LCM
upperBounds
=
upperBounds
.
filterNot
{
case
(
ub
,
uc
)
=>
if
(
uc
==
1
)
{
upperBounds
=
upperBounds
.
filterNot
{
case
(
ub
,
uc
)
=>
if
(
uc
==
1
)
{
exprNotUsed
++=
lowerBounds
.
map
{
case
(
lb
,
lc
)
=>
LessEquals
(
lb
,
Times
(
IntLiteral
(
lc
),
ub
))}
exprNotUsed
++=
lowerBounds
.
map
{
case
(
lb
,
lc
)
=>
LessEquals
(
lb
,
Times
(
IntLiteral
(
lc
),
ub
))}
true
true
}
else
false
}
}
else
false
}
lowerBounds
=
lowerBounds
.
filterNot
{
case
(
lb
,
lc
)
=>
if
(
lc
==
1
)
{
lowerBounds
=
lowerBounds
.
filterNot
{
case
(
lb
,
lc
)
=>
if
(
lc
==
1
)
{
exprNotUsed
++=
upperBounds
.
map
{
case
(
ub
,
uc
)
=>
LessEquals
(
Times
(
IntLiteral
(
uc
),
lb
),
ub
)}
exprNotUsed
++=
upperBounds
.
map
{
case
(
ub
,
uc
)
=>
LessEquals
(
Times
(
IntLiteral
(
uc
),
lb
),
ub
)}
true
true
}
else
false
}
}
else
false
}
upperBounds
=
upperBounds
.
filterNot
{
case
(
ub
,
uc
)
=>
{
lowerBounds
.
forall
{
case
(
lb
,
lc
)
=>
{
println
(
simplifyArithmetic
(
Minus
(
ub
,
lb
)))
simplifyArithmetic
(
Minus
(
ub
,
lb
))
match
{
case
IntLiteral
(
n
)
=>
println
(
"found N: "
+
n
);
L
-
1
<=
n
case
_
=>
false
}}}
}}
println
(
"lowerBounds: "
+
lowerBounds
)
println
(
"lowerBounds: "
+
lowerBounds
)
println
(
"upperBounds: "
+
upperBounds
)
println
(
"upperBounds: "
+
upperBounds
)
...
@@ -142,7 +158,6 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
...
@@ -142,7 +158,6 @@ class IntegerInequalities(synth: Synthesizer) extends Rule("Integer Inequalities
val
remainderIds
:
List
[
Identifier
]
=
upperBounds
.
map
(
_
=>
FreshIdentifier
(
"k"
,
true
).
setType
(
Int32Type
))
val
remainderIds
:
List
[
Identifier
]
=
upperBounds
.
map
(
_
=>
FreshIdentifier
(
"k"
,
true
).
setType
(
Int32Type
))
val
quotientIds
:
List
[
Identifier
]
=
lowerBounds
.
map
(
_
=>
FreshIdentifier
(
"l"
,
true
).
setType
(
Int32Type
))
val
quotientIds
:
List
[
Identifier
]
=
lowerBounds
.
map
(
_
=>
FreshIdentifier
(
"l"
,
true
).
setType
(
Int32Type
))
val
L
=
if
(
remainderIds
.
isEmpty
)
-
1
else
lcm
((
upperBounds
:::
lowerBounds
).
map
(
_
.
_2
))
val
newUpperBounds
:
List
[
Expr
]
=
upperBounds
.
map
{
case
(
bound
,
coef
)
=>
Times
(
IntLiteral
(
L
/
coef
),
bound
)}
val
newUpperBounds
:
List
[
Expr
]
=
upperBounds
.
map
{
case
(
bound
,
coef
)
=>
Times
(
IntLiteral
(
L
/
coef
),
bound
)}
val
newLowerBounds
:
List
[
Expr
]
=
lowerBounds
.
map
{
case
(
bound
,
coef
)
=>
Times
(
IntLiteral
(
L
/
coef
),
bound
)}
val
newLowerBounds
:
List
[
Expr
]
=
lowerBounds
.
map
{
case
(
bound
,
coef
)
=>
Times
(
IntLiteral
(
L
/
coef
),
bound
)}
...
...
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