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

[Merged by Bors] - feat(set_theory/game): short games, boards, and domineering #1540

Closed
wants to merge 14 commits into from

Conversation

semorrison
Copy link
Collaborator

@semorrison semorrison commented Oct 12, 2019

This is a do-over of my previous attempt to implement the combinatorial game of domineering. This time, we get a nice clean definition, and it computes!

To achieve this, I follow Reid's advice: generalise! We define

class state (S : Type u) :=
(turn_bound : S → ℕ)
(L : S → finset S)
(R : S → finset S)
(left_bound : ∀ {s t : S} (m : t ∈ L s), turn_bound t < turn_bound s)
(right_bound : ∀ {s t : S} (m : t ∈ R s), turn_bound t < turn_bound s)

a typeclass describing S as "the state of a game", and provide pgame.of [state S] : S \to pgame.

This allows a short and straightforward definition of Domineering:

/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
def board := finset (ℤ × ℤ)

...

/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
  L := λ s, (left s).image (move_left s),
  R := λ s, (right s).image (move_right s),
  left_bound := _
  right_bound := _, }

which computes:

example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) := dec_trivial

@robertylewis robertylewis added the awaiting-review The author would like community review of the PR label Oct 15, 2019
@semorrison
Copy link
Collaborator Author

Obviously this, as some "recreational maths", is low priority, but I'll assign to @rwbarton as the only person who's previously been interested. :-)

@bryangingechen bryangingechen self-assigned this Feb 28, 2020
@bryangingechen
Copy link
Collaborator

I'll take a look after the linting errors are addressed: https://github.com/leanprover-community/mathlib/runs/475593766#step:12:16

@semorrison
Copy link
Collaborator Author

@bryangingechen, I've fixed up the linting problems.

@bryangingechen
Copy link
Collaborator

bryangingechen commented Mar 2, 2020

Thanks, I'll try to take a look this week.

Update (2020-03-11): I have been looking at this, but it's taking a while since I started looking over all of pgame.lean first.

Copy link
Collaborator

@bryangingechen bryangingechen left a comment

Choose a reason for hiding this comment

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

Overall this looks good to me! Mainly I would like the lines to be within the <100 limit if possible, and I also made a bunch of mostly proof golf suggestions, though some of those might break after you merge in master.

It's nice to see computable definitions put to work in Lean. The real test of short and state will be how easy it will be to define other games, so let's try and get this in quickly and then continue the experimentation in future PRs.

src/set_theory/game/state.lean Outdated Show resolved Hide resolved
src/algebra/ring.lean Outdated Show resolved Hide resolved
src/set_theory/game/domineering.lean Outdated Show resolved Hide resolved
src/set_theory/game/domineering.lean Outdated Show resolved Hide resolved
src/set_theory/game/domineering.lean Outdated Show resolved Hide resolved
src/set_theory/game/state.lean Outdated Show resolved Hide resolved
src/set_theory/game/state.lean Outdated Show resolved Hide resolved
src/set_theory/game/state.lean Outdated Show resolved Hide resolved
src/set_theory/game/state.lean Outdated Show resolved Hide resolved
src/set_theory/game/state.lean Outdated Show resolved Hide resolved
@bryangingechen bryangingechen added awaiting-author A reviewer has asked the author a question or requested changes and removed awaiting-review The author would like community review of the PR labels Apr 12, 2020
@semorrison
Copy link
Collaborator Author

Sorry about the line lengths, that PR was particularly egregious. Perhaps we need a linter. :-)

Thanks very much for the review comments, they were all helpful!

(And now I want to go off and tell mathlib about Hex. :-)

@bryangingechen
Copy link
Collaborator

bors r+

@bors
Copy link

bors bot commented Apr 12, 2020

👎 Rejected by label

@bryangingechen bryangingechen removed the awaiting-author A reviewer has asked the author a question or requested changes label Apr 12, 2020
@github-actions github-actions bot added the ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.) label Apr 12, 2020
@bryangingechen
Copy link
Collaborator

bors r+

bors bot pushed a commit that referenced this pull request Apr 12, 2020
This is a do-over of my previous attempt to implement the combinatorial game of domineering. This time, we get a nice clean definition, and it computes!

To achieve this, I follow Reid's advice: generalise! We define 
```
class state (S : Type u) :=
(turn_bound : S → ℕ)
(L : S → finset S)
(R : S → finset S)
(left_bound : ∀ {s t : S} (m : t ∈ L s), turn_bound t < turn_bound s)
(right_bound : ∀ {s t : S} (m : t ∈ R s), turn_bound t < turn_bound s)
```
a typeclass describing `S` as "the state of a game", and provide `pgame.of [state S] : S \to pgame`.

This allows a short and straightforward definition of Domineering:
```lean
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
def board := finset (ℤ × ℤ)

...

/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
  L := λ s, (left s).image (move_left s),
  R := λ s, (right s).image (move_right s),
  left_bound := _
  right_bound := _, }
```
which computes:
```
example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) := dec_trivial
```
@bors
Copy link

bors bot commented Apr 12, 2020

Build succeeded

@bors
Copy link

bors bot commented Apr 12, 2020

Pull request successfully merged into master.

@bors bors bot changed the title feat(set_theory/game): short games, boards, and domineering [Merged by Bors] - feat(set_theory/game): short games, boards, and domineering Apr 12, 2020
@bors bors bot closed this Apr 12, 2020
@bors bors bot deleted the domineering branch April 12, 2020 08:25
b-mehta pushed a commit that referenced this pull request Apr 13, 2020
This is a do-over of my previous attempt to implement the combinatorial game of domineering. This time, we get a nice clean definition, and it computes!

To achieve this, I follow Reid's advice: generalise! We define 
```
class state (S : Type u) :=
(turn_bound : S → ℕ)
(L : S → finset S)
(R : S → finset S)
(left_bound : ∀ {s t : S} (m : t ∈ L s), turn_bound t < turn_bound s)
(right_bound : ∀ {s t : S} (m : t ∈ R s), turn_bound t < turn_bound s)
```
a typeclass describing `S` as "the state of a game", and provide `pgame.of [state S] : S \to pgame`.

This allows a short and straightforward definition of Domineering:
```lean
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
def board := finset (ℤ × ℤ)

...

/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
  L := λ s, (left s).image (move_left s),
  R := λ s, (right s).image (move_right s),
  left_bound := _
  right_bound := _, }
```
which computes:
```
example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) := dec_trivial
```
anrddh pushed a commit to anrddh/mathlib that referenced this pull request May 15, 2020
…er-community#1540)

This is a do-over of my previous attempt to implement the combinatorial game of domineering. This time, we get a nice clean definition, and it computes!

To achieve this, I follow Reid's advice: generalise! We define 
```
class state (S : Type u) :=
(turn_bound : S → ℕ)
(L : S → finset S)
(R : S → finset S)
(left_bound : ∀ {s t : S} (m : t ∈ L s), turn_bound t < turn_bound s)
(right_bound : ∀ {s t : S} (m : t ∈ R s), turn_bound t < turn_bound s)
```
a typeclass describing `S` as "the state of a game", and provide `pgame.of [state S] : S \to pgame`.

This allows a short and straightforward definition of Domineering:
```lean
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
def board := finset (ℤ × ℤ)

...

/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
  L := λ s, (left s).image (move_left s),
  R := λ s, (right s).image (move_right s),
  left_bound := _
  right_bound := _, }
```
which computes:
```
example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) := dec_trivial
```
anrddh pushed a commit to anrddh/mathlib that referenced this pull request May 16, 2020
…er-community#1540)

This is a do-over of my previous attempt to implement the combinatorial game of domineering. This time, we get a nice clean definition, and it computes!

To achieve this, I follow Reid's advice: generalise! We define 
```
class state (S : Type u) :=
(turn_bound : S → ℕ)
(L : S → finset S)
(R : S → finset S)
(left_bound : ∀ {s t : S} (m : t ∈ L s), turn_bound t < turn_bound s)
(right_bound : ∀ {s t : S} (m : t ∈ R s), turn_bound t < turn_bound s)
```
a typeclass describing `S` as "the state of a game", and provide `pgame.of [state S] : S \to pgame`.

This allows a short and straightforward definition of Domineering:
```lean
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
def board := finset (ℤ × ℤ)

...

/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
  L := λ s, (left s).image (move_left s),
  R := λ s, (right s).image (move_right s),
  left_bound := _
  right_bound := _, }
```
which computes:
```
example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) := dec_trivial
```
cipher1024 pushed a commit to cipher1024/mathlib that referenced this pull request Mar 15, 2022
…er-community#1540)

This is a do-over of my previous attempt to implement the combinatorial game of domineering. This time, we get a nice clean definition, and it computes!

To achieve this, I follow Reid's advice: generalise! We define 
```
class state (S : Type u) :=
(turn_bound : S → ℕ)
(L : S → finset S)
(R : S → finset S)
(left_bound : ∀ {s t : S} (m : t ∈ L s), turn_bound t < turn_bound s)
(right_bound : ∀ {s t : S} (m : t ∈ R s), turn_bound t < turn_bound s)
```
a typeclass describing `S` as "the state of a game", and provide `pgame.of [state S] : S \to pgame`.

This allows a short and straightforward definition of Domineering:
```lean
/-- A Domineering board is an arbitrary finite subset of `ℤ × ℤ`. -/
def board := finset (ℤ × ℤ)

...

/-- The instance describing allowed moves on a Domineering board. -/
instance state : state board :=
{ turn_bound := λ s, s.card / 2,
  L := λ s, (left s).image (move_left s),
  R := λ s, (right s).image (move_right s),
  left_bound := _
  right_bound := _, }
```
which computes:
```
example : (domineering ([(0,0), (0,1), (1,0), (1,1)].to_finset) ≈ pgame.of_lists [1] [-1]) := dec_trivial
```
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ready-to-merge All that is left is for bors to build and merge this PR. (Remember you need to say `bors r+`.)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants