Note: Isabelle/ML is the primary environment for logical operations.
*/
package isabelle
object Term { /* types and terms */
sealedcaseclass Indexname(name: String, index: Int = 0) { privatelazyval hash: Int = (name, index).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = if (index == -1) name else { val dot =
Symbol.explode(name).reverse match { case _ :: s :: _ if s == Symbol.sub_decoded || s == Symbol.sub => false case c :: _ => Symbol.is_digit(c) case _ => true
} if (dot) "?" + name + "." + index elseif (index != 0) "?" + name + index else"?" + name
}
}
typeClass = String type Sort = List[Class]
sealedabstractclass Typ caseclassType(name: String, args: List[Typ] = Nil) extends Typ { privatelazyval hash: Int = ("Type", name, args).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = if (this == dummyT) "_" else"Type(" + name + if_proper(args, "," + args) + ")"
} caseclass TFree(name: String, sort: Sort = Nil) extends Typ { privatelazyval hash: Int = ("TFree", name, sort).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = "TFree(" + name + if_proper(sort, "," + sort) + ")"
} caseclass TVar(name: Indexname, sort: Sort = Nil) extends Typ { privatelazyval hash: Int = ("TVar", name, sort).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = "TVar(" + name + if_proper(sort, "," + sort) + ")"
} val dummyT: Type = Type("dummy")
sealedabstractclass Term { def head: Term = thismatch { case App(fun, _) => fun.head case _ => this
}
} caseclass Const(name: String, typargs: List[Typ] = Nil) extends Term { privatelazyval hash: Int = ("Const", name, typargs).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = if (this == dummy) "_" else"Const(" + name + if_proper(typargs, "," + typargs) + ")"
} caseclass Free(name: String, typ: Typ = dummyT) extends Term { privatelazyval hash: Int = ("Free", name, typ).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = "Free(" + name + (if (typ == dummyT) ""else"," + typ) + ")"
} caseclassVar(name: Indexname, typ: Typ = dummyT) extends Term { privatelazyval hash: Int = ("Var", name, typ).hashCode() overridedef hashCode(): Int = hash
overridedef toString: String = "Var(" + name + (if (typ == dummyT) ""else"," + typ) + ")"
} caseclass Bound(index: Int) extends Term caseclass Abs(name: String, typ: Typ, body: Term) extends Term { privatelazyval hash: Int = ("Abs", name, typ, body).hashCode() overridedef hashCode(): Int = hash
} caseclass App(fun: Term, arg: Term) extends Term { privatelazyval hash: Int = ("App", fun, arg).hashCode() overridedef hashCode(): Int = hash
} caseclass OFCLASS(typ: Typ, name: String) extends Term { privatelazyval hash: Int = ("OFCLASS", typ, name).hashCode() overridedef hashCode(): Int = hash
}
def dummy_pattern(ty: Typ): Term = Const("Pure.dummy_pattern", List(ty)) val dummy: Term = dummy_pattern(dummyT)
protecteddef cache_typ(x: Typ): Typ = { if (x == dummyT) dummyT else
lookup(x) match { case Some(y) => y case None =>
x match { caseType(name, args) => store(Type(cache_string(name), cache_typs(args))) case TFree(name, sort) => store(TFree(cache_string(name), cache_sort(sort))) case TVar(name, sort) => store(TVar(cache_indexname(name), cache_sort(sort)))
}
}
}
protecteddef cache_typs(x: List[Typ]): List[Typ] = { if (x.isEmpty) Nil else {
lookup(x) match { case Some(y) => y case None => store(x.map(cache_typ))
}
}
}
protecteddef cache_term(x: Term): Term = {
lookup(x) match { case Some(y) => y case None =>
x match { case Const(name, typargs) => store(Const(cache_string(name), cache_typs(typargs))) case Free(name, typ) => store(Free(cache_string(name), cache_typ(typ))) caseVar(name, typ) => store(Var(cache_indexname(name), cache_typ(typ))) case Bound(_) => store(x) case Abs(name, typ, body) =>
store(Abs(cache_string(name), cache_typ(typ), cache_term(body))) case App(fun, arg) => store(App(cache_term(fun), cache_term(arg))) case OFCLASS(typ, name) => store(OFCLASS(cache_typ(typ), cache_string(name)))
}
}
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung ist noch experimentell.