Class LoggingScript

java.lang.Object
de.uni_freiburg.informatik.ultimate.logic.WrapperScript
de.uni_freiburg.informatik.ultimate.logic.LoggingScript
All Implemented Interfaces:
Script

public class LoggingScript
extends WrapperScript
A logging script variant. This is actually a wrapper around a concrete implementation of the Script interface that produces an interaction file in (almost) SMTLIB 2 compliant format. We still have some extra commands like "simplify", "reset", or "get-interpolants".
Author:
Juergen Christ
  • Constructor Details

    • LoggingScript

      public LoggingScript​(java.lang.String file, boolean autoFlush) throws java.io.IOException
      Create a new script logging the commands by the user. Most commands are not supported, e.g., checkSat always returns unknown. Furthermore, common subexpression elimination is not used in the output.
      Parameters:
      file - The name of the logging file (should end in .smt2).
      autoFlush - Automatically flush the output stream after every command.
      Throws:
      java.io.IOException - IOException If an I/O error has occurred.
    • LoggingScript

      public LoggingScript​(java.lang.String file, boolean autoFlush, boolean useCSE) throws java.io.IOException
      Create a new script logging the commands by the user. Most commands are not supported, e.g., checkSat always returns unknown. This constructor can be used to set up logging using common subexpression elimination.
      Parameters:
      file - The name of the logging file (should end in .smt2).
      autoFlush - Automatically flush the output stream after every command.
      useCSE - Use common subexpression elimination in output (introduces let terms)
      Throws:
      java.io.IOException - IOException If an I/O error has occurred.
    • LoggingScript

      public LoggingScript​(Script script, java.lang.String file, boolean autoFlush) throws java.io.IOException
      Create a new script logging the interaction between the user and the wrapped script into a file. This constructor sets up logging to not use common subexpression elimination.
      Parameters:
      script - The wrapped script.
      file - The name of the logging file (should end in .smt2).
      autoFlush - Automatically flush the output stream after every command.
      Throws:
      java.io.IOException - IOException If an I/O error has occurred.
    • LoggingScript

      public LoggingScript​(Script script, java.lang.String file, boolean autoFlush, boolean useCSE) throws java.io.IOException
      Create a new script logging the interaction between the user and the wrapped script into a file. This constructor can be used to set up logging using common subexpression elimination.
      Parameters:
      script - The wrapped script.
      file - The name of the logging file (should end in .smt2).
      autoFlush - Automatically flush the output stream after every command.
      useCSE - Use common subexpression elimination in output (introduces let terms)
      Throws:
      java.io.IOException - IOException If an I/O error has occurred.
  • Method Details

    • setLogic

      public void setLogic​(java.lang.String logic) throws java.lang.UnsupportedOperationException, SMTLIBException
      Description copied from interface: Script
      Set the logic for the solver. The logic should be the name of one of the elements in the Logics enumeration.
      Specified by:
      setLogic in interface Script
      Overrides:
      setLogic in class WrapperScript
      Parameters:
      logic - Name of the logic to set.
      Throws:
      java.lang.UnsupportedOperationException - If the logic is not supported by the solver.
      SMTLIBException - If a logic is already set.
    • setLogic

      public void setLogic​(Logics logic) throws java.lang.UnsupportedOperationException, SMTLIBException
      Description copied from interface: Script
      Set the logic for the solver.
      Specified by:
      setLogic in interface Script
      Overrides:
      setLogic in class WrapperScript
      Parameters:
      logic - Name of the logic to set.
      Throws:
      java.lang.UnsupportedOperationException - If the logic is not supported by the solver.
      SMTLIBException - If a logic is already set.
    • setOption

      public void setOption​(java.lang.String opt, java.lang.Object value) throws java.lang.UnsupportedOperationException, SMTLIBException
      Description copied from interface: Script
      Set an option for the solver. At least the options described in the standard should be valid options.
      Specified by:
      setOption in interface Script
      Overrides:
      setOption in class WrapperScript
      Parameters:
      opt - Name of the option. Note that it has to start with a colon (:).
      value - Value for this option.
      Throws:
      java.lang.UnsupportedOperationException - If the option is unsupported.
      SMTLIBException - In case of type errors.
    • setInfo

      public void setInfo​(java.lang.String info, java.lang.Object value)
      Description copied from interface: Script
      Set some information for the solver. Note that according to the standard a solver has to return success, but ignore the info.
      Specified by:
      setInfo in interface Script
      Overrides:
      setInfo in class WrapperScript
      Parameters:
      info - Name of the info. Note that it has to start with a colon (:).
      value - Value for this info.
    • getFunctionSymbol

      public FunctionSymbol getFunctionSymbol​(java.lang.String constructor)
      Description copied from interface: Script
      Check if constructor is the Constructor of a Datatype within the Theory.
      Parameters:
      constructor - The Name of the constructor.
      Returns:
      The Constructor or null if it does not exist.
    • declareSort

      public void declareSort​(java.lang.String sort, int arity) throws SMTLIBException
      Description copied from interface: Script
      Declare a user-defined sort.
      Specified by:
      declareSort in interface Script
      Overrides:
      declareSort in class WrapperScript
      Parameters:
      sort - The name of the new sort.
      arity - The arity of the new sort.
      Throws:
      SMTLIBException - If no logic is set, the logic does not allow user-defined sorts, or a sort with this name already exists.
    • defineSort

      public void defineSort​(java.lang.String sort, Sort[] sortParams, Sort definition) throws SMTLIBException
      Description copied from interface: Script
      Define an alias of a sort.
      Specified by:
      defineSort in interface Script
      Overrides:
      defineSort in class WrapperScript
      Parameters:
      sort - Name of the alias.
      sortParams - Sort parameters.
      definition - Original sort.
      Throws:
      SMTLIBException - If no logic is set, the logic does not allow user-defined sorts, or a sort with this name already exists.
    • declareDatatype

      public void declareDatatype​(DataType datatype, DataType.Constructor[] constrs) throws SMTLIBException
      Description copied from interface: Script
      Declare new datatypes by setting their constructors.
      Specified by:
      declareDatatype in interface Script
      Overrides:
      declareDatatype in class WrapperScript
      constrs - The constructors.
      Throws:
      SMTLIBException - if any problem occurs, e.g. symbols with same name already declared.
    • declareDatatypes

      public void declareDatatypes​(DataType[] datatypes, DataType.Constructor[][] constrs, Sort[][] sortParams) throws SMTLIBException
      Description copied from interface: Script
      Declare new datatypes by setting their constructors.
      Specified by:
      declareDatatypes in interface Script
      Overrides:
      declareDatatypes in class WrapperScript
      Parameters:
      datatypes - the datatypes to declare.
      constrs - The constructors for each datatype (with constrs.length == datatypes.length).
      sortParams - The sort parameters for each datatype, the outer array contains null if the datatype is not generic (sortParams.length == datatypes.length).
      Throws:
      SMTLIBException - if any problem occurs, e.g, symbols with same name already declared, wrong array lengths.
    • declareFun

      public void declareFun​(java.lang.String fun, Sort[] paramSorts, Sort resultSort) throws SMTLIBException
      Description copied from interface: Script
      Declare a function symbol.
      Specified by:
      declareFun in interface Script
      Overrides:
      declareFun in class WrapperScript
      Parameters:
      fun - Name of the function symbol.
      paramSorts - Sorts of the parameters.
      resultSort - Sort of the result of an application of this function.
      Throws:
      SMTLIBException - If the logic is not set, the logic is not an UF logic but the function takes parameters, or a function with this name already exists.
    • defineFun

      public void defineFun​(java.lang.String fun, TermVariable[] params, Sort resultSort, Term definition) throws SMTLIBException
      Description copied from interface: Script
      Define an alias of a function symbol.
      Specified by:
      defineFun in interface Script
      Overrides:
      defineFun in class WrapperScript
      Parameters:
      fun - Name of the alias.
      params - Parameters of the alias.
      resultSort - Return sort of the alias.
      definition - Definition of the function alias.
      Throws:
      SMTLIBException - If the logic is not set, the logic is not an UF logic but the function takes parameters, or a function with this name already exists.
    • push

      public void push​(int levels) throws SMTLIBException
      Description copied from interface: Script
      Push some levels onto the assertion stack.
      Specified by:
      push in interface Script
      Overrides:
      push in class WrapperScript
      Parameters:
      levels - The number of levels to push.
      Throws:
      SMTLIBException - If logic is not set.
    • pop

      public void pop​(int levels) throws SMTLIBException
      Description copied from interface: Script
      Pop some levels from the assertion stack.
      Specified by:
      pop in interface Script
      Overrides:
      pop in class WrapperScript
      Parameters:
      levels - The number of levels to pop.
      Throws:
      SMTLIBException - If not enough stack levels are available.
    • assertTerm

      public Script.LBool assertTerm​(Term term) throws SMTLIBException
      Description copied from interface: Script
      Assert a Boolean term into the solver. The solver might return a change in the state of the logical context. Compliant solvers do not have to do a full check here but return Script.LBool.UNKNOWN.
      Specified by:
      assertTerm in interface Script
      Overrides:
      assertTerm in class WrapperScript
      Parameters:
      term - The Boolean term to assert.
      Returns:
      Possibly an unsatisfiability detected by the solver.
      Throws:
      SMTLIBException - If the term is not Boolean or a named term matches an already defined function.
    • checkSat

      public Script.LBool checkSat() throws SMTLIBException
      Description copied from interface: Script
      Check for satisfiability of the current context. Note that this function should return Script.LBool.UNKNOWN in case of errors.
      Specified by:
      checkSat in interface Script
      Overrides:
      checkSat in class WrapperScript
      Returns:
      The result of the check as a lifted Boolean.
      Throws:
      SMTLIBException - If the logic is not set.
    • checkSatAssuming

      public Script.LBool checkSatAssuming​(Term... assumptions) throws SMTLIBException
      Description copied from interface: Script
      Check for satisfiability of the current context under additional assumptions. Note that this function should return Script.LBool.UNKNOWN in case of errors.
      Specified by:
      checkSatAssuming in interface Script
      Overrides:
      checkSatAssuming in class WrapperScript
      Parameters:
      assumptions - Additional assumptions as Boolean constants (nullary ApplicationTerms of sort Bool or their negations).
      Returns:
      The result of the check as a lifted Boolean.
      Throws:
      SMTLIBException - If the logic is not set.
    • getAssertions

      public Term[] getAssertions() throws SMTLIBException
      Description copied from interface: Script
      Get all assertions contained in the assertion stack. Note that this command is only available in interactive mode. To enable interactive mode, call setOption(":interactive-mode", true).
      Specified by:
      getAssertions in interface Script
      Overrides:
      getAssertions in class WrapperScript
      Returns:
      An array of all asserted terms.
      Throws:
      SMTLIBException - If interactive mode is not enabled.
    • getProof

      public Term getProof() throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Trigger a call to a proof processor. Note that this command is only available if proof production is enabled and the last Script.checkSat() returned Script.LBool.UNSAT. To enable proof production, call setOption(":produce-proofs", true).
      Specified by:
      getProof in interface Script
      Overrides:
      getProof in class WrapperScript
      Returns:
      the proof. This is given as a big smtlib term of the internal type @proof.
      Throws:
      SMTLIBException - If proof production is not enabled or the solver did not detect unsatisfiability.
      java.lang.UnsupportedOperationException - If proof generation is unsupported.
    • getUnsatCore

      public Term[] getUnsatCore() throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get the unsat core. Note that this command is only available if unsat core production is enabled and the last Script.checkSat() returned Script.LBool.UNSAT. To enable unsat core production, call setOption(":produce-unsat-cores", true).
      Specified by:
      getUnsatCore in interface Script
      Overrides:
      getUnsatCore in class WrapperScript
      Returns:
      An array of terms forming an unsat core.
      Throws:
      SMTLIBException - If proof production is not enabled or the solver did not detect unsatisfiability.
      java.lang.UnsupportedOperationException - If unsat core computation is unsupported.
    • getValue

      public java.util.Map<Term,​Term> getValue​(Term[] terms) throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get values for some terms in the model. Note that this command is only available if model production is enabled and the last Script.checkSat() did not return Script.LBool.UNSAT. To enable model production, call setOption(":produce-models", true).
      Specified by:
      getValue in interface Script
      Overrides:
      getValue in class WrapperScript
      Parameters:
      terms - an array of terms whose value should be computed.
      Returns:
      A valuation (mapping from term to value (which is again represented by a term) where the keys are the given terms.
      Throws:
      SMTLIBException - If model production is not enabled or the solver detected unsatisfiability.
      java.lang.UnsupportedOperationException - If model computation is unsupported
    • getAssignment

      public Assignments getAssignment() throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get values for all named boolean terms in the model. Note that this command is only available if assignment production is enabled and the last Script.checkSat() did not return Script.LBool.UNSAT. To enable assignment production, call setOption(":produce-assignments", true).
      Specified by:
      getAssignment in interface Script
      Overrides:
      getAssignment in class WrapperScript
      Returns:
      An Assignments.
      Throws:
      SMTLIBException - If assignment production is not enabled, or the solver did not detect unsatisfiability.
      java.lang.UnsupportedOperationException - If model computation is unsupported
    • getOption

      public java.lang.Object getOption​(java.lang.String opt) throws java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get the value of an option.
      Specified by:
      getOption in interface Script
      Overrides:
      getOption in class WrapperScript
      Parameters:
      opt - Name of an option.
      Returns:
      The value of this option.
      Throws:
      java.lang.UnsupportedOperationException - If option is unsupported.
    • getInfo

      public java.lang.Object getInfo​(java.lang.String info) throws java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get information from the solver. Note that the solver only has to implement the info values described in the standard.
      Specified by:
      getInfo in interface Script
      Overrides:
      getInfo in class WrapperScript
      Parameters:
      info - Name of the info. Note that it has to start with a colon (:).
      Returns:
      Value of the option.
      Throws:
      java.lang.UnsupportedOperationException - If the info is unsupported.
    • simplify

      public Term simplify​(Term term) throws SMTLIBException
      Description copied from interface: Script
      Simplify a term. This returns a term that is under the current assertions equivalent to the input term.
      Specified by:
      simplify in interface Script
      Overrides:
      simplify in class WrapperScript
      Parameters:
      term - A (usually Boolean) term to simplify.
      Returns:
      The simplified term.
      Throws:
      SMTLIBException - If an error occurred or unsupported.
    • reset

      public void reset()
      Description copied from interface: Script
      Reset the solver completely. Note that this invalidates all objects previously returned and unsets the logic.
      Specified by:
      reset in interface Script
      Overrides:
      reset in class WrapperScript
    • getInterpolants

      public Term[] getInterpolants​(Term[] partition) throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get interpolants for the partitions. Note that the arguments to this call must either be the names of Boolean top-level assertions, or the conjunction of such names.
      Specified by:
      getInterpolants in interface Script
      Overrides:
      getInterpolants in class WrapperScript
      Parameters:
      partition - Partitioning of the assertion stack.
      Returns:
      Interpolants.
      Throws:
      SMTLIBException - An error occurred.
      java.lang.UnsupportedOperationException - If interpolant computation is unsupported.
    • getInterpolants

      public Term[] getInterpolants​(Term[] partition, int[] startOfSubtree) throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Compute a sequence of interpolants. The nesting array describes the start of the subtree for tree interpolants. For inductive sequences of interpolants use a nesting array completely filled with 0.
      Specified by:
      getInterpolants in interface Script
      Overrides:
      getInterpolants in class WrapperScript
      Parameters:
      partition - The array of formulas. This should contain either top-level names or conjunction of top-level names.
      startOfSubtree - The start of the subtree containing the formula at this index as root.
      Returns:
      Tree interpolants respecting the nesting relation.
      Throws:
      SMTLIBException - An error occurred.
      java.lang.UnsupportedOperationException - If interpolant computation is unsupported.
    • getInterpolants

      public Term[] getInterpolants​(Term[] partition, int[] startOfSubtree, Term proofTree) throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Compute a sequence of interpolants. The nesting array describes the start of the subtree for tree interpolants. For inductive sequences of interpolants use a nesting array completely filled with 0. This computes the interpolants from the given proof. It can be called at any time, even if the assertion stack has been modified since computing the proof.
      Parameters:
      partition - The array of formulas. This should contain either top-level names or conjunction of top-level names.
      startOfSubtree - The start of the subtree containing the formula at this index as root.
      proofTree - The proof tree that used to compute interpolants.
      Returns:
      Tree interpolants respecting the nesting relation.
      Throws:
      SMTLIBException - An error occurred.
      java.lang.UnsupportedOperationException - If interpolant computation is unsupported.
    • exit

      public void exit()
      Description copied from interface: Script
      Exit the solver.
      Specified by:
      exit in interface Script
      Overrides:
      exit in class WrapperScript
    • getModel

      public Model getModel() throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Retrieve a complete model from the solver. This is an optional (non- SMTLIB compliant) operation. This function can only be called when the previous Script.checkSat() returned Script.LBool.SAT or (optionally) Script.LBool.UNKNOWN and no assertion stack command was issued after this check.
      Specified by:
      getModel in interface Script
      Overrides:
      getModel in class WrapperScript
      Returns:
      A model for the current formula.
      Throws:
      SMTLIBException - Model production was not enabled.
      java.lang.UnsupportedOperationException - The solver does not support this operation.
    • checkAllsat

      public java.lang.Iterable<Term[]> checkAllsat​(Term[] predicates) throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Perform an AllSAT computation over some important predicates.
      Specified by:
      checkAllsat in interface Script
      Overrides:
      checkAllsat in class WrapperScript
      Parameters:
      predicates - The important predicates. Must be Boolean.
      Returns:
      Iterator over minterms found during iteration.
      Throws:
      SMTLIBException - If a predicate is non-Boolean.
      java.lang.UnsupportedOperationException - If the operation is unsupported.
    • findImpliedEquality

      public Term[] findImpliedEquality​(Term[] x, Term[] y)
      Description copied from interface: Script
      Try to find an equality between x and y that is implied in the current satisfiable context. If successful, this method returns an array of parameters a,b,c such that the equality a*x = b*y + c is implied by the current context. Note that the x array and the y array must be of equal length and of length at least 2.
      Specified by:
      findImpliedEquality in interface Script
      Overrides:
      findImpliedEquality in class WrapperScript
      Parameters:
      x - The different incarnations of the lhs variable.
      y - The different incarnations of the rhs variable.
      Returns:
      Array of length 3 or array of length 0 if no equality is implied.
    • echo

      public QuotedObject echo​(QuotedObject msg)
      Description copied from interface: Script
      Echo a message on the regular output channel of the solver. Although this function is not specified in the SMTLIB standard, we do not expect implementations to throw any exceptions. Instead, if the command is unsupported, it should simply be implemented as the identity function.
      Specified by:
      echo in interface Script
      Overrides:
      echo in class WrapperScript
      Parameters:
      msg - The message to print.
      Returns:
      The message.
    • comment

      public void comment​(java.lang.String comment)
      Write a comment to the generated SMTLIB dump file. Note that this function is only available in the LoggingScript and not in the interface Script since it only makes sense for logging and not for solving.
      Parameters:
      comment - The comment to write to the dump file.
    • resetAssertions

      public void resetAssertions()
      Description copied from interface: Script
      Resets the assertion stack. This option will keep the logic and all globally defined symbols.
      Specified by:
      resetAssertions in interface Script
      Overrides:
      resetAssertions in class WrapperScript
    • getUnsatAssumptions

      public Term[] getUnsatAssumptions() throws SMTLIBException, java.lang.UnsupportedOperationException
      Description copied from interface: Script
      Get the unsatisfiable assumptions. Note that this command is only available if unsat assumption production is enabled and the last Script.checkSatAssuming(Term...) returned Script.LBool.UNSAT. To enable unsat assumption production, call setOption (":produce-unsat-assumptions", true).
      Specified by:
      getUnsatAssumptions in interface Script
      Overrides:
      getUnsatAssumptions in class WrapperScript
      Returns:
      An array of terms that correspond to an unsatisfiable subset of last assumptions.
      Throws:
      SMTLIBException - If unsat assumption production is not enabled or the solver did not detect unsatisfiability.
      java.lang.UnsupportedOperationException - If unsat assumption computation is unsupported.