如果语句使用逻辑推论来缩短层次结构

时间:2018-10-09 17:16:31

标签: windows-installer installshield logical-operators propositional-calculus

背景:在构建逻辑树时,Installshield仅允许AND/OR/NOT操作员+比较各个条件。尝试建立版本检测条件时,我对此感到困惑。

基本上我正在尝试这样做

bool IsUpToDatePackageInstalled(major, minor, build, rev)
{
  if (installedMajor > major)
      return true

  if (installedMajor < major)
      return false

  if (installedMinor > minor)
      return true

  if (installedMinor < minor)
      return false

  if (installedBuild > build)
      return true

  if (installedBuild < build)
      return false

  if (installedRev >= rev)
      return true

  return false
}

基本上只使用AND/OR/NOT来构建它

Any
    InstalledMajor > major
    All
        InstalledMajor == major
        InstalledMinor > minor
    All
        InstalledMajor == major
        InstalledMinor == minor
        InstalledBld > bld
    All
        InstalledMajor == major
        InstalledMinor == minor
        InstalledBld == bld
        InstalledRev >= rev

或将其翻译为And / or

(InstalledMajor > major) 
OR (InstalledMajor == major AND InstalledMinor > minor) 
OR (InstalledMajor == major AND InstalledMinor == minor AND InstalledBld > bld) 
OR (InstalledMajor == major AND InstalledMinor == minor AND InstalledBld == bld AND InstalledRev >= rev)

是否可以对此语句应用逻辑推论,以便每个变量仅使用一次,而不是复制所有先前的变量?

0 个答案:

没有答案