我正在尝试在Idris中实现McCarthy91功能并证明它的一些属性(完整代码为here)。但我在这里遇到了一个问题。
该功能通过分为两种情况来定义:> 100和< = 100.为了达到这个目的,我定义了一个类型级函数isLte
(几乎和标准库中的函数一样):
data (<=): (x, y: Peano) -> Type where
OLte: (x: Peano) -> O <= x
SLte: x <= y -> ((++)x) <= ((++)y)
total
isLte: (x, y: Peano) -> Result (x <= y) ((++)y <= x)
isLte O x = Yes (OLte x)
isLte ((++)x) O = No (SLte (OLte x))
isLte ((++)x) ((++)y) = case isLte x y of
No revLteProof => No (SLte revLteProof)
Yes lteProof => Yes (SLte lteProof)
mcCarthy: Peano -> Peano
mcCarthy n = case n `isLte` Main.hundred of
No hundredOneLteN => totalMinus (trans tenLteHundredOne hundredOneLteN)
Yes lteProof => mcCarthy (mcCarthy (n + Main.eleven))
我想要证明的内容可以写成:
mcCarthyIdentity2: (hundredOneLteX: Main.hundredOne <= x) -> mcCarthy x = totalMinus (trans Main.tenLteHundredOne hundredOneLteX)
mcCarthyIdentity: n <= Main.hundred -> mcCarthy x = Main.ninetyOne
问题是,我如何告诉Idris n <= Main.hundred
,例如,mcCarthy n
会让rewrite
落入案件的第二个分支?简单地Refl
或total
f: Nat -> Nat
f x = if x > 10 then 1 else 2
total
proofOfF: x < 4 -> f x = 2
-- What to write?
似乎无效。
一个更简单的问题(可能或可能不直接相关)可以证明:
class MenuViewController1: UIViewController,UITableViewDataSource, UITableViewDelegate{
/**
* Array to display menu options
*/
@IBOutlet var tblMenuOptions : UITableView!
/**
* Transparent button to hide menu
*/
@IBOutlet var btnCloseMenuOverlay : UIButton!
/**
* Array containing menu options
*/
var arrayMenuOptions = [Dictionary<String,String>]()
/**
* Menu button which was tapped to display the menu
*/
var btnMenu : UIButton!
/**
* Delegate of the MenuVC
*/
var delegate : SlideMenuDelegate?
// var delegateP: Profile?
@IBOutlet weak var userProfilePhoto: UIImageView!
@IBOutlet weak var userName: UILabel!
override func viewDidLoad() {
super.viewDidLoad()
tblMenuOptions.tableFooterView = UIView()
// Do any additional setup after loading the view.
//let name = userName.text
self.delegateP?.name_changed(name: userName.text!)
}
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
// Dispose of any resources that can be recreated.
}
override func viewWillAppear(_ animated: Bool) {
super.viewWillAppear(animated)
updateArrayMenuOptions()
}
func updateArrayMenuOptions(){
arrayMenuOptions.append(["title":"Home", "icon":"HomeIcon"])
arrayMenuOptions.append(["title":"LogIn", "icon":"LogIn"])
arrayMenuOptions.append(["title":"House Owner","icon":"House Owner"])
arrayMenuOptions.append(["title":"ShortTerm", "icon":"ShortTerm"])
arrayMenuOptions.append(["title":"LongTerm","icon":"LongTerm"])
tblMenuOptions.reloadData()
}
@IBAction func onCloseMenuClick(_ button:UIButton!){
btnMenu.tag = 0
if (self.delegate != nil) {
var index = Int32(button.tag)
if(button == self.btnCloseMenuOverlay){
index = -1
}
delegate?.slideMenuItemSelectedAtIndex(index)
}
UIView.animate(withDuration: 0.3, animations: { () -> Void in
self.view.frame = CGRect(x: -UIScreen.main.bounds.size.width, y: 0, width: UIScreen.main.bounds.size.width,height: UIScreen.main.bounds.size.height)
self.view.layoutIfNeeded()
self.view.backgroundColor = UIColor.clear
}, completion: { (finished) -> Void in
self.view.removeFromSuperview()
self.removeFromParentViewController()
})
}
func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
let cell : UITableViewCell = tableView.dequeueReusableCell(withIdentifier: "cellMenu")!
cell.selectionStyle = UITableViewCellSelectionStyle.none
cell.layoutMargins = UIEdgeInsets.zero
cell.preservesSuperviewLayoutMargins = false
cell.backgroundColor = UIColor.clear
let lblTitle : UILabel = cell.contentView.viewWithTag(101) as! UILabel
let imgIcon : UIImageView = cell.contentView.viewWithTag(100) as! UIImageView
imgIcon.image = UIImage(named: arrayMenuOptions[indexPath.row]["icon"]!)
lblTitle.text = arrayMenuOptions[indexPath.row]["title"]!
return cell
}
func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {
let btn = UIButton(type: UIButtonType.custom)
btn.tag = indexPath.row
self.onCloseMenuClick(btn)
}
func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
return arrayMenuOptions.count
}
func numberOfSections(in tableView: UITableView) -> Int {
return 1;
}
}
我怎样才能真正告诉Idris条件与分支有关?