Skip to content

Commit

Permalink
Improve LaTeX output
Browse files Browse the repository at this point in the history
  • Loading branch information
p-e-w committed Feb 21, 2015
1 parent a4b170a commit a58e409
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 8 deletions.
2 changes: 1 addition & 1 deletion build.sbt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
name := "Sequencer"

version := "1.2.0"
version := "1.2.1"

organization := "com.worldwidemann"

Expand Down
5 changes: 3 additions & 2 deletions src/main/scala/com/worldwidemann/sequencer/Sequencer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,9 @@ class Sequencer(configuration: Configuration) {
// Sequence matched numerically (or test skipped) => verify symbolically
if (Verifier.verifyFormula(formula, sequenceSimplified)) {
try {
identifications += SequenceIdentification(getFullFormula(formula, sequenceSimplified),
Predictor.predict(formula, sequenceSimplified, configuration.predictionLength))
val continuation = Predictor.predict(formula, sequenceSimplified, configuration.predictionLength)
.map(element => if (configuration.outputLaTeX) Utilities.getLaTeX(element) else element)
identifications += SequenceIdentification(getFullFormula(formula, sequenceSimplified), continuation)
if (configuration.maximumIdentifications > 0 && identifications.distinct.size >= configuration.maximumIdentifications)
return identifications.distinct.sortBy(_.formula.length)
} catch {
Expand Down
10 changes: 5 additions & 5 deletions src/main/scala/com/worldwidemann/sequencer/SequencerRunner.scala
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ import scopt.OptionParser

object SequencerRunner {
def main(args: Array[String]): Unit = {
println("Sequencer 1.2.0 (https://github.com/p-e-w/sequencer)\n")
println("Sequencer 1.2.1 (https://github.com/p-e-w/sequencer)\n")

// Suppress annoying Symja console output (idea from http://stackoverflow.com/a/8363580).
// This is a very brittle solution. In particular, if we do not use the Console stream
Expand Down Expand Up @@ -67,9 +67,9 @@ object SequencerRunner {
case Some(configuration) => {
println("Searching for formulas for sequence " +
(if (configuration.outputLaTeX)
"$(a_n)_{n\\geq 1} = " + sequence.map(Utilities.getLaTeX).mkString(", ") + ", \\dots$"
"$(a_n)_{n\\geq 1} = " + Utilities.formatSequence(sequence.map(Utilities.getLaTeX), true) + "$"
else
"(a(n)) = " + sequence.mkString(", ") + ", ..."))
"(a(n)) = " + Utilities.formatSequence(sequence, false)))

val time = System.currentTimeMillis

Expand All @@ -78,8 +78,8 @@ object SequencerRunner {
println("\n" + (if (configuration.outputLaTeX) "$$" else "") + identification.formula +
(if (configuration.outputLaTeX) "$$" else ""))
println("Continuation: " + (if (configuration.outputLaTeX) "$" else "") +
identification.continuation.mkString(", ") +
(if (configuration.outputLaTeX) ", \\dots$" else ", ..."))
Utilities.formatSequence(identification.continuation, configuration.outputLaTeX) +
(if (configuration.outputLaTeX) "$" else ""))
})

if (identifications.isEmpty)
Expand Down
7 changes: 7 additions & 0 deletions src/main/scala/com/worldwidemann/sequencer/Utilities.scala
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,13 @@ object Utilities {
writer.toString
}

def formatSequence(sequence: Seq[String], latex: Boolean) = {
if (latex)
(sequence :+ "\\ldots").mkString(",\\; ")
else
(sequence :+ "...").mkString(", ")
}

// Retrieves the index from which on the general part of the formula applies
// (1 for non-recurrence formulas)
def getStartIndex(formula: Node) = {
Expand Down

0 comments on commit a58e409

Please sign in to comment.