// $Id: Rule.java,v 1.7 2004/02/27 16:29:56 m31 Exp $
//
// This file is part of the program suite "Principia Mathematica II"
// which is a working prototype for the main project:
// "Hilbert II" - http://www.qedeq.org
//
// Copyright 2001-2004  Michael Meyling <mime@qedeq.org>.
//
// "Principia Mathematica II" is free software; you can redistribute
// it and/or modify it under the terms of the GNU General Public
// License as published by the Free Software Foundation; either
// version 2 of the License, or (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.

package com.meyling.principia.logic.rule;


import com.meyling.principia.argument.Argument;
import com.meyling.principia.argument.ArgumentException;
import com.meyling.principia.logic.basic.Formula;
import com.meyling.principia.logic.paragraph.ProofLineList;
import com.meyling.principia.module.Module;
import com.meyling.principia.module.Version;


/**
 * Every logical rule must implement this interface. Each rule makes it possible
 * to extend a proof.
 *
 * @version $Revision: 1.7 $
 * @author  Michael Meyling
 */
public interface Rule extends Argument {


    /**
     * Check if proof could be extended with formula (using the arguments of rule).
     *
     * @param   module    the module context
     * @param   proofLines the proof lines
     * @param   position number of proof lines that could be used
     *                    in the rule
     * @param   formula  formula to add
     * @throws  ArgumentException    if addition is not possible
     */
    public void check(Module module, ProofLineList proofLines,
            int position, Formula formula)
            throws ArgumentException;


    /**
     * Return proof lines that could replace the proof line
     * <code>position</code>.
     *
     * @param   module      the belonging module
     * @param   proofLines  proof lines
     * @param   position    referenced proof line (starting with 0)
     *                       in <code>proofLines</code>
     * @return  proof lines that could substitute the single
     *           proof line <code>position</code>
     * @throws  IllegalArgumentException  if extension is impossible
     *           or other problems occured
     *           if the module was checked before, this exception
     *           could only occur if there is an programming error
     * @throws  UnsupportedOperationException if this rule couldn't
     *           be reduced at all because it is a basic rule
     */
    public ProofLineList extendWithout(final Module module,
            final ProofLineList proofLines, final int position)
            throws IllegalArgumentException;


    /**
     * Get proof line numbers that are used to derive the new formula.
     *
     * @return  numbers of involved proof lines
     */
    public int[] getProofLines();


    /**
     * Get proof line numbers that are used to derive the new formula.
     *
     * @param   mapping     array that maps old proof line numbers (index) to
     *                      new ones (value)
     * @return  same rule but with changed numbers of involved proof lines
     * @throws  IllegalArgumentException    if a needed value is -1
     */
    public Rule changeProofLines(int[] mapping);


    /**
     * Get version of this rule.
     *
     * @return  rule version
     */
    public Version getVersion();


}
