Skip to content

Proposal: Allow bottom-up prover to unify work variables more broadly (long-term) #77

Open

Description

@david-a-wheeler

I have an idea - it'd be great if the unifier/bottom-up prover could unify on work variables more aggressively, at least optionally. This is an area where mmj2 can currently do more than metamath-lamp can.

I'm trying to re-prove syl when loading set.mm and stopped after ax-3 (that is, I only have the axioms in the context).

I want to prove, using ax-2, the following step which was created earlier by a backwards application of ax-mp:

|- ( &W1 -> ( ( ph -> ps ) -> ( ph -> ch ) ) )

However, when I select this statement and unify (prove bottom-up), ax-2 doesn't appear as an option. That's true even if I allow "everything" by changing the Length restriction to "No", allow root statements at all levels, and enable everything else. If I try to enter ax-2 directly as a label, the backwards prover won't offer ax-2 as an option - it clearly thinks this statement cannot match ax-2.

Follow this link to see the state. The full situation is also captured by this json:

{"srcs":[{"typ":"Web","fileName":"","url":"https://us.metamath.org/metamath/set.mm","readInstr":"StopAfter","label":"ax-3","resetNestingLevel":true,"allLabels":[]}],"descr":"Reprove syllogism (\"syl\"), using only axioms.","varsText":"var1 wff &W1","disjText":"","stmts":[{"label":"syl.1","typ":"e","cont":"|- ( ph -> ps )","jstfText":""},{"label":"syl.2","typ":"e","cont":"|- ( ps -> ch )","jstfText":""},{"label":"3","typ":"p","cont":"|- ( &W1 -> ( ( ph -> ps ) -> ( ph -> ch ) ) )","jstfText":""},{"label":"2","typ":"p","cont":"|- &W1","jstfText":""},{"label":"1","typ":"p","cont":"|- ( ( ph -> ps ) -> ( ph -> ch ) )","jstfText":"2 3 : ax-mp"},{"label":"syl","typ":"p","cont":"|- ( ph -> ch )","jstfText":"syl.1 1 : ax-mp"}]}

The desired state is to be able to unify it with ax-2.

It also won't unify through merging. I can search for ax-2 and insert it, which is fine, and the instance has a bunch of metavariables as expected. But "merge" will not merge the original statement and the instance of ax-2, no matter what the order is.

I can replace the work variable &W1 with ( ph -> ( ps -> ch ) ) and apply "unify". Then bottom-up proving immediately unifies to that result.

This is unfortunate. If the backwards prover could handle this case (even optionally) I bet it could automatically prove a lot more. In fact, if it noticed these matches, it could probably prove some things that mmj2 struggles with (because in mmj2 you can't really control the search of just one statement very well).

I tested on this, but I don't think the version matters: https://expln.github.io/lamp/dev/index.html

This is in contrast to mmj2, which can unify some work variables and lets you specify an assertion like ax-2 to be used on such a statement. A "before" and "after" should clarify things. For example, here's an example of "syllogism" where I just typed in ax-2 in the analogous situation (the "*" comments are hints to myself of where I'm going):

$( <MM> <PROOF_ASST> THEOREM=syllogism LOC_AFTER=

hd1::syllogism.1 |- ( ph -> ps ) 
hd2::syllogism.2 |- ( ps -> ch ) 

* !              |- ( ph -> ( ps -> ch ) ) 
* !              |- ( ( ph -> ps ) -> ( ph -> ch ) ) 
!d3::              |- &W1
!d5::              |- &W2
!d6::ax-2              |- ( &W2 -> ( &W1 -> ( ph -> ch ) ) )
d4:d5,d6:ax-mp          |- ( &W1 -> ( ph -> ch ) )
qed:d3,d4:ax-mp     |- ( ph -> ch ) 

$)

In mmj2, after pressing control-U, I get a unification which helps me to keep going:

$( <MM> <PROOF_ASST> THEOREM=syllogism LOC_AFTER=

hd1::syllogism.1 |- ( ph -> ps ) 
hd2::syllogism.2 |- ( ps -> ch ) 

* !              |- ( ph -> ( ps -> ch ) ) 
* !              |- ( ( ph -> ps ) -> ( ph -> ch ) ) 
!d3::              |- ( ph -> &W3 )
!d5::              |- ( ph -> ( &W3 -> ch ) )
d6::ax-2           |- (  ( ph -> ( &W3 -> ch ) )
                      -> ( ( ph -> &W3 ) -> ( ph -> ch ) ) )
d4:d5,d6:ax-mp     |- ( ( ph -> &W3 ) -> ( ph -> ch ) )
qed:d3,d4:ax-mp     |- ( ph -> ch ) 

$)

Activity

  1. expln commented on Jun 4, 2023

    @expln
    Owner

    Thanks for the detailed explanations. I will analyze the issue and return with some response.

  2. david-a-wheeler commented on Jun 4, 2023

    @david-a-wheeler
    ContributorAuthor

    Thanks, and as always, thanks for your time.

    I did an experiment with a surprising result, which may be helpful to you. I expected that the problem was that "&W1" would only match a wff variable (which would be an understandable limitation). So I modified "Variables" to say:

    .tempwff wff &W1
    

    I then modified my "statement 3" to delete its justification & changed the first wff variable to a work variable, resulting in this:

    |- ( ( &W1 -> ( ps -> ch ) ) -> ( ( ph -> ps ) -> ( ph -> ch ) ) )
    

    Even with this change, a bottom-up proof didn't find ax-2.

  3. david-a-wheeler commented on Jun 5, 2023

    @david-a-wheeler
    ContributorAuthor

    In case it's relevant, it'd also be awesome if the tool could automatically replace work variables on unification. The review posted on May 27, 2023, at 10:17 AM, by Alexander van der Vekens on the Metamath mailing list (metamath@googlegroups.com) said:

    The replacement of a temporary variable is a little bit cumberson: if you want to replace &C1 by 6, you cannot change it at one place (and then it is replaced everywhere, as in mmj2), but you have to click A (apply a substitution to all statements), then enter &C1 and 6 manually.

    I'm not sure this is related, but since it might be, I thought I'd note it.

  4. expln commented on Jun 5, 2023

    @expln
    Owner

    I analyzed this issue and yes indeed this is not a bug, this is a limitation of the mm-lamp unifier.

    This case is special because of the following reason.
    In order to unify ax-2 with |- ( &W1 -> ( ( ph -> ps ) -> ( ph -> ch ) ) ) we have to substitute variables in both expressions.
    But mm-lamp's unifier is unable to find such substitutions.

    What it can do is: given two expressions exprA and exprB, it can find a substitution subsUni such that by applying subsUni to exprA we are obtaining exprB, i.e.:
    subsUni(exprA) = exprB.

    What the case described in this issue requires is to find a substitution subsBi such that (using similar notation):
    subsBi(exprA) = subsBi(exprB).

    In my notation, Uni stands for "unidirectional" and Bi stands for "bidirectional".

    Let me demonstrate this on real expressions.
    In oder for the next example not to be misleading, I have to express ax-2 using work variables, but this should not be a problem because it doesn't matter what variable names we choose to describe an assertion as soon as variable types are correct (please correct me if I am wrong).

    exprA = |- ( ( &W3 -> ( &W4 -> &W2 ) ) -> ( ( &W3 -> &W4 ) -> ( &W3 -> &W2 ) ) )
    exprB = |- ( &W1 -> ( ( ph -> ps ) -> ( ph -> ch ) ) )

    A substitution subsBi (such that subsBi(exprA) = subsBi(exprB) ) exists, and it is as follows:

    &W2 → ch
    &W3 → ph
    &W4 → ps
    &W1 → ( ph -> ( ps -> ch ) )
    

    But mm-lamp searches only for subsUni, such that subsUni(exprA) = exprB. Obviously it doesn't exist because length(exprB) < length(exprA).

    The workaround you've described in the guide, when you manually substitute &W1 → ( ph -> ( ps -> ch ) ) is absolutely correct. It allows to bypass this limitation using the smallest amount of logical steps.

    I would like to share another possible solution. It uses more logical steps, but it demonstrates that such a "bidirectional" substitution may be achieved by two "unidirectional" substitutions. I recorded a video because it would be difficult to write (and probably to read) an explanation - (no sound) https://drive.google.com/file/d/1KIr0eOEmH4VoIHOHFhqXwBn08h-xGicV/view?usp=sharing

    To fix this issue, I plan to use the fact that a "bidirectional" substitution may be achieved by two "unidirectional" substitutions.
    I don't have a very clear plan how to implement this in mm-lamp, but I have some ideas to begin with.

    Sorry if my explanation is difficult to understand because of unusual terminology. I am ready to answer clarifying questions if you have any.

  5. david-a-wheeler commented on Jun 6, 2023

    @david-a-wheeler
    ContributorAuthor

    @expln - thanks for the explanation! I also appreciate you pointing out that it's possible to select two expressions to make replacements easier.

    For now, I think the solution is to document both approaches in the guide, given the current limitations in the unification algorithm. That said, I hope we don't stop there, see my next comment here...

  6. david-a-wheeler commented on Jun 6, 2023

    @david-a-wheeler
    ContributorAuthor

    In the longer term, it'd be great if the unifier could handle this more general case, at least as an enable-able option. Unification has been studied to death, I bet there are some awesome algorithms that do much with decent performance.

    @digama0 - any suggestions on how to improve the metamath-lamp unification algorithm, given the discussion above? In particular, any pointers to some of the most relevant literature?

  7. digama0 commented on Jun 6, 2023

    @digama0

    There is a canonical algorithm for what @expln calls "bidirectional unification" (normally this is called "unification" and the unidirectional version is called "matching") which can be done purely recursively. There is a description on wikipedia, although I think the version I have implemented for MM1 is both more executable and simpler. I will summarize it:

    • The interface is a function unify(e1, e2) which takes two expressions e1 and e2 containing metavariables (work variables) and will assign those variables to make e1 and e2 equal.
    • (There are additional mechanisms in that implementation for returning unfolding proofs for definitions, which can be ignored for MM.)
    • unify(e1, e2): Pattern match e1 and e2.
      • If e1 = e2 then success
      • If e1 is a metavariable then assign(e1, e2)
      • If e2 is a metavariable then assign(e2, e1)
      • If e1 and e2 are distinct variables, or one is a variable and the other is a constructor, or both are distinct constructors then fail
      • If e1 = t(a1, ..., an) and e2 = t(b1,..., bn) then unify(ai, bi) for 1 <= i <= n
    • assign(mv, e) takes mv a metavariable and assigns it to e, if possible:
      • If e = mv then success
      • If e contains mv then fail (this is the occurs check)
      • otherwise assign mv := e; all other equality checks should be performed modulo this assignment so either you should rewrite the whole state to replace occurrences of mv with e, or store an mvar state and transparently use it in the pattern match in unify.
  8. david-a-wheeler commented on Jun 6, 2023

    @david-a-wheeler
    ContributorAuthor

    @digama0 - thank you so much for your wonderfully clear & specific reply!

    Now things make much more sense. Alexander van der Vekens earlier complained of problems using metamath-lamp, and while I'm sure part of the problem was a lack of documentation, this difference is almost certainly part of the issue as well.

    I don't know how long it would take to implement full unification instead. I suspect that once it is, the tool would become much more capable AND would be easier to use for those who've used other tools like mmj2. Full unification might be slower than matching; I can see selecting matching vs. unification as a possible option in the search dialogue. That said, I suspect "full unification" would be the preferred setting, as that would greatly increase the likelihood of finding solutions.

  9. expln commented on Jun 6, 2023

    @expln
    Owner

    Thank you @digama0 for your detailed answer and especially for providing the summary of the algorithm. I would not understand it from the Rust code without that summary.

    In this notation t(a1, ..., an), is my understanding correct that this represents a tree structure where a1,...,an are sibling nodes of this tree? And overall, all expressions are stored as trees (or in other format which may be transformed into a tree very fast)?

    @david-a-wheeler

    I hope we don't stop there
    In the longer term, it'd be great if the unifier could handle this more general case, at least as an enable-able option.

    Sure, I already have one idea what I can do to handle this and other similar cases. But yeah, that's not a simple change, so it will need some time for implementation.

    Thank you for posting this issue with detailed description and explanations how it is handled in mmj2. Currently this is the only way how I can discover such non-trivial uses cases commonly used during creation of proofs.

  10. digama0 commented on Jun 6, 2023

    @digama0

    In this notation t(a1, ..., an), is my understanding correct that this represents a tree structure where a1,...,an are sibling nodes of this tree? And overall, all expressions are stored as trees (or in other format which may be transformed into a tree very fast)?

    Yes, a1, ..., an are the children of a node with t as the constructor. And yes, this is presuming that the expressions are stored as trees, or else already parsed to trees. For example, ( &W1 -> ( ph -> &W2 ) ) is represented as app[wi](mvar[wff, 1], app[wi](var[wph], mvar[wff, 2])) (where t(a1,..., an) is now being written more explicitly as app[t](a1, ..., an)); for most purposes you can probably treat var nodes the same as app, except for $d propagation.

    I would say that not doing parsing would be a big misstep for any MM proof assistant - you gain the ability to read some unusual metamath databases at the cost of not being able to reason about the proof at a high enough level to perform useful automation activities.

  11. david-a-wheeler commented on Jun 9, 2023

    @david-a-wheeler
    ContributorAuthor

    If it's not too hard, I suggest leaving the old unifier as an option, at least for bottom-up search. If the bottom up prover is too powerful, it's hard to make simple examples in the guide to explain how to deal with cases where the automation doesn't work. So having ways to disable the automation can help. That said, I expect that the default should be full unification.

  12. david-a-wheeler commented on Jun 9, 2023

    @david-a-wheeler
    ContributorAuthor

    FYI, I looked for some more resources about implementing Unification, especially in OCaml, Rescript, or JavaScript. My hope is that this would help in addition to the awesome info from Mario above. Unification is a really old well-studied problem; Robinson's unification algorithm dates from 1965.

    Here are some things I found that might be useful:

    BTW, there's a nice video of the Curry-Howard Correspondence here (I found it while looking for examples): https://cs3110.github.io/textbook/chapters/adv/curry-howard.html

  13. expln commented on Jun 10, 2023

    @expln
    Owner

    Thanks David and Mario for the detailed explanations! The unification algorithm described by Mario looks really easy. I will analyze everything and return with my feedback.

  14. david-a-wheeler commented on Jun 25, 2023

    @david-a-wheeler
    ContributorAuthor

    I totally understand if that's deferred, but I think this one is key. I think there are two parts to this:

    1. full unification during global substitution (the "substitution" icon) - I think this should always be the case.
    2. full unification during bottom-up search - I think this should be an option for bottom-up search, but also supporting the current matching algorithm.
  15. 38 remaining items

  16. david-a-wheeler commented on Jul 30, 2023

    @david-a-wheeler
    ContributorAuthor

    Merge can only eliminate one of two identical statements. Unification of two statements is done how you described previously - select the new step 4 and step 3, click on "substitute"... If you mean that I can add such feature to the merge button, then I will think on that.

    Yes, please. If I click on 2 statements and click on merge. I think users would expect the tool to do it if it's possible.

    I think there is much to like about the way in which unification can be used as a zero-configuration tool. In mmj2, it's literally just one "do everything" button that users are quickly trained to press frequently.

    I agree with @digama0 - unification is a powerful general-purpose algorithm that can do a number of actions automatically, and I'd really like to see it used so that a single change in one place can cause automatic replacements like this.

  17. expln commented on Sep 8, 2023

    @expln
    Owner

    @digama0

    Hi Mario,

    Can you explain how MM1 builds syntax trees? Currently, I have performance problems with the algorithm I use in mm-lamp. My algorithm of building a syntax tree for an expression, for example s1 s2 s3 ..., is as follows:

    1. Try to prove each of the statements until a proof is found: class s1 s2 s3 ... , setvar s1 s2 s3 ... , wff s1 s2 s3 ...;
    2. If a proof is found, then transform it to a syntax tree.

    Transforming a proof into a syntax tree is a straightforward process because the proof is already a tree. Finding a proof is much more expensive process. I am using the same algorithm as in mm-lamp's bottom-up prover to find syntax proofs, which tries to apply all possible assertions to build a proof bottom-up. If needed I can provide more details on this algorithm, but I think this should be enough to understand why it is not very fast.

    This algorithm works sufficiently well for a small amount of statements. But now I want to build syntax trees for all assertions in set.mm, and that will be very slow.

  18. digama0 commented on Sep 9, 2023

    @digama0

    The process of building syntax trees from expressions is called parsing. There are a few ways you can do it, but the simplest is to put the syntax axioms into a trie and do a general backtracking algorithm. This can perform poorly on highly ambiguous grammars, but set.mm is unambiguous by design, and even though some backtracking is still needed because things might only be resolved after a while, it's not so bad in practice on set.mm.

    A trie node has the following data:

    • A map from constants c to trie nodes (shown as const c below)
    • A map from variable sorts (typecodes) v to trie nodes (shown as var v below)
    • Zero or one syntax axioms that end at this node (shown as reduce ax below)

    The top level of the trie is a map from typecodes to trie nodes. Every path through the tree represents a sequence of constants and variables, and during grammar initialization (which you can do either up front or as you encounter syntax axioms) you travel down the tree and add the syntax axiom. For example, starting from the empty tree:

    T: {}
    

    we can insert axiom wi, that is wff ( ph -> ps ), to produce the tree:

    T: {'wff': N0}
    N0: {const '(': N1}
    N1: {var 'wff': N2}
    N2: {const '->': N3}
    N3: {var 'wff': N4}
    N4: {const ')': N5}
    N5: {reduce 'wi'}
    

    If we insert wa $a wff ( ph /\ ps ) and wn $a wff -. ph into the tree as well, we get:

    T: {'wff': N0}
    N0: {const '(': N1, const '-.': N9}
    N1: {var 'wff': N2}
    N2: {const '->': N3, const '/\': N6}
    N3: {var 'wff': N4}
    N4: {const ')': N5}
    N5: {reduce 'wi'}
    N6: {var 'wff': N7}
    N7: {const ')': N8}
    N8: {reduce 'wa'}
    N9: {var 'wff': N10}
    N10: {reduce 'wn'}
    

    Having prepared a data structure for parsing, now suppose we have a string of constants and variables we want to parse. Here's a rendering of the algorithm as lean code:

    inductive Node where
      | mk (const : String → Option Node)
           (var : List (String × Node))
           (done : Option String)
    
    def Trie := String → Option Node
    
    def Node.empty : Node := ⟨fun _ => none, [], none⟩
    
    inductive Sym where
      | const (_ : String)
      | var (_ : String)
    
    inductive Expr where
      | var (_ : String)
      | app (_ : String) (_ : Array Expr)
    
    -- Given a variable symbol like "v", returns ("setvar", "wv"),
    -- i.e. the typecode and the variable hypothesis for the symbol
    def getVarHyp : String → String × String := sorry
    
    variable (p : Trie) (input : Array Sym) in
    mutual
    partial def parseC (q : Trie) (c : String) (pos : Nat) (args : Array Expr)
        (k : Expr → Nat → Option Expr) : Option Expr :=
      parsePT pos args k ((q c).getD .empty)
    
    partial def parseV (pos : Nat)
        (args : Array Expr) (k : Expr → Nat → Option Expr) :
        List (String × Node) → Option Expr
      | [] => none
      | (s', q) :: vs =>
        (parse s' pos fun v f' => parsePT f' (args.push v) k q)
        <|> parseV pos args k vs
    
    partial def parsePT (pos : Nat) (args : Array Expr)
        (k : Expr → Nat → Option Expr) : Node → Option Expr
      | ⟨cs, vs, d⟩ =>
        (match input[pos]? with
        | some (.const c) => parseC cs c (pos + 1) args k
        | _ => none)
        <|> parseV pos args k vs
        <|> (d.bind fun a => k (.app a args) pos)
    
    partial def parse (tc : String) (pos : Nat) (k : Expr → Nat → Option Expr) : Option Expr :=
      (match input[pos]? with
      | some (.var v) =>
        let (tc', v') := getVarHyp v
        if tc == tc' then k (.var v') (pos + 1) else none
      | _ => none)
      <|> parseC p tc pos #[] k
    end
    
    def parseFmla (s : String) (t : Trie) (input : Array Sym) : Option Expr :=
      parse t input s 0 fun e pos => if pos == input.size then some e else none

    Described in more detail:

    • Given the string s1 s2 ... with expected typecode c (usually wff for set.mm) we run parseFmla(c, T, [s1, s2, ...]), which returns the first successful parse
    • parseFmla depends on some mutually recursive functions:
      • parse(tc, pos, k) parses the substring of the input starting at pos as an expression of type tc, passing each successful parse to k and returning the first success
      • parsePT(pos, args, k, N) uses tree node N to decide what to do: if the next symbol is a constant c then call parseC, and if that fails then try parseV for all variable children, and if N.reduce is nonempty then return k(app(N.reduce, args), pos).
      • parseC(q, c, pos, args, k) just calls parsePT(pos, args, k, q[c])
      • parseV(pos, args, k, vs) loops over all the variable children, and tries to parse with each of them

    Each individual case is fairly straightforward given the data structure; I can explain in more detail if required. This is also a transcription of the algorithm https://github.com/digama0/mm0/blob/master/mm0-hs/src/MM0/FromMM/Parser.hs#L575-L612 , although that one assumes lazy evaluation and so hopefully this one is more suitable to be adapted to your context.

  19. expln commented on Sep 9, 2023

    @expln
    Owner

    Thank you so much, Mario!

    I can explain in more detail if required.

    Thanks, I need some time to understand this and probably then I will ask additional questions.

  20. david-a-wheeler commented on Sep 9, 2023

    @david-a-wheeler
    ContributorAuthor

    @digama0 - as always, thanks so much for your help!!

  21. expln commented on Sep 15, 2023

    @expln
    Owner

    @digama0

    the simplest is to put the syntax axioms into a trie and do a general backtracking algorithm. This can perform poorly on highly ambiguous grammars, but set.mm is unambiguous by design, and even though some backtracking is still needed because things might only be resolved after a while, it's not so bad in practice on set.mm.

    I understood the algorithm. But I have not implemented it yet because it will take some time. I am wondering how much time could this algorithm take to parse all assertion statements in set.mm (only the resulting statements of axioms and theorems without hypotheses). Do you have any statistics from your implementation of how much time it takes to parse set.mm? I've done some improvements to my current algorithm in mm-lamp, so now it takes about 40 seconds to parse set.mm (previously it was about an hour).

  22. digama0 commented on Sep 16, 2023

    @digama0

    The lower bound of this parsing algorithm is definitely sub-second if done well. I doubt knowing that will be useful to you though.

  23. david-a-wheeler commented on Dec 28, 2023

    @david-a-wheeler
    ContributorAuthor

    Metamath-lamp has gown into a very useful tool. I personally think this issue is now of the most important issues holding it back. While there is always room for better auto.ation, full unification would automate much (compared to the current state) and is 100% general.

  24. david-a-wheeler commented on Dec 28, 2023

    @david-a-wheeler
    ContributorAuthor

    Having this would certainly simplify the tutorial! :-)

  25. expln commented on Dec 30, 2023

    @expln
    Owner

    I started working on full unification a few months ago. But it turned out to be much harder than I imagined. I needed to change the parts of the code which I don't want to change (at least for now). So, I postponed this activity. Currently I am implementing automation. My current results in automation are promising, so I want to release it first. After that, I will try to do another attempt to implement full unification. Probably I will use that new automation to implement the full unification.

  26. david-a-wheeler commented on Nov 2, 2024

    @david-a-wheeler
    ContributorAuthor

    I would love to see this. This is extremely general & is itself a form of automation.

    I appreciate it's not easy. If there's something I can do to help, let me know.

  27. expln commented on Nov 3, 2024

    @expln
    Owner

    I guess I need help in comparing mmj2 behavior with mm-lamp, because I don’t know mmj2 well. I will try to come up with some solution to the problem you started this issue with (when you typed ax-2 and pressed Ctrl-U). When I implement some analogous solution in mm-lamp, I will ask you to come up with another example of what is possible in mmj2 and not possible in mm-lamp.

  28. expln commented on Jan 2, 2025

    @expln
    Owner

    Hi David,

    I have made some progress here. I implemented the unification for the simple case you described in the first comment in this issue (the case with two MMP files, before and after pressing Ctrl+U). To achieve the same in mm-lamp, do the following:

    1. Click the “Run a macro” button.
    2. In the dropdown select MMJ2.
    3. If you open that dialog for the first time, you’ll see “MMJ2 (inactive)”. Click the “Activate” button. This will make MMJ2 macros active. It means that mm-lamp will run a predefined JavaScript program which registers two macros in mm-lamp.
    4. Select “Import from MMP file” and paste the content of an MMP file. Click OK.
    5. Then again click the “Run a macro” button, and select “Unify”.

    This is available in dev version currently.

    Here is a corresponding demo https://drive.google.com/file/d/14Y6hV97bxytiG60wbdcAn_71m1K9VoQD/view?usp=drive_link

    This functionality is implemented using macros. All of this can be achieved manually. Currently, the “Unify” macro finds a step with an error, takes its assertion and puts the assertion’s statements above. Then it uses the substitution to unify new statements with the existing one. It also merges duplicated steps (which appear after the substitution) and renames the new step to have the name of the old step (so it looks like the existing step was modified). If you open the browser’s console, you’ll see the logs of the macros interaction with mm-lamp. You can also see the macros code if you click the small + button to the right of the MMJ2 dropdown and copy-paste the text from the small text field to any JS editor (or simply text editor). (To copy the text from the small text field, left click the text field, then press Ctrl+A and Ctrl+C)

    As I understand, your proposal was to make the full unification a “first-class citizen” in mm-lamp. But this requires a lot of changes in mm-lamp for which I am not ready now. However, I can try to write macros to cover mmj2 functionality using existing mm-lamp functionality. Do you have any other scenarios when mmj2 can do more than mm-lamp in terms of a more broad unification? If you can, it would be convenient for me if you send one or a few such cases in the form of MMP pairs, one before and another after pressing Ctrl+U.

  29. david-a-wheeler commented on Jan 2, 2025

    @david-a-wheeler
    ContributorAuthor

    @expln - thanks for working to implement something related to unification!

    @digama0 is an expert on what full unification does and means in this context - not me. He'd be the much better person to comment on it. I'm hoping he'll have a chance to say something. Mario: I know you're busy, but this is outside my expertise.

    I don't care how unification is implemented. Implementing it via macros is probably unnecessarily slow, but if it works, it's fine by me. A decent implementation should still run quickly. I'd like for it to have an easy invocation though; control+U would be the obvious keymap for it :-). Eventually it should just be something that comes with the tool and doesn't need special enablement before use.

    I wouldn't call it "mmj2" or use that term anywhere. The issue is unification, a well-known algorithm. I believe the unification algorithm goes back to 1965. The fact that mmj2 is one of the many many many programs that has a unification algorithm implementation is not really relevant to anything.

  30. expln commented on Jan 28, 2025

    @expln
    Owner

    Hi David,

    I'd like for it to have an easy invocation though; control+U would be the obvious keymap for it

    Yes, I agree, I plan to add key shortcuts for macros. I don’t want to hardcode them though. I need some time to think on how to make it flexible.

    I wouldn't call it "mmj2" or use that term anywhere. The issue is unification, a well-known algorithm. I believe the unification algorithm goes back to 1965. The fact that mmj2 is one of the many many many programs that has a unification algorithm implementation is not really relevant to anything.

    My intention is to simulate mmj2 behavior when one invokes the “Unify” macro (I am not sure if it is possible using existing mm-lamp functionality though :) ) The “Unify” macro is not the algorithm invented back in 1965. The “Unify” macro should do whatever mmj2 does when a user presses control+U. And this is unique to mmj2. Also, as I know, the MMP format is highly coupled with mmj2 (Yamma also uses it, but if I am not mistaken it was introduced by mmj2). In the future, also an “Export to MMP” macro may be added. Then it will be possible to develop a proof in mmj2 (or Yamma, or whatever other mmj2-like assistants will appear by that time :) ), then temporarily move it to mm-lamp to do some actions which are not supported in mmj2, and after that move the proof back to mmj2 to continue working there. So, I guess it should be fine to use the “mmj2” term in that place.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Algrelated to algorithms

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions