From a58e4093ddd109a25c709517d7703d53b6502806 Mon Sep 17 00:00:00 2001 From: Philipp Emanuel Weidmann Date: Sat, 21 Feb 2015 20:19:47 +0100 Subject: [PATCH] Improve LaTeX output --- build.sbt | 2 +- .../scala/com/worldwidemann/sequencer/Sequencer.scala | 5 +++-- .../com/worldwidemann/sequencer/SequencerRunner.scala | 10 +++++----- .../scala/com/worldwidemann/sequencer/Utilities.scala | 7 +++++++ 4 files changed, 16 insertions(+), 8 deletions(-) diff --git a/build.sbt b/build.sbt index fffd03d..38e1897 100644 --- a/build.sbt +++ b/build.sbt @@ -1,6 +1,6 @@ name := "Sequencer" -version := "1.2.0" +version := "1.2.1" organization := "com.worldwidemann" diff --git a/src/main/scala/com/worldwidemann/sequencer/Sequencer.scala b/src/main/scala/com/worldwidemann/sequencer/Sequencer.scala index 8c29024..ddf1e7e 100644 --- a/src/main/scala/com/worldwidemann/sequencer/Sequencer.scala +++ b/src/main/scala/com/worldwidemann/sequencer/Sequencer.scala @@ -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 { diff --git a/src/main/scala/com/worldwidemann/sequencer/SequencerRunner.scala b/src/main/scala/com/worldwidemann/sequencer/SequencerRunner.scala index 8ebd5fa..7d65b82 100644 --- a/src/main/scala/com/worldwidemann/sequencer/SequencerRunner.scala +++ b/src/main/scala/com/worldwidemann/sequencer/SequencerRunner.scala @@ -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 @@ -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 @@ -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) diff --git a/src/main/scala/com/worldwidemann/sequencer/Utilities.scala b/src/main/scala/com/worldwidemann/sequencer/Utilities.scala index 79a5094..cecaca3 100644 --- a/src/main/scala/com/worldwidemann/sequencer/Utilities.scala +++ b/src/main/scala/com/worldwidemann/sequencer/Utilities.scala @@ -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) = {