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

Added property tests for Algebra.Graph.Label #232

Merged
merged 25 commits into from
Nov 18, 2019

Conversation

adithyaov
Copy link
Contributor

The initial draft for Algebra.Graph.Test.Label.

@adithyaov
Copy link
Contributor Author

adithyaov commented Aug 23, 2019

Minimum unfortunately fails the right distributive property. It cannot be a Semiring.
Consider String as the underlying monoid.
With,

<+> ~ min
<.> ~ mappend
0 ~ inf
1 ~ ""

Consider,

a = Minimum (Finite "a")
b = Minimum (Finite "") ~ 1
c = Minimum (Finite "c")

x = (a <+> b) <.> c = Minimum (Finite "c")
y = (a <.> c) <+> (b <.> c) = Minimum (Finite "ac")

Clearly x is not equal to y.
This property fails if the monoid is String.
Similarly, this property will fail if the monoid is Path a as well.

Minimum String and Minimum (Path a) can be described as a Left Near Ring but not a Semiring.
In general, I think Minimum a can be described as a left near ring (intuition). I'm still working out the formal proof though.

@snowleopard
Copy link
Owner

Many thanks @adithyaov! This looks very nice. I've left a couple of minor comments.

@snowleopard
Copy link
Owner

@adithyaov This doesn't currently pass CI. Could you push a fix please?

@snowleopard
Copy link
Owner

Just restarted CI, perhaps we need to increase/remove Travis time limit for long-running commands?

@snowleopard
Copy link
Owner

@adithyaov Very nice PR, many thanks!

Just managed to find time for review and left a few minor comments.

P.S.: CI has passed after restarting.

@adithyaov
Copy link
Contributor Author

@snowleopard Although semigroup and rightNearRing are unused I'm leaving them there, gives a sense of completion of properties.
Ideally, I'd want to replace liftA2 with coerce but using liftA2 seems cleaner. Since the correctness isn't violated, I don't think it's a problem.

@adithyaov
Copy link
Contributor Author

@snowleopard Could you please restart Travis CI. I don't understand why it fails. As you suggested, increasing the time limit might work.

@snowleopard
Copy link
Owner

@adithyaov I've restarted the CI.

If you can find a way to make CI more reliable, please let me know how.

@adithyaov
Copy link
Contributor Author

@snowleopard I think this PR is ready for merge. Profiling might take a little more time. Can we safely ignore timeouts for the time being?

@snowleopard
Copy link
Owner

snowleopard commented Nov 7, 2019

@adithyaov Having reliable CI is very important since it helps a lot with reviews.

This particular PR seems to push the testsuite too far, making CI unreliable, so I don't think we should merge it until we either get rid of slow tests in general, or slow tests in this particular PR that are responsible for slowing down the testsuite.

@adithyaov
Copy link
Contributor Author

@snowleopard Agreed. I'll try to complete profiling the tests as soon as possible.

test "StarSemiring" $ \(a :: Capacity Int) b c -> testStarSemiring a b c
test "Dioid" $ \(a :: Capacity Int) b c -> testDioid a b c

putStrLn "\n============ Minimum ============"
Copy link
Owner

Choose a reason for hiding this comment

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

You are actually testing Minimum (Path Int) below, not Minimum.

I think we should add tests for all types of labels we define in Algebra.Graph.Label, perhaps, also adding some combinations like Minimum (Path Int).

Copy link
Contributor Author

@adithyaov adithyaov Nov 13, 2019

Choose a reason for hiding this comment

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

perhaps, also adding some combinations like Minimum (Path Int).

Perhaps you meant something else? Minimum (Path Int) already exists.

Copy link
Owner

Choose a reason for hiding this comment

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

I meant similar to Minimum Path that you are already testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I will do it in another PR. Some types (Optimum) need not satisfy Semiring yet can be used. I need to come up with a proper/better reasoning.

@snowleopard
Copy link
Owner

@adithyaov Thanks a lot for fixing the testsuite! I've added some comments.

Label:
1. In label change (+) such that there is symmetry with (*)

Test.Label
1. Change the placement of (//) annotations
2. Change string headers accordingly
1. Change CountShortestPaths e a to CountShortestPaths e
2. Add arbitrary instance for Optimum
@snowleopard snowleopard merged commit e0aa4be into snowleopard:master Nov 18, 2019
@snowleopard
Copy link
Owner

@adithyaov Great work, thank you. Merged!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants