building-envelope-data / api

API specification to exchange data about building envelopes
MIT License
3 stars 1 forks source link

DataPropositionInput - why is an empty "and" true and an empty "or" false? #240

Closed StephenCzarnecki closed 3 years ago

StephenCzarnecki commented 3 years ago

In the database.graphql file in the DataPropositionInput section there are the following comments:

  """
  True for data for which each proposition in `and` is true, otherwise false.
  In particular, it is true if there is no proposition in `and`.
  """
  and: [DataPropositionInput!]

#...

  """
  True for data for which at least one proposition in `or` is true, otherwise
  false. In particular, it is false if there is no proposition in `or`.
  """
  or: [DataPropositionInput!]

It seems to me that means that and:[] evaluates to true and or:[] evaluates to false.

For example:

If a query to the IGSDB has this where section

where: {
  nearnormalHemisphericalVisibleTransmittance: {greaterThanOrEqualTo: 0.0, lessThanOrEqualTo: 1.0 }}
  and: []
}

then it would return almost all of the records in the IGSDB (there are some records that do not have visible transmittance)

However if the query instead had this where section:

where: {
  nearnormalHemisphericalVisibleTransmittance: {greaterThanOrEqualTo: 0.0, lessThanOrEqualTo: 1.0 }}
  or: []
}

Then it would return no results.

If this is true can you clarify why this is? And if this is not correct can you correct where I have gone wrong?

christoph-maurer commented 3 years ago

Can you please explain it, @simon-wacker ?

simon-wacker commented 3 years ago

That an empty conjuncation (and) is true and an empty disjunction (or) is false is the standard in propositional logic. The reason is simply that for an empty list of propositions ps the statement

for each proposition p in ps it holds that p is true

is true (just because there is no proposition in ps). And analogously the statement

there is a proposition p in ps such that p is true

is false (again because there is no proposition in ps).

Another reason is that true is the neutral element of conjunction and false is the neutral element for disjunction (that is the proposition "p and true" is equivalent to the proposition p, and analogously "p or false" is equivalent to the proposition p. This is a sensible definition because it makes the following correct

formula

and analogously for conjunction. To clafiry: The funny v is the logical or operator in logics, and ps and ts are both sets of propositions (so p in ps is just some proposition of ps, and t in ts is some proposition of ts). In the formula above you could also replace the funny v by the mathematical sum symbol (in some sense logical or (disjunction) and mathematical sums behave similarly; and analogously logical and (conjunction) and mathematical products behave similarly). The sum over an empty set of numbers is also usually defined as 0 (the neutral element with respect to addition) and the product over an empty set of numbers as 1 (the neutral element with respect to multiplication).

In your examples

where: {
  nearnormalHemisphericalVisibleTransmittance: {greaterThanOrEqualTo: 0.0, lessThanOrEqualTo: 1.0 }}
  and: []
}

is a shortcut for

where: {
  and: [
    { nearnormalHemisphericalVisibleTransmittance: {greaterThanOrEqualTo: 0.0, lessThanOrEqualTo: 1.0 }} }
    { and: [] }
  ]
}

and

where: {
  nearnormalHemisphericalVisibleTransmittance: {greaterThanOrEqualTo: 0.0, lessThanOrEqualTo: 1.0 }}
  or: []
}

is a shortcut for

where: {
  and: [
    { nearnormalHemisphericalVisibleTransmittance: {greaterThanOrEqualTo: 0.0, lessThanOrEqualTo: 1.0 }} }
    { or: [] }
  ]
}

Notice the asymmetry. In the first case the { and: [] } (which is true) is nested within and and in the second case the { or: [] } (which is false) is also nested within and.

christoph-maurer commented 3 years ago

Thank you, @simon-wacker !