Replies: 1 comment
-
It seems I can turn leftPath and rightPath into ghost variables. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
Hi,
I am trying to verify the following solution to this problem. https://leetcode.com/problems/diameter-of-binary-tree/description/
I have verified the following.
The full code is here because it is actually far too long to fit in this post. Anyway, I have shown that a valid path exists and is returned, but the problem suggests that it is the largest such path.
I attempted to tack on
&& largestPath(path, root)
to the final ensure of the method.So I'm running into the problem that if I make largestPath not ghost Dafny asserts that paths many not be finite, which is false. It is happy if I leave the predicate as ghost but when I create variables based on the recursive calls of method (leftPath, rightPath) then there is a conflict that a concrete variable exists and therefore can't be ghost for largestPath.
Do I need to assert that there exists an iset of all possible paths inside a tree given a root and that the size of the iset is finite? Is that even possible?
Alternatively, is this situation where I need to use a greatest/least lemma? How would I do/use that?
Beta Was this translation helpful? Give feedback.
All reactions