Skip to content

Commit

Permalink
Add examples and tests (#56)
Browse files Browse the repository at this point in the history
* Add a simple example

* Add examples of different reductions for the term presented after Definition 3.1

* Add tests for the infinite rewrite sequence

---------

Co-authored-by: eyihluyc <[email protected]>
  • Loading branch information
Anatolay and eyihluyc authored Dec 7, 2024
1 parent a3885e5 commit 1e67968
Showing 1 changed file with 179 additions and 0 deletions.
179 changes: 179 additions & 0 deletions Minimal/Examples.lean
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@ open Term
open OptionalAttr
open Reduce

/-!
# Confluence of minimal φ-calculus
This file contains examples of minimal φ-calculus terms and their reductions.
## References
* [Nikolai Kudasov and Violetta Sim. 2023. Formalizing 𝜑-Calculus: A Purely Object-Oriented Calculus of Decorated Objects.][KS22]
-/

-- TEST 1: ⟦ x ↦ ξ.y, y ↦ ⟦ ⟧ ⟧.x ⇝* ⟦ ⟧

-- bindings: x ↦ ξ.y, y ↦ ⟦ ⟧
Expand Down Expand Up @@ -515,3 +525,172 @@ def test5 : example5 ⇝* example5_res :=
ReflTransGen.head
test5_red
ReflTransGen.refl

---------------------------------
-- TEST 6: infinite reduction sequence presented after Definition 3.1 [KS22]
-- ⟦ x ↦ ρ⁰.y, y ↦ ρ⁰.x ⟧.x ⇝ ⟦ x ↦ ρ⁰.y, y ↦ ρ⁰.x ⟧.y
-- ⟦ x ↦ ρ⁰.y, y ↦ ρ⁰.x ⟧.y ⇝ ⟦ x ↦ ρ⁰.y, y ↦ ρ⁰.x ⟧.x

def example6_bindings : Bindings ["x", "y"] :=
.cons "x" (by simp) (attached (dot (loc 0) "y"))
(.cons "y" (by simp) (attached (dot (loc 0) "x")) .nil)

def example6_obj : Term := obj example6_bindings

def test6_1 : (dot example6_obj "x" ⇝ dot example6_obj "y") := by
have reduction :=
dot_c
(dot (loc 0) "y")
"x"
example6_bindings
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction

def test6_2 : (dot example6_obj "y" ⇝ dot example6_obj "x") := by
have reduction :=
dot_c
(dot (loc 0) "x")
"y"
example6_bindings
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction

---------------------------------
-- Examples/tests of different term reductions presented after Definition 3.1 [KS22]
-- ⟦x ↦ ⟦y ↦ ∅⟧⟧.x(y ↦ ⟦z ↦ w⟧.z)

def w : Term := obj Bindings.nil
def example_graph_init : Term :=
app
(dot
(obj
(.cons "x" (by simp) (attached (obj (.cons "y" (by simp) void .nil))) .nil)
)
"x"
)
"y"
(dot (obj (.cons "z" (by simp) (attached w) .nil)) "z")

def example_graph_l1 : Term :=
app
(obj (.cons "y" (by simp) void .nil))
"y"
(dot (obj (.cons "z" (by simp) (attached w) .nil)) "z")
def example_graph_r1 : Term :=
app
(dot
(obj
(.cons "x" (by simp) (attached (obj (.cons "y" (by simp) void .nil))) .nil)
)
"x"
)
"y"
w
def example_graph_l2 : Term :=
obj
(.cons "y" (by simp)
(attached (dot (obj (.cons "z" (by simp) (attached w) .nil)) "z")) .nil
)
def example_graph_r2 : Term :=
app
(obj (.cons "y" (by simp) void .nil))
"y"
w
def example_graph_last : Term :=
obj (.cons "y" (by simp) (attached w) .nil)

def test_graph_1 : example_graph_init ⇝ example_graph_l1
:= congAPPₗ _ _ _ _
(by
have reduction := dot_c
(obj (.cons "y" (by simp) void .nil))
"x"
(.cons "x" (by simp) (attached (obj (.cons "y" (by simp) void .nil))) .nil)
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction
)
def test_graph_2 : example_graph_init ⇝ example_graph_r1
:= congAPPᵣ _ _ _ _
(by
have reduction := dot_c
w
"z"
(.cons "z" (by simp) (attached w) .nil)
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction
)
def test_graph_3 : example_graph_l1 ⇝ example_graph_l2
:= by
have reduction := app_c
(obj (.cons "y" (by simp) void .nil))
(dot (obj (.cons "z" (by simp) (attached w) .nil)) "z")
"y"
(.cons "y" (by simp) void .nil)
rfl
(by simp [lookup])
simp [insert_φ] at reduction
exact reduction
def test_graph_4 : example_graph_l1 ⇝ example_graph_r2
:= congAPPᵣ _ _ _ _
(by
have reduction := dot_c
w
"z"
(.cons "z" (by simp) (attached w) .nil)
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction
)
def test_graph_5 : example_graph_r1 ⇝ example_graph_r2
:= congAPPₗ _ _ _ _
(by
have reduction := dot_c
(obj (.cons "y" (by simp) void .nil))
"x"
(.cons "x" (by simp) (attached (obj (.cons "y" (by simp) void .nil))) .nil)
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction
)
def test_graph_6 : example_graph_l2 ⇝ example_graph_last
:= by
have reduction := congOBJ
"y"
(.cons "y" (by simp)
(attached (dot (obj (.cons "z" (by simp) (attached w) .nil)) "z"))
.nil
)
(by
have reduction := dot_c
w
"z"
(.cons "z" (by simp) (attached w) .nil)
rfl
(by simp [lookup])
simp [substitute] at reduction
exact reduction
)
(.zeroth_attached _ _ _ _)
simp [insert_φ] at reduction
exact reduction
def test_graph_7 : example_graph_r2 ⇝ example_graph_last
:= by
have reduction := app_c
(obj (.cons "y" (by simp) void .nil))
w
"y"
(.cons "y" (by simp) void .nil)
rfl
(by simp [lookup])
simp [insert_φ] at reduction
exact reduction

1 comment on commit 1e67968

@0pdd
Copy link

@0pdd 0pdd commented on 1e67968 Dec 7, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wasn't able to retrieve PDD puzzles from the code base and submit them to github. If you think that it's a bug on our side, please submit it to yegor256/0pdd:

set -x && set -e && set -o pipefail && cd /tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA && pdd -v -f /tmp/20241207-3299-mj7exj [1]: + set -e + set -o pipefail + cd /tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA + pdd -v -f...

Please, copy and paste this stack trace to GitHub:

UserError
set -x && set -e && set -o pipefail && cd /tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA && pdd -v -f /tmp/20241207-3299-mj7exj [1]:
+ set -e
+ set -o pipefail
+ cd /tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA
+ pdd -v -f /tmp/20241207-3299-mj7exj

My version is 0.24.0
Ruby version is 3.1.4 at x86_64-linux
Reading from root dir /tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA
/tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA/lake-manifest.json is a binary file (4329 bytes)
/tmp/0pdd20241207-2-g3rzko/Z2l0QGdpdGh1Yi5jb206b2JqZWN0aW9uYXJ5L3Byb29mLmdpdA/renovate.json is a binary file (114 bytes)
Reading .github/workflows/lean.yml ...
Reading .gitignore ...
Reading Extended/ARS.lean ...
Reading Extended/Confluence/CompleteDevelopment.lean ...
Reading Extended/Confluence/Equivalence.lean ...
Reading Extended/Record.lean ...
Reading Extended/Reduction/Parallel/Definition.lean ...
Reading Extended/Reduction/Parallel/Properties.lean ...
Reading Extended/Reduction/Regular/Definition.lean ...
ERROR: ERROR: Extended/Reduction/Regular/Definition.lean; PDD::Error at Extended/Reduction/Regular/Definition.lean:102: TODO found, but puzzle can't be parsed, most probably because TODO is not followed by a puzzle marker, as this page explains: https://github.com/cqfn/pdd#how-to-format
If you can't understand the cause of this issue or you don't know how to fix it, please submit a GitHub issue, we will try to help you: https://github.com/cqfn/pdd/issues. This tool is still in its beta version and we will appreciate your feedback. Here is where you can find more documentation: https://github.com/cqfn/pdd/blob/master/README.md.
Exit code is 1

/app/objects/git_repo.rb:74:in `rescue in block in xml'
/app/objects/git_repo.rb:71:in `block in xml'
/app/vendor/ruby-3.1.4/lib/ruby/3.1.0/tempfile.rb:317:in `open'
/app/objects/git_repo.rb:70:in `xml'
/app/objects/puzzles.rb:46:in `deploy'
/app/objects/jobs/job.rb:38:in `proceed'
/app/objects/jobs/job_starred.rb:32:in `proceed'
/app/objects/jobs/job_recorded.rb:31:in `proceed'
/app/objects/jobs/job_emailed.rb:33:in `proceed'
/app/objects/jobs/job_commiterrors.rb:33:in `proceed'
/app/objects/jobs/job_detached.rb:48:in `exclusive'
/app/objects/jobs/job_detached.rb:36:in `block in proceed'
/app/objects/jobs/job_detached.rb:36:in `fork'
/app/objects/jobs/job_detached.rb:36:in `proceed'
/app/0pdd.rb:549:in `process_request'
/app/0pdd.rb:380:in `block in <top (required)>'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1804:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1804:in `block in compile!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1071:in `block (3 levels) in route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1089:in `route_eval'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1071:in `block (2 levels) in route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1120:in `block in process_route'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1118:in `catch'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1118:in `process_route'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1069:in `block in route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1066:in `each'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1066:in `route!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1190:in `block in dispatch!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1161:in `catch'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1161:in `invoke'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1185:in `dispatch!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1001:in `block in call!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1161:in `catch'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1161:in `invoke'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1001:in `call!'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:990:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-3.0.9/lib/rack/rewindable_input.rb:25:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-3.0.9/lib/rack/deflater.rb:47:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-4.0.0/lib/rack/protection/xss_header.rb:20:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-4.0.0/lib/rack/protection/path_traversal.rb:18:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-4.0.0/lib/rack/protection/json_csrf.rb:28:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-4.0.0/lib/rack/protection/base.rb:53:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-4.0.0/lib/rack/protection/base.rb:53:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-protection-4.0.0/lib/rack/protection/frame_options.rb:33:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-3.0.9/lib/rack/logger.rb:19:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-3.0.9/lib/rack/common_logger.rb:43:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:266:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:259:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-3.0.9/lib/rack/head.rb:15:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rack-3.0.9/lib/rack/method_override.rb:28:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:224:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:2115:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1674:in `block in call'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1890:in `synchronize'
/app/vendor/bundle/ruby/3.1.0/gems/sinatra-4.0.0/lib/sinatra/base.rb:1674:in `call'
/app/vendor/bundle/ruby/3.1.0/gems/rackup-2.1.0/lib/rackup/handler/webrick.rb:111:in `service'
/app/vendor/bundle/ruby/3.1.0/gems/webrick-1.8.1/lib/webrick/httpserver.rb:140:in `service'
/app/vendor/bundle/ruby/3.1.0/gems/webrick-1.8.1/lib/webrick/httpserver.rb:96:in `run'
/app/vendor/bundle/ruby/3.1.0/gems/webrick-1.8.1/lib/webrick/server.rb:310:in `block in start_thread'

Please sign in to comment.