Skip to content

Commit

Permalink
Heuristic to filter out recurrence relations that do not make sense
Browse files Browse the repository at this point in the history
  • Loading branch information
p-e-w committed Feb 20, 2015
1 parent a35bb71 commit 90b8762
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions src/main/scala/com/worldwidemann/sequencer/Sequencer.scala
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,23 @@ class Sequencer(configuration: Configuration) {

for (nodes <- 1 to configuration.maximumComplexity) {
new FormulaGenerator(configuration).getFormulas(nodes, formula => {
if (!configuration.numericalTest || Verifier.testFormula(formula, sequenceNumerical)) {
// 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))
if (configuration.maximumIdentifications > 0 && identifications.distinct.size >= configuration.maximumIdentifications)
return identifications.distinct.sortBy(_.formula.length)
} catch {
// Occasionally, simplification or prediction throw an exception although
// symbolic verification did not. This indicates a bug in Symja
// and is simply ignored
case e: Exception => {}
// Consider recurrence relations only if they predict at least one element
// of the sequence without referencing a seed value
if (sequence.size > 2 * (Utilities.getStartIndex(formula) - 1)) {
if (!configuration.numericalTest || Verifier.testFormula(formula, sequenceNumerical)) {
// 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))
if (configuration.maximumIdentifications > 0 && identifications.distinct.size >= configuration.maximumIdentifications)
return identifications.distinct.sortBy(_.formula.length)
} catch {
// Occasionally, simplification or prediction throw an exception although
// symbolic verification did not. This indicates a bug in Symja
// and is simply ignored
case e: Exception => {}
}
}
}
}
Expand Down

0 comments on commit 90b8762

Please sign in to comment.