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

Add inference for #917 #927

Merged
merged 4 commits into from
May 19, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -245,6 +245,15 @@ private[refined] trait BooleanInference0 extends BooleanInference1 {
implicit def conjunctionCommutativity[A, B]: (A And B) ==> (B And A) =
Inference.alwaysValid("conjunctionCommutativity")

implicit def substitutionInConjunction[A, B, C](implicit p1: B ==> C): (A And B) ==> (A And C) =
p1.adapt("substitutionInConjunction(%s)")

implicit def disjunctionTautologyElimination[A, B, C](implicit
p1: B ==> C,
p2: A ==> C
): (A Or B) ==> C =
Inference.combine(p1, p2, "disjunctionElimination")

implicit def conjunctionEliminationR[A, B, C](implicit p1: B ==> C): (A And B) ==> C =
p1.adapt("conjunctionEliminationR(%s)")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -273,6 +273,15 @@ private[refined] trait BooleanInference0 extends BooleanInference1 {
implicit def conjunctionCommutativity[A, B]: (A And B) ==> (B And A) =
Inference.alwaysValid("conjunctionCommutativity")

implicit def substitutionInConjunction[A, B, C](implicit p1: B ==> C): (A And B) ==> (A And C) =
p1.adapt("substitutionInConjunction(%s)")

implicit def disjunctionTautologyElimination[A, B, C](implicit
p1: B ==> C,
matwojcik marked this conversation as resolved.
Show resolved Hide resolved
p2: A ==> C
): (A Or B) ==> C =
Inference.combine(p1, p2, "disjunctionElimination")
Copy link
Contributor

Choose a reason for hiding this comment

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

Combine is "and", did you mean to make this use "or"? (as we discussed, probably rqeuires a new method)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yep, but we were wrong :) In order to imply that A Or B can be replaced by C, both A and C needs to be equivalents of C.

Here is the truth table for OR option:

  A B C  │  ((B ↔ C) ∨ (A ↔ C)) → ((A ∨ B) ↔ C)
  ───────┼─────────────────────────────────────
  1 1 1  │      1    1    1    *1     1    1   
  1 1 0  │      0    0    0    *1     1    0   
  1 0 1  │      0    1    1    *1     1    1   
  1 0 0  │      1    1    0    *0     1    0   
  0 1 1  │      1    1    0    *1     1    1   
  0 1 0  │      0    1    1    *0     1    0   
  0 0 1  │      0    0    0    *1     0    0   
  0 0 0  │      1    1    1    *1     0    1  


implicit def conjunctionEliminationR[A, B, C](implicit p1: B ==> C): (A And B) ==> C =
p1.adapt("conjunctionEliminationR(%s)")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import eu.timepit.refined.api.Inference
import eu.timepit.refined.boolean._
Copy link
Contributor

Choose a reason for hiding this comment

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

I'm kinda worried that this file is only in scala-3.0- 🤔

Copy link
Contributor Author

Choose a reason for hiding this comment

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

import eu.timepit.refined.char.{Digit, Letter, UpperCase, Whitespace}
import eu.timepit.refined.numeric._
import eu.timepit.refined.string._
import eu.timepit.refined.collection._
import org.scalacheck.Prop._
import org.scalacheck.Properties
import shapeless.test.illTyped
Expand All @@ -20,6 +22,14 @@ class BooleanInferenceSpec extends Properties("BooleanInference") {
Inference[Not[Not[UpperCase]], UpperCase].isValid
}

property("substitution in conjunction") = secure {
Inference[NonEmpty And ValidLong, NonEmpty And (ValidLong Or ValidDouble)].isValid
}

property("elimination of tautology in disjunction") = secure {
Inference[(NonEmpty And ValidLong) Or (NonEmpty And ValidDouble), NonEmpty].isValid
}

property("double negation elimination 2x") = secure {
Inference[Not[Not[Not[Not[UpperCase]]]], UpperCase].isValid
}
Expand Down