[thebeast] r729 committed - undid some changes to TheBeastEnv

1 view
Skip to first unread message

codesite...@google.com

unread,
Mar 21, 2010, 5:08:49 PM3/21/10
to thebeas...@googlegroups.com
Revision: 729
Author: sebastian.riedel
Date: Sun Mar 21 14:06:34 2010
Log: undid some changes to TheBeastEnv
http://code.google.com/p/thebeast/source/detail?r=729

Modified:

/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/alchemy/AlchemyParser.scala

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

/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/booleans/BooleanTerm.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/doubles/Factorizer.scala

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

=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/alchemy/AlchemyParser.scala
Mon Sep 28 01:01:08 2009
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/alchemy/AlchemyParser.scala
Sun Mar 21 14:06:34 2010
@@ -1,15 +1,9 @@
package org.riedelcastro.thebeast.alchemy


-import _root_.scala.util.parsing.combinator.{RegexParsers,
JavaTokenParsers}
-import collection.mutable.{HashSet, ArrayBuffer, HashMap}
-import env._
-import booleans.{BooleanFunApp, BooleanTerm}
-import doubles.{AlchemyIndicator, DoubleConstant, DoubleTerm}
-import java.io.{Reader}
-import tuples.{TupleValues, TupleTerm, TupleValues3, TupleValues2}
-import vectors._
-
+import scala.util.parsing.combinator.{RegexParsers, JavaTokenParsers}
+import collection.mutable.{HashSet, HashMap}
+import org.riedelcastro.thebeast.env.tuples.{TupleTerm}
/**
* @author Sebastian Riedel
*/
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/Term.scala
Sun Mar 14 17:41:16 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/Term.scala
Sun Mar 21 14:06:34 2010
@@ -65,6 +65,33 @@
//def cloneWithNewSubterms(subterms:Seq[Term[Any]]): Term[T]

}
+
+/**
+ * A Composite term consists of one more other terms. It knows how to
+ * take a sequence of members and create a new composite term, and
+ * how to return the composite members.
+ */
+trait Composite[V,T<:Term[V], M<:Term[_]] extends Term[V] {
+
+ def members:Seq[M]
+ def build(members:Seq[M]):T
+
+ override def ground(env: Env): T =
build(members.map(_.ground(env).asInstanceOf[M]))
+
+ override def isGround: Boolean = members.forall(_.isGround)
+}
+
+trait Composite1[V,T<:Term[V],M<:Term[_]] extends Composite[V,T,M] {
+
+ def build(member:M):T
+
+ def build(members: Seq[M]): T = build(members(0))
+
+ def member: M
+
+ def members: Seq[M] = Seq(member)
+}
+

/**
* Grounded is a pattern matcher that matches terms which are ground (no
variables), and extracts
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/TheBeastEnv.scala
Sun Mar 21 13:01:44 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/TheBeastEnv.scala
Sun Mar 21 14:06:34 2010
@@ -144,7 +144,7 @@
def apply(t: Term[Any]) = BooleanFunApp(fun, t)
}

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

=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/booleans/BooleanTerm.scala
Sun Mar 21 13:01:44 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/booleans/BooleanTerm.scala
Sun Mar 21 14:06:34 2010
@@ -53,12 +53,18 @@
def elements = seq.elements
}

-case class Conjunction[+T <: BooleanTerm](override val args: Seq[T])
extends Fold[Boolean](Constant(And), args, Constant(true))
- with BooleanTerm {
- override def ground(env: Env) = Conjunction(args.map(_.ground(env)))
+case class Conjunction[T <: BooleanTerm](override val args: Seq[T])
extends Fold[Boolean](Constant(And), args, Constant(true))
+ with BooleanTerm with Composite[Boolean,Conjunction[T],T] {
+ //override def ground(env: Env) = Conjunction(args.map(_.ground(env)))
+
+

//def this(args:T*) = this((args:*).toSeq)

+ def build(members: Seq[T]) = Conjunction(members)
+
+ def members: Seq[T] = args
+
def upperBound = !args.exists(!_.upperBound)

def negate = Disjunction(args.map(_.negate))
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/combinatorics/SpanningTreeConstraint.scala
Sun Mar 21 13:01:44 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/combinatorics/SpanningTreeConstraint.scala
Sun Mar 21 14:06:34 2010
@@ -28,20 +28,21 @@
def asLogic: DoubleTerm = {
import TheBeastImplicits._
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",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}
+ this
}


=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/Factorizer.scala
Sun Mar 21 11:26:30 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/doubles/Factorizer.scala
Sun Mar 21 14:06:34 2010
@@ -1,6 +1,7 @@
package org.riedelcastro.thebeast.env.doubles

import org.riedelcastro.thebeast.env.vectors.{VectorDotApp, VectorTerm,
VectorSum, QuantifiedVectorSum}
+import org.riedelcastro.thebeast.env.booleans.{BooleanTerm, Disjunction,
Conjunction}

/**
* @author sriedel
@@ -12,19 +13,28 @@
case Multiplication(args) =>
Multiplication(args.flatMap(toMultiplication(_).args))
case Exp(Sum(args)) => Multiplication(args.map(Exp(_)))
case Exp(v: VectorDotApp) =>
Multiplication(v.distribute.asInstanceOf[Sum[DoubleTerm]].args.map(Exp(_)))
+ case Indicator(Conjunction(args)) =>
Multiplication(args.map(Indicator(_)))
case x => Multiplication(Seq(x))
}
}

+ //todo: this should all be done by a generic unroll method and the
generic builder framework
private def unroll(term: DoubleTerm): DoubleTerm = term match {
case Multiplication(args) => Multiplication(args.map(unroll(_)))
case Sum(args) => Sum(args.map(unroll(_)))
case x: QuantifiedSum[_] => x.unroll
case Normalize(x) => Normalize(unroll(x))
case Exp(x) => Exp(unroll(x))
+ case Indicator(arg) => Indicator(unrollBoolean(arg))
case VectorDotApp(lhs, rhs) => VectorDotApp(unrollVectorTerm(lhs),
unrollVectorTerm(rhs))
case x => x
}
+
+ private def unrollBoolean(term:BooleanTerm):BooleanTerm = term match {
+ case Conjunction(args) => Conjunction(args.map(unrollBoolean(_)))
+ case Disjunction(args) => Disjunction(args.map(unrollBoolean(_)))
+ case x => x
+ }

private def unrollVectorTerm(term: VectorTerm): VectorTerm = term match {
case VectorSum(args) => VectorSum(args.map(unrollVectorTerm(_)))
=======================================
---
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/vectors/Vector.scala
Sun Mar 14 23:39:26 2010
+++
/branches/thefuture-modules/thebeast-core/src/main/scala/org/riedelcastro/thebeast/env/vectors/Vector.scala
Sun Mar 21 14:06:34 2010
@@ -3,7 +3,8 @@

import collection.mutable.{HashMap}
import util.SimpleNamed
-import org.riedelcastro.thebeast.env.Values
+import org.riedelcastro.thebeast.util.SimpleNamed
+import org.riedelcastro.thebeast.env.{TheBeastEnv, Values}

/**
* @author Sebastian Riedel

Reply all
Reply to author
Forward
0 new messages