[thebeast] r730 committed - separated implicit conversions that convert generic function Terms T=>...

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 21, 2010, 5:24:24 PM3/21/10
to thebeas...@googlegroups.com
Revision: 730
Author: sebastian.riedel
Date: Sun Mar 21 14:23:37 2010
Log: separated implicit conversions that convert generic function Terms
T=>Boolean from the specific ones.
http://code.google.com/p/thebeast/source/detail?r=730

Modified:

/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/TheBeastEnv.scala

/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/combinatorics/SpanningTreeConstraint.scala

=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/TheBeastEnv.scala
Sun Mar 21 14:06:34 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/TheBeastEnv.scala
Sun Mar 21 14:23:37 2010
@@ -15,10 +15,10 @@
object TheBeastImplicits extends TheBeastEnv {
}

-trait TheBeastEnv extends QuantificationShortCuts {
- val Bools = booleans.Bools
- //val Bools = Values(false,true)
-
+trait TermShortCuts {
+ def $(term: BooleanTerm) = Indicator(term)
+
+ def $$(term: BooleanTerm) = AlchemyIndicator(term)

def unit(key: Term[Any]*) = UnitVector(key: _*)

@@ -26,10 +26,41 @@

def normalize(arg: DoubleTerm) = Normalize(arg)

+ def ^[T](t: T) = Constant(t)
+
def ptree[V](edges: Term[FunctionValue[(V, V), Boolean]],
vertices: Term[FunctionValue[V, Boolean]],
root: Term[V],
order: Term[FunctionValue[(V, V), Boolean]]) =
SpanningTreeConstraint(edges, vertices, root, order)
+}
+
+trait GenericTermConversion {
+
+ implicit def genericTerm2booleanFunAppBuilder[T](fun:
Term[FunctionValue[T, Boolean]]) = new (Term[T] => BooleanFunApp[T]) {
+ def apply(t: Term[T]) = BooleanFunApp(fun, t)
+ }
+
+ implicit def tuple2term2booleanFunAppBuilder[T1, T2](fun:
Term[FunctionValue[(T1, T2), Boolean]]) = new (TupleTerm2[T1, T2] =>
BooleanFunApp[(T1, T2)]) {
+ def apply(t: TupleTerm2[T1, T2]) = BooleanFunApp(fun, t)
+
+ def apply(t1: Term[T1], t2: Term[T2]) = BooleanFunApp(fun,
TupleTerm2(t1, t2))
+ }
+
+ implicit def tuple3term2booleanFunAppBuilder[T1, T2, T3](fun:
Term[FunctionValue[(T1, T2, T3), Boolean]]) = new (TupleTerm3[T1, T2, T3]
=> BooleanFunApp[(T1, T2, T3)]) {
+ def apply(t: TupleTerm3[T1, T2, T3]) = BooleanFunApp(fun, t)
+
+ def apply(t1: Term[T1], t2: Term[T2], t3: Term[T3]) =
BooleanFunApp(fun, TupleTerm3(t1, t2, t3))
+ }
+
+
+}
+
+object GenericImplicits extends QuantificationShortCuts with TermShortCuts
with GenericTermConversion
+
+trait TheBeastEnv extends QuantificationShortCuts with TermShortCuts {
+ val Bools = booleans.Bools
+ //val Bools = Values(false,true)
+

implicit def string2varbuilder(name: String) = new {
def <~[T](values: Values[T]) = Var(name, values)
@@ -43,6 +74,10 @@

implicit def termToTermBuilder[T](term: Term[T]) = TermBuilder(term)

+ def genericTerm2booleanFunAppBuilder[T](fun: Term[FunctionValue[T,
Boolean]]) = new (Term[T] => BooleanFunApp[T]) {
+ def apply(t: Term[T]) = BooleanFunApp(fun, t)
+ }
+

@@ -144,11 +179,8 @@
def apply(t: Term[Any]) = BooleanFunApp(fun, t)
}

- def genericTerm2booleanFunAppBuilder[T](fun: Term[FunctionValue[T,
Boolean]]) = new (Term[T] => BooleanFunApp[T]) {
- def apply(t: Term[T]) = BooleanFunApp(fun, t)
- }
-
- implicit def intTerm2booleanFunAppBuilder[T](fun:
Term[FunctionValue[Int, Boolean]]) =
+
+ implicit def intTerm2booleanFunAppBuilder(fun: Term[FunctionValue[Int,
Boolean]]) =
genericTerm2booleanFunAppBuilder(fun)

// implicit def anyterm2booleanFunAppBuilder[T1, T2](fun:
Term[FunctionValue[Any, Boolean]]) = new {
@@ -190,7 +222,6 @@
FunctionValuesBuilder[T, R](domain)


- def ^[T](t: T) = Constant(t)

// implicit def term2envVar[T](env:Term[T]): EnvVar[T] = {
// env match {
@@ -222,10 +253,6 @@
def -->(rhs: BooleanTerm) = ImpliesApp(lhs, rhs)

}
-
- def $(term: BooleanTerm) = Indicator(term)
-
- def $$(term: BooleanTerm) = AlchemyIndicator(term)


}
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/combinatorics/SpanningTreeConstraint.scala
Sun Mar 21 14:06:34 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/combinatorics/SpanningTreeConstraint.scala
Sun Mar 21 14:23:37 2010
@@ -4,6 +4,7 @@
import doubles.{DoubleConstant, DoubleTerm}
import collection.mutable.{HashSet, Stack, HashMap, MultiMap}
import java.lang.String
+import tuples.TupleValues2

/**
* A SpanningTreeConstraint is a term that maps graphs to 1 if they are
@@ -26,22 +27,22 @@
}

def asLogic: DoubleTerm = {
- import TheBeastImplicits._
+ import GenericImplicits._
val domain =
vertices.values.asInstanceOf[FunctionValues[V,Boolean]].domain
-// val uniqueHead = forall(domain,domain,domain) {
-// (h,i,o)=> vertices(i) && vertices(h) && vertices(o) && edges(h,i)
~> !edges(o,i)}
-// val dominates = Predicate("dominates",domain x domain)
-// val linkAndDominates = forall(domain,domain) {
-// (h,i) => vertices(i) && vertices(h) && edges(h,i) ~>
dominates(h,i)}
-// val transitive = forall(domain,domain,domain){
-// (h,m,g)=> vertices(h) && vertices(m) && vertices(g) &&
dominates(h,m) && edges(m,g) ~> dominates(h,g)}
-// val acyclic = forall(domain) {
-// i => vertices(i) ~> !dominates(i,i)}
-// val projective1 = forall(domain,domain,domain) {
-// (h,m,i)=> vertices(h) && vertices(m) && vertices(i) && edges(h,m)
&& order(h,i) && order(i,m) ~> dominates(h,i)}
-// val projective2 = forall(domain,domain,domain) {
-// (h,m,i)=> vertices(h) && vertices(m) && vertices(i) && edges(h,m)
&& order(m,i) && order(i,h) ~> dominates(h,i)}
-// ${uniqueHead && linkAndDominates && transitive && acyclic &&
projective1 && projective2}
+ val uniqueHead = forall(domain,domain,domain) {
+ (h,i,o)=> vertices(i) && vertices(h) && vertices(o) && edges(h,i)
~> !edges(o,i)}
+ val dominates = Predicate("dominates", TupleValues2(domain, domain))
+ val linkAndDominates = forall(domain,domain) {
+ (h,i) => vertices(i) && vertices(h) && edges(h,i) ~> dominates(h,i)}
+ val transitive = forall(domain,domain,domain){
+ (h,m,g)=> vertices(h) && vertices(m) && vertices(g) &&
dominates(h,m) && edges(m,g) ~> dominates(h,g)}
+ val acyclic = forall(domain) {
+ i => vertices(i) ~> !dominates(i,i)}
+ val projective1 = forall(domain,domain,domain) {
+ (h,m,i)=> vertices(h) && vertices(m) && vertices(i) && edges(h,m) &&
order(h,i) && order(i,m) ~> dominates(h,i)}
+ val projective2 = forall(domain,domain,domain) {
+ (h,m,i)=> vertices(h) && vertices(m) && vertices(i) && edges(h,m) &&
order(m,i) && order(i,h) ~> dominates(h,i)}
+ ${uniqueHead && linkAndDominates && transitive && acyclic &&
projective1 && projective2}
this
}

Reply all
Reply to author
Forward
0 new messages