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
171ae35a
Commit
171ae35a
authored
9 years ago
by
Viktor Kuncak
Browse files
Options
Downloads
Patches
Plain Diff
Started another lambda calculus case study
parent
c4bf3e88
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
testcases/verification/case-studies/LambdaSound.scala
+76
-0
76 additions, 0 deletions
testcases/verification/case-studies/LambdaSound.scala
with
76 additions
and
0 deletions
testcases/verification/case-studies/LambdaSound.scala
0 → 100644
+
76
−
0
View file @
171ae35a
import
leon.lang._
import
leon.annotation._
import
leon.collection._
import
leon.lang.synthesis._
import
leon._
import
leon.lang.string._
object
Lambda
{
case
class
Id
(
v
:
BigInt
)
abstract
class
Expr
case
class
Var
(
id
:
Id
)
extends
Expr
case
class
App
(
f
:
Expr
,
arg
:
Expr
)
extends
Expr
case
class
Abs
(
b
:
Id
,
tpe
:
Type
,
e
:
Expr
)
extends
Expr
case
class
Env
(
binds
:
Map
[
Id
,
Expr
])
abstract
class
Type
case
object
Tind
extends
Type
case
object
Tbool
extends
Type
case
class
Arrow
(
from
:
Type
,
to
:
Type
)
extends
Type
case
class
TEnv
(
binds
:
Map
[
Id
,
Type
])
def
fv
(
e
:
Expr
)
:
Set
[
Id
]
=
e
match
{
case
Var
(
id
)
=>
Set
(
id
)
case
App
(
f
,
arg
)
=>
fv
(
f
)
++
fv
(
arg
)
case
Abs
(
b
,
_
,
e
)
=>
fv
(
e
)
--
Set
(
b
)
}
def
subst
(
in
:
Expr
,
v
:
Id
,
by
:
Expr
)
:
Expr
=
{
in
match
{
case
Var
(
id
)
=>
{
if
(
id
==
v
)
by
else
in
}
case
App
(
f
,
arg
)
=>
App
(
subst
(
f
,
v
,
by
),
subst
(
arg
,
v
,
by
))
case
Abs
(
b
,
tpe
,
e
)
=>
{
if
(
b
==
v
)
in
else
{
// ADD CHECK FOR CAPTURE HERE
Abs
(
b
,
tpe
,
subst
(
e
,
v
,
by
))
}
}
}
}
def
id1
=
Id
(
BigInt
(
1
))
def
id2
=
Id
(
BigInt
(
2
))
def
exprId
=
Abs
(
id1
,
Tind
,
Var
(
id1
))
abstract
class
Outcome
case
class
Ok
(
v
:
Expr
)
extends
Outcome
case
class
Err
(
s
:
String
,
sub
:
Expr
)
extends
Outcome
def
CBV
(
env
:
Env
,
e
:
Expr
)
:
Outcome
=
{
e
match
{
case
Var
(
id
)
=>
{
env
.
binds
.
get
(
id
)
match
{
case
None
()
=>
Err
(
"Unknown identifier in environment"
,
e
)
case
Some
(
expr
)
=>
Ok
(
expr
)
}}
case
Abs
(
b
,
tpe
,
body
)
=>
Ok
(
e
)
case
App
(
f
,
arg
)
=>
{
CBV
(
env
,
f
)
match
{
case
Ok
(
Abs
(
b
,
t
,
fbody
))
=>
{
CBV
(
env
,
arg
)
match
{
case
Ok
(
argv
)
=>
CBV
(
env
,
subst
(
fbody
,
b
,
argv
))
case
err
=>
err
}}
case
Ok
(
expr
)
=>
Err
(
"Tried to apply non-function value"
,
expr
)
case
err
=>
err
}}
}
}
def
env1
:
Env
=
Env
(
Map
[
Id
,
Expr
](
id2
->
Var
(
id2
)))
def
r1
=
CBV
(
env1
,
App
(
exprId
,
Var
(
id2
)))
}
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