是否有一个算法,如果语句比较? [英] Is there an algorithm for comparing if statements?

查看:163
本文介绍了是否有一个算法,如果语句比较?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否有检测,如果两套如果语句具有相同条件的算法和/或工具的相同呢?当我说等价物 - 我的意思是,他们执行相同的code对所有给定的输入。例如:

Is there an algorithm and/or tool for detecting if two sets of if statements with the same conditions are equivalent? When I say "equivalent" - I mean that they execute the same code for all given inputs. For example:

# set 1
if a
  if b
    someMethod()
  end
end

# set 2
if a && b
  someMethod()
end

# set 3
if a || b
  someMethod()
end

由于这3套如果语句,你可以考虑设置1和设置2为相当于在的someMethod 只被执行时,a和b都为真。同样设置1和设置3不是因为的someMethod 相当于将不会获得由1集时执行一个是真,b为假,但会在3组根据这些执行相同的条件。

Given these 3 sets of if statements, you could consider set 1 and set 2 to be "equivalent" in that someMethod only gets executed when a and b are true. Likewise set 1 and set 3 are not equivalent since someMethod won't get executed by set 1 when a is true and b is false, but will be executed in set 3 under those same conditions.

推荐答案

我会用的卡诺图

  • 这是标准的非时序逻辑综合和分析。

1,创建卡诺图每个组IF

1.create Karnaugh Map for each set of ifs

2,如果地图不一样,那么的if语句是等价的

2.if the map is the same then the if statements are equivalent

  • 如果没有的话,他们是不同的

...很抱歉很短的答案,但我没有什么线索其他补充,因为这是基本常识。

... Sorry for a short answer but I do not have a clue what else to add because this is basic knowledge.

刚才你的情况......

  • 设置1 ==设置2
  • SET3不同的是

这篇关于是否有一个算法,如果语句比较?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆