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

Question: Can you have calc blocks in games? #223

Open
lnay opened this issue May 2, 2024 · 11 comments
Open

Question: Can you have calc blocks in games? #223

lnay opened this issue May 2, 2024 · 11 comments
Labels
client Functionality of the client side code enhancement New feature or request ideal for volunteers Feature request which should make for a good isolated project. Currently out-of-scope/unclaimed

Comments

@lnay
Copy link
Contributor

lnay commented May 2, 2024

What is the status of using a calc block in a level?
Is it possible right now (I couldn't find a way to, or see anything in docs)?

@joneugster
Copy link
Collaborator

joneugster commented May 2, 2024

You can state your proof as

Statement ... : ... = yada yada := by
  Template
    Hole
      calc .....

Which will force the user to stay in the "editor mode", i.e where they can freely type in a multi-line editor (there's one sentence about it here). There they can enter anything, even calc-blocks, but the user experience might be less guided.

It's not possible to use calc as a tactic in the "typewriter mode", i.e. where you enter one tactic at a time as you see e.g. in the NNG. In fact it does not support any multi-line tactics at all.

I can recommend using the trans tactic instead of calc, that usually works quite well. (i.e. make trans [the most complicated type in your calc block] and then got on simplifying both new equations.)

@lnay
Copy link
Contributor Author

lnay commented May 2, 2024

Thanks!

@lnay lnay closed this as completed May 2, 2024
@lnay
Copy link
Contributor Author

lnay commented May 2, 2024

@AlexBrodbelt , useful note here on level design

@joneugster joneugster reopened this Jun 4, 2024
@joneugster joneugster added client Functionality of the client side code ideal for volunteers Feature request which should make for a good isolated project. Currently out-of-scope/unclaimed enhancement New feature or request labels Jun 4, 2024
@joneugster
Copy link
Collaborator

I'll reuse this issue for anything about calc blocks in games, as it does come up occationally.

Current state: It would require serious modifications to the "Typewriter interface" in order to support calc-blocks in a semi-reasonable way, and it's afaik not on anybody's TODO-list. However, if there is serious interest and somebody wants to work on it, this might be the right place to discuss further details.

@AlexBrodbelt
Copy link

I would be happy to work on this, what would I have to do?

@JadAbouHawili
Copy link
Contributor

You can state your proof as

Statement ... : ... = yada yada := by
  Template
    Hole
      calc .....

Which will force the user to stay in the "editor mode", i.e where they can freely type in a multi-line editor (there's one sentence about it here). There they can enter anything, even calc-blocks, but the user experience might be less guided.

Ah, I have a weird work around to make the user experience more guided. Here's an example:

Statement {x : ℤ} (h : x + 2 = 4)
  : x = 2 := by{
  Template
    calc 
      x = x + 2 - 2 := by sorry 
      _ = 4 - 2 := by sorry
      _ = 2 := by sorry
  }

Now, when the user enters the level, there is going to be a sorry tactic not available in this game error. Placing the text cursor before sorry would show you the normal proof state making the level playable. The obvious downside is that this would give off tactic needed but not introduced warnings when building and warnings in your editor. @joneugster , is there a cleaner way or even a 'right' way to do this because this doesn't look like it.

@JadAbouHawili
Copy link
Contributor

This approach would work for more than just calc blocks:

variable {P Q : Prop}
Statement (hP : P) (hQ : Q) : P ∧ Q := by 
  Template
     constructor 
        · sorry
        · sorry

Comments can also clarify each step, serving the function of Hint. Maybe allowing multiple uses of Hole would make this less weird, using Hole in place of sorry. Based on my testing, Hole can only be used once(indicate otherwise if I'm wrong). @joneugster should this go to a new issue?

@joneugster
Copy link
Collaborator

Hole should be usable multiple times, that sound like a bug.

@joneugster
Copy link
Collaborator

amd if you ever get tactic "sorry" not available thats also a bug.

For your first message, I think you are supposed to put by Hole _ where you have by sorry in your calc block and you should also be able to use Hint there, bit I havent tested that much.

Maybe you can share your wip progress with me privately, then I can use it as a MWE

@JadAbouHawili
Copy link
Contributor

JadAbouHawili commented Aug 4, 2024

Doing by Hole _ instead of by sorry gives an unsolved goals error, and lake build fails. Instead of _, I can prove the goal and it would work fine.
I'll make a separate pull request regarding calc documentation later.
Here's what the code now looks like(works fine):

Statement {x : ℤ} (h : x + 2 = 4)
  : x = 2 := by{
  Template
    calc 
      x = x + 2 - 2 := by 
        Hole 
        Hint "hint here, works fine"
        ring
      _ = 4 - 2 := by Hole rw [h]
      _ = 2 := by Hole norm_num
  }

Note: Hint doesn't give a syntax error but doesn't seem to be working properly either.
Question: whats wip?

@joneugster
Copy link
Collaborator

Instead of _, I can prove the goal and it would work fine.
That's what I meant indeed! Probably want to indent everything inside the Hole:

        Hole 
          Hint "hint here, works fine"
          ring

Note: Hint doesn't give a syntax error but doesn't seem to be working properly either.

I'll look into that!

Question: whats wip?

(it's the abbreviation for Work in Progress)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Functionality of the client side code enhancement New feature or request ideal for volunteers Feature request which should make for a good isolated project. Currently out-of-scope/unclaimed
Projects
None yet
Development

No branches or pull requests

4 participants