Big update

(And translated the code to english)
This commit is contained in:
XDrake99 2016-09-12 16:30:51 +02:00
parent f1b74b9842
commit 46138875bb
67 changed files with 1770 additions and 1601 deletions

View File

@ -3,10 +3,10 @@ encoding//src/org/nevec/rjm/BigSurd.java=UTF-8
encoding//src/org/nevec/rjm/BigSurdVec.java=UTF-8 encoding//src/org/nevec/rjm/BigSurdVec.java=UTF-8
encoding//src/org/warp/engine=UTF-8 encoding//src/org/warp/engine=UTF-8
encoding//src/org/warp/engine/Display.java=UTF-8 encoding//src/org/warp/engine/Display.java=UTF-8
encoding//src/org/warp/picalculator/Espressione.java=UTF-8 encoding//src/org/warp/picalculator/Expression.java=UTF-8
encoding//src/org/warp/picalculator/Main.java=UTF-8 encoding//src/org/warp/picalculator/Main.java=UTF-8
encoding//src/org/warp/picalculator/Radice.java=UTF-8 encoding//src/org/warp/picalculator/MathematicalSymbols.java=UTF-8
encoding//src/org/warp/picalculator/RadiceQuadrata.java=UTF-8 encoding//src/org/warp/picalculator/Root.java=UTF-8
encoding//src/org/warp/picalculator/Simboli.java=UTF-8 encoding//src/org/warp/picalculator/RootSquare.java=UTF-8
encoding//src/org/warp/picalculator/screens/EquationScreen.java=UTF-8 encoding//src/org/warp/picalculator/screens/EquationScreen.java=UTF-8
encoding/<project>=UTF-8 encoding/<project>=UTF-8

BIN
res/marioground.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.4 KiB

BIN
res/marioground.xcf Normal file

Binary file not shown.

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

Binary file not shown.

BIN
res/temp.rft Normal file

Binary file not shown.

View File

@ -3,7 +3,7 @@ package org.nevec.rjm;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* Bernoulli numbers. * Bernoulli numbers.
@ -50,9 +50,9 @@ public class Bernoulli {
* @param n * @param n
* the index, non-negative. * the index, non-negative.
* @return the B_0=1 for n=0, B_1=-1/2 for n=1, B_2=1/6 for n=2 etc * @return the B_0=1 for n=0, B_1=-1/2 for n=1, B_2=1/6 for n=2 etc
* @throws Errore * @throws Error
*/ */
public Rational at(int n) throws Errore { public Rational at(int n) throws Error {
if (n == 1) if (n == 1)
return (new Rational(-1, 2)); return (new Rational(-1, 2));
else if (n % 2 != 0) else if (n % 2 != 0)
@ -74,7 +74,7 @@ public class Bernoulli {
* *
* @return The Bernoulli number at n. * @return The Bernoulli number at n.
*/ */
private Rational doubleSum(int n) throws Errore { private Rational doubleSum(int n) throws Error {
Rational resul = Rational.ZERO; Rational resul = Rational.ZERO;
for (int k = 0; k <= n; k++) { for (int k = 0; k <= n; k++) {
Rational jsum = Rational.ZERO; Rational jsum = Rational.ZERO;

View File

@ -5,7 +5,7 @@ import java.math.BigInteger;
import java.math.MathContext; import java.math.MathContext;
import java.security.ProviderException; import java.security.ProviderException;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* BigDecimal special functions. * BigDecimal special functions.
@ -55,10 +55,10 @@ public class BigDecimalMath {
* @param mc * @param mc
* The required precision of the result. * The required precision of the result.
* @return 3.14159... * @return 3.14159...
* @throws Errore * @throws Error
* @since 2009-05-29 * @since 2009-05-29
*/ */
static public BigDecimal pi(final MathContext mc) throws Errore { static public BigDecimal pi(final MathContext mc) throws Error {
/* look it up if possible */ /* look it up if possible */
if (mc.getPrecision() < PI.precision()) if (mc.getPrecision() < PI.precision())
return PI.round(mc); return PI.round(mc);
@ -79,10 +79,10 @@ public class BigDecimalMath {
* @param mc * @param mc
* The required precision of the result. * The required precision of the result.
* @return 0.577... * @return 0.577...
* @throws Errore * @throws Error
* @since 2009-08-13 * @since 2009-08-13
*/ */
static public BigDecimal gamma(MathContext mc) throws Errore { static public BigDecimal gamma(MathContext mc) throws Error {
/* look it up if possible */ /* look it up if possible */
if (mc.getPrecision() < GAMMA.precision()) if (mc.getPrecision() < GAMMA.precision())
return GAMMA.round(mc); return GAMMA.round(mc);
@ -574,9 +574,9 @@ public class BigDecimalMath {
* @return ln(n). * @return ln(n).
* @since 2009-08-08 * @since 2009-08-08
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static public BigDecimal log(int n, final MathContext mc) throws Errore { static public BigDecimal log(int n, final MathContext mc) throws Error {
/* /*
* the value is undefined if x is negative. * the value is undefined if x is negative.
*/ */
@ -1017,10 +1017,10 @@ public class BigDecimalMath {
* @param x * @param x
* The argument in radians. * The argument in radians.
* @return sin(x) in the range -1 to 1. * @return sin(x) in the range -1 to 1.
* @throws Errore * @throws Error
* @since 2009-06-01 * @since 2009-06-01
*/ */
static public BigDecimal sin(final BigDecimal x) throws Errore { static public BigDecimal sin(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) < 0) if (x.compareTo(BigDecimal.ZERO) < 0)
return sin(x.negate()).negate(); return sin(x.negate()).negate();
else if (x.compareTo(BigDecimal.ZERO) == 0) else if (x.compareTo(BigDecimal.ZERO) == 0)
@ -1111,10 +1111,10 @@ public class BigDecimalMath {
* @param x * @param x
* The argument in radians. * The argument in radians.
* @return cos(x) in the range -1 to 1. * @return cos(x) in the range -1 to 1.
* @throws Errore * @throws Error
* @since 2009-06-01 * @since 2009-06-01
*/ */
static public BigDecimal cos(final BigDecimal x) throws Errore { static public BigDecimal cos(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) < 0) if (x.compareTo(BigDecimal.ZERO) < 0)
return cos(x.negate()); return cos(x.negate());
else if (x.compareTo(BigDecimal.ZERO) == 0) else if (x.compareTo(BigDecimal.ZERO) == 0)
@ -1207,9 +1207,9 @@ public class BigDecimalMath {
* @param x * @param x
* the argument in radians. * the argument in radians.
* @return the tan(x) * @return the tan(x)
* @throws Errore * @throws Error
*/ */
static public BigDecimal tan(final BigDecimal x) throws Errore { static public BigDecimal tan(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) == 0) if (x.compareTo(BigDecimal.ZERO) == 0)
return BigDecimal.ZERO; return BigDecimal.ZERO;
else if (x.compareTo(BigDecimal.ZERO) < 0) { else if (x.compareTo(BigDecimal.ZERO) < 0) {
@ -1271,10 +1271,10 @@ public class BigDecimalMath {
* @param x * @param x
* the argument in radians. * the argument in radians.
* @return the cot(x) * @return the cot(x)
* @throws Errore * @throws Error
* @since 2009-07-31 * @since 2009-07-31
*/ */
static public BigDecimal cot(final BigDecimal x) throws Errore { static public BigDecimal cot(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) == 0) { if (x.compareTo(BigDecimal.ZERO) == 0) {
throw new ArithmeticException("Cannot take cot of zero " + x.toString()); throw new ArithmeticException("Cannot take cot of zero " + x.toString());
} else if (x.compareTo(BigDecimal.ZERO) < 0) { } else if (x.compareTo(BigDecimal.ZERO) < 0) {
@ -1334,9 +1334,9 @@ public class BigDecimalMath {
* @param x * @param x
* the argument. * the argument.
* @return the arcsin(x) in radians. * @return the arcsin(x) in radians.
* @throws Errore * @throws Error
*/ */
static public BigDecimal asin(final BigDecimal x) throws Errore { static public BigDecimal asin(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ONE) > 0 || x.compareTo(BigDecimal.ONE.negate()) < 0) { if (x.compareTo(BigDecimal.ONE) > 0 || x.compareTo(BigDecimal.ONE.negate()) < 0) {
throw new ArithmeticException("Out of range argument " + x.toString() + " of asin"); throw new ArithmeticException("Out of range argument " + x.toString() + " of asin");
} else if (x.compareTo(BigDecimal.ZERO) == 0) } else if (x.compareTo(BigDecimal.ZERO) == 0)
@ -1436,10 +1436,10 @@ public class BigDecimalMath {
* @param x * @param x
* the argument. * the argument.
* @return the arccos(x) in radians. * @return the arccos(x) in radians.
* @throws Errore * @throws Error
* @since 2009-09-29 * @since 2009-09-29
*/ */
static public BigDecimal acos(final BigDecimal x) throws Errore { static public BigDecimal acos(final BigDecimal x) throws Error {
/* /*
* Essentially forwarded to pi/2 - asin(x) * Essentially forwarded to pi/2 - asin(x)
*/ */
@ -1470,10 +1470,10 @@ public class BigDecimalMath {
* the argument. * the argument.
* @return the principal value of arctan(x) in radians in the range -pi/2 to * @return the principal value of arctan(x) in radians in the range -pi/2 to
* +pi/2. * +pi/2.
* @throws Errore * @throws Error
* @since 2009-08-03 * @since 2009-08-03
*/ */
static public BigDecimal atan(final BigDecimal x) throws Errore { static public BigDecimal atan(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) < 0) { if (x.compareTo(BigDecimal.ZERO) < 0) {
return atan(x.negate()).negate(); return atan(x.negate()).negate();
} else if (x.compareTo(BigDecimal.ZERO) == 0) } else if (x.compareTo(BigDecimal.ZERO) == 0)
@ -1568,10 +1568,10 @@ public class BigDecimalMath {
* The argument. * The argument.
* @return The cosh(x) = (exp(x)+exp(-x))/2 . * @return The cosh(x) = (exp(x)+exp(-x))/2 .
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
* @since 2009-08-19 * @since 2009-08-19
*/ */
static public BigDecimal cosh(final BigDecimal x) throws Errore { static public BigDecimal cosh(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) < 0) if (x.compareTo(BigDecimal.ZERO) < 0)
return cos(x.negate()); return cos(x.negate());
else if (x.compareTo(BigDecimal.ZERO) == 0) else if (x.compareTo(BigDecimal.ZERO) == 0)
@ -1643,10 +1643,10 @@ public class BigDecimalMath {
* the argument. * the argument.
* @return the sinh(x) = (exp(x)-exp(-x))/2 . * @return the sinh(x) = (exp(x)-exp(-x))/2 .
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
* @since 2009-08-19 * @since 2009-08-19
*/ */
static public BigDecimal sinh(final BigDecimal x) throws Errore { static public BigDecimal sinh(final BigDecimal x) throws Error {
if (x.compareTo(BigDecimal.ZERO) < 0) if (x.compareTo(BigDecimal.ZERO) < 0)
return sinh(x.negate()).negate(); return sinh(x.negate()).negate();
else if (x.compareTo(BigDecimal.ZERO) == 0) else if (x.compareTo(BigDecimal.ZERO) == 0)
@ -1817,10 +1817,10 @@ public class BigDecimalMath {
* @param x * @param x
* The argument. * The argument.
* @return Gamma(x). * @return Gamma(x).
* @throws Errore * @throws Error
* @since 2009-08-06 * @since 2009-08-06
*/ */
static public BigDecimal Gamma(final BigDecimal x) throws Errore { static public BigDecimal Gamma(final BigDecimal x) throws Error {
/* /*
* reduce to interval near 1.0 with the functional relation, * reduce to interval near 1.0 with the functional relation,
* Abramowitz-Stegun 6.1.33 * Abramowitz-Stegun 6.1.33
@ -1924,10 +1924,10 @@ public class BigDecimalMath {
* @param mc * @param mc
* The required accuracy in the result. * The required accuracy in the result.
* @return Gamma(x). * @return Gamma(x).
* @throws Errore * @throws Error
* @since 2010-05-26 * @since 2010-05-26
*/ */
static public BigDecimal Gamma(final Rational q, final MathContext mc) throws Errore { static public BigDecimal Gamma(final Rational q, final MathContext mc) throws Error {
if (q.isBigInteger()) { if (q.isBigInteger()) {
if (q.compareTo(Rational.ZERO) <= 0) if (q.compareTo(Rational.ZERO) <= 0)
throw new ArithmeticException("Gamma at " + q.toString()); throw new ArithmeticException("Gamma at " + q.toString());
@ -2025,10 +2025,10 @@ public class BigDecimalMath {
* @param x * @param x
* the original value * the original value
* @return the value modulo 2*pi in the interval from 0 to 2*pi. * @return the value modulo 2*pi in the interval from 0 to 2*pi.
* @throws Errore * @throws Error
* @since 2009-06-01 * @since 2009-06-01
*/ */
static public BigDecimal mod2pi(BigDecimal x) throws Errore { static public BigDecimal mod2pi(BigDecimal x) throws Error {
/* /*
* write x= 2*pi*k+r with the precision in r defined by the precision of * write x= 2*pi*k+r with the precision in r defined by the precision of
* x and not * x and not
@ -2074,10 +2074,10 @@ public class BigDecimalMath {
* @param x * @param x
* The original value * The original value
* @return The value modulo pi, shifted to the interval from -Pi/2 to Pi/2. * @return The value modulo pi, shifted to the interval from -Pi/2 to Pi/2.
* @throws Errore * @throws Error
* @since 2009-07-31 * @since 2009-07-31
*/ */
static public BigDecimal modpi(BigDecimal x) throws Errore { static public BigDecimal modpi(BigDecimal x) throws Error {
/* /*
* write x= pi*k+r with the precision in r defined by the precision of x * write x= pi*k+r with the precision in r defined by the precision of x
* and not * and not
@ -2128,10 +2128,10 @@ public class BigDecimalMath {
* @param mc * @param mc
* Specification of the accuracy of the result. * Specification of the accuracy of the result.
* @return zeta(n). * @return zeta(n).
* @throws Errore * @throws Error
* @since 2009-08-05 * @since 2009-08-05
*/ */
static public BigDecimal zeta(final int n, final MathContext mc) throws Errore { static public BigDecimal zeta(final int n, final MathContext mc) throws Error {
if (n <= 0) if (n <= 0)
throw new ProviderException("Not implemented: zeta at negative argument " + n); throw new ProviderException("Not implemented: zeta at negative argument " + n);
if (n == 1) if (n == 1)
@ -2311,10 +2311,10 @@ public class BigDecimalMath {
* @param n * @param n
* The positive integer argument. * The positive integer argument.
* @return zeta(n)-1. * @return zeta(n)-1.
* @throws Errore * @throws Error
* @since 2009-08-20 * @since 2009-08-20
*/ */
static public double zeta1(final int n) throws Errore { static public double zeta1(final int n) throws Error {
/* /*
* precomputed static table in double precision * precomputed static table in double precision
*/ */
@ -2358,10 +2358,10 @@ public class BigDecimalMath {
* @return psi(x). * @return psi(x).
* The error is sometimes up to 10 ulp, where AS 6.3.15 suffers from * The error is sometimes up to 10 ulp, where AS 6.3.15 suffers from
* cancellation of digits and psi=0 * cancellation of digits and psi=0
* @throws Errore * @throws Error
* @since 2009-08-26 * @since 2009-08-26
*/ */
static public double psi(final double x) throws Errore { static public double psi(final double x) throws Error {
/* /*
* the single positive zero of psi(x) * the single positive zero of psi(x)
*/ */
@ -2411,11 +2411,11 @@ public class BigDecimalMath {
* @param mc * @param mc
* Specification of the accuracy of the result * Specification of the accuracy of the result
* @return S_(n,p)(a) * @return S_(n,p)(a)
* @throws Errore * @throws Error
* @since 2009-08-09 * @since 2009-08-09
* @see <a href="http://arxiv.org/abs/math/9803067">arXiv:math/9803067</a> * @see <a href="http://arxiv.org/abs/math/9803067">arXiv:math/9803067</a>
*/ */
static protected BigDecimal broadhurstBBP(final int n, final int p, final int a[], MathContext mc) throws Errore { static protected BigDecimal broadhurstBBP(final int n, final int p, final int a[], MathContext mc) throws Error {
/* /*
* Explore the actual magnitude of the result first with a quick * Explore the actual magnitude of the result first with a quick
* estimate. * estimate.

View File

@ -3,7 +3,7 @@ package org.nevec.rjm;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* BigInteger special functions and Number theory. * BigInteger special functions and Number theory.
@ -416,9 +416,9 @@ public class BigIntegerMath {
* @return The vector of x in A*x=rhs. * @return The vector of x in A*x=rhs.
* @since 2010-08-28 * @since 2010-08-28
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static public Rational[] solve(final BigInteger[][] A, final BigInteger[] rhs) throws ArithmeticException, Errore { static public Rational[] solve(final BigInteger[][] A, final BigInteger[] rhs) throws ArithmeticException, Error {
final int rL = A.length; final int rL = A.length;
if (rL == 0) if (rL == 0)
@ -547,11 +547,11 @@ public class BigIntegerMath {
* @return t(n,k) * @return t(n,k)
* @since 2009-08-06 * @since 2009-08-06
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
* @see <a href="http://dx.doi.org/10.1080/01630568908816313">P. L. Butzer * @see <a href="http://dx.doi.org/10.1080/01630568908816313">P. L. Butzer
* et al, Num. Funct. Anal. Opt. 10 (5)( 1989) 419-488</a> * et al, Num. Funct. Anal. Opt. 10 (5)( 1989) 419-488</a>
*/ */
static public Rational centrlFactNumt(int n, int k) throws Errore { static public Rational centrlFactNumt(int n, int k) throws Error {
if (k > n || k < 0 || (k % 2) != (n % 2)) if (k > n || k < 0 || (k % 2) != (n % 2))
return Rational.ZERO; return Rational.ZERO;
else if (k == n) else if (k == n)

View File

@ -5,7 +5,7 @@ import java.math.BigInteger;
import java.util.Scanner; import java.util.Scanner;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* Polynomial with integer coefficients. * Polynomial with integer coefficients.
@ -574,10 +574,10 @@ public class BigIntegerPoly implements Cloneable {
* Only factors with non-zero absolute coefficient are generated. * Only factors with non-zero absolute coefficient are generated.
* This means the factors are of the form x^2+a*x+b=0 with nonzero * This means the factors are of the form x^2+a*x+b=0 with nonzero
* b. * b.
* @throws Errore * @throws Error
* @since 2012-03-01 * @since 2012-03-01
*/ */
protected Vector<BigIntegerPoly> i2roots() throws Errore { protected Vector<BigIntegerPoly> i2roots() throws Error {
/* /*
* The vector of the factors to be returned * The vector of the factors to be returned
*/ */
@ -672,10 +672,10 @@ public class BigIntegerPoly implements Cloneable {
* *
* @return The vector of factors. Factors with higher multiplicity are * @return The vector of factors. Factors with higher multiplicity are
* represented by repetition. * represented by repetition.
* @throws Errore * @throws Error
* @since 2012-03-01 * @since 2012-03-01
*/ */
public Vector<BigIntegerPoly> ifactor() throws Errore { public Vector<BigIntegerPoly> ifactor() throws Error {
/* /*
* this ought be entirely rewritten in terms of the LLL algorithm * this ought be entirely rewritten in terms of the LLL algorithm
*/ */

View File

@ -5,7 +5,7 @@ import java.math.BigInteger;
import java.math.MathContext; import java.math.MathContext;
import java.security.ProviderException; import java.security.ProviderException;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
/** /**
@ -70,7 +70,7 @@ public class BigSurd implements Cloneable, Comparable<BigSurd> {
try { try {
normalize(); normalize();
normalizeG(); normalizeG();
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -212,10 +212,10 @@ public class BigSurd implements Cloneable, Comparable<BigSurd> {
* @param val * @param val
* A second number of this type. * A second number of this type.
* @return The value of this/val * @return The value of this/val
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public BigSurd divide(final BigSurd val) throws Errore { public BigSurd divide(final BigSurd val) throws Error {
if (val.signum() == 0) if (val.signum() == 0)
throw new ArithmeticException("Dividing " + toFancyString() + " through zero."); throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
return new BigSurd(pref.divide(val.pref), disc.divide(val.disc)); return new BigSurd(pref.divide(val.pref), disc.divide(val.disc));
@ -258,10 +258,10 @@ public class BigSurd implements Cloneable, Comparable<BigSurd> {
* @param val * @param val
* a second number. * a second number.
* @return the value of this/val * @return the value of this/val
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public BigSurd divide(final BigInteger val) throws Errore { public BigSurd divide(final BigInteger val) throws Error {
if (val.signum() == 0) if (val.signum() == 0)
throw new ArithmeticException("Dividing " + toFancyString() + " through zero."); throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
return new BigSurd(pref.divide(val), disc); return new BigSurd(pref.divide(val), disc);
@ -273,10 +273,10 @@ public class BigSurd implements Cloneable, Comparable<BigSurd> {
* @param val * @param val
* A second number. * A second number.
* @return The value of this/val * @return The value of this/val
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public BigSurd divide(int val) throws Errore { public BigSurd divide(int val) throws Error {
if (val == 0) if (val == 0)
throw new ArithmeticException("Dividing " + toFancyString() + " through zero."); throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
return new BigSurd(pref.divide(val), disc); return new BigSurd(pref.divide(val), disc);
@ -452,10 +452,10 @@ public class BigSurd implements Cloneable, Comparable<BigSurd> {
/** /**
* Normalize to squarefree discriminant. * Normalize to squarefree discriminant.
* *
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
protected void normalize() throws Errore { protected void normalize() throws Error {
/* /*
* Move squares out of the numerator and denominator of the discriminant * Move squares out of the numerator and denominator of the discriminant
*/ */
@ -492,10 +492,10 @@ public class BigSurd implements Cloneable, Comparable<BigSurd> {
* Normalize to coprime numerator and denominator in prefactor and * Normalize to coprime numerator and denominator in prefactor and
* discriminant * discriminant
* *
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
protected void normalizeG() throws Errore { protected void normalizeG() throws Error {
/* /*
* Is there a common factor between the numerator of the prefactor * Is there a common factor between the numerator of the prefactor
* and the denominator of the discriminant ? * and the denominator of the discriminant ?

View File

@ -5,7 +5,7 @@ import java.math.BigInteger;
import java.math.MathContext; import java.math.MathContext;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
/** /**
@ -69,7 +69,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
terms.add(b); terms.add(b);
try { try {
normalize(); normalize();
} catch (Errore e) { } catch (Error e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -79,11 +79,11 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* Combine terms that can be written as a single surd. This unites for * Combine terms that can be written as a single surd. This unites for
* example the terms sqrt(90) and sqrt(10) to 4*sqrt(10). * example the terms sqrt(90) and sqrt(10) to 4*sqrt(10).
* *
* @throws Errore * @throws Error
* *
* @since 2012-02-15 * @since 2012-02-15
*/ */
protected void normalize() throws Errore { protected void normalize() throws Error {
/* /*
* nothing to be done if at most one term * nothing to be done if at most one term
*/ */
@ -148,7 +148,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
try { try {
diff = this.subtract(oth); diff = this.subtract(oth);
return diff.signum(); return diff.signum();
} catch (Errore e) { } catch (Error e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
return 0; return 0;
@ -160,10 +160,10 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* equal to or larger than zero. * equal to or larger than zero.
* *
* @return 0 or +-1. * @return 0 or +-1.
* @throws Errore * @throws Error
* @since 2012-02-15 * @since 2012-02-15
*/ */
public int signum() throws Errore { public int signum() throws Error {
/* /*
* the case of zero is unique, because no (reduced) vector of surds * the case of zero is unique, because no (reduced) vector of surds
* other than the one element 0 itself can add/subtract to zero. * other than the one element 0 itself can add/subtract to zero.
@ -308,9 +308,9 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* @param val * @param val
* The value to be added to this. * The value to be added to this.
* @return The new value representing this+val. * @return The new value representing this+val.
* @throws Errore * @throws Error
*/ */
public BigSurdVec add(final BigSurdVec val) throws Errore { public BigSurdVec add(final BigSurdVec val) throws Error {
BigSurdVec sum = new BigSurdVec(); BigSurdVec sum = new BigSurdVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -335,9 +335,9 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* @param val * @param val
* The value to be added to this. * The value to be added to this.
* @return The new value representing this+val. * @return The new value representing this+val.
* @throws Errore * @throws Error
*/ */
public BigSurdVec add(final BigSurd val) throws Errore { public BigSurdVec add(final BigSurd val) throws Error {
BigSurdVec sum = new BigSurdVec(); BigSurdVec sum = new BigSurdVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -354,9 +354,9 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* @param val * @param val
* The value to be subtracted from this. * The value to be subtracted from this.
* @return The new value representing this-val. * @return The new value representing this-val.
* @throws Errore * @throws Error
*/ */
public BigSurdVec subtract(final BigSurdVec val) throws Errore { public BigSurdVec subtract(final BigSurdVec val) throws Error {
BigSurdVec sum = new BigSurdVec(); BigSurdVec sum = new BigSurdVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -374,9 +374,9 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* @param val * @param val
* The value to be subtracted from this. * The value to be subtracted from this.
* @return The new value representing this-val. * @return The new value representing this-val.
* @throws Errore * @throws Error
*/ */
public BigSurdVec subtract(final BigSurd val) throws Errore { public BigSurdVec subtract(final BigSurd val) throws Error {
BigSurdVec sum = new BigSurdVec(); BigSurdVec sum = new BigSurdVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -411,10 +411,10 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* Compute the square. * Compute the square.
* *
* @return this value squared. * @return this value squared.
* @throws Errore * @throws Error
* @since 2012-02-15 * @since 2012-02-15
*/ */
public BigSurdVec sqr() throws Errore { public BigSurdVec sqr() throws Error {
/* /*
* Binomial expansion. First the sum of the terms squared, then 2 times * Binomial expansion. First the sum of the terms squared, then 2 times
* the mixed products. * the mixed products.
@ -435,10 +435,10 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
* @param val * @param val
* a second number of this type. * a second number of this type.
* @return the product of this with the val. * @return the product of this with the val.
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public BigSurdVec multiply(final BigSurd val) throws Errore { public BigSurdVec multiply(final BigSurd val) throws Error {
BigSurdVec resul = new BigSurdVec(); BigSurdVec resul = new BigSurdVec();
for (BigSurd s : terms) for (BigSurd s : terms)
resul.terms.add(s.multiply(val)); resul.terms.add(s.multiply(val));
@ -446,7 +446,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
return resul; return resul;
} /* multiply */ } /* multiply */
public BigSurdVec multiply(final BigSurdVec val) throws Errore { public BigSurdVec multiply(final BigSurdVec val) throws Error {
BigSurdVec resul = new BigSurdVec(); BigSurdVec resul = new BigSurdVec();
for (BigSurd s : terms) { for (BigSurd s : terms) {
resul.terms.add(s); resul.terms.add(s);
@ -457,7 +457,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
return resul; return resul;
} /* multiply */ } /* multiply */
public BigSurdVec divide(final BigSurd val) throws Errore { public BigSurdVec divide(final BigSurd val) throws Error {
BigSurdVec resul = new BigSurdVec(); BigSurdVec resul = new BigSurdVec();
for (BigSurd s : terms) for (BigSurd s : terms)
resul.terms.add(s.divide(val)); resul.terms.add(s.divide(val));
@ -465,7 +465,7 @@ public class BigSurdVec implements Comparable<BigSurdVec> {
return resul; return resul;
} /* multiply */ } /* multiply */
public BigSurdVec divide(final BigSurdVec val) throws Errore { public BigSurdVec divide(final BigSurdVec val) throws Error {
BigSurdVec resul = new BigSurdVec(); BigSurdVec resul = new BigSurdVec();
resul.terms = terms; resul.terms = terms;
for (BigSurd s : val.terms) { for (BigSurd s : val.terms) {

View File

@ -4,7 +4,7 @@ import java.math.BigInteger;
import java.util.Collections; import java.util.Collections;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* Factored integers. * Factored integers.
@ -465,10 +465,10 @@ public class Ifactor implements Cloneable, Comparable<Ifactor> {
* The return value falls into the Ifactor class if r is positive, * The return value falls into the Ifactor class if r is positive,
* but if r is negative * but if r is negative
* a Rational type is needed. * a Rational type is needed.
* @throws Errore * @throws Error
* @since 2009-05-18 * @since 2009-05-18
*/ */
public Rational root(final int r) throws ArithmeticException, Errore { public Rational root(final int r) throws ArithmeticException, Error {
if (r == 0) if (r == 0)
throw new ArithmeticException("Cannot pull zeroth root of " + toString()); throw new ArithmeticException("Cannot pull zeroth root of " + toString());
else if (r < 0) { else if (r < 0) {

View File

@ -5,8 +5,8 @@ import java.math.BigInteger;
import java.math.MathContext; import java.math.MathContext;
import java.security.ProviderException; import java.security.ProviderException;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Incognite; import org.warp.picalculator.Variables;
/** /**
* Square roots on the real line. These represent numbers which are a product of * Square roots on the real line. These represent numbers which are a product of
@ -32,11 +32,11 @@ public class NumeroAvanzato implements Cloneable {
*/ */
Rational pref; Rational pref;
private Incognite incognitex; private Variables variablex;
private Incognite incognitey; private Variables variabley;
private Incognite incognitez; private Variables variablez;
/** /**
* The number underneath the square root, always non-negative. The * The number underneath the square root, always non-negative. The
@ -52,9 +52,9 @@ public class NumeroAvanzato implements Cloneable {
public NumeroAvanzato() { public NumeroAvanzato() {
pref = Rational.ZERO; pref = Rational.ZERO;
disc = Rational.ZERO; disc = Rational.ZERO;
incognitex = new Incognite(); variablex = new Variables();
incognitey = new Incognite(); variabley = new Variables();
incognitez = new Incognite(); variablez = new Variables();
} }
/** /**
@ -65,7 +65,7 @@ public class NumeroAvanzato implements Cloneable {
* the prefactor. * the prefactor.
* @param b * @param b
* the discriminant. * the discriminant.
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato(Rational a, Rational b) { public NumeroAvanzato(Rational a, Rational b) {
@ -76,18 +76,18 @@ public class NumeroAvanzato implements Cloneable {
if (b.signum() < 0) if (b.signum() < 0)
throw new ProviderException("Not implemented: imaginary surds"); throw new ProviderException("Not implemented: imaginary surds");
this.disc = b; this.disc = b;
incognitex = new Incognite(); variablex = new Variables();
incognitey = new Incognite(); variabley = new Variables();
incognitez = new Incognite(); variablez = new Variables();
try { try {
normalize(); normalize();
normalizeG(); normalizeG();
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
public NumeroAvanzato(Rational a, Rational b, Incognite x, Incognite y, Incognite z) { public NumeroAvanzato(Rational a, Rational b, Variables x, Variables y, Variables z) {
this.pref = a; this.pref = a;
/* /*
* reject attempts to use a negative b * reject attempts to use a negative b
@ -95,13 +95,13 @@ public class NumeroAvanzato implements Cloneable {
if (b.signum() < 0) if (b.signum() < 0)
throw new ProviderException("Not implemented: imaginary surds"); throw new ProviderException("Not implemented: imaginary surds");
this.disc = b; this.disc = b;
incognitex = x; variablex = x;
incognitey = y; variabley = y;
incognitez = z; variablez = z;
try { try {
normalize(); normalize();
normalizeG(); normalizeG();
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -145,9 +145,9 @@ public class NumeroAvanzato implements Cloneable {
public NumeroAvanzato clone() { public NumeroAvanzato clone() {
Rational fclon = pref.clone(); Rational fclon = pref.clone();
Rational dclon = disc.clone(); Rational dclon = disc.clone();
Incognite incognitexb = incognitex; Variables incognitexb = variablex;
Incognite incogniteyb = incognitey; Variables incogniteyb = variabley;
Incognite incognitezb = incognitez; Variables incognitezb = variablez;
/* /*
* the main intent here is to bypass any attempt to reduce the * the main intent here is to bypass any attempt to reduce the
* discriminant by figuring out the square-free part in normalize(), * discriminant by figuring out the square-free part in normalize(),
@ -156,9 +156,9 @@ public class NumeroAvanzato implements Cloneable {
NumeroAvanzato cl = new NumeroAvanzato(); NumeroAvanzato cl = new NumeroAvanzato();
cl.pref = fclon; cl.pref = fclon;
cl.disc = dclon; cl.disc = dclon;
cl.incognitex = incognitexb; cl.variablex = incognitexb;
cl.incognitey = incogniteyb; cl.variabley = incogniteyb;
cl.incognitez = incognitezb; cl.variablez = incognitezb;
return cl; return cl;
} /* NumeroAvanzato.clone */ } /* NumeroAvanzato.clone */
@ -189,7 +189,7 @@ public class NumeroAvanzato implements Cloneable {
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato multiply(final NumeroAvanzato val) { public NumeroAvanzato multiply(final NumeroAvanzato val) {
return new NumeroAvanzato(pref.multiply(val.pref), disc.multiply(val.disc), incognitex.multiply(val.incognitex), incognitey.multiply(val.incognitey), incognitez.multiply(val.incognitez)); return new NumeroAvanzato(pref.multiply(val.pref), disc.multiply(val.disc), variablex.multiply(val.variablex), variabley.multiply(val.variabley), variablez.multiply(val.variablez));
} /* NumeroAvanzato.multiply */ } /* NumeroAvanzato.multiply */
/** /**
@ -201,7 +201,7 @@ public class NumeroAvanzato implements Cloneable {
* @since 2011-02-15 * @since 2011-02-15
*/ */
public NumeroAvanzato multiply(final Rational val) { public NumeroAvanzato multiply(final Rational val) {
return new NumeroAvanzato(pref.multiply(val), disc, incognitex, incognitey, incognitez); return new NumeroAvanzato(pref.multiply(val), disc, variablex, variabley, variablez);
} /* NumeroAvanzato.multiply */ } /* NumeroAvanzato.multiply */
/** /**
@ -213,7 +213,7 @@ public class NumeroAvanzato implements Cloneable {
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato multiply(final BigInteger val) { public NumeroAvanzato multiply(final BigInteger val) {
return new NumeroAvanzato(pref.multiply(val), disc, incognitex, incognitey, incognitez); return new NumeroAvanzato(pref.multiply(val), disc, variablex, variabley, variablez);
} /* NumeroAvanzato.multiply */ } /* NumeroAvanzato.multiply */
/** /**
@ -233,10 +233,10 @@ public class NumeroAvanzato implements Cloneable {
* Compute the square. * Compute the square.
* *
* @return this value squared. * @return this value squared.
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato pow2() throws Errore { public NumeroAvanzato pow2() throws Error {
NumeroAvanzato res = new NumeroAvanzato(); NumeroAvanzato res = new NumeroAvanzato();
BigInteger a = pref.a; BigInteger a = pref.a;
BigInteger b = pref.b; BigInteger b = pref.b;
@ -245,9 +245,9 @@ public class NumeroAvanzato implements Cloneable {
res.pref = new Rational(a.pow(2).multiply(c).multiply(d), b.pow(2).multiply(d)); res.pref = new Rational(a.pow(2).multiply(c).multiply(d), b.pow(2).multiply(d));
res.disc = new Rational(0, 1); res.disc = new Rational(0, 1);
res.normalize(); res.normalize();
res.incognitex = incognitex; res.variablex = variablex;
res.incognitey = incognitey.multiply(incognitey); res.variabley = variabley.multiply(variabley);
res.incognitez = incognitez.multiply(incognitez); res.variablez = variablez.multiply(variablez);
return res; return res;
} /* NumeroAvanzato.sqr */ } /* NumeroAvanzato.sqr */
@ -257,21 +257,21 @@ public class NumeroAvanzato implements Cloneable {
* @param val * @param val
* A second number of this type. * A second number of this type.
* @return The value of this/val * @return The value of this/val
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato divide(final NumeroAvanzato val) throws Errore { public NumeroAvanzato divide(final NumeroAvanzato val) throws Error {
if (val.signum() == 0) if (val.signum() == 0)
throw new ArithmeticException("Dividing " + toFancyString() + " through zero."); throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
NumeroAvanzato result = new NumeroAvanzato(pref.divide(val.pref), disc.divide(val.disc)); NumeroAvanzato result = new NumeroAvanzato(pref.divide(val.pref), disc.divide(val.disc));
result.incognitex = incognitex.divide(val.incognitex); result.variablex = variablex.divide(val.variablex);
result.incognitey = incognitey.divide(val.incognitey); result.variabley = variabley.divide(val.variabley);
result.incognitez = incognitez.divide(val.incognitez); result.variablez = variablez.divide(val.variablez);
result.normalize(); result.normalize();
return result; return result;
} /* NumeroAvanzato.divide */ } /* NumeroAvanzato.divide */
private String toFancyString() throws Errore { private String toFancyString() throws Error {
return new NumeroAvanzatoVec(this).toFancyString(); return new NumeroAvanzatoVec(this).toFancyString();
} }
@ -281,10 +281,10 @@ public class NumeroAvanzato implements Cloneable {
* @param val * @param val
* a second number. * a second number.
* @return the value of this/val * @return the value of this/val
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato divide(final BigInteger val) throws Errore { public NumeroAvanzato divide(final BigInteger val) throws Error {
if (val.signum() == 0) if (val.signum() == 0)
throw new ArithmeticException("Dividing " + toFancyString() + " through zero."); throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
return new NumeroAvanzato(pref.divide(val), disc); return new NumeroAvanzato(pref.divide(val), disc);
@ -296,10 +296,10 @@ public class NumeroAvanzato implements Cloneable {
* @param val * @param val
* A second number. * A second number.
* @return The value of this/val * @return The value of this/val
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzato divide(int val) throws Errore { public NumeroAvanzato divide(int val) throws Error {
if (val == 0) if (val == 0)
throw new ArithmeticException("Dividing " + toFancyString() + " through zero."); throw new ArithmeticException("Dividing " + toFancyString() + " through zero.");
return new NumeroAvanzato(pref.divide(val), disc); return new NumeroAvanzato(pref.divide(val), disc);
@ -338,10 +338,10 @@ public class NumeroAvanzato implements Cloneable {
* the other constant to compare with * the other constant to compare with
* @return -1, 0 or 1 if this number is numerically less than, equal to, or * @return -1, 0 or 1 if this number is numerically less than, equal to, or
* greater than val. * greater than val.
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public int signumComparedTo(final NumeroAvanzato val) throws Errore { public int signumComparedTo(final NumeroAvanzato val) throws Error {
/* /*
* Since we keep the discriminant positive, the rough estimate comes * Since we keep the discriminant positive, the rough estimate comes
* from comparing the signs of the prefactors. * from comparing the signs of the prefactors.
@ -390,7 +390,7 @@ public class NumeroAvanzato implements Cloneable {
public String toString() { public String toString() {
try { try {
return toFancyString(); return toFancyString();
} catch (Errore e) { } catch (Error e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
@ -442,13 +442,13 @@ public class NumeroAvanzato implements Cloneable {
*/ */
public boolean isBigInteger(boolean hasBigIntegerVariables) { public boolean isBigInteger(boolean hasBigIntegerVariables) {
if (pref.isBigInteger() && (disc.signum() == 0 || disc.compareTo(Rational.ONE) == 0)) { if (pref.isBigInteger() && (disc.signum() == 0 || disc.compareTo(Rational.ONE) == 0)) {
if (disc.signum() != 0 && incognitex.count() > 0) { if (disc.signum() != 0 && variablex.count() > 0) {
return false; return false;
} }
if (hasBigIntegerVariables == false && incognitey.count() > 0) { if (hasBigIntegerVariables == false && variabley.count() > 0) {
return false; return false;
} }
if (pref.b.compareTo(BigInteger.ZERO) != 0 && disc.b.compareTo(BigInteger.ZERO) != 0 && incognitez.count() > 0) { if (pref.b.compareTo(BigInteger.ZERO) != 0 && disc.b.compareTo(BigInteger.ZERO) != 0 && variablez.count() > 0) {
return false; return false;
} }
return true; return true;
@ -458,10 +458,10 @@ public class NumeroAvanzato implements Cloneable {
public boolean isRational(boolean hasRationalVariables) { public boolean isRational(boolean hasRationalVariables) {
if (disc.signum() == 0 || disc.compareTo(new Rational(1, 1)) == 0) { if (disc.signum() == 0 || disc.compareTo(new Rational(1, 1)) == 0) {
if (incognitex.count() > 0) { if (variablex.count() > 0) {
return false; return false;
} else if (hasRationalVariables == false) { } else if (hasRationalVariables == false) {
if (incognitey.count() > 0 || incognitez.count() > 0) { if (variabley.count() > 0 || variablez.count() > 0) {
return false; return false;
} }
} }
@ -477,10 +477,10 @@ public class NumeroAvanzato implements Cloneable {
public boolean isTooPreciseRational(boolean hasRationalVariables) { public boolean isTooPreciseRational(boolean hasRationalVariables) {
if (disc.signum() == 0 || disc.compareTo(new Rational(1, 1)) == 0) { if (disc.signum() == 0 || disc.compareTo(new Rational(1, 1)) == 0) {
if (incognitex.count() > 0) { if (variablex.count() > 0) {
return false; return false;
} else if (hasRationalVariables == false) { } else if (hasRationalVariables == false) {
if (incognitey.count() > 0 || incognitez.count() > 0) { if (variabley.count() > 0 || variablez.count() > 0) {
return false; return false;
} }
} }
@ -496,18 +496,18 @@ public class NumeroAvanzato implements Cloneable {
/** /**
* Convert to a rational value if possible * Convert to a rational value if possible
* *
* @throws Errore * @throws Error
* *
* @since 2012-02-15 * @since 2012-02-15
*/ */
public Rational toRational(boolean hasRationalVariables) throws Errore { public Rational toRational(boolean hasRationalVariables) throws Error {
if (isRational(hasRationalVariables) || isTooPreciseRational(hasRationalVariables)) if (isRational(hasRationalVariables) || isTooPreciseRational(hasRationalVariables))
return pref; return pref;
else else
throw new ArithmeticException("Undefined conversion " + toFancyString() + " to Rational."); throw new ArithmeticException("Undefined conversion " + toFancyString() + " to Rational.");
} /* NumeroAvanzato.toRational */ } /* NumeroAvanzato.toRational */
public Rational toRational() throws Errore { public Rational toRational() throws Error {
if (isRational(true)) if (isRational(true))
return pref; return pref;
else else
@ -532,11 +532,11 @@ public class NumeroAvanzato implements Cloneable {
/** /**
* Normalize to squarefree discriminant. * Normalize to squarefree discriminant.
* *
* @throws Errore * @throws Error
* *
* @since 2011-02-12 * @since 2011-02-12
*/ */
protected void normalize() throws Errore { protected void normalize() throws Error {
/* /*
* Move squares out of the numerator and denominator of the discriminant * Move squares out of the numerator and denominator of the discriminant
*/ */
@ -572,31 +572,31 @@ public class NumeroAvanzato implements Cloneable {
disc = new Rational(numC, denC); disc = new Rational(numC, denC);
if (disc.b.compareTo(BigInteger.ZERO) == 0 || disc.a.compareTo(BigInteger.ZERO) == 0 || pref.a.compareTo(BigInteger.ZERO) == 0) { if (disc.b.compareTo(BigInteger.ZERO) == 0 || disc.a.compareTo(BigInteger.ZERO) == 0 || pref.a.compareTo(BigInteger.ZERO) == 0) {
incognitex = new Incognite(); variablex = new Variables();
incognitey = new Incognite(); variabley = new Variables();
} }
if (disc.b.compareTo(BigInteger.ZERO) == 0 || pref.b.compareTo(BigInteger.ZERO) == 0) { if (disc.b.compareTo(BigInteger.ZERO) == 0 || pref.b.compareTo(BigInteger.ZERO) == 0) {
incognitez = new Incognite(); variablez = new Variables();
} }
if (incognitey.compareTo(incognitez)) { if (variabley.compareTo(variablez)) {
incognitey = new Incognite(); variabley = new Variables();
incognitez = new Incognite(); variablez = new Variables();
} }
/**/ /**/
Incognite[] incognitetemp = new Incognite[] { incognitex, incognitey, incognitez }; Variables[] incognitetemp = new Variables[] { variablex, variabley, variablez };
incognitetemp = Incognite.normalizeBigSurdVariables(incognitetemp); incognitetemp = Variables.normalizeBigSurdVariables(incognitetemp);
incognitex = incognitetemp[0]; variablex = incognitetemp[0];
incognitey = incognitetemp[1]; variabley = incognitetemp[1];
incognitez = incognitetemp[2]; variablez = incognitetemp[2];
/**/ /**/
} else { } else {
pref = Rational.ZERO; pref = Rational.ZERO;
incognitex = new Incognite(); variablex = new Variables();
incognitey = new Incognite(); variabley = new Variables();
incognitez = new Incognite(); variablez = new Variables();
} }
} /* NumeroAvanzato.normalize */ } /* NumeroAvanzato.normalize */
@ -604,11 +604,11 @@ public class NumeroAvanzato implements Cloneable {
* Normalize to coprime numerator and denominator in prefactor and * Normalize to coprime numerator and denominator in prefactor and
* discriminant * discriminant
* *
* @throws Errore * @throws Error
* *
* @since 2011-02-12 * @since 2011-02-12
*/ */
protected void normalizeG() throws Errore { protected void normalizeG() throws Error {
/* /*
* Is there a common factor between the numerator of the prefactor and * Is there a common factor between the numerator of the prefactor and
* the denominator of the discriminant ? * the denominator of the discriminant ?
@ -681,65 +681,65 @@ public class NumeroAvanzato implements Cloneable {
if (pow2().pref == Rational.ZERO) { if (pow2().pref == Rational.ZERO) {
return true; return true;
} else { } else {
if (incognitex == na.incognitex) { if (variablex == na.variablex) {
if (incognitey == na.incognitey) { if (variabley == na.variabley) {
if (incognitez == na.incognitez) { if (variablez == na.variablez) {
return true; return true;
} }
} }
} }
} }
} }
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
} }
} }
return false; return false;
} }
public Incognite getIncognitex() { public Variables getVariableX() {
if (incognitex == null) { if (variablex == null) {
return incognitex; return variablex;
} }
return incognitex.clone(); return variablex.clone();
} }
public NumeroAvanzato setIncognitex(Incognite incognitex) { public NumeroAvanzato setVariableX(Variables x) {
NumeroAvanzato result = this.clone(); NumeroAvanzato result = this.clone();
result.incognitex = incognitex; result.variablex = x;
return result; return result;
} }
public Incognite getIncognitey() { public Variables getVariableY() {
if (incognitey == null) { if (variabley == null) {
return incognitey; return variabley;
} }
return incognitey.clone(); return variabley.clone();
} }
public NumeroAvanzato setIncognitey(Incognite incognitey) { public NumeroAvanzato setVariableY(Variables y) {
NumeroAvanzato result = this.clone(); NumeroAvanzato result = this.clone();
result.incognitey = incognitey; result.variabley = y;
return result; return result;
} }
public Incognite getIncognitez() { public Variables getVariableZ() {
if (incognitez == null) { if (variablez == null) {
return incognitez; return variablez;
} }
return incognitez.clone(); return variablez.clone();
} }
public NumeroAvanzato setIncognitez(Incognite incognitez) { public NumeroAvanzato setVariableZ(Variables z) {
NumeroAvanzato result = this.clone(); NumeroAvanzato result = this.clone();
result.incognitez = incognitez; result.variablez = z;
return result; return result;
} }
public NumeroAvanzato divideUnsafe(BigInteger denominator) { public NumeroAvanzato divideUnsafe(BigInteger denominator) {
try { try {
return divide(denominator); return divide(denominator);
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
return new NumeroAvanzato(); return new NumeroAvanzato();
} }

View File

@ -6,8 +6,8 @@ import java.math.MathContext;
import java.util.Comparator; import java.util.Comparator;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Incognite; import org.warp.picalculator.Variables;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
/** /**
@ -75,7 +75,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
terms.add(b); terms.add(b);
try { try {
normalize(); normalize();
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
} }
} /* ctor */ } /* ctor */
@ -84,11 +84,11 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* Combine terms that can be written as a single surd. This unites for * Combine terms that can be written as a single surd. This unites for
* example the terms sqrt(90) and sqrt(10) to 4*sqrt(10). * example the terms sqrt(90) and sqrt(10) to 4*sqrt(10).
* *
* @throws Errore * @throws Error
* *
* @since 2012-02-15 * @since 2012-02-15
*/ */
protected void normalize() throws Errore { protected void normalize() throws Error {
/* /*
* nothing to be done if at most one term * nothing to be done if at most one term
*/ */
@ -111,7 +111,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* if this reduction works. * if this reduction works.
*/ */
NumeroAvanzato r = todo.divide(v); NumeroAvanzato r = todo.divide(v);
if ((r.isRational(true) || r.isTooPreciseRational(true)) && todo.getIncognitex().compareTo(v.getIncognitex()) && todo.getIncognitey().compareTo(v.getIncognitey()) && todo.getIncognitez().compareTo(v.getIncognitez())) { if ((r.isRational(true) || r.isTooPreciseRational(true)) && todo.getVariableX().compareTo(v.getVariableX()) && todo.getVariableY().compareTo(v.getVariableY()) && todo.getVariableZ().compareTo(v.getVariableZ())) {
/* compute r+1 */ /* compute r+1 */
Rational newpref = r.toRational(true).add(1); Rational newpref = r.toRational(true).add(1);
/* /*
@ -137,8 +137,8 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
newter.sort(new Comparator<NumeroAvanzato>() { newter.sort(new Comparator<NumeroAvanzato>() {
@Override @Override
public int compare(NumeroAvanzato o1, NumeroAvanzato o2) { public int compare(NumeroAvanzato o1, NumeroAvanzato o2) {
int index1 = Incognite.priorità(o1.getIncognitex().sqrt().multiply(o1.getIncognitey()).divide(o1.getIncognitez())); int index1 = Variables.priority(o1.getVariableX().sqrt().multiply(o1.getVariableY()).divide(o1.getVariableZ()));
int index2 = Incognite.priorità(o2.getIncognitex().sqrt().multiply(o2.getIncognitey()).divide(o2.getIncognitez())); int index2 = Variables.priority(o2.getVariableX().sqrt().multiply(o2.getVariableY()).divide(o2.getVariableZ()));
return index2 - index1; return index2 - index1;
} }
}); });
@ -162,7 +162,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
try { try {
diff = this.subtract(oth); diff = this.subtract(oth);
return diff.signum(); return diff.signum();
} catch (Errore e) { } catch (Error e) {
e.printStackTrace(); e.printStackTrace();
return 0; return 0;
} }
@ -173,10 +173,10 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* equal to or larger than zero. * equal to or larger than zero.
* *
* @return 0 or +-1. * @return 0 or +-1.
* @throws Errore * @throws Error
* @since 2012-02-15 * @since 2012-02-15
*/ */
public int signum() throws Errore { public int signum() throws Error {
/* /*
* the case of zero is unique, because no (reduced) vector of surds * the case of zero is unique, because no (reduced) vector of surds
* other than the one element 0 itself can add/subtract to zero. * other than the one element 0 itself can add/subtract to zero.
@ -325,9 +325,9 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* @param val * @param val
* The value to be added to this. * The value to be added to this.
* @return The new value representing this+val. * @return The new value representing this+val.
* @throws Errore * @throws Error
*/ */
public NumeroAvanzatoVec add(final NumeroAvanzatoVec val) throws Errore { public NumeroAvanzatoVec add(final NumeroAvanzatoVec val) throws Error {
NumeroAvanzatoVec sum = new NumeroAvanzatoVec(); NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -352,9 +352,9 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* @param val * @param val
* The value to be added to this. * The value to be added to this.
* @return The new value representing this+val. * @return The new value representing this+val.
* @throws Errore * @throws Error
*/ */
public NumeroAvanzatoVec add(final NumeroAvanzato val) throws Errore { public NumeroAvanzatoVec add(final NumeroAvanzato val) throws Error {
NumeroAvanzatoVec sum = new NumeroAvanzatoVec(); NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -371,9 +371,9 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* @param val * @param val
* The value to be subtracted from this. * The value to be subtracted from this.
* @return The new value representing this-val. * @return The new value representing this-val.
* @throws Errore * @throws Error
*/ */
public NumeroAvanzatoVec subtract(final NumeroAvanzatoVec val) throws Errore { public NumeroAvanzatoVec subtract(final NumeroAvanzatoVec val) throws Error {
NumeroAvanzatoVec sum = new NumeroAvanzatoVec(); NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -391,9 +391,9 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* @param val * @param val
* The value to be subtracted from this. * The value to be subtracted from this.
* @return The new value representing this-val. * @return The new value representing this-val.
* @throws Errore * @throws Error
*/ */
public NumeroAvanzatoVec subtract(final NumeroAvanzato val) throws Errore { public NumeroAvanzatoVec subtract(final NumeroAvanzato val) throws Error {
NumeroAvanzatoVec sum = new NumeroAvanzatoVec(); NumeroAvanzatoVec sum = new NumeroAvanzatoVec();
/* /*
* concatenate the vectors and eliminate common overlaps * concatenate the vectors and eliminate common overlaps
@ -428,10 +428,10 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* Compute the square. * Compute the square.
* *
* @return this value squared. * @return this value squared.
* @throws Errore * @throws Error
* @since 2012-02-15 * @since 2012-02-15
*/ */
public NumeroAvanzatoVec sqr() throws Errore { public NumeroAvanzatoVec sqr() throws Error {
/* /*
* Binomial expansion. First the sum of the terms squared, then 2 times * Binomial expansion. First the sum of the terms squared, then 2 times
* the mixed products. * the mixed products.
@ -452,10 +452,10 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
* @param val * @param val
* a second number of this type. * a second number of this type.
* @return the product of this with the val. * @return the product of this with the val.
* @throws Errore * @throws Error
* @since 2011-02-12 * @since 2011-02-12
*/ */
public NumeroAvanzatoVec multiply(final NumeroAvanzato val) throws Errore { public NumeroAvanzatoVec multiply(final NumeroAvanzato val) throws Error {
NumeroAvanzatoVec resul = new NumeroAvanzatoVec(); NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
for (NumeroAvanzato s : terms) for (NumeroAvanzato s : terms)
resul.terms.add(s.multiply(val)); resul.terms.add(s.multiply(val));
@ -463,7 +463,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
return resul; return resul;
} /* multiply */ } /* multiply */
public NumeroAvanzatoVec multiply(final NumeroAvanzatoVec val) throws Errore { public NumeroAvanzatoVec multiply(final NumeroAvanzatoVec val) throws Error {
NumeroAvanzatoVec resul = new NumeroAvanzatoVec(); NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
for (NumeroAvanzato s : terms) { for (NumeroAvanzato s : terms) {
for (NumeroAvanzato s2 : val.terms) { for (NumeroAvanzato s2 : val.terms) {
@ -473,7 +473,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
return resul; return resul;
} /* multiply */ } /* multiply */
public NumeroAvanzatoVec divide(final NumeroAvanzato val) throws Errore { public NumeroAvanzatoVec divide(final NumeroAvanzato val) throws Error {
NumeroAvanzatoVec resul = new NumeroAvanzatoVec(); NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
for (NumeroAvanzato s : terms) { for (NumeroAvanzato s : terms) {
resul.terms.add(s.divide(val)); resul.terms.add(s.divide(val));
@ -482,7 +482,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
return resul; return resul;
} /* divide */ } /* divide */
public NumeroAvanzatoVec divide(final NumeroAvanzatoVec val) throws Errore { public NumeroAvanzatoVec divide(final NumeroAvanzatoVec val) throws Error {
NumeroAvanzatoVec resul = new NumeroAvanzatoVec(); NumeroAvanzatoVec resul = new NumeroAvanzatoVec();
resul.terms = this.terms; resul.terms = this.terms;
for (NumeroAvanzato s : val.terms) { for (NumeroAvanzato s : val.terms) {
@ -523,7 +523,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
for (NumeroAvanzato s : terms) { for (NumeroAvanzato s : terms) {
val = s.isBigInteger(hasBigIntegerVariables); val = s.isBigInteger(hasBigIntegerVariables);
if (val == true) { if (val == true) {
if (s.getIncognitex().count() > 0 || s.getIncognitez().count() > 0) { if (s.getVariableX().count() > 0 || s.getVariableZ().count() > 0) {
val = false; val = false;
} }
} }
@ -625,17 +625,17 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
} else { } else {
s += num; s += num;
} }
s += bs.getIncognitey().toString(); s += bs.getVariableY().toString();
return s; return s;
} else { } else {
BigInteger denominator = BigInteger.ONE; BigInteger denominator = BigInteger.ONE;
Incognite incognitedenom = new Incognite(); Variables incognitedenom = new Variables();
for (int i = 0; i < terms.size(); i++) { for (int i = 0; i < terms.size(); i++) {
denominator = BigIntegerMath.lcm(denominator, terms.elementAt(i).pref.b); denominator = BigIntegerMath.lcm(denominator, terms.elementAt(i).pref.b);
// denominator = // denominator =
// denominator.multiply(terms.elementAt(i).pref.b); // denominator.multiply(terms.elementAt(i).pref.b);
Incognite iz = terms.elementAt(i).getIncognitez(); Variables iz = terms.elementAt(i).getVariableZ();
incognitedenom = Incognite.lcm(incognitedenom, iz); incognitedenom = Variables.lcm(incognitedenom, iz);
} }
String s = ""; String s = "";
@ -660,7 +660,7 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
} }
s += num; s += num;
} }
s += bs.getIncognitey().toString(); s += bs.getVariableY().toString();
} }
return s; return s;
} }
@ -673,10 +673,10 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
for (int t = 0; t < terms.size(); t++) { for (int t = 0; t < terms.size(); t++) {
NumeroAvanzato bs = terms.elementAt(t).clone(); NumeroAvanzato bs = terms.elementAt(t).clone();
bs = bs.setIncognitey(bs.getIncognitey().divide(bs.getIncognitez())); bs = bs.setVariableY(bs.getVariableY().divide(bs.getVariableZ()));
bs = bs.setIncognitey(bs.getIncognitey().multiply(incognitedenom)); bs = bs.setVariableY(bs.getVariableY().multiply(incognitedenom));
bs = bs.multiply(denominator); bs = bs.multiply(denominator);
bs = bs.setIncognitez(incognitedenom); bs = bs.setVariableZ(incognitedenom);
bs.pref = new Rational(bs.pref.a, BigInteger.ONE); bs.pref = new Rational(bs.pref.a, BigInteger.ONE);
if (bs.signum() > 0 && t > 0) if (bs.signum() > 0 && t > 0)
@ -685,12 +685,12 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
String numb; String numb;
try { try {
numb = bs.toRational(true).a.toString(); numb = bs.toRational(true).a.toString();
} catch (Errore e) { } catch (Error e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
numb = ""; numb = "";
} }
String incognite = bs.getIncognitey().toString(); String incognite = bs.getVariableY().toString();
if (((numb.equals("1") || numb.equals("-1")) == false && incognite.length() > 0) || incognite.length() == 0) { if (((numb.equals("1") || numb.equals("-1")) == false && incognite.length() > 0) || incognite.length() == 0) {
s += numb; s += numb;
} else if (numb.equals("-1")) { } else if (numb.equals("-1")) {
@ -700,16 +700,16 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
} else if (bs.isRational(true) || bs.isTooPreciseRational(true)) { } else if (bs.isRational(true) || bs.isTooPreciseRational(true)) {
try { try {
s += bs.toRational(true).toString(); s += bs.toRational(true).toString();
} catch (Errore e) { } catch (Error e) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
s += bs.getIncognitey().toString(); s += bs.getVariableY().toString();
} else { } else {
BigInteger numerator = bs.pref.numer(); BigInteger numerator = bs.pref.numer();
if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getIncognitey().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getIncognitex().count() > 0)) { if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getVariableY().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getVariableX().count() > 0)) {
if (((bs.getIncognitey().count() > 0) || (bs.getIncognitey().count() == 0 && numerator.toString().length() > 0))) { if (((bs.getVariableY().count() > 0) || (bs.getVariableY().count() == 0 && numerator.toString().length() > 0))) {
if ((bs.getIncognitey().count() > 0 && (numerator.toString().equals("1") || numerator.toString().equals("-1")) == false) || bs.getIncognitey().count() == 0) { if ((bs.getVariableY().count() > 0 && (numerator.toString().equals("1") || numerator.toString().equals("-1")) == false) || bs.getVariableY().count() == 0) {
s += numerator.toString(); s += numerator.toString();
} else if (numerator.toString().equals("-1")) { } else if (numerator.toString().equals("-1")) {
s += "-"; s += "-";
@ -717,27 +717,27 @@ public class NumeroAvanzatoVec implements Comparable<NumeroAvanzatoVec> {
} }
// s += "("; // s += "(";
} }
if (bs.disc.isInteger() && bs.getIncognitex().count() == 0) { if (bs.disc.isInteger() && bs.getVariableX().count() == 0) {
s += "Ⓐ("; s += "Ⓐ(";
s += bs.disc.toString(); s += bs.disc.toString();
s += ")"; s += ")";
} else if ((bs.disc.toString().equals("1") || bs.disc.toString().equals("-1")) && bs.getIncognitex().count() > 0) { } else if ((bs.disc.toString().equals("1") || bs.disc.toString().equals("-1")) && bs.getVariableX().count() > 0) {
s += "Ⓐ("; s += "Ⓐ(";
if (bs.disc.toString().equals("-1")) { if (bs.disc.toString().equals("-1")) {
s += "-"; s += "-";
} }
s += bs.getIncognitex().toString(); s += bs.getVariableX().toString();
s += ")"; s += ")";
} else { } else {
s += "Ⓐ(" + bs.disc.toString() + bs.getIncognitex().toString() + ")"; s += "Ⓐ(" + bs.disc.toString() + bs.getVariableX().toString() + ")";
} }
if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getIncognitey().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getIncognitex().count() > 0)) { if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getVariableY().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getVariableX().count() > 0)) {
if (((bs.getIncognitey().count() > 0) || (bs.getIncognitey().count() == 0 && numerator.toString().length() > 0))) { if (((bs.getVariableY().count() > 0) || (bs.getVariableY().count() == 0 && numerator.toString().length() > 0))) {
s += bs.getIncognitey().toString(); s += bs.getVariableY().toString();
} }
// s += "("; // s += "(";
} }
if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getIncognitey().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getIncognitex().count() > 0)) { if ((numerator.compareTo(BigInteger.ONE) != 0 || bs.getVariableY().count() > 0) && (bs.disc.compareTo(BigInteger.ONE) != 0 || bs.getVariableX().count() > 0)) {
// s += ")"; // s += ")";
} }
} }

View File

@ -7,7 +7,7 @@ import java.util.Random;
import java.util.Scanner; import java.util.Scanner;
import java.util.Vector; import java.util.Vector;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* A one-parameter polynomial with rational coefficients. * A one-parameter polynomial with rational coefficients.
@ -75,10 +75,10 @@ class RatPoly {
* the list of values in the denominator of AFB * the list of values in the denominator of AFB
* @param nmax * @param nmax
* the order of the truncated polynomial representation * the order of the truncated polynomial representation
* @throws Errore * @throws Error
* @since 2008-11-13 * @since 2008-11-13
*/ */
public RatPoly(final Vector<BigInteger> A, final Vector<BigInteger> B, int nmax) throws Errore { public RatPoly(final Vector<BigInteger> A, final Vector<BigInteger> B, int nmax) throws Error {
/* /*
* To allow common initialization with the signature below, * To allow common initialization with the signature below,
* the main body is assembled in a separate function. * the main body is assembled in a separate function.
@ -96,10 +96,10 @@ class RatPoly {
* the order of the new polynomial. * the order of the new polynomial.
* @param B * @param B
* the list of values in the denominator of AFB * the list of values in the denominator of AFB
* @throws Errore * @throws Error
* @since 2009-08-05 * @since 2009-08-05
*/ */
public RatPoly(final Vector<BigInteger> A, final Vector<BigInteger> B) throws Errore { public RatPoly(final Vector<BigInteger> A, final Vector<BigInteger> B) throws Error {
BigInteger Nmax = BigInteger.ONE.negate(); BigInteger Nmax = BigInteger.ONE.negate();
for (int j = 0; j < A.size(); j++) { for (int j = 0; j < A.size(); j++) {
if (A.elementAt(j).compareTo(BigInteger.ZERO) <= 0) { if (A.elementAt(j).compareTo(BigInteger.ZERO) <= 0) {
@ -125,10 +125,10 @@ class RatPoly {
* the list of values in the denominator of AFB * the list of values in the denominator of AFB
* @param nmax * @param nmax
* the order of the truncated polynomial representation * the order of the truncated polynomial representation
* @throws Errore * @throws Error
* @since 2008-11-13 * @since 2008-11-13
*/ */
protected void init(final Vector<BigInteger> A, final Vector<BigInteger> B, int nmax) throws Errore { protected void init(final Vector<BigInteger> A, final Vector<BigInteger> B, int nmax) throws Error {
a = new Vector<Rational>(); a = new Vector<Rational>();
Factorial f = new Factorial(); Factorial f = new Factorial();
for (int n = 0; n <= nmax; n++) { for (int n = 0; n <= nmax; n++) {
@ -433,10 +433,10 @@ class RatPoly {
* @param r * @param r
* the exponent of the power * the exponent of the power
* @return This^r . * @return This^r .
* @throws Errore * @throws Error
* @since 2009-05-18 * @since 2009-05-18
*/ */
public RatPoly pow(final Rational r) throws ArithmeticException, Errore { public RatPoly pow(final Rational r) throws ArithmeticException, Error {
/* /*
* split (a0+a1*x+a2*x^2+...)^r = a0^r*(1+a1/a0*r+a2/a0*r^2+..)^r * split (a0+a1*x+a2*x^2+...)^r = a0^r*(1+a1/a0*r+a2/a0*r^2+..)^r
*/ */
@ -520,10 +520,10 @@ class RatPoly {
* @param val * @param val
* the constant through which the coefficients will be divided. * the constant through which the coefficients will be divided.
* @return the Taylor expansion of this/val . * @return the Taylor expansion of this/val .
* @throws Errore * @throws Error
* @since 2009-05-18 * @since 2009-05-18
*/ */
public RatPoly divide(final Rational val) throws Errore { public RatPoly divide(final Rational val) throws Error {
if (val.compareTo(Rational.ZERO) != 0) { if (val.compareTo(Rational.ZERO) != 0) {
RatPoly resul = new RatPoly(); RatPoly resul = new RatPoly();
for (int n = 0; n < a.size(); n++) for (int n = 0; n < a.size(); n++)
@ -541,9 +541,9 @@ class RatPoly {
* @param nmax * @param nmax
* the maximum degree of the Taylor expansion of the result. * the maximum degree of the Taylor expansion of the result.
* @return the Taylor expansion of this/val up to degree nmax. * @return the Taylor expansion of this/val up to degree nmax.
* @throws Errore * @throws Error
*/ */
public RatPoly divide(final RatPoly val, int nmax) throws Errore { public RatPoly divide(final RatPoly val, int nmax) throws Error {
RatPoly num = this; RatPoly num = this;
RatPoly denom = val; RatPoly denom = val;
@ -583,10 +583,10 @@ class RatPoly {
* difference of thisdegree and the degree of val. [1] the remainder * difference of thisdegree and the degree of val. [1] the remainder
* polynomial. * polynomial.
* This = returnvalue[0] + returnvalue[1]/val . * This = returnvalue[0] + returnvalue[1]/val .
* @throws Errore * @throws Error
* @since 2012-03-01 * @since 2012-03-01
*/ */
public RatPoly[] divideAndRemainder(final RatPoly val) throws Errore { public RatPoly[] divideAndRemainder(final RatPoly val) throws Error {
RatPoly[] ret = new RatPoly[2]; RatPoly[] ret = new RatPoly[2];
/* /*
* remove any high-order zeros * remove any high-order zeros
@ -738,10 +738,10 @@ class RatPoly {
* degree is unity. * degree is unity.
* *
* @return The scaled polynomial * @return The scaled polynomial
* @throws Errore * @throws Error
* @since 2008-10-26 * @since 2008-10-26
*/ */
public RatPoly monic() throws Errore { public RatPoly monic() throws Error {
RatPoly m = new RatPoly(); RatPoly m = new RatPoly();
final int d = degree(); final int d = degree();
for (int i = 0; i <= d; i++) { for (int i = 0; i <= d; i++) {
@ -879,10 +879,10 @@ class RatPoly {
* Kerner method</a> * Kerner method</a>
* @param the * @param the
* number of floating point digits * number of floating point digits
* @throws Errore * @throws Error
* @since 2008-10-26 * @since 2008-10-26
*/ */
public Vector<BigComplex> roots(int digits) throws Errore { public Vector<BigComplex> roots(int digits) throws Error {
RatPoly mon = monic(); RatPoly mon = monic();
Random rand = new Random(); Random rand = new Random();

View File

@ -5,8 +5,8 @@ import java.math.BigInteger;
import java.math.MathContext; import java.math.MathContext;
import java.math.RoundingMode; import java.math.RoundingMode;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Errori; import org.warp.picalculator.Errors;
/** /**
* Fractions (rational numbers). They are divisions of two BigInteger numbers, * Fractions (rational numbers). They are divisions of two BigInteger numbers,
@ -232,15 +232,15 @@ public class Rational implements Cloneable, Comparable<Rational> {
* the exponent. * the exponent.
* @return this value raised to the power given by the exponent. If the * @return this value raised to the power given by the exponent. If the
* exponent is 0, the value 1 is returned. * exponent is 0, the value 1 is returned.
* @throws Errore * @throws Error
* @since 2009-05-18 * @since 2009-05-18
*/ */
public Rational pow(BigInteger exponent) throws Errore { public Rational pow(BigInteger exponent) throws Error {
/* test for overflow */ /* test for overflow */
if (exponent.compareTo(MAX_INT) == 1) if (exponent.compareTo(MAX_INT) == 1)
throw new Errore(Errori.NUMBER_TOO_LARGE); throw new Error(Errors.NUMBER_TOO_LARGE);
if (exponent.compareTo(MIN_INT) == -1) if (exponent.compareTo(MIN_INT) == -1)
throw new Errore(Errori.NUMBER_TOO_SMALL); throw new Error(Errors.NUMBER_TOO_SMALL);
/* promote to the simpler interface above */ /* promote to the simpler interface above */
return pow(exponent.intValue()); return pow(exponent.intValue());
@ -254,20 +254,20 @@ public class Rational implements Cloneable, Comparable<Rational> {
* third root etc * third root etc
* @return this value raised to the inverse power given by the root * @return this value raised to the inverse power given by the root
* argument, this^(1/r). * argument, this^(1/r).
* @throws Errore * @throws Error
* @since 2009-05-18 * @since 2009-05-18
*/ */
public Rational root(BigInteger r) throws Errore { public Rational root(BigInteger r) throws Error {
/* test for overflow */ /* test for overflow */
if (r.compareTo(MAX_INT) == 1) if (r.compareTo(MAX_INT) == 1)
throw new Errore(Errori.NUMBER_TOO_LARGE); throw new Error(Errors.NUMBER_TOO_LARGE);
if (r.compareTo(MIN_INT) == -1) if (r.compareTo(MIN_INT) == -1)
throw new Errore(Errori.NUMBER_TOO_SMALL); throw new Error(Errors.NUMBER_TOO_SMALL);
int rthroot = r.intValue(); int rthroot = r.intValue();
/* cannot pull root of a negative value with even-valued root */ /* cannot pull root of a negative value with even-valued root */
if (compareTo(ZERO) == -1 && (rthroot % 2) == 0) if (compareTo(ZERO) == -1 && (rthroot % 2) == 0)
throw new Errore(Errori.NEGATIVE_PARAMETER); throw new Error(Errors.NEGATIVE_PARAMETER);
/* /*
* extract a sign such that we calculate |n|^(1/r), still r carrying any * extract a sign such that we calculate |n|^(1/r), still r carrying any
@ -294,10 +294,10 @@ public class Rational implements Cloneable, Comparable<Rational> {
* The exponent. * The exponent.
* @return This value raised to the power given by the exponent. If the * @return This value raised to the power given by the exponent. If the
* exponent is 0, the value 1 is returned. * exponent is 0, the value 1 is returned.
* @throws Errore * @throws Error
* @since 2009-05-18 * @since 2009-05-18
*/ */
public Rational pow(Rational exponent) throws Errore { public Rational pow(Rational exponent) throws Error {
if (exponent.a.compareTo(BigInteger.ZERO) == 0) if (exponent.a.compareTo(BigInteger.ZERO) == 0)
return new Rational(1, 1); return new Rational(1, 1);
@ -315,11 +315,11 @@ public class Rational implements Cloneable, Comparable<Rational> {
* @param val * @param val
* A second rational number. * A second rational number.
* @return The value of this/val * @return The value of this/val
* @throws Errore * @throws Error
*/ */
public Rational divide(final Rational val) throws Errore { public Rational divide(final Rational val) throws Error {
if (val.compareTo(Rational.ZERO) == 0) if (val.compareTo(Rational.ZERO) == 0)
throw new Errore(Errori.DIVISION_BY_ZERO); throw new Error(Errors.DIVISION_BY_ZERO);
BigInteger num = a.multiply(val.b); BigInteger num = a.multiply(val.b);
BigInteger deno = b.multiply(val.a); BigInteger deno = b.multiply(val.a);
/* /*
@ -335,11 +335,11 @@ public class Rational implements Cloneable, Comparable<Rational> {
* @param val * @param val
* a second number. * a second number.
* @return the value of this/val * @return the value of this/val
* @throws Errore * @throws Error
*/ */
public Rational divide(BigInteger val) throws Errore { public Rational divide(BigInteger val) throws Error {
if (val.compareTo(BigInteger.ZERO) == 0) if (val.compareTo(BigInteger.ZERO) == 0)
throw new Errore(Errori.DIVISION_BY_ZERO); throw new Error(Errors.DIVISION_BY_ZERO);
Rational val2 = new Rational(val, BigInteger.ONE); Rational val2 = new Rational(val, BigInteger.ONE);
return (divide(val2)); return (divide(val2));
} /* Rational.divide */ } /* Rational.divide */
@ -350,11 +350,11 @@ public class Rational implements Cloneable, Comparable<Rational> {
* @param val * @param val
* A second number. * A second number.
* @return The value of this/val * @return The value of this/val
* @throws Errore * @throws Error
*/ */
public Rational divide(int val) throws Errore { public Rational divide(int val) throws Error {
if (val == 0) if (val == 0)
throw new Errore(Errori.DIVISION_BY_ZERO); throw new Error(Errors.DIVISION_BY_ZERO);
Rational val2 = new Rational(val, 1); Rational val2 = new Rational(val, 1);
return (divide(val2)); return (divide(val2));
} /* Rational.divide */ } /* Rational.divide */
@ -452,9 +452,9 @@ public class Rational implements Cloneable, Comparable<Rational> {
* @return the binomial coefficient. * @return the binomial coefficient.
* @since 2006-06-27 * @since 2006-06-27
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
public static Rational binomial(Rational n, BigInteger m) throws Errore { public static Rational binomial(Rational n, BigInteger m) throws Error {
if (m.compareTo(BigInteger.ZERO) == 0) if (m.compareTo(BigInteger.ZERO) == 0)
return Rational.ONE; return Rational.ONE;
Rational bin = n; Rational bin = n;
@ -474,9 +474,9 @@ public class Rational implements Cloneable, Comparable<Rational> {
* @return the binomial coefficient. * @return the binomial coefficient.
* @since 2009-05-19 * @since 2009-05-19
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
public static Rational binomial(Rational n, int m) throws Errore { public static Rational binomial(Rational n, int m) throws Error {
if (m == 0) if (m == 0)
return Rational.ONE; return Rational.ONE;
Rational bin = n; Rational bin = n;
@ -496,13 +496,13 @@ public class Rational implements Cloneable, Comparable<Rational> {
* @return Gamma(n+k+1/2)/k!/GAMMA(n-k+1/2) * @return Gamma(n+k+1/2)/k!/GAMMA(n-k+1/2)
* @since 2010-07-18 * @since 2010-07-18
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
public static Rational hankelSymb(Rational n, int k) throws Errore { public static Rational hankelSymb(Rational n, int k) throws Error {
if (k == 0) if (k == 0)
return Rational.ONE; return Rational.ONE;
else if (k < 0) else if (k < 0)
throw new Errore(Errori.NEGATIVE_PARAMETER); throw new Error(Errors.NEGATIVE_PARAMETER);
Rational nkhalf = n.subtract(k).add(Rational.HALF); Rational nkhalf = n.subtract(k).add(Rational.HALF);
nkhalf = nkhalf.Pochhammer(2 * k); nkhalf = nkhalf.Pochhammer(2 * k);
Factorial f = new Factorial(); Factorial f = new Factorial();
@ -792,26 +792,26 @@ public class Rational implements Cloneable, Comparable<Rational> {
/** /**
* Conversion to an integer value, if this can be done exactly. * Conversion to an integer value, if this can be done exactly.
* *
* @throws Errore * @throws Error
* *
* @since 2011-02-13 * @since 2011-02-13
*/ */
int intValue() throws Errore { int intValue() throws Error {
if (!isInteger()) if (!isInteger())
throw new Errore(Errori.CONVERSION_ERROR); throw new Error(Errors.CONVERSION_ERROR);
return a.intValue(); return a.intValue();
} }
/** /**
* Conversion to a BigInteger value, if this can be done exactly. * Conversion to a BigInteger value, if this can be done exactly.
* *
* @throws Errore * @throws Error
* *
* @since 2012-03-02 * @since 2012-03-02
*/ */
BigInteger BigIntegerValue() throws Errore { BigInteger BigIntegerValue() throws Error {
if (!isBigInteger()) if (!isBigInteger())
throw new Errore(Errori.CONVERSION_ERROR); throw new Error(Errors.CONVERSION_ERROR);
return a; return a;
} }

View File

@ -3,7 +3,7 @@ package org.nevec.rjm;
import java.math.BigInteger; import java.math.BigInteger;
import java.util.Scanner; import java.util.Scanner;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* Exact representations of Wigner 3jm and 3nj values of half-integer arguments. * Exact representations of Wigner 3jm and 3nj values of half-integer arguments.
@ -32,9 +32,9 @@ public class Wigner3j {
* *
* @since 2011-02-15 * @since 2011-02-15
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static public void main(String args[]) throws Errore { static public void main(String args[]) throws Error {
if (args[0].compareTo("6j") == 0) { if (args[0].compareTo("6j") == 0) {
try { try {
String m1 = "6"; String m1 = "6";
@ -105,9 +105,9 @@ public class Wigner3j {
* inequalities is violated or some parameters are out of range. * inequalities is violated or some parameters are out of range.
* @since 2011-02-13 * @since 2011-02-13
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static public BigSurd wigner3jm(int j1, int j2, int j3, int m1, int m2, int m3) throws Errore { static public BigSurd wigner3jm(int j1, int j2, int j3, int m1, int m2, int m3) throws Error {
Rational J1 = new Rational(j1, 2); Rational J1 = new Rational(j1, 2);
Rational J2 = new Rational(j2, 2); Rational J2 = new Rational(j2, 2);
Rational J3 = new Rational(j3, 2); Rational J3 = new Rational(j3, 2);
@ -140,9 +140,9 @@ public class Wigner3j {
* @since 2011-02-13 * @since 2011-02-13
* @since 2012-02-15 Upgraded return value to BigSurdVec * @since 2012-02-15 Upgraded return value to BigSurdVec
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static public BigSurdVec wigner3j(String m1, String t1, String t2, String j) throws Errore { static public BigSurdVec wigner3j(String m1, String t1, String t2, String j) throws Error {
/* /*
* The first number in the line "m" is the number of angular momenta. * The first number in the line "m" is the number of angular momenta.
* The rest of the line is ignored. * The rest of the line is ignored.
@ -270,10 +270,10 @@ public class Wigner3j {
* @since 2011-02-13 * @since 2011-02-13
* @since 2012-02-15 Upgraded to return BigSurdVec * @since 2012-02-15 Upgraded to return BigSurdVec
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static private BigSurdVec wigner3j(final int[] tvec, final Rational[] J, final Rational[] M, final int[] triadidx) static private BigSurdVec wigner3j(final int[] tvec, final Rational[] J, final Rational[] M, final int[] triadidx)
throws Errore { throws Error {
/* /*
* The result of the computation. The sum over all m-combinations of the * The result of the computation. The sum over all m-combinations of the
* triads. * triads.
@ -480,10 +480,10 @@ public class Wigner3j {
* inequalities is violated or some parameters are out of range. * inequalities is violated or some parameters are out of range.
* @since 2011-02-13 * @since 2011-02-13
* @author Richard J. Mathar * @author Richard J. Mathar
* @throws Errore * @throws Error
*/ */
static protected BigSurd wigner3jm(Rational j1, Rational j2, Rational j3, Rational m1, Rational m2, Rational m3) static protected BigSurd wigner3jm(Rational j1, Rational j2, Rational j3, Rational m1, Rational m2, Rational m3)
throws Errore { throws Error {
/* /*
* Check that m1+m2+m3 = 0 * Check that m1+m2+m3 = 0
*/ */

View File

@ -16,7 +16,7 @@ import javax.swing.JList;
import javax.swing.event.ListSelectionEvent; import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener; import javax.swing.event.ListSelectionListener;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
/** /**
* An interactive interface to the Wigner3j class. The GUI allows to preselect * An interactive interface to the Wigner3j class. The GUI allows to preselect
@ -134,10 +134,10 @@ public class Wigner3jGUI implements ActionListener, ListSelectionListener {
} /* init */ } /* init */
/** /**
* @throws Errore * @throws Error
* @since 2010-08-27 * @since 2010-08-27
*/ */
public void compute() throws Errore { public void compute() throws Error {
String tr = inpGtria.getText(); String tr = inpGtria.getText();
String[] trias = new String[4]; String[] trias = new String[4];
@ -211,7 +211,7 @@ public class Wigner3jGUI implements ActionListener, ListSelectionListener {
outG.setText(""); outG.setText("");
try { try {
compute(); compute();
} catch (Errore e1) { } catch (Error e1) {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e1.printStackTrace(); e1.printStackTrace();
} }

View File

@ -25,7 +25,8 @@ public class Keyboard {
private static final int QH_pin = 40; private static final int QH_pin = 40;
private static final int CLK_INH_pin = 33; private static final int CLK_INH_pin = 33;
private static boolean[][] precedentStates = new boolean[8][8]; private static volatile boolean[][] precedentStates = new boolean[8][8];
public static volatile boolean[][] debugKeysDown = new boolean[8][8];
public static void startKeyboard() { public static void startKeyboard() {
if (Utils.debugOn == false) { if (Utils.debugOn == false) {
@ -75,7 +76,11 @@ public class Keyboard {
} }
public static boolean isKeyDown(int row, int col) { public static boolean isKeyDown(int row, int col) {
return precedentStates[row][col]; if (Utils.debugOn == false) {
return precedentStates[row-1][col-1];
} else {
return debugKeysDown[row-1][col-1];
}
} }
private static void keyReleasedRaw(int row, int col) { private static void keyReleasedRaw(int row, int col) {
@ -84,7 +89,7 @@ public class Keyboard {
} }
} }
private static void keyPressedRaw(int row, int col) { static void keyPressedRaw(int row, int col) {
if (row == 1 && col == 1) { if (row == 1 && col == 1) {
keyPressed(Key.SHIFT); keyPressed(Key.SHIFT);
} else if (row == 1 && col == 2) { } else if (row == 1 && col == 2) {

View File

@ -1,15 +1,6 @@
package org.warp.device; package org.warp.device;
import static org.warp.engine.Display.Render.getMatrixOfImage; import static org.warp.engine.Display.Render.*;
import static org.warp.engine.Display.Render.glClear;
import static org.warp.engine.Display.Render.glColor3f;
import static org.warp.engine.Display.Render.glColor4f;
import static org.warp.engine.Display.Render.glDrawLine;
import static org.warp.engine.Display.Render.glDrawSkin;
import static org.warp.engine.Display.Render.glDrawStringCenter;
import static org.warp.engine.Display.Render.glDrawStringLeft;
import static org.warp.engine.Display.Render.glDrawStringRight;
import static org.warp.engine.Display.Render.setFont;
import java.awt.image.BufferedImage; import java.awt.image.BufferedImage;
import java.io.IOException; import java.io.IOException;
@ -203,6 +194,8 @@ public final class PIDisplay {
} }
private void draw_status() { private void draw_status() {
glColor3f(204, 231, 212);
glFillRect(0, 0, Main.screenSize[0], 20);
glColor3f(0, 0, 0); glColor3f(0, 0, 0);
glDrawLine(0, 20, Main.screenSize[0]-1, 20); glDrawLine(0, 20, Main.screenSize[0]-1, 20);
glColor3f(0, 0, 0); glColor3f(0, 0, 0);
@ -317,8 +310,8 @@ public final class PIDisplay {
colore(0.0f, 0.0f, 0.0f, 0.5f); colore(0.0f, 0.0f, 0.0f, 0.5f);
glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 22, "PLEASE WAIT..."); glDrawStringCenter((Main.screenSize[0] / 2), (Main.screenSize[1]/ 2) + 22, "PLEASE WAIT...");
} else { } else {
draw_status();
draw_screen(); draw_screen();
draw_status();
draw_bottom(); draw_bottom();
} }
} }

View File

@ -103,6 +103,9 @@ public class PIFrame extends JFrame {
} else { } else {
Keyboard.keyPressed(Key.NONE); Keyboard.keyPressed(Key.NONE);
} }
int row = 2;
int col = 1;
Keyboard.debugKeysDown[row-1][col-1] = true;
break; break;
case KeyEvent.VK_1: case KeyEvent.VK_1:
if (!Keyboard.shift && !Keyboard.alpha) { if (!Keyboard.shift && !Keyboard.alpha) {
@ -223,6 +226,10 @@ public class PIFrame extends JFrame {
} }
break; break;
case KeyEvent.VK_LEFT: case KeyEvent.VK_LEFT:
//LEFT
row = 2;
col = 3;
Keyboard.debugKeysDown[row-1][col-1] = true;
if (!Keyboard.shift && !Keyboard.alpha) { if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.LEFT); Keyboard.keyPressed(Key.LEFT);
} else { } else {
@ -230,6 +237,10 @@ public class PIFrame extends JFrame {
} }
break; break;
case KeyEvent.VK_RIGHT: case KeyEvent.VK_RIGHT:
//RIGHT
row = 2;
col = 5;
Keyboard.debugKeysDown[row-1][col-1] = true;
if (!Keyboard.shift && !Keyboard.alpha) { if (!Keyboard.shift && !Keyboard.alpha) {
Keyboard.keyPressed(Key.RIGHT); Keyboard.keyPressed(Key.RIGHT);
} else { } else {
@ -315,6 +326,9 @@ public class PIFrame extends JFrame {
} else { } else {
Keyboard.keyReleased(Key.NONE); Keyboard.keyReleased(Key.NONE);
} }
int row = 2;
int col = 1;
Keyboard.debugKeysDown[row-1][col-1] = false;
break; break;
case KeyEvent.VK_1: case KeyEvent.VK_1:
if (!Keyboard.shift && !Keyboard.alpha) { if (!Keyboard.shift && !Keyboard.alpha) {
@ -357,6 +371,16 @@ public class PIFrame extends JFrame {
case KeyEvent.VK_A: case KeyEvent.VK_A:
Keyboard.keyReleased(Key.ALPHA); Keyboard.keyReleased(Key.ALPHA);
break; break;
case KeyEvent.VK_LEFT:
//LEFT
row = 2;
col = 3;
Keyboard.debugKeysDown[row-1][col-1] = false;
case KeyEvent.VK_RIGHT:
//RIGHT
row = 2;
col = 5;
Keyboard.debugKeysDown[row-1][col-1] = false;
} }
} }

View File

@ -147,22 +147,56 @@ public class Display {
public static void glDrawSkin(int skinwidth, int[] skin, int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) { public static void glDrawSkin(int skinwidth, int[] skin, int x0, int y0, int s0, int t0, int s1, int t1, boolean transparent) {
x0+=Main.screenPos[0]; x0+=Main.screenPos[0];
y0+=Main.screenPos[1]; y0+=Main.screenPos[1];
int oldColor;
int newColor;
int onex = s0 <= s1?1:-1;
int oney = t0 <= t1?1:-1;
int width = 0;
int height = 0;
if (onex == -1) {
int s00 = s0;
s0 = s1;
s1 = s00;
width = s1-s0;
}
if (oney == -1) {
int t00 = t0;
t0 = t1;
t1 = t00;
height = t1-t0;
}
if (x0 >= size[0] || y0 >= size[0]) { if (x0 >= size[0] || y0 >= size[0]) {
return; return;
} }
if (x0 + (s1-s0) >= size[0]) { if (x0 + width >= size[0]) {
s1 = size[0] - x0 + s0; s1 = size[0] - x0 + s0;
} }
if (y0 + (t1-t0) >= size[1]) { if (y0 + height >= size[1]) {
t1 = size[1] - y0 + t0; t1 = size[1] - y0 + t0;
} }
int oldColor; if (x0 < 0) {
int newColor; if (onex == -1) {
width += x0;
s1 += x0 + 1;
} else {
s0 -= x0;
}
x0 = 0;
}
if (y0 < 0) {
if (oney == -1) {
height += y0;
t1 += y0 + 1;
} else {
t0 -= y0;
}
y0 = 0;
}
for (int texx = 0; texx < s1 - s0; texx++) { for (int texx = 0; texx < s1 - s0; texx++) {
for (int texy = 0; texy < t1 - t0; texy++) { for (int texy = 0; texy < t1 - t0; texy++) {
newColor = skin[(s0 + texx) + (t0 + texy) * skinwidth]; newColor = skin[(s0 + texx) + (t0 + texy) * skinwidth];
if (transparent) { if (transparent) {
oldColor = canvas2d[(x0 + texx) + (y0 + texy) * size[0]]; oldColor = canvas2d[(x0 + texx*onex + width) + (y0 + texy*oney + height) * size[0]];
float a2 = ((float)(newColor >> 24 & 0xFF)) / 255f; float a2 = ((float)(newColor >> 24 & 0xFF)) / 255f;
float a1 = 1f-a2; float a1 = 1f-a2;
int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2); int r = (int) ((oldColor >> 16 & 0xFF) * a1 + (newColor >> 16 & 0xFF) * a2);
@ -170,7 +204,7 @@ public class Display {
int b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2); int b = (int) ((oldColor & 0xFF) * a1 + (newColor & 0xFF) * a2);
newColor = 0xFF000000 | r << 16 | g << 8 | b; newColor = 0xFF000000 | r << 16 | g << 8 | b;
} }
canvas2d[(x0 + texx) + (y0 + texy) * size[0]] = newColor; canvas2d[(x0 + texx*onex + width) + (y0 + texy*oney + height) * size[0]] = newColor;
} }
} }
} }

View File

@ -9,37 +9,37 @@ import org.warp.engine.Display;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunzioneAnteriore implements Funzione { public abstract class AnteriorFunction implements Function {
public FunzioneAnteriore(Funzione value) { public AnteriorFunction(Function value) {
setVariable(value); setVariable(value);
} }
protected Funzione variable = new Termine(NumeroAvanzatoVec.ZERO); protected Function variable = new Number(NumeroAvanzatoVec.ZERO);
protected int width; protected int width;
protected int height; protected int height;
protected int line; protected int line;
protected boolean small; protected boolean small;
public Funzione getVariable() { public Function getVariable() {
return variable; return variable;
} }
public void setVariable(Funzione value) { public void setVariable(Function value) {
variable = value; variable = value;
} }
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Funzione calcola() throws Errore; public abstract Function solve() throws Error;
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable.setSmall(small); variable.setSmall(small);
variable.calcolaGrafica(); variable.generateGraphics();
width = getStringWidth(simbolo()) + 1 + getVariable().getWidth(); width = getStringWidth(getSymbol()) + 1 + getVariable().getWidth();
height = variable.getHeight(); height = variable.getHeight();
line = variable.getLine(); line = variable.getLine();
} }
@ -47,7 +47,7 @@ public abstract class FunzioneAnteriore implements Funzione {
@Override @Override
public void draw(int x, int y) { public void draw(int x, int y) {
float h1 = getVariable().getHeight(); float h1 = getVariable().getHeight();
int wsegno = getStringWidth(simbolo()); int wsegno = getStringWidth(getSymbol());
float hsegno = Utils.getFontHeight(small); float hsegno = Utils.getFontHeight(small);
float maxh = getHeight(); float maxh = getHeight();
if (small) { if (small) {
@ -56,7 +56,7 @@ public abstract class FunzioneAnteriore implements Funzione {
Display.Render.setFont(PIDisplay.fonts[0]); Display.Render.setFont(PIDisplay.fonts[0]);
} }
glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), simbolo()); glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), getSymbol());
getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2)); getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2));
} }
@ -78,14 +78,14 @@ public abstract class FunzioneAnteriore implements Funzione {
@Override @Override
public String toString() { public String toString() {
try { try {
return calcola().toString(); return solve().toString();
} catch (Errore e) { } catch (Error e) {
return e.id.toString(); return e.id.toString();
} }
} }
@Override @Override
public FunzioneAnteriore clone() { public AnteriorFunction clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }

View File

@ -9,37 +9,37 @@ import org.warp.engine.Display;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunzioneAnterioreBase extends FunzioneBase { public abstract class AnteriorFunctionBase extends FunctionBase {
public FunzioneAnterioreBase(FunzioneBase value) { public AnteriorFunctionBase(FunctionBase value) {
setVariable(value); setVariable(value);
} }
protected FunzioneBase variable = new Termine(NumeroAvanzatoVec.ZERO); protected FunctionBase variable = new Number(NumeroAvanzatoVec.ZERO);
protected int width; protected int width;
protected int height; protected int height;
protected int line; protected int line;
protected boolean small; protected boolean small;
public FunzioneBase getVariable() { public FunctionBase getVariable() {
return variable; return variable;
} }
public void setVariable(FunzioneBase value) { public void setVariable(FunctionBase value) {
variable = value; variable = value;
} }
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Termine calcola() throws Errore; public abstract Number solve() throws Error;
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable.setSmall(small); variable.setSmall(small);
variable.calcolaGrafica(); variable.generateGraphics();
width = getStringWidth(simbolo()) + 1 + getVariable().getWidth(); width = getStringWidth(getSymbol()) + 1 + getVariable().getWidth();
height = variable.getHeight(); height = variable.getHeight();
line = variable.getLine(); line = variable.getLine();
} }
@ -47,7 +47,7 @@ public abstract class FunzioneAnterioreBase extends FunzioneBase {
@Override @Override
public void draw(int x, int y) { public void draw(int x, int y) {
float h1 = getVariable().getHeight(); float h1 = getVariable().getHeight();
int wsegno = getStringWidth(simbolo()); int wsegno = getStringWidth(getSymbol());
float hsegno = Utils.getFontHeight(small); float hsegno = Utils.getFontHeight(small);
float maxh = getHeight(); float maxh = getHeight();
if (small) { if (small) {
@ -56,7 +56,7 @@ public abstract class FunzioneAnterioreBase extends FunzioneBase {
Display.Render.setFont(PIDisplay.fonts[0]); Display.Render.setFont(PIDisplay.fonts[0]);
} }
glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), simbolo()); glDrawStringLeft(x, (int) Math.floor(y + (maxh - hsegno) / 2), getSymbol());
getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2)); getVariable().draw(x + wsegno + 1, (int) Math.floor(y + (maxh - h1) / 2));
} }
@ -78,14 +78,14 @@ public abstract class FunzioneAnterioreBase extends FunzioneBase {
@Override @Override
public String toString() { public String toString() {
try { try {
return calcola().toString(); return solve().toString();
} catch (Errore e) { } catch (Error e) {
return e.id.toString(); return e.id.toString();
} }
} }
@Override @Override
public FunzioneAnterioreBase clone() { public AnteriorFunctionBase clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }

View File

@ -13,61 +13,61 @@ public class Calculator {
public static int currentSession = 0; public static int currentSession = 0;
public static boolean haxMode = true; public static boolean haxMode = true;
public static Termine calcolarisultato(String string) throws Errore { public static Number solveResult(String string) throws Error {
System.out.println("INPUT: " + string); System.out.println("INPUT: " + string);
Espressione espressione = new Espressione(string); Expression expression = new Expression(string);
return espressione.calcola(); return expression.solve();
} }
public static Funzione interpreta(String string) throws Errore { public static Function parseString(String string) throws Error {
if (string.contains("{")) { if (string.contains("{")) {
if (!string.startsWith("{")) { if (!string.startsWith("{")) {
throw new Errore(Errori.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
String[] parts = string.substring(1).split("\\{"); String[] parts = string.substring(1).split("\\{");
Sistema s = new Sistema(); EquationsSystem s = new EquationsSystem();
for (String part : parts) { for (String part : parts) {
s.addVariableToEnd(interpretaEquazione(part)); s.addVariableToEnd(parseEquationString(part));
} }
return s; return s;
} else if (string.contains("=")) { } else if (string.contains("=")) {
return interpretaEquazione(string); return parseEquationString(string);
} else { } else {
return new Espressione(string); return new Expression(string);
} }
} }
public static Funzione interpretaEquazione(String string) throws Errore { public static Function parseEquationString(String string) throws Error {
String[] parts = string.split("="); String[] parts = string.split("=");
if (parts.length == 1) { if (parts.length == 1) {
return new Equazione(new Espressione(parts[0]), new Termine(NumeroAvanzato.ZERO)); return new Equation(new Expression(parts[0]), new Number(NumeroAvanzato.ZERO));
} else if (parts.length == 2) { } else if (parts.length == 2) {
return new Equazione(new Espressione(parts[0]), new Espressione(parts[1])); return new Equation(new Expression(parts[0]), new Expression(parts[1]));
} else { } else {
throw new Errore(Errori.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
} }
public static void solve() throws Errore { public static void solve() throws Error {
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) { if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
EquationScreen es = (EquationScreen) Calculator.sessions[0]; EquationScreen es = (EquationScreen) Calculator.sessions[0];
Funzione f = es.f; Function f = es.f;
if (f instanceof Equazione) { if (f instanceof Equation) {
PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es)); PIDisplay.INSTANCE.setScreen(new SolveEquationScreen(es));
} else { } else {
es.f2 = es.f.calcola(); es.f2 = es.f.solve();
es.f2.calcolaGrafica(); es.f2.generateGraphics();
} }
} }
} }
public static void solve(char letter) throws Errore { public static void solve(char letter) throws Error {
if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) { if (Calculator.currentSession == 0 && Calculator.sessions[0] instanceof EquationScreen) {
EquationScreen es = (EquationScreen) Calculator.sessions[0]; EquationScreen es = (EquationScreen) Calculator.sessions[0];
Funzione f = es.f; Function f = es.f;
if (f instanceof Equazione) { if (f instanceof Equation) {
es.f2 = ((Equazione)f).calcola(letter); es.f2 = ((Equation)f).solve(letter);
es.f2.calcolaGrafica(); es.f2.generateGraphics();
} }
} }
} }

View File

@ -9,26 +9,26 @@ import org.nevec.rjm.NumeroAvanzatoVec;
import org.warp.device.PIDisplay; import org.warp.device.PIDisplay;
import org.warp.engine.Display; import org.warp.engine.Display;
public class Divisione extends FunzioneDueValoriBase { public class Division extends FunctionTwoValuesBase {
public Divisione(FunzioneBase value1, FunzioneBase value2) { public Division(FunctionBase value1, FunctionBase value2) {
super(value1, value2); super(value1, value2);
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return Simboli.DIVISION; return MathematicalSymbols.DIVISION;
} }
@Override @Override
public Termine calcola() throws Errore { public Number solve() throws Error {
if (variable2 == null || variable1 == null) { if (variable2 == null || variable1 == null) {
return new Termine("0"); return new Number("0");
} }
if (variable2.calcola().getTerm().compareTo(NumeroAvanzatoVec.ZERO) == 0) { if (variable2.solve().getTerm().compareTo(NumeroAvanzatoVec.ZERO) == 0) {
throw new Errore(Errori.DIVISION_BY_ZERO); throw new Error(Errors.DIVISION_BY_ZERO);
} }
return variable1.calcola().divide(variable2.calcola()); return variable1.solve().divide(variable2.solve());
} }
public boolean hasMinus() { public boolean hasMinus() {
@ -49,12 +49,12 @@ public class Divisione extends FunzioneDueValoriBase {
private boolean drawMinus = true; private boolean drawMinus = true;
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable1.setSmall(true); variable1.setSmall(true);
variable1.calcolaGrafica(); variable1.generateGraphics();
variable2.setSmall(true); variable2.setSmall(true);
variable2.calcolaGrafica(); variable2.generateGraphics();
width = calcWidth(); width = calcWidth();
height = calcHeight(); height = calcHeight();
@ -72,8 +72,8 @@ public class Divisione extends FunzioneDueValoriBase {
boolean minus = false; boolean minus = false;
int minusw = 0; int minusw = 0;
int minush = 0; int minush = 0;
String numerator = ((Funzione) var1).toString(); String numerator = ((Function) var1).toString();
if (numerator.startsWith("-") && ((Funzione) var1) instanceof Termine && ((Termine) var1).term.isBigInteger(true)) { if (numerator.startsWith("-") && ((Function) var1) instanceof Number && ((Number) var1).term.isBigInteger(true)) {
minus = true; minus = true;
numerator = numerator.substring(1); numerator = numerator.substring(1);
} }
@ -83,10 +83,10 @@ public class Divisione extends FunzioneDueValoriBase {
w1 = getStringWidth(numerator); w1 = getStringWidth(numerator);
h1 = Utils.getFontHeight(small); h1 = Utils.getFontHeight(small);
} else { } else {
w1 = ((Funzione) var1).getWidth(); w1 = ((Function) var1).getWidth();
h1 = ((Funzione) var1).getHeight(); h1 = ((Function) var1).getHeight();
} }
int w2 = ((Funzione) var2).getWidth(); int w2 = ((Function) var2).getWidth();
int maxw; int maxw;
if (w1 > w2) { if (w1 > w2) {
maxw = 1 + w1; maxw = 1 + w1;
@ -104,9 +104,9 @@ public class Divisione extends FunzioneDueValoriBase {
glDrawStringLeft(x+1, y + h1 + 1 + 1 - (minush / 2), "-"); glDrawStringLeft(x+1, y + h1 + 1 + 1 - (minush / 2), "-");
glDrawStringLeft((int) (x+1 + minusw + 1 + (maxw - w1) / 2d), y, numerator); glDrawStringLeft((int) (x+1 + minusw + 1 + (maxw - w1) / 2d), y, numerator);
} else { } else {
((Funzione) var1).draw((int) (x+1 + minusw + (maxw - w1) / 2d), y); ((Function) var1).draw((int) (x+1 + minusw + (maxw - w1) / 2d), y);
} }
((Funzione) var2).draw((int) (x+1 + minusw + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1); ((Function) var2).draw((int) (x+1 + minusw + (maxw - w2) / 2d), y + h1 + 1 + 1 + 1);
glColor3f(0, 0, 0); glColor3f(0, 0, 0);
glFillRect(x+1+ minusw, y + h1 + 1, maxw, 1); glFillRect(x+1+ minusw, y + h1 + 1, maxw, 1);
} }
@ -121,7 +121,7 @@ public class Divisione extends FunzioneDueValoriBase {
boolean minus = false; boolean minus = false;
String numerator = variable1.toString(); String numerator = variable1.toString();
if (numerator.startsWith("-") && variable1 instanceof Termine && ((Termine) variable1).term.isBigInteger(true)) { if (numerator.startsWith("-") && variable1 instanceof Number && ((Number) variable1).term.isBigInteger(true)) {
minus = true; minus = true;
numerator = numerator.substring(1); numerator = numerator.substring(1);
} }
@ -149,7 +149,7 @@ public class Divisione extends FunzioneDueValoriBase {
protected int calcWidth() { protected int calcWidth() {
boolean minus = false; boolean minus = false;
String numerator = variable1.toString(); String numerator = variable1.toString();
if (numerator.startsWith("-") && variable1 instanceof Termine && ((Termine) variable1).term.isBigInteger(true)) { if (numerator.startsWith("-") && variable1 instanceof Number && ((Number) variable1).term.isBigInteger(true)) {
minus = true; minus = true;
numerator = numerator.substring(1); numerator = numerator.substring(1);
} }

View File

@ -0,0 +1,59 @@
package org.warp.picalculator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import com.rits.cloning.Cloner;
public class Equation extends FunctionTwoValues {
public Equation(Function value1, Function value2) {
super(value1,value2);
}
@Override
public String getSymbol() {
return MathematicalSymbols.EQUATION;
}
@Override
public Function solve() throws Error {
return new Equation(new Subtraction((FunctionBase)variable1.solve(), (FunctionBase)variable2.solve()).solve(), new Number("0"));
}
public Function solve(char variableCharacter) {
@SuppressWarnings("unused")
ArrayList<Equation> e;
//TODO: WORK IN PROGRESS.
//TODO: Finire. Fare in modo che risolva i passaggi fino a che non ce ne sono più
return null;
}
//WORK IN PROGRESS
public ArrayList<Equation> solveStep(char charIncognita) {
ArrayList<Equation> result = new ArrayList<Equation>();
result.add(this.clone());
for (SolveMethod t : SolveMethod.techniques) {
ArrayList<Equation> newResults = new ArrayList<Equation>();
final int sz = result.size();
for (int n = 0; n < sz; n++) {
newResults.addAll(t.solve(result.get(n)));
}
Set<Equation> hs = new HashSet<>();
hs.addAll(newResults);
newResults.clear();
newResults.addAll(hs);
result = newResults;
}
// TODO: controllare se è a posto
return result;
}
@Override
public Equation clone() {
Cloner cloner = new Cloner();
return cloner.deepClone(this);
}
}

View File

@ -0,0 +1,13 @@
package org.warp.picalculator;
import java.math.BigInteger;
public class EquationResult {
public boolean isAnEquation = false;
public Number LR = new Number(new BigInteger("0"));
public EquationResult(Number LR, boolean isAnEquation) {
this.LR = LR;
this.isAnEquation = isAnEquation;
}
}

View File

@ -0,0 +1,92 @@
package org.warp.picalculator;
import static org.warp.engine.Display.Render.glDrawLine;
public class EquationsSystem extends FunctionMultipleValues {
static final int spacing = 2;
public EquationsSystem() {
super();
}
public EquationsSystem(Function value) {
super(new Function[]{value});
}
public EquationsSystem(Function[] value) {
super(value);
}
@Override
public String getSymbol() {
return null;
}
@Override
public Function solve() throws NumberFormatException, Error {
// TODO implementare il calcolo dei sistemi
return variables[0].solve();
}
@Override
public void generateGraphics() {
for (Function f : variables) {
f.setSmall(false);
f.generateGraphics();
}
width = 0;
for (Function f : variables) {
if (f.getWidth() > width) {
width = f.getWidth();
}
}
width += 5;
height = 3;
for (Function f : variables) {
height += f.getHeight()+spacing;
}
height = height - spacing + 2;
line = height/2;
}
@Override
public void draw(int x, int y) {
final int h = this.getHeight() - 1;
final int marginTop = 3;
final int marginBottom = (h - 3 - 2) / 2 + marginTop;
final int spazioSopra = h - marginBottom;
int dy = marginTop;
for (Function f : variables) {
f.draw(x + 5, y + dy);
dy+=f.getHeight()+spacing;
}
glDrawLine(x + 2, y + 0, x + 3, y + 0);
glDrawLine(x + 1, y + 1, x + 1, y + marginBottom / 2);
glDrawLine(x + 2, y + marginBottom / 2 + 1, x + 2, y + marginBottom - 1);
glDrawLine(x + 0, y + marginBottom, x + 1, y + marginBottom);
glDrawLine(x + 2, y + marginBottom + 1, x + 2, y + marginBottom + spazioSopra / 2 - 1);
glDrawLine(x + 1, y + marginBottom + spazioSopra / 2, x + 1, y + h - 1);
glDrawLine(x + 2, y + h, x + 3, y + h);
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public int getLine() {
return line;
}
}

View File

@ -3,27 +3,27 @@ package org.warp.picalculator;
import static org.warp.engine.Display.Render.glColor3f; import static org.warp.engine.Display.Render.glColor3f;
import static org.warp.engine.Display.Render.glDrawLine; import static org.warp.engine.Display.Render.glDrawLine;
public class ParteSistema extends FunzioneAnteriore { public class EquationsSystemPart extends AnteriorFunction {
public ParteSistema(Equazione equazione) { public EquationsSystemPart(Equation equazione) {
super(equazione); super(equazione);
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return Simboli.SYSTEM; return MathematicalSymbols.SYSTEM;
} }
@Override @Override
public Equazione calcola() throws NumberFormatException, Errore { public Equation solve() throws NumberFormatException, Error {
// TODO implementare il calcolo dei sistemi // TODO implementare il calcolo dei sistemi
return (Equazione) variable.calcola(); return (Equation) variable.solve();
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable.setSmall(false); variable.setSmall(false);
variable.calcolaGrafica(); variable.generateGraphics();
width = 5 + getVariable().getWidth(); width = 5 + getVariable().getWidth();
height = 3 + getVariable().getHeight() + 2; height = 3 + getVariable().getHeight() + 2;

View File

@ -1,57 +0,0 @@
package org.warp.picalculator;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;
import com.rits.cloning.Cloner;
public class Equazione extends FunzioneDueValori {
public Equazione(Funzione value1, Funzione value2) {
super(value1,value2);
}
@Override
public String simbolo() {
return Simboli.EQUATION;
}
@Override
public Funzione calcola() throws Errore {
return new Equazione(new Sottrazione((FunzioneBase)variable1.calcola(), (FunzioneBase)variable2.calcola()).calcola(), new Termine("0"));
}
public Funzione calcola(char charIncognita) {
@SuppressWarnings("unused")
ArrayList<Equazione> e;
//TODO: Finire. Fare in modo che risolva i passaggi fino a che non ce ne sono più
return null;
}
public ArrayList<Equazione> risolviPassaggio(char charIncognita) {
ArrayList<Equazione> result = new ArrayList<Equazione>();
result.add(this.clone());
for (Tecnica t : Tecnica.tecniche) {
ArrayList<Equazione> newResults = new ArrayList<Equazione>();
final int sz = result.size();
for (int n = 0; n < sz; n++) {
newResults.addAll(t.risolvi(result.get(n)));
}
Set<Equazione> hs = new HashSet<>();
hs.addAll(newResults);
newResults.clear();
newResults.addAll(hs);
result = newResults;
}
// TODO: controllare se è a posto
return result;
}
@Override
public Equazione clone() {
Cloner cloner = new Cloner();
return cloner.deepClone(this);
}
}

View File

@ -0,0 +1,15 @@
package org.warp.picalculator;
public class Error extends java.lang.Throwable {
/**
*
*/
private static final long serialVersionUID = -1014947815755694651L;
public Error(Errors ErrorID) {
id = ErrorID;
}
public Errors id = Errors.ERROR;
}

View File

@ -1,15 +0,0 @@
package org.warp.picalculator;
public class Errore extends java.lang.Throwable {
/**
*
*/
private static final long serialVersionUID = -1014947815755694651L;
public Errore(Errori IDErrore) {
id = IDErrore;
}
public Errori id = Errori.ERROR;
}

View File

@ -1,5 +1,5 @@
package org.warp.picalculator; package org.warp.picalculator;
public enum Errori { public enum Errors {
ERROR, DIVISION_BY_ZERO, UNBALANCED_BRACKETS, NOT_IMPLEMENTED, NEGATIVE_PARAMETER, NUMBER_TOO_LARGE, NUMBER_TOO_SMALL, CONVERSION_ERROR, SYNTAX_ERROR, NOT_AN_EQUATION ERROR, DIVISION_BY_ZERO, UNBALANCED_BRACKETS, NOT_IMPLEMENTED, NEGATIVE_PARAMETER, NUMBER_TOO_LARGE, NUMBER_TOO_SMALL, CONVERSION_ERROR, SYNTAX_ERROR, NOT_AN_EQUATION
} }

View File

@ -14,30 +14,31 @@ import java.util.regex.Pattern;
import org.nevec.rjm.NumeroAvanzato; import org.nevec.rjm.NumeroAvanzato;
import org.nevec.rjm.NumeroAvanzatoVec; import org.nevec.rjm.NumeroAvanzatoVec;
public class Espressione extends FunzioneMultiplaBase { public class Expression extends FunctionMultipleValuesBase {
public Espressione() { public Expression() {
super(); super();
} }
public Espressione(FunzioneBase[] values) { public Expression(FunctionBase[] values) {
super(values); super(values);
} }
private boolean parentesiIniziale = false; private boolean initialParenthesis = false;
public Espressione(String string) throws Errore { public Expression(String string) throws Error {
this(string, "", true); this(string, "", true);
} }
public Espressione(String string, String debugSpaces, boolean parentesiIniziale) throws Errore { public Expression(String string, String debugSpaces, boolean initialParenthesis) throws Error {
super(); super();
this.parentesiIniziale = parentesiIniziale; this.initialParenthesis = initialParenthesis;
boolean isNumber = false; boolean isNumber = false;
// Determine if the expression is already a number:
// Determina se l'espressione è già un numero: // Determina se l'espressione è già un numero:
try { try {
new Termine(string); new Number(string);
isNumber = true; isNumber = true;
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
isNumber = false; isNumber = false;
@ -47,115 +48,121 @@ public class Espressione extends FunzioneMultiplaBase {
Utils.debug.println(debugSpaces + "•Analyzing expression:" + processExpression); Utils.debug.println(debugSpaces + "•Analyzing expression:" + processExpression);
if (isNumber){ if (isNumber){
// If the expression is already a number:
// Se l'espressione è già un numero: // Se l'espressione è già un numero:
Termine t = new Termine(string); Number t = new Number(string);
setVariables(new FunzioneBase[] { t }); setVariables(new FunctionBase[] { t });
Utils.debug.println(debugSpaces + "•Result:" + t.toString()); Utils.debug.println(debugSpaces + "•Result:" + t.toString());
} else { } else {
// Else prepare the expression:
// Altrimenti prepara l'espressione: // Altrimenti prepara l'espressione:
debugSpaces += " "; debugSpaces += " ";
// IF the expression is not a number:
// Se l'espressione non è già un numero: // Se l'espressione non è già un numero:
// Controlla se ci sono più di un uguale // Check if there are more than one equal symbol (=)
// Controlla se ci sono più di un uguale (=)
int equationsFound = 0; int equationsFound = 0;
int systemsFound = 0; int systemsFound = 0;
for (char c : processExpression.toCharArray()) { for (char c : processExpression.toCharArray()) {
if (("" + c).equals(Simboli.EQUATION)) { if (("" + c).equals(MathematicalSymbols.EQUATION)) {
equationsFound += 1; equationsFound += 1;
} }
if (("" + c).equals(Simboli.SYSTEM)) { if (("" + c).equals(MathematicalSymbols.SYSTEM)) {
equationsFound += 1; equationsFound += 1;
} }
} }
if (equationsFound == 1 && systemsFound == 0) { if (equationsFound == 1 && systemsFound == 0) {
processExpression = Simboli.SYSTEM + processExpression; processExpression = MathematicalSymbols.SYSTEM + processExpression;
systemsFound += 1; systemsFound += 1;
} }
if (equationsFound != systemsFound) { if (equationsFound != systemsFound) {
throw new Errore(Errori.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
//Solve the exceeding symbols ++ and --
// Correggi i segni ++ e -- in eccesso // Correggi i segni ++ e -- in eccesso
Pattern pattern = Pattern.compile("\\+\\++?|\\-\\-+?"); Pattern pattern = Pattern.compile("\\+\\++?|\\-\\-+?");
Matcher matcher = pattern.matcher(processExpression); Matcher matcher = pattern.matcher(processExpression);
boolean cambiati = false; boolean symbolsChanged = false;
while (matcher.find()) { while (matcher.find()) {
cambiati = true; symbolsChanged = true;
String correzione = "+"; String correzione = "+";
processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length()); processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
} }
// Correct the exceeding symbols +- and -+
// Correggi i segni +- e -+ in eccesso // Correggi i segni +- e -+ in eccesso
pattern = Pattern.compile("\\+\\-|\\-\\+"); pattern = Pattern.compile("\\+\\-|\\-\\+");
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
while (matcher.find()) { while (matcher.find()) {
cambiati = true; symbolsChanged = true;
String correzione = "-"; String correzione = "-";
processExpression = processExpression.substring(0, matcher.start(0)) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length()); processExpression = processExpression.substring(0, matcher.start(0)) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
} }
// Rimuovi i segni appena dopo le parentesi // Rimuovi i segni appena dopo le parentesi
if (processExpression.contains("(+")) { if (processExpression.contains("(+")) {
cambiati = true; symbolsChanged = true;
processExpression = processExpression.replace("(+", "("); processExpression = processExpression.replace("(+", "(");
} }
// Cambia i segni appena prima le parentesi // Cambia i segni appena prima le parentesi
if (processExpression.contains("-(")) { if (processExpression.contains("-(")) {
cambiati = true; symbolsChanged = true;
processExpression = processExpression.replace("-(", "-1*("); processExpression = processExpression.replace("-(", "-1*(");
} }
// Rimuovi i segni appena dopo l'inizio // Rimuovi i segni appena dopo l'inizio
if (processExpression.startsWith("+")) { if (processExpression.startsWith("+")) {
cambiati = true; symbolsChanged = true;
processExpression = processExpression.substring(1, processExpression.length()); processExpression = processExpression.substring(1, processExpression.length());
} }
// Rimuovi i + in eccesso // Rimuovi i + in eccesso
pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(Simboli.segni(true, true), Simboli.funzioni()), "(")) + "]\\+[^" + ArrayToRegex(concat(concat(Simboli.segni(true, true), Simboli.funzioni()), new String[] { "(", ")" })) + "]+?[" + ArrayToRegex(concat(Simboli.segni(true, true), Simboli.funzioni())) + "]|[" + ArrayToRegex(concat(Simboli.segni(true, true), Simboli.funzioni())) + "]+?\\+[^" + ArrayToRegex(concat(concat(Simboli.segni(true, true), Simboli.funzioni()), new String[] { "(", ")" })) + "]"); pattern = Pattern.compile("[" + ArrayToRegex(Utils.add(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions()), "(")) + "]\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]+?[" + ArrayToRegex(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions())) + "]|[" + ArrayToRegex(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions())) + "]+?\\+[^" + ArrayToRegex(concat(concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.functions()), new String[] { "(", ")" })) + "]");
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
cambiati = false; symbolsChanged = false;
while (matcher.find()) { while (matcher.find()) {
cambiati = true; symbolsChanged = true;
String correzione = matcher.group(0).replaceFirst(Matcher.quoteReplacement("+"), ""); String correzione = matcher.group(0).replaceFirst(Matcher.quoteReplacement("+"), "");
processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length()); processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
} }
// Correggi i segni - in +- // Correggi i segni - in +-
pattern = Pattern.compile("[^" + Utils.ArrayToRegex(concat(concat(Simboli.funzioni(), new String[] { Simboli.PARENTHESIS_OPEN }), Simboli.segni(true, true))) + "]-"); pattern = Pattern.compile("[^" + Utils.ArrayToRegex(concat(concat(MathematicalSymbols.functions(), new String[] { MathematicalSymbols.PARENTHESIS_OPEN }), MathematicalSymbols.signums(true, true))) + "]-");
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
while (matcher.find()) { while (matcher.find()) {
cambiati = true; symbolsChanged = true;
String correzione = "+-"; String correzione = "+-";
processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length()); processExpression = processExpression.substring(0, matcher.start(0) + 1) + correzione + processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
} }
if (cambiati) { if (symbolsChanged) {
Utils.debug.println(debugSpaces + "•Resolved signs:" + processExpression); Utils.debug.println(debugSpaces + "•Resolved signs:" + processExpression);
} }
// Aggiungi i segni * accanto alle parentesi // Aggiungi i segni * accanto alle parentesi
pattern = Pattern.compile("\\([^\\(]+?\\)"); pattern = Pattern.compile("\\([^\\(]+?\\)");
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
cambiati = false; symbolsChanged = false;
while (matcher.find()) { while (matcher.find()) {
cambiati = true; symbolsChanged = true;
// sistema i segni * impliciti prima e dopo l'espressione. // sistema i segni * impliciti prima e dopo l'espressione.
String beforeexp = processExpression.substring(0, matcher.start(0)); String beforeexp = processExpression.substring(0, matcher.start(0));
String newexp = matcher.group(0).substring(1, matcher.group(0).length() - 1); String newexp = matcher.group(0).substring(1, matcher.group(0).length() - 1);
String afterexp = processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length()); String afterexp = processExpression.substring(matcher.start(0) + matcher.group(0).length(), processExpression.length());
if (Pattern.compile("[^\\-" + Utils.ArrayToRegex(Utils.add(concat(Simboli.funzioni(), concat(Simboli.segni(true, true), Simboli.sintassiGenerale())), "(")) + "]$").matcher(beforeexp).find()) { if (Pattern.compile("[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.genericSyntax())), "(")) + "]$").matcher(beforeexp).find()) {
// Se la stringa precedente finisce con un numero // Se la stringa precedente finisce con un numero
beforeexp += Simboli.MULTIPLICATION; beforeexp += MathematicalSymbols.MULTIPLICATION;
} }
if (Pattern.compile("^[^\\-" + Utils.ArrayToRegex(Utils.add(concat(Simboli.funzioni(), concat(Simboli.segni(true, true), Simboli.sintassiGenerale())), ")")) + "]").matcher(afterexp).find()) { if (Pattern.compile("^[^\\-" + Utils.ArrayToRegex(Utils.add(concat(MathematicalSymbols.functions(), concat(MathematicalSymbols.signums(true, true), MathematicalSymbols.genericSyntax())), ")")) + "]").matcher(afterexp).find()) {
// Se la stringa successiva inizia con un numero // Se la stringa successiva inizia con un numero
afterexp = Simboli.MULTIPLICATION + afterexp; afterexp = MathematicalSymbols.MULTIPLICATION + afterexp;
} }
processExpression = beforeexp + "" + newexp + "" + afterexp; processExpression = beforeexp + "" + newexp + "" + afterexp;
matcher = pattern.matcher(processExpression); matcher = pattern.matcher(processExpression);
@ -163,7 +170,7 @@ public class Espressione extends FunzioneMultiplaBase {
processExpression = processExpression.replace("", "(").replace("", ")"); processExpression = processExpression.replace("", "(").replace("", ")");
if (cambiati) { if (symbolsChanged) {
Utils.debug.println(debugSpaces + "•Added implicit multiplications:" + processExpression); Utils.debug.println(debugSpaces + "•Added implicit multiplications:" + processExpression);
} }
@ -171,61 +178,63 @@ public class Espressione extends FunzioneMultiplaBase {
debugSpaces += " "; debugSpaces += " ";
// Suddividi tutto // Convert the expression to a list of objects
Espressione parentesiNonSuddivisaCorrettamente = new Espressione(); Expression imputRawParenthesis = new Expression();
parentesiNonSuddivisaCorrettamente.setVariables(new FunzioneBase[] {}); imputRawParenthesis.setVariables(new FunctionBase[] {});
String tmp = ""; String tmp = "";
final String[] funzioni = concat(concat(concat(concat(Simboli.funzioni(), Simboli.parentesi()), Simboli.segni(true, true)), Simboli.incognite()), Simboli.sintassiGenerale()); final String[] functions = concat(concat(concat(concat(MathematicalSymbols.functions(), MathematicalSymbols.parentheses()), MathematicalSymbols.signums(true, true)), MathematicalSymbols.variables()), MathematicalSymbols.genericSyntax());
for (int i = 0; i < processExpression.length(); i++) { for (int i = 0; i < processExpression.length(); i++) {
// Per ogni carattere cerca se è un numero o una funzione: // Per ogni carattere cerca se è un numero o una funzione:
String charI = processExpression.charAt(i) + ""; String charI = processExpression.charAt(i) + "";
if (Utils.isInArray(charI, funzioni)) { if (Utils.isInArray(charI, functions)) {
// Finds the type of function fron the following list
// Cerca il tipo di funzione tra le esistenti // Cerca il tipo di funzione tra le esistenti
FunzioneBase f = null; FunctionBase f = null;
switch (charI) { switch (charI) {
case Simboli.SUM: case MathematicalSymbols.SUM:
f = new Somma(null, null); f = new Sum(null, null);
break; break;
case Simboli.MULTIPLICATION: case MathematicalSymbols.MULTIPLICATION:
f = new Moltiplicazione(null, null); f = new Multiplication(null, null);
break; break;
case Simboli.PRIORITARY_MULTIPLICATION: case MathematicalSymbols.PRIORITARY_MULTIPLICATION:
f = new MoltiplicazionePrioritaria(null, null); f = new PrioritaryMultiplication(null, null);
break; break;
case Simboli.DIVISION: case MathematicalSymbols.DIVISION:
f = new Divisione(null, null); f = new Division(null, null);
break; break;
case Simboli.NTH_ROOT: case MathematicalSymbols.NTH_ROOT:
f = new Radice(null, null); f = new Root(null, null);
break; break;
case Simboli.SQUARE_ROOT: case MathematicalSymbols.SQUARE_ROOT:
f = new RadiceQuadrata(null); f = new RootSquare(null);
break; break;
case Simboli.POTENZA: case MathematicalSymbols.POWER:
f = new Potenza(null, null); f = new Power(null, null);
break; break;
case Simboli.PARENTHESIS_OPEN: case MathematicalSymbols.PARENTHESIS_OPEN:
// Find the last closed parenthesis
// cerca l'ultima parentesi chiusa // cerca l'ultima parentesi chiusa
int startIndex = i; int startIndex = i;
int endIndex = -1; int endIndex = -1;
int jumps = -1; int jumps = -1;
for (int i2 = startIndex; i2 < processExpression.length(); i2++) { for (int i2 = startIndex; i2 < processExpression.length(); i2++) {
if ((processExpression.charAt(i2) + "").equals(Simboli.PARENTHESIS_CLOSE)) { if ((processExpression.charAt(i2) + "").equals(MathematicalSymbols.PARENTHESIS_CLOSE)) {
if (jumps == 0) { if (jumps == 0) {
endIndex = i2; endIndex = i2;
break; break;
} else if (jumps > 0) { } else if (jumps > 0) {
jumps -= 1; jumps -= 1;
} else if (jumps < 0) { } else if (jumps < 0) {
throw new Errore(Errori.UNBALANCED_BRACKETS); throw new Error(Errors.UNBALANCED_BRACKETS);
} }
} else if ((processExpression.charAt(i2) + "").equals(Simboli.PARENTHESIS_OPEN)) { } else if ((processExpression.charAt(i2) + "").equals(MathematicalSymbols.PARENTHESIS_OPEN)) {
jumps += 1; jumps += 1;
} }
} }
if (endIndex == -1 || endIndex < startIndex) { if (endIndex == -1 || endIndex < startIndex) {
throw new Errore(Errori.UNBALANCED_BRACKETS); throw new Error(Errors.UNBALANCED_BRACKETS);
} }
startIndex += 1; startIndex += 1;
i = startIndex; i = startIndex;
@ -235,55 +244,55 @@ public class Espressione extends FunzioneMultiplaBase {
tmpExpr += processExpression.charAt(i); tmpExpr += processExpression.charAt(i);
i++; i++;
} }
f = new Espressione(tmpExpr, debugSpaces, false); f = new Expression(tmpExpr, debugSpaces, false);
break; break;
default: default:
if (Utils.isInArray(charI, Simboli.incognite())) { if (Utils.isInArray(charI, MathematicalSymbols.variables())) {
// Fallback // Fallback
NumeroAvanzato na = NumeroAvanzato.ONE; NumeroAvanzato na = NumeroAvanzato.ONE;
Incognite iy = na.getIncognitey(); Variables iy = na.getVariableY();
iy.incognite.add(new Incognita(charI.charAt(0), 1, 1)); iy.variables.add(new Variable(charI.charAt(0), 1, 1));
na = na.setIncognitey(iy); na = na.setVariableY(iy);
f = new Termine(na); f = new Number(na);
} else { } else {
throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!"); throw new java.lang.RuntimeException("Il carattere " + charI + " non è tra le funzioni designate!\nAggiungerlo ad esse o rimuovere il carattere dall'espressione!");
} }
} }
if (f instanceof Espressione) { if (f instanceof Expression) {
tmp = ""; tmp = "";
} else if (f instanceof Termine) { } else if (f instanceof Number) {
if (parentesiNonSuddivisaCorrettamente.getVariablesLength() == 0) { if (imputRawParenthesis.getVariablesLength() == 0) {
if (tmp.length() > 0) { if (tmp.length() > 0) {
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new Termine(tmp)); imputRawParenthesis.addVariableToEnd(new Number(tmp));
Utils.debug.println(debugSpaces + "•Added value to expression:" + tmp); Utils.debug.println(debugSpaces + "•Added value to expression:" + tmp);
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new MoltiplicazionePrioritaria(null, null)); imputRawParenthesis.addVariableToEnd(new PrioritaryMultiplication(null, null));
Utils.debug.println(debugSpaces + "•Added variable to expression:" + new MoltiplicazionePrioritaria(null, null).simbolo()); Utils.debug.println(debugSpaces + "•Added variable to expression:" + new PrioritaryMultiplication(null, null).getSymbol());
} }
} else { } else {
if (tmp.length() > 0) { if (tmp.length() > 0) {
if (parentesiNonSuddivisaCorrettamente.getVariable(parentesiNonSuddivisaCorrettamente.getVariablesLength() - 1) instanceof Termine) { if (imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1) instanceof Number) {
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new MoltiplicazionePrioritaria(null, null)); imputRawParenthesis.addVariableToEnd(new PrioritaryMultiplication(null, null));
Utils.debug.println(debugSpaces + "•Added variable to expression:" + new MoltiplicazionePrioritaria(null, null).simbolo()); Utils.debug.println(debugSpaces + "•Added variable to expression:" + new PrioritaryMultiplication(null, null).getSymbol());
} }
if (tmp.equals("-")) { if (tmp.equals("-")) {
tmp = "-1"; tmp = "-1";
} }
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new Termine(tmp)); imputRawParenthesis.addVariableToEnd(new Number(tmp));
Utils.debug.println(debugSpaces + "•Added value to expression:" + tmp); Utils.debug.println(debugSpaces + "•Added value to expression:" + tmp);
} }
if (tmp.length() > 0 || parentesiNonSuddivisaCorrettamente.getVariable(parentesiNonSuddivisaCorrettamente.getVariablesLength() - 1) instanceof Termine) { if (tmp.length() > 0 || imputRawParenthesis.getVariable(imputRawParenthesis.getVariablesLength() - 1) instanceof Number) {
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new MoltiplicazionePrioritaria(null, null)); imputRawParenthesis.addVariableToEnd(new PrioritaryMultiplication(null, null));
Utils.debug.println(debugSpaces + "•Added variable to expression:" + new MoltiplicazionePrioritaria(null, null).simbolo()); Utils.debug.println(debugSpaces + "•Added variable to expression:" + new PrioritaryMultiplication(null, null).getSymbol());
} }
} }
} else { } else {
if (tmp.length() != 0) { if (tmp.length() != 0) {
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new Termine(tmp)); imputRawParenthesis.addVariableToEnd(new Number(tmp));
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp); Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
} }
} }
parentesiNonSuddivisaCorrettamente.addVariableToEnd(f); imputRawParenthesis.addVariableToEnd(f);
Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.simbolo()); Utils.debug.println(debugSpaces + "•Added variable to expression:" + f.getSymbol());
tmp = ""; tmp = "";
} else { } else {
try { try {
@ -301,9 +310,9 @@ public class Espressione extends FunzioneMultiplaBase {
if (tmp.length() > 0) { if (tmp.length() > 0) {
Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp); Utils.debug.println(debugSpaces + "•Added variable to expression:" + tmp);
try { try {
parentesiNonSuddivisaCorrettamente.addVariableToEnd(new Termine(tmp)); imputRawParenthesis.addVariableToEnd(new Number(tmp));
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
throw new Errore(Errori.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} }
tmp = ""; tmp = "";
} }
@ -317,13 +326,13 @@ public class Espressione extends FunzioneMultiplaBase {
// Fine suddivisione di insieme // Fine suddivisione di insieme
Utils.debug.println(debugSpaces + "•Removing useless parentheses"); Utils.debug.println(debugSpaces + "•Removing useless parentheses");
for (int i = 0; i < parentesiNonSuddivisaCorrettamente.variables.length; i++) { for (int i = 0; i < imputRawParenthesis.variables.length; i++) {
if (parentesiNonSuddivisaCorrettamente.variables[i] instanceof Espressione) { if (imputRawParenthesis.variables[i] instanceof Expression) {
Espressione par = (Espressione) parentesiNonSuddivisaCorrettamente.variables[i]; Expression par = (Expression) imputRawParenthesis.variables[i];
if (par.variables.length == 1) { if (par.variables.length == 1) {
FunzioneBase subFunz = par.variables[0]; FunctionBase subFunz = par.variables[0];
if (subFunz instanceof Espressione || subFunz instanceof Termine) { if (subFunz instanceof Expression || subFunz instanceof Number) {
parentesiNonSuddivisaCorrettamente.variables[i] = subFunz; imputRawParenthesis.variables[i] = subFunz;
Utils.debug.println(debugSpaces + " •Useless parentheses removed"); Utils.debug.println(debugSpaces + " •Useless parentheses removed");
} }
} }
@ -333,142 +342,142 @@ public class Espressione extends FunzioneMultiplaBase {
// Inizia l'affinazione dell'espressione // Inizia l'affinazione dell'espressione
Utils.debug.println(debugSpaces + "•Pushing classes..."); Utils.debug.println(debugSpaces + "•Pushing classes...");
FunzioneBase[] funzioniOLDArray = parentesiNonSuddivisaCorrettamente.getVariables(); FunctionBase[] oldFunctionsArray = imputRawParenthesis.getVariables();
ArrayList<FunzioneBase> funzioniOLD = new ArrayList<FunzioneBase>(); ArrayList<FunctionBase> oldFunctionsList = new ArrayList<FunctionBase>();
for (int i = 0; i < funzioniOLDArray.length; i++) { for (int i = 0; i < oldFunctionsArray.length; i++) {
FunzioneBase funzione = funzioniOLDArray[i]; FunctionBase funzione = oldFunctionsArray[i];
if (funzione != null) { if (funzione != null) {
//Affinazione //Affinazione
if (funzione instanceof Radice) { if (funzione instanceof Root) {
if ((i - 1) >= 0 && funzioniOLDArray[i-1] instanceof Termine && ((Termine)funzioniOLDArray[i-1]).getTerm().compareTo(new NumeroAvanzatoVec(new NumeroAvanzato(new BigInteger("2")))) == 0) { if ((i - 1) >= 0 && oldFunctionsArray[i-1] instanceof Number && ((Number)oldFunctionsArray[i-1]).getTerm().compareTo(new NumeroAvanzatoVec(new NumeroAvanzato(new BigInteger("2")))) == 0) {
funzioniOLDArray[i] = null; oldFunctionsArray[i] = null;
funzioniOLDArray[i-1] = null; oldFunctionsArray[i-1] = null;
funzioniOLD.remove(funzioniOLD.size()-1); oldFunctionsList.remove(oldFunctionsList.size()-1);
i -= 1; i -= 1;
funzione = new RadiceQuadrata(null); funzione = new RootSquare(null);
} }
} }
//Aggiunta della funzione alla lista grezza //Aggiunta della funzione alla lista grezza
funzioniOLD.add(funzione); oldFunctionsList.add(funzione);
} }
} }
if (funzioniOLD.size() > 1) { if (oldFunctionsList.size() > 1) {
Utils.debug.println(debugSpaces + " •Correcting classes:"); Utils.debug.println(debugSpaces + " •Correcting classes:");
int before = 0; int before = 0;
String fase = "funzioniSN"; String step = "SN Functions";
int n = 0; int n = 0;
do { do {
before = funzioniOLD.size(); before = oldFunctionsList.size();
int i = 0; int i = 0;
boolean change = false; boolean change = false;
if (Utils.ciSonoMoltiplicazioniPrioritarieNonImpostate(funzioniOLD)) { if (Utils.areThereEmptyPrioritaryMultiplications(oldFunctionsList)) {
fase = "moltiplicazioni prioritarie"; // PRIMA FASE step = "prioritary multiplications"; // PRIMA FASE
} else if (Utils.ciSonoFunzioniSNnonImpostate(funzioniOLD)) { } else if (Utils.areThereOnlyEmptySNFunctions(oldFunctionsList)) {
fase = "funzioniSN"; // SECONDA FASE step = "SN Functions"; // SECONDA FASE
} else if (Utils.ciSonoFunzioniNSNnonImpostate(funzioniOLD)) { } else if (Utils.areThereOnlyEmptyNSNFunctions(oldFunctionsList)) {
fase = "funzioniNSN"; // TERZA FASE step = "NSN Functions"; // TERZA FASE
} else if (Utils.ciSonoMoltiplicazioniNonImpostate(funzioniOLD)) { } else if (Utils.areThereEmptyMultiplications(oldFunctionsList)) {
fase = "moltiplicazioni"; // QUARTA FASE step = "multiplications"; // QUARTA FASE
} else if (Utils.ciSonoSommeNonImpostate(funzioniOLD)) { } else if (Utils.areThereEmptySums(oldFunctionsList)) {
fase = "somme"; // QUINTA FASE step = "sums"; // QUINTA FASE
} else { } else {
// fase = "errore"; // fase = "errore";
System.out.println("WARN: ---> POSSIBILE ERRORE????? <---");// BOH System.out.println("WARN: ---> POSSIBILE ERRORE????? <---");// BOH
// throw new Errore(Errori.SYNTAX_ERROR); // throw new Errore(Errori.SYNTAX_ERROR);
while (funzioniOLD.size() > 1) { while (oldFunctionsList.size() > 1) {
funzioniOLD.set(0, new Moltiplicazione(funzioniOLD.get(0), funzioniOLD.remove(1))); oldFunctionsList.set(0, new Multiplication(oldFunctionsList.get(0), oldFunctionsList.remove(1)));
} }
} }
Utils.debug.println(debugSpaces + " •Phase: "+fase); Utils.debug.println(debugSpaces + " •Phase: "+step);
while (i < funzioniOLD.size() && change == false && funzioniOLD.size() > 1) { while (i < oldFunctionsList.size() && change == false && oldFunctionsList.size() > 1) {
FunzioneBase funzioneTMP = funzioniOLD.get(i); FunctionBase funzioneTMP = oldFunctionsList.get(i);
if (funzioneTMP instanceof FunzioneDueValoriBase) { if (funzioneTMP instanceof FunctionTwoValuesBase) {
if (fase != "funzioniSN") { if (step != "SN Functions") {
if ( if (
(fase == "somme" && (funzioneTMP instanceof Somma) == true && ((funzioneTMP instanceof FunzioneAnterioreBase && ((FunzioneAnterioreBase) funzioneTMP).variable == null) || (funzioneTMP instanceof FunzioneDueValoriBase && ((FunzioneDueValoriBase) funzioneTMP).variable1 == null && ((FunzioneDueValoriBase) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof FunzioneAnterioreBase) && !(funzioneTMP instanceof FunzioneDueValoriBase)))) (step == "sums" && (funzioneTMP instanceof Sum) == true && ((funzioneTMP instanceof AnteriorFunctionBase && ((AnteriorFunctionBase) funzioneTMP).variable == null) || (funzioneTMP instanceof FunctionTwoValuesBase && ((FunctionTwoValuesBase) funzioneTMP).variable1 == null && ((FunctionTwoValuesBase) funzioneTMP).variable2 == null) || (!(funzioneTMP instanceof AnteriorFunctionBase) && !(funzioneTMP instanceof FunctionTwoValuesBase))))
|| ||
( (
fase.equals("moltiplicazioni prioritarie") step.equals("prioritary multiplications")
&& &&
(funzioneTMP instanceof MoltiplicazionePrioritaria) (funzioneTMP instanceof PrioritaryMultiplication)
&& &&
((FunzioneDueValoriBase) funzioneTMP).variable1 == null ((FunctionTwoValuesBase) funzioneTMP).variable1 == null
&& &&
((FunzioneDueValoriBase) funzioneTMP).variable2 == null ((FunctionTwoValuesBase) funzioneTMP).variable2 == null
) )
|| ||
( (
fase.equals("moltiplicazioni") step.equals("multiplications")
&& &&
( (
(funzioneTMP instanceof Moltiplicazione) (funzioneTMP instanceof Multiplication)
|| ||
(funzioneTMP instanceof Divisione) (funzioneTMP instanceof Division)
) )
&& &&
((FunzioneDueValoriBase) funzioneTMP).variable1 == null ((FunctionTwoValuesBase) funzioneTMP).variable1 == null
&& &&
((FunzioneDueValoriBase) funzioneTMP).variable2 == null ((FunctionTwoValuesBase) funzioneTMP).variable2 == null
) )
|| ||
( (
fase == "funzioniNSN" step == "NSN Functions"
&& &&
(funzioneTMP instanceof Somma) == false (funzioneTMP instanceof Sum) == false
&& &&
(funzioneTMP instanceof Moltiplicazione) == false (funzioneTMP instanceof Multiplication) == false
&& &&
(funzioneTMP instanceof MoltiplicazionePrioritaria) == false (funzioneTMP instanceof PrioritaryMultiplication) == false
&& &&
(funzioneTMP instanceof Divisione) == false (funzioneTMP instanceof Division) == false
&& &&
( (
( (
funzioneTMP instanceof FunzioneAnterioreBase funzioneTMP instanceof AnteriorFunctionBase
&& &&
((FunzioneAnterioreBase) funzioneTMP).variable == null ((AnteriorFunctionBase) funzioneTMP).variable == null
) )
|| ||
( (
funzioneTMP instanceof FunzioneDueValoriBase funzioneTMP instanceof FunctionTwoValuesBase
&& &&
((FunzioneDueValoriBase) funzioneTMP).variable1 == null ((FunctionTwoValuesBase) funzioneTMP).variable1 == null
&& &&
((FunzioneDueValoriBase) funzioneTMP).variable2 == null ((FunctionTwoValuesBase) funzioneTMP).variable2 == null
) )
|| ||
( (
!(funzioneTMP instanceof FunzioneAnterioreBase) !(funzioneTMP instanceof AnteriorFunctionBase)
&& &&
!(funzioneTMP instanceof FunzioneDueValoriBase) !(funzioneTMP instanceof FunctionTwoValuesBase)
) )
) )
) )
) { ) {
change = true; change = true;
if (i + 1 < funzioniOLD.size() && i - 1 >= 0) { if (i + 1 < oldFunctionsList.size() && i - 1 >= 0) {
((FunzioneDueValoriBase) funzioneTMP).setVariable1((FunzioneBase) funzioniOLD.get(i - 1)); ((FunctionTwoValuesBase) funzioneTMP).setVariable1((FunctionBase) oldFunctionsList.get(i - 1));
((FunzioneDueValoriBase) funzioneTMP).setVariable2((FunzioneBase) funzioniOLD.get(i + 1)); ((FunctionTwoValuesBase) funzioneTMP).setVariable2((FunctionBase) oldFunctionsList.get(i + 1));
funzioniOLD.set(i, funzioneTMP); oldFunctionsList.set(i, funzioneTMP);
// è importante togliere prima gli elementi // è importante togliere prima gli elementi
// in fondo e poi quelli davanti, perché gli // in fondo e poi quelli davanti, perché gli
// indici scalano da destra a sinistra. // indici scalano da destra a sinistra.
funzioniOLD.remove(i + 1); oldFunctionsList.remove(i + 1);
funzioniOLD.remove(i - 1); oldFunctionsList.remove(i - 1);
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.simbolo()); Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
try { try {
Utils.debug.println(debugSpaces + " " + "var1=" + ((FunzioneDueValoriBase) funzioneTMP).getVariable1().calcola()); Utils.debug.println(debugSpaces + " " + "var1=" + ((FunctionTwoValuesBase) funzioneTMP).getVariable1().solve());
} catch (NullPointerException ex2) {} } catch (NullPointerException ex2) {}
try { try {
Utils.debug.println(debugSpaces + " " + "var2=" + ((FunzioneDueValoriBase) funzioneTMP).getVariable2().calcola()); Utils.debug.println(debugSpaces + " " + "var2=" + ((FunctionTwoValuesBase) funzioneTMP).getVariable2().solve());
} catch (NullPointerException ex2) {} } catch (NullPointerException ex2) {}
try { try {
Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunzioneDueValoriBase) funzioneTMP).calcola()); Utils.debug.println(debugSpaces + " " + "(result)=" + ((FunctionTwoValuesBase) funzioneTMP).solve());
} catch (NullPointerException ex2) {} } catch (NullPointerException ex2) {}
} else { } else {
@ -476,24 +485,24 @@ public class Espressione extends FunzioneMultiplaBase {
} }
} }
} }
} else if (funzioneTMP instanceof FunzioneAnterioreBase) { } else if (funzioneTMP instanceof AnteriorFunctionBase) {
if ((fase == "funzioniSN" && ((FunzioneAnterioreBase) funzioneTMP).variable == null)) { if ((step == "SN Functions" && ((AnteriorFunctionBase) funzioneTMP).variable == null)) {
if (i + 1 < funzioniOLD.size()) { if (i + 1 < oldFunctionsList.size()) {
FunzioneBase nextFunc = funzioniOLD.get(i + 1); FunctionBase nextFunc = oldFunctionsList.get(i + 1);
if (nextFunc instanceof FunzioneAnterioreBase && ((FunzioneAnterioreBase)nextFunc).variable == null) { if (nextFunc instanceof AnteriorFunctionBase && ((AnteriorFunctionBase)nextFunc).variable == null) {
} else { } else {
change = true; change = true;
((FunzioneAnterioreBase) funzioneTMP).setVariable((FunzioneBase) nextFunc); ((AnteriorFunctionBase) funzioneTMP).setVariable((FunctionBase) nextFunc);
funzioniOLD.set(i, funzioneTMP); oldFunctionsList.set(i, funzioneTMP);
// è importante togliere prima gli elementi in // è importante togliere prima gli elementi in
// fondo e poi quelli davanti, perché gli indici // fondo e poi quelli davanti, perché gli indici
// scalano da destra a sinistra. // scalano da destra a sinistra.
funzioniOLD.remove(i + 1); oldFunctionsList.remove(i + 1);
Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.simbolo()); Utils.debug.println(debugSpaces + " •Set variable to expression:" + funzioneTMP.getSymbol());
FunzioneBase var = ((FunzioneAnterioreBase) funzioneTMP).getVariable().calcola(); FunctionBase var = ((AnteriorFunctionBase) funzioneTMP).getVariable().solve();
if (var == null) { if (var == null) {
Utils.debug.println(debugSpaces + " " + "var=null"); Utils.debug.println(debugSpaces + " " + "var=null");
} else { } else {
@ -504,7 +513,7 @@ public class Espressione extends FunzioneMultiplaBase {
throw new java.lang.RuntimeException("Argomenti mancanti! Sistemare l'equazione!"); throw new java.lang.RuntimeException("Argomenti mancanti! Sistemare l'equazione!");
} }
} }
} else if (funzioneTMP instanceof Termine || funzioneTMP instanceof Espressione) { } else if (funzioneTMP instanceof Number || funzioneTMP instanceof Expression) {
if (n < 300) { if (n < 300) {
// Utils.debug.println(debugSpaces+" •Set variable // Utils.debug.println(debugSpaces+" •Set variable
// to number:"+funzioneTMP.calcola()); // to number:"+funzioneTMP.calcola());
@ -515,9 +524,9 @@ public class Espressione extends FunzioneMultiplaBase {
i++; i++;
n++; n++;
} }
} while (((funzioniOLD.size() != before || fase != "somme") && funzioniOLD.size() > 1)); } while (((oldFunctionsList.size() != before || step != "sums") && oldFunctionsList.size() > 1));
} }
setVariables(funzioniOLD); setVariables(oldFunctionsList);
dsl = debugSpaces.length(); dsl = debugSpaces.length();
debugSpaces = ""; debugSpaces = "";
@ -526,36 +535,36 @@ public class Espressione extends FunzioneMultiplaBase {
} }
Utils.debug.println(debugSpaces + "•Finished correcting classes."); Utils.debug.println(debugSpaces + "•Finished correcting classes.");
Termine result = calcola(); Number result = solve();
Utils.debug.println(debugSpaces + "•Result:" + result); Utils.debug.println(debugSpaces + "•Result:" + result);
} }
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return "Parentesi"; return "Parentesi";
} }
@Override @Override
public Termine calcola() throws Errore { public Number solve() throws Error {
if (variables.length == 0) { if (variables.length == 0) {
return new Termine("0"); return new Number("0");
} else if (variables.length == 1) { } else if (variables.length == 1) {
return (Termine) variables[0].calcola(); return (Number) variables[0].solve();
} else { } else {
Termine result = new Termine("0"); Number result = new Number("0");
for (Funzione f : variables) { for (Function f : variables) {
result = result.add((Termine) f.calcola()); result = result.add((Number) f.solve());
} }
return result; return result;
} }
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
for (Funzione var : variables) { for (Function var : variables) {
var.setSmall(small); var.setSmall(small);
var.calcolaGrafica(); var.generateGraphics();
} }
width = calcWidth(); width = calcWidth();
@ -565,11 +574,11 @@ public class Espressione extends FunzioneMultiplaBase {
public boolean parenthesesNeeded() { public boolean parenthesesNeeded() {
boolean parenthesesneeded = true; boolean parenthesesneeded = true;
if (parentesiIniziale) { if (initialParenthesis) {
parenthesesneeded = false; parenthesesneeded = false;
} else { } else {
if (variables.length == 1) { if (variables.length == 1) {
if (variables[0] instanceof Divisione) { if (variables[0] instanceof Division) {
parenthesesneeded = false; parenthesesneeded = false;
} else { } else {
parenthesesneeded = true; parenthesesneeded = true;
@ -593,7 +602,7 @@ public class Espressione extends FunzioneMultiplaBase {
glDrawLine(x, y + 2, x, y + h - 3); glDrawLine(x, y + 2, x, y + h - 3);
glDrawLine(x, y + h - 3, x + 2, y + h - 1); glDrawLine(x, y + h - 3, x + 2, y + h - 1);
x += 4; x += 4;
for (Funzione f : variables) { for (Function f : variables) {
float fheight = f.getHeight(); float fheight = f.getHeight();
float y2 = miny + ((maxy - miny) / 2 - fheight / 2); float y2 = miny + ((maxy - miny) / 2 - fheight / 2);
f.draw(x, (int) y2); f.draw(x, (int) y2);
@ -617,7 +626,7 @@ public class Espressione extends FunzioneMultiplaBase {
return this.variables[0].getWidth(); return this.variables[0].getWidth();
} else { } else {
int w = 0; int w = 0;
for (Funzione f : variables) { for (Function f : variables) {
w += f.getWidth(); w += f.getWidth();
} }
return 1 + 4 + w + 2 + 4; return 1 + 4 + w + 2 + 4;
@ -630,12 +639,12 @@ public class Espressione extends FunzioneMultiplaBase {
} }
private int calcHeight() { private int calcHeight() {
if (parentesiIniziale || variables.length == 1) { if (initialParenthesis || variables.length == 1) {
return this.variables[0].getHeight(); return this.variables[0].getHeight();
} else { } else {
Funzione tmin = null; Function tmin = null;
Funzione tmax = null; Function tmax = null;
for (Funzione t : variables) { for (Function t : variables) {
if (tmin == null || t.getLine() >= tmin.getLine()) { if (tmin == null || t.getLine() >= tmin.getLine()) {
tmin = t; tmin = t;
} }
@ -655,11 +664,11 @@ public class Espressione extends FunzioneMultiplaBase {
} }
private int calcLine() { private int calcLine() {
if (parentesiIniziale || variables.length == 1) { if (initialParenthesis || variables.length == 1) {
return this.variables[0].getLine(); return this.variables[0].getLine();
} else { } else {
Funzione tl = null; Function tl = null;
for (Funzione t : variables) { for (Function t : variables) {
if (tl == null || t.getLine() >= tl.getLine()) { if (tl == null || t.getLine() >= tl.getLine()) {
tl = t; tl = t;
} }

View File

@ -1,11 +1,11 @@
package org.warp.picalculator; package org.warp.picalculator;
public interface Funzione { public interface Function {
public String simbolo(); public String getSymbol();
public Funzione calcola() throws Errore; public Function solve() throws Error;
public void calcolaGrafica(); public void generateGraphics();
public void draw(int x, int y); public void draw(int x, int y);

View File

@ -1,15 +1,15 @@
package org.warp.picalculator; package org.warp.picalculator;
public abstract class FunzioneBase implements Funzione { public abstract class FunctionBase implements Function {
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Termine calcola() throws Errore; public abstract Number solve() throws Error;
@Override @Override
public abstract void calcolaGrafica(); public abstract void generateGraphics();
@Override @Override
public abstract void draw(int x, int y); public abstract void draw(int x, int y);

View File

@ -5,47 +5,47 @@ import java.util.List;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunzioneMultipla implements Funzione { public abstract class FunctionMultipleValues implements Function {
public FunzioneMultipla() { public FunctionMultipleValues() {
setVariables(new Funzione[] {}); setVariables(new Function[] {});
} }
public FunzioneMultipla(Funzione[] values) { public FunctionMultipleValues(Function[] values) {
setVariables(values); setVariables(values);
} }
protected Funzione[] variables; protected Function[] variables;
protected int width; protected int width;
protected int height; protected int height;
protected int line; protected int line;
protected boolean small; protected boolean small;
public Funzione[] getVariables() { public Function[] getVariables() {
return variables; return variables;
} }
public void setVariables(Funzione[] value) { public void setVariables(Function[] value) {
variables = value; variables = value;
} }
public void setVariables(final List<Funzione> value) { public void setVariables(final List<Function> value) {
int vsize = value.size(); int vsize = value.size();
Funzione[] tmp = new Funzione[vsize]; Function[] tmp = new Function[vsize];
for (int i = 0; i < vsize; i++) { for (int i = 0; i < vsize; i++) {
tmp[i] = value.get(i); tmp[i] = value.get(i);
} }
variables = tmp; variables = tmp;
} }
public Funzione getVariable(int index) { public Function getVariable(int index) {
return variables[index]; return variables[index];
} }
public void setVariable(int index, Funzione value) { public void setVariable(int index, Function value) {
variables[index] = value; variables[index] = value;
} }
public void addVariableToEnd(Funzione value) { public void addVariableToEnd(Function value) {
int index = variables.length; int index = variables.length;
setVariablesLength(index + 1); setVariablesLength(index + 1);
variables[index] = value; variables[index] = value;
@ -60,25 +60,25 @@ public abstract class FunzioneMultipla implements Funzione {
} }
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Funzione calcola() throws Errore; public abstract Function solve() throws Error;
@Override @Override
public abstract void calcolaGrafica(); public abstract void generateGraphics();
@Override @Override
public String toString() { public String toString() {
try { try {
return calcola().toString(); return solve().toString();
} catch (Errore e) { } catch (Error e) {
return e.id.toString(); return e.id.toString();
} }
} }
@Override @Override
public Funzione clone() { public Function clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }

View File

@ -5,47 +5,47 @@ import java.util.List;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunzioneMultiplaBase extends FunzioneBase { public abstract class FunctionMultipleValuesBase extends FunctionBase {
public FunzioneMultiplaBase() { public FunctionMultipleValuesBase() {
setVariables(new FunzioneBase[] {}); setVariables(new FunctionBase[] {});
} }
public FunzioneMultiplaBase(FunzioneBase[] values) { public FunctionMultipleValuesBase(FunctionBase[] values) {
setVariables(values); setVariables(values);
} }
protected FunzioneBase[] variables; protected FunctionBase[] variables;
protected int width; protected int width;
protected int height; protected int height;
protected int line; protected int line;
protected boolean small; protected boolean small;
public FunzioneBase[] getVariables() { public FunctionBase[] getVariables() {
return variables; return variables;
} }
public void setVariables(FunzioneBase[] value) { public void setVariables(FunctionBase[] value) {
variables = value; variables = value;
} }
public void setVariables(final List<FunzioneBase> value) { public void setVariables(final List<FunctionBase> value) {
int vsize = value.size(); int vsize = value.size();
FunzioneBase[] tmp = new FunzioneBase[vsize]; FunctionBase[] tmp = new FunctionBase[vsize];
for (int i = 0; i < vsize; i++) { for (int i = 0; i < vsize; i++) {
tmp[i] = value.get(i); tmp[i] = value.get(i);
} }
variables = tmp; variables = tmp;
} }
public FunzioneBase getVariable(int index) { public FunctionBase getVariable(int index) {
return variables[index]; return variables[index];
} }
public void setVariable(int index, FunzioneBase value) { public void setVariable(int index, FunctionBase value) {
variables[index] = value; variables[index] = value;
} }
public void addVariableToEnd(FunzioneBase value) { public void addVariableToEnd(FunctionBase value) {
int index = variables.length; int index = variables.length;
setVariablesLength(index + 1); setVariablesLength(index + 1);
variables[index] = value; variables[index] = value;
@ -60,25 +60,25 @@ public abstract class FunzioneMultiplaBase extends FunzioneBase {
} }
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Termine calcola() throws Errore; public abstract Number solve() throws Error;
@Override @Override
public abstract void calcolaGrafica(); public abstract void generateGraphics();
@Override @Override
public String toString() { public String toString() {
try { try {
return calcola().toString(); return solve().toString();
} catch (Errore e) { } catch (Error e) {
return e.id.toString(); return e.id.toString();
} }
} }
@Override @Override
public FunzioneMultiplaBase clone() { public FunctionMultipleValuesBase clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }

View File

@ -9,49 +9,49 @@ import org.warp.engine.Display;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunzioneDueValori implements Funzione { public abstract class FunctionTwoValues implements Function {
public FunzioneDueValori(Funzione value1, Funzione value2) { public FunctionTwoValues(Function value1, Function value2) {
setVariable1(value1); setVariable1(value1);
setVariable2(value2); setVariable2(value2);
} }
protected Funzione variable1 = new Termine(Rational.ZERO); protected Function variable1 = new Number(Rational.ZERO);
protected int width; protected int width;
protected int height; protected int height;
protected int line; protected int line;
protected boolean small; protected boolean small;
public Funzione getVariable1() { public Function getVariable1() {
return variable1; return variable1;
} }
public void setVariable1(Funzione value) { public void setVariable1(Function value) {
variable1 = value; variable1 = value;
} }
protected Funzione variable2 = new Termine(Rational.ZERO); protected Function variable2 = new Number(Rational.ZERO);
public Funzione getVariable2() { public Function getVariable2() {
return variable2; return variable2;
} }
public void setVariable2(Funzione value) { public void setVariable2(Function value) {
variable2 = value; variable2 = value;
} }
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Funzione calcola() throws Errore; public abstract Function solve() throws Error;
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable1.setSmall(small); variable1.setSmall(small);
variable1.calcolaGrafica(); variable1.generateGraphics();
variable2.setSmall(small); variable2.setSmall(small);
variable2.calcolaGrafica(); variable2.generateGraphics();
width = calcWidth(); width = calcWidth();
height = calcHeight(); height = calcHeight();
@ -70,8 +70,8 @@ public abstract class FunzioneDueValori implements Funzione {
} else { } else {
Display.Render.setFont(PIDisplay.fonts[1]); Display.Render.setFont(PIDisplay.fonts[1]);
} }
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, simbolo()); glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
dx += getStringWidth(simbolo()); dx += getStringWidth(getSymbol());
} }
variable2.draw(dx + x, ln - variable2.getLine() + y); variable2.draw(dx + x, ln - variable2.getLine() + y);
} }
@ -94,14 +94,14 @@ public abstract class FunzioneDueValori implements Funzione {
@Override @Override
public String toString() { public String toString() {
try { try {
return calcola().toString(); return solve().toString();
} catch (Errore e) { } catch (Error e) {
return e.id.toString(); return e.id.toString();
} }
} }
@Override @Override
public FunzioneDueValori clone() { public FunctionTwoValues clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }
@ -116,13 +116,13 @@ public abstract class FunzioneDueValori implements Funzione {
} }
protected int calcWidth() { protected int calcWidth() {
return variable1.getWidth() + 1 + (drawSignum() ? getStringWidth(simbolo()) : 0) + variable2.getWidth(); return variable1.getWidth() + 1 + (drawSignum() ? getStringWidth(getSymbol()) : 0) + variable2.getWidth();
} }
protected int calcHeight() { protected int calcHeight() {
Funzione tmin = variable1; Function tmin = variable1;
Funzione tmax = variable1; Function tmax = variable1;
if (tmin == null || variable2.getLine() >= tmin.getLine()) { if (tmin == null || variable2.getLine() >= tmin.getLine()) {
tmin = variable2; tmin = variable2;
} }
@ -133,7 +133,7 @@ public abstract class FunzioneDueValori implements Funzione {
} }
protected int calcLine() { protected int calcLine() {
Funzione tl = variable1; Function tl = variable1;
if (tl == null || variable2.getLine() >= tl.getLine()) { if (tl == null || variable2.getLine() >= tl.getLine()) {
tl = variable2; tl = variable2;
} }

View File

@ -9,49 +9,49 @@ import org.warp.engine.Display;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public abstract class FunzioneDueValoriBase extends FunzioneBase { public abstract class FunctionTwoValuesBase extends FunctionBase {
public FunzioneDueValoriBase(FunzioneBase value1, FunzioneBase value2) { public FunctionTwoValuesBase(FunctionBase value1, FunctionBase value2) {
setVariable1(value1); setVariable1(value1);
setVariable2(value2); setVariable2(value2);
} }
protected FunzioneBase variable1 = new Termine(Rational.ZERO); protected FunctionBase variable1 = new Number(Rational.ZERO);
protected int width; protected int width;
protected int height; protected int height;
protected int line; protected int line;
protected boolean small; protected boolean small;
public FunzioneBase getVariable1() { public FunctionBase getVariable1() {
return variable1; return variable1;
} }
public void setVariable1(FunzioneBase value) { public void setVariable1(FunctionBase value) {
variable1 = value; variable1 = value;
} }
protected FunzioneBase variable2 = new Termine(Rational.ZERO); protected FunctionBase variable2 = new Number(Rational.ZERO);
public FunzioneBase getVariable2() { public FunctionBase getVariable2() {
return variable2; return variable2;
} }
public void setVariable2(FunzioneBase value) { public void setVariable2(FunctionBase value) {
variable2 = value; variable2 = value;
} }
@Override @Override
public abstract String simbolo(); public abstract String getSymbol();
@Override @Override
public abstract Termine calcola() throws Errore; public abstract Number solve() throws Error;
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable1.setSmall(small); variable1.setSmall(small);
variable1.calcolaGrafica(); variable1.generateGraphics();
variable2.setSmall(small); variable2.setSmall(small);
variable2.calcolaGrafica(); variable2.generateGraphics();
width = calcWidth(); width = calcWidth();
height = calcHeight(); height = calcHeight();
@ -70,8 +70,8 @@ public abstract class FunzioneDueValoriBase extends FunzioneBase {
} else { } else {
Display.Render.setFont(PIDisplay.fonts[0]); Display.Render.setFont(PIDisplay.fonts[0]);
} }
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, simbolo()); glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
dx += getStringWidth(simbolo()); dx += getStringWidth(getSymbol());
} }
variable2.draw(dx + x, ln - variable2.getLine() + y); variable2.draw(dx + x, ln - variable2.getLine() + y);
} }
@ -94,14 +94,14 @@ public abstract class FunzioneDueValoriBase extends FunzioneBase {
@Override @Override
public String toString() { public String toString() {
try { try {
return calcola().toString(); return solve().toString();
} catch (Errore e) { } catch (Error e) {
return e.id.toString(); return e.id.toString();
} }
} }
@Override @Override
public FunzioneDueValoriBase clone() { public FunctionTwoValuesBase clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }
@ -116,13 +116,13 @@ public abstract class FunzioneDueValoriBase extends FunzioneBase {
} }
protected int calcWidth() { protected int calcWidth() {
return variable1.getWidth() + 1 + (drawSignum() ? getStringWidth(simbolo()) : 0) + variable2.getWidth(); return variable1.getWidth() + 1 + (drawSignum() ? getStringWidth(getSymbol()) : 0) + variable2.getWidth();
} }
protected int calcHeight() { protected int calcHeight() {
FunzioneBase tmin = variable1; FunctionBase tmin = variable1;
FunzioneBase tmax = variable1; FunctionBase tmax = variable1;
if (tmin == null || variable2.getLine() >= tmin.getLine()) { if (tmin == null || variable2.getLine() >= tmin.getLine()) {
tmin = variable2; tmin = variable2;
} }
@ -133,7 +133,7 @@ public abstract class FunzioneDueValoriBase extends FunzioneBase {
} }
protected int calcLine() { protected int calcLine() {
FunzioneBase tl = variable1; FunctionBase tl = variable1;
if (tl == null || variable2.getLine() >= tl.getLine()) { if (tl == null || variable2.getLine() >= tl.getLine()) {
tl = variable2; tl = variable2;
} }

View File

@ -1,40 +0,0 @@
package org.warp.picalculator;
import org.nevec.rjm.Rational;
public class Incognita {
public char simbolo = 'X';
public Rational esponente = Rational.ONE;
public Incognita(char simbolo, Rational esponente) {
this.simbolo = simbolo;
this.esponente = esponente;
}
public Incognita(char simbolo, int a, int b) {
this.simbolo = simbolo;
this.esponente = new Rational(a, b);
}
public Incognita(char simbolo) {
this.simbolo = simbolo;
this.esponente = new Rational(1, 1);
}
@Override
public boolean equals(Object o) {
if (o instanceof Incognita) {
if (this.simbolo == ((Incognita) o).simbolo) {
if (this.esponente == ((Incognita) o).esponente) {
return true;
}
}
}
return false;
}
@Override
public int hashCode() {
return Character.getNumericValue(simbolo) * 3 + esponente.hashCode();
}
}

View File

@ -1,391 +0,0 @@
package org.warp.picalculator;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.Vector;
import org.nevec.rjm.BigIntegerMath;
import org.nevec.rjm.Rational;
public class Incognite {
Vector<Incognita> incognite;
public Incognite() {
incognite = new Vector<Incognita>();
}
public Incognite(Incognita[] value) {
this();
for (Incognita i : value) {
incognite.add(i);
}
}
public Incognite(Vector<Incognita> value) {
this();
incognite = value;
}
public Incognite(Incognita value) {
this();
incognite.add(value);
}
public int count() {
return incognite.size();
}
public boolean contieneSimbolo(char simbolo) {
for (Incognita i : incognite) {
if (i.simbolo == simbolo) {
return true;
}
}
return false;
}
public Rational prendiEsponenteSimbolo(char simbolo) {
for (Incognita i : incognite) {
if (i.simbolo == simbolo) {
return i.esponente;
}
}
return new Rational(0, 1);
}
public void impostaEsponenteSimbolo(char simbolo, Rational esponente) {
for (Incognita i : incognite) {
if (i.simbolo == simbolo) {
i.esponente = esponente;
}
}
}
@SuppressWarnings("unchecked")
@Override
public Incognite clone() {
return new Incognite((Vector<Incognita>) incognite.clone()).normalize();
}
public Incognite multiply(Incognite val) {
Incognite result = new Incognite();
// Passaggio 1: test vari
// Se il primo gruppo di incognite à nullo allora ritorna il secondo
// gruppo
if (this.count() == 0) {
result = val.clone();
return result;
}
// Se il secondo gruppo di incognite à nullo allora ritorna il primo
// gruppo
if (val.count() == 0) {
result = this.clone();
return result;
}
// Passaggio 2: le incognite doppie vengono raggruppate.
for (Incognita i1 : incognite) {
for (Incognita i2 : val.incognite) {
if (i1.simbolo == i2.simbolo) {
if (!result.contieneSimbolo(i1.simbolo)) {
Incognita ir = new Incognita(i1.simbolo, i1.esponente.add(i2.esponente));
result.incognite.add(ir);
}
}
}
}
// Passaggio 3: le incognite non ancora presenti vengono aggiunte.
for (Incognita i : incognite) {
if (!result.contieneSimbolo(i.simbolo)) {
result.incognite.add(i);
}
}
for (Incognita i : val.incognite) {
if (!result.contieneSimbolo(i.simbolo)) {
result.incognite.add(i);
}
}
return result.normalize();
}
public Incognite divide(Incognite val) {
Incognite result = new Incognite();
// Passaggio 2: le incognite doppie vengono raggruppate.
for (Incognita i1 : incognite) {
for (Incognita i2 : val.incognite) {
if (i1.simbolo == i2.simbolo) {
if (!result.contieneSimbolo(i1.simbolo)) {
Incognita ir = new Incognita(i1.simbolo, i1.esponente.add(i2.esponente.multiply(new Rational(-1, 1))));
result.incognite.add(ir);
}
}
}
}
// Passaggio 3: le incognite non ancora presenti vengono aggiunte.
for (Incognita i : incognite) {
if (!result.contieneSimbolo(i.simbolo)) {
result.incognite.add(i);
}
}
for (Incognita i : val.incognite) {
if (!result.contieneSimbolo(i.simbolo)) {
result.incognite.add(new Incognita(i.simbolo, i.esponente.multiply(new Rational(-1, 1))));
}
}
return result.normalize();
}
public Incognite sqrt() {
Incognite result = new Incognite();
for (Incognita i1 : incognite) {
Incognita ir = null;
try {
ir = new Incognita(i1.simbolo, i1.esponente.divide(new Rational(2, 1)));
} catch (Errore e) {
e.printStackTrace();
}
result.incognite.add(ir);
}
return result.normalize();
}
public Incognite normalize() {
Incognite result = new Incognite();
for (Incognita i1 : incognite) {
if (i1.esponente.compareTo(Rational.ZERO) != 0) {
result.incognite.add(i1);
}
}
result.incognite.sort(new Comparator<Incognita>() {
@Override
public int compare(Incognita o1, Incognita o2) {
int index1 = letterIndex(o1.simbolo);
int index2 = letterIndex(o2.simbolo);
return index1 - index2;
}
});
return result;
}
public byte letterIndex(char l) {
return letterIndex(l, false);
}
public static byte letterIndex(char l, boolean reverse) {
int total = Simboli.incognite().length - 1;
for (byte x = 0; x < Simboli.incognite().length; x++) {
if (Simboli.incognite()[x].equals("" + l)) {
if (reverse) {
return (byte) (total - x);
} else {
return x;
}
}
}
return -1;
}
public boolean compareTo(Incognite val) {
if (this.equals(val))
return true;
return false;
}
@Override
public boolean equals(Object val) {
if (val == null)
return false;
if (val instanceof Incognite) {
Incognite ii2 = (Incognite) val;
for (Incognita i1 : incognite) {
boolean found = false;
for (Incognita i2 : ii2.incognite) {
if (i1.simbolo == i2.simbolo) {
if (i1.esponente.compareTo(i2.esponente) != 0)
return false;
found = true;
}
}
if (!found) {
return false;
}
}
for (Incognita i1 : ii2.incognite) {
boolean found = false;
for (Incognita i2 : incognite) {
if (i1.simbolo == i2.simbolo) {
if (i1.esponente.compareTo(i2.esponente) != 0)
return false;
found = true;
}
}
if (!found) {
return false;
}
}
return true;
}
return false;
}
@Override
public String toString() {
String result = "";
if (incognite.size() != 1) {
for (Incognita i : incognite) {
if (i.esponente.compareTo(Rational.ONE) != 0) {
result += "(" + i.simbolo + "^" + i.esponente + ")";
} else {
result += i.simbolo;
}
}
} else if (incognite.size() == 1) {
Incognita i = incognite.get(0);
if (i.esponente.compareTo(Rational.ONE) != 0) {
result += "" + i.simbolo + "^" + i.esponente + "";
} else if (i.esponente.compareTo(Rational.ONE) == 0) {
result += i.simbolo;
}
}
return result;
}
public static Incognite lcm(Incognite val1, Incognite val2) {
Incognite result = new Incognite();
// Passaggio 1: test vari
// Se il primo gruppo di incognite à nullo allora ritorna il secondo
// gruppo
if (val1.count() == 0) {
result = val2.clone();
return result;
}
// Se il secondo gruppo di incognite à nullo allora ritorna il primo
// gruppo
if (val2.count() == 0) {
result = val1.clone();
return result;
}
// Passaggio 2: le incognite doppie vengono raggruppate.
for (Incognita i1 : val1.incognite) {
for (Incognita i2 : val2.incognite) {
if (i1.simbolo == i2.simbolo) {
if (!result.contieneSimbolo(i1.simbolo)) {
Incognita ir = new Incognita(i1.simbolo);
if (i1.esponente.compareTo(i2.esponente) > 0) {
ir.esponente = i1.esponente;
} else {
ir.esponente = i2.esponente;
}
result.incognite.add(ir);
}
}
}
}
// Passaggio 3: le incognite non ancora presenti vengono aggiunte.
for (Incognita i : val1.incognite) {
if (!result.contieneSimbolo(i.simbolo)) {
result.incognite.add(i);
}
}
for (Incognita i : val2.incognite) {
if (!result.contieneSimbolo(i.simbolo)) {
result.incognite.add(i);
}
}
return result.normalize();
}
@SuppressWarnings("unchecked")
public Vector<Incognita> listaIncognite() {
return (Vector<Incognita>) this.incognite.clone();
}
public static Incognite[] normalizeBigSurdVariables(Incognite[] incognitetemp) throws Errore {
Incognite incognitex = incognitetemp[0].clone();
Incognite incognitey = incognitetemp[1].clone();
Incognite incognitez = incognitetemp[2].clone();
Incognite newincognitex = new Incognite();
for (Incognita i : incognitex.incognite) {
Vector<BigInteger> divisori = BigIntegerMath.divisors(i.esponente.divide(2).denom());
if (divisori.contains(new BigInteger("2"))) {
newincognitex = newincognitex.multiply(new Incognite(i));
} else {
incognitey = incognitey.multiply(new Incognite(new Incognita(i.simbolo, i.esponente.divide(2))));
}
}
incognitex = newincognitex;
for (Incognita i : incognitey.incognite) {
if (i.esponente.signum() < 0) {
incognitey = incognitey.divide(new Incognite(i));
incognitez = incognitez.divide(new Incognite(i));
}
}
for (Incognita i : incognitez.incognite) {
if (i.esponente.signum() < 0) {
incognitey = incognitey.divide(new Incognite(i));
incognitez = incognitez.divide(new Incognite(i));
}
}
// TODO: SPOSTARE LE Y NEGATIVE SOTTO LA FRAZIONE, DALLA Y ALLA Z
Incognite incogniteyresult = new Incognite();
Incognite incognitezresult = new Incognite();
// Le incognite doppie vengono tolte
for (Incognita i1 : incognitey.incognite) {
for (Incognita i2 : incognitez.incognite) {
if (i1.simbolo == i2.simbolo) {
if (i1.esponente.compareTo(i2.esponente) > 0) {
incogniteyresult = incogniteyresult.multiply(new Incognite(new Incognita(i1.simbolo, i1.esponente.subtract(i2.esponente))));
} else if (i2.esponente.compareTo(i1.esponente) > 0) {
incognitezresult = incognitezresult.multiply(new Incognite(new Incognita(i1.simbolo, i2.esponente.subtract(i1.esponente))));
}
}
}
}
// Le altre incognite vengono ri-messe
for (Incognita i : incognitey.incognite) {
if (!incogniteyresult.contieneSimbolo(i.simbolo)) {
incogniteyresult = incogniteyresult.multiply(new Incognite(i));
}
}
for (Incognita i : incognitez.incognite) {
if (!incognitezresult.contieneSimbolo(i.simbolo)) {
incognitezresult = incognitezresult.multiply(new Incognite(i));
}
}
incognitey = incogniteyresult;
incognitez = incognitezresult;
return new Incognite[] { incognitex, incognitey, incognitez };
}
public static int priorità(Incognite ii) {
double priorità = 0;
double letterMax = 0;
for (Incognita i : ii.incognite) {
int lettIndex = letterIndex(i.simbolo, true);
if (lettIndex > letterMax) {
letterMax = lettIndex;
}
}
priorità += letterMax * 100000;
for (Incognita i : ii.incognite) {
int lettIndex = letterIndex(i.simbolo, true);
if (letterMax == lettIndex) {
priorità += i.esponente.doubleValue() * 100000;
}
priorità += +i.esponente.doubleValue();
}
return (int) priorità;
}
}

View File

@ -47,15 +47,6 @@ public class Main {
} }
public static void main(String[] args) throws InterruptedException { public static void main(String[] args) throws InterruptedException {
try {
Termine t = new Termine("9999.9");
Termine r = t.calcola();
System.out.println(t.toString());
System.out.println(r.toString());
} catch (Errore e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
new Main(); new Main();
} }
} }

View File

@ -2,7 +2,7 @@ package org.warp.picalculator;
import static org.warp.picalculator.Utils.concat; import static org.warp.picalculator.Utils.concat;
public class Simboli { public class MathematicalSymbols {
public static final String SUM = "+"; public static final String SUM = "+";
public static final String SUBTRACTION = "-"; public static final String SUBTRACTION = "-";
public static final String MULTIPLICATION = "*"; public static final String MULTIPLICATION = "*";
@ -12,23 +12,23 @@ public class Simboli {
public static final String SQUARE_ROOT = ""; public static final String SQUARE_ROOT = "";
public static final String PARENTHESIS_OPEN = "("; public static final String PARENTHESIS_OPEN = "(";
public static final String PARENTHESIS_CLOSE = ")"; public static final String PARENTHESIS_CLOSE = ")";
public static final String POTENZA = ""; public static final String POWER = "";
public static final String EQUATION = "="; public static final String EQUATION = "=";
public static final String SYSTEM = "{"; public static final String SYSTEM = "{";
public static final String[] funzioni() { public static final String[] functions() {
return concat(funzioniNSN(), funzioniSN()); return concat(functionsNSN(), functionsSN());
} }
public static final String[] funzioniNSN() { public static final String[] functionsNSN() {
return new String[] { NTH_ROOT, POTENZA }; return new String[] { NTH_ROOT, POWER };
} }
public static final String[] funzioniSN() { public static final String[] functionsSN() {
return new String[] { SQUARE_ROOT }; return new String[] { SQUARE_ROOT };
} }
public static final String[] segni(boolean withMultiplication, boolean withPrioritaryMultiplication) { public static final String[] signums(boolean withMultiplication, boolean withPrioritaryMultiplication) {
String[] ret = new String[] { SUM, DIVISION }; String[] ret = new String[] { SUM, DIVISION };
if (withMultiplication) { if (withMultiplication) {
ret = Utils.add(ret, MULTIPLICATION); ret = Utils.add(ret, MULTIPLICATION);
@ -39,15 +39,15 @@ public class Simboli {
return ret; return ret;
} }
public static final String[] parentesi() { public static final String[] parentheses() {
return new String[] { PARENTHESIS_OPEN, PARENTHESIS_CLOSE }; return new String[] { PARENTHESIS_OPEN, PARENTHESIS_CLOSE };
} }
public static String[] incognite() { public static String[] variables() {
return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" }; return new String[] { "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z" };
} }
public static String[] sintassiGenerale() { public static String[] genericSyntax() {
return new String[] { SYSTEM, EQUATION }; return new String[] { SYSTEM, EQUATION };
} }
} }

View File

@ -1,81 +0,0 @@
package org.warp.picalculator;
import java.math.BigInteger;
public class Moltiplicazione extends FunzioneDueValoriBase {
public Moltiplicazione(FunzioneBase value1, FunzioneBase value2) {
super(value1, value2);
}
@Override
public String simbolo() {
return Simboli.MULTIPLICATION;
}
@Override
public Termine calcola() throws Errore {
return getVariable1().calcola().multiply(getVariable2().calcola());
}
@Override
public boolean drawSignum() {
Funzione[] tmpVar = new Funzione[] { variable1, variable2 };
boolean[] ok = new boolean[] { false, false };
for (int val = 0; val < 2; val++) {
while (!ok[val]) {
if (tmpVar[val] instanceof Divisione) {
ok[0] = true;
ok[1] = true;
} else if (tmpVar[val] instanceof Incognita) {
ok[val] = true;
} else if (tmpVar[val] instanceof Termine) {
if (val == 0) {
ok[val] = true;
} else {
if (!(tmpVar[0] instanceof Termine)) {
ok[val] = true;
} else {
if (((Termine) tmpVar[val]).term.isBigInteger(false)) { // TODO: prima era tmpVar[0], ma crashava. RICONTROLLARE! La logica potrebbe essere sbagliata
if (((Termine) tmpVar[val]).term.toBigInteger(true).compareTo(new BigInteger("1")) == 0) {
if (((Termine) tmpVar[val]).term.toNumeroAvanzato().getIncognitey().count() > 0) {
ok[val] = true;
} else {
break;
}
} else {
break;
}
} else {
ok[val] = true;
}
}
}
} else if (tmpVar[val] instanceof Potenza) {
tmpVar[val] = ((Potenza) tmpVar[val]).variable1;
} else if (tmpVar[val] instanceof Radice) {
ok[val] = true;
} else if (tmpVar[val] instanceof RadiceQuadrata) {
ok[val] = true;
} else if (tmpVar[val] instanceof Espressione) {
ok[0] = true;
ok[1] = true;
} else if (tmpVar[val] instanceof FunzioneDueValoriBase) {
if (val == 0) {
tmpVar[val] = ((FunzioneDueValoriBase) tmpVar[val]).variable2;
} else {
tmpVar[val] = ((FunzioneDueValoriBase) tmpVar[val]).variable1;
}
} else if (tmpVar[val] instanceof FunzioneAnterioreBase) {
tmpVar[val] = ((FunzioneAnterioreBase) tmpVar[val]).variable;
}
}
}
if (ok[0] == true && ok[1] == true) {
return false;
} else {
return true;
}
}
}

View File

@ -1,23 +0,0 @@
package org.warp.picalculator;
public class MoltiplicazionePrioritaria extends FunzioneDueValoriBase {
public MoltiplicazionePrioritaria(FunzioneBase value1, FunzioneBase value2) {
super(value1, value2);
}
@Override
public String simbolo() {
return Simboli.PRIORITARY_MULTIPLICATION;
}
@Override
public Termine calcola() throws Errore {
return getVariable1().calcola().multiply(getVariable2().calcola());
}
@Override
public boolean drawSignum() {
return false;
}
}

View File

@ -0,0 +1,81 @@
package org.warp.picalculator;
import java.math.BigInteger;
public class Multiplication extends FunctionTwoValuesBase {
public Multiplication(FunctionBase value1, FunctionBase value2) {
super(value1, value2);
}
@Override
public String getSymbol() {
return MathematicalSymbols.MULTIPLICATION;
}
@Override
public Number solve() throws Error {
return getVariable1().solve().multiply(getVariable2().solve());
}
@Override
public boolean drawSignum() {
Function[] tmpVar = new Function[] { variable1, variable2 };
boolean[] ok = new boolean[] { false, false };
for (int val = 0; val < 2; val++) {
while (!ok[val]) {
if (tmpVar[val] instanceof Division) {
ok[0] = true;
ok[1] = true;
} else if (tmpVar[val] instanceof Variable) {
ok[val] = true;
} else if (tmpVar[val] instanceof Number) {
if (val == 0) {
ok[val] = true;
} else {
if (!(tmpVar[0] instanceof Number)) {
ok[val] = true;
} else {
if (((Number) tmpVar[val]).term.isBigInteger(false)) { // TODO: prima era tmpVar[0], ma crashava. RICONTROLLARE! La logica potrebbe essere sbagliata
if (((Number) tmpVar[val]).term.toBigInteger(true).compareTo(new BigInteger("1")) == 0) {
if (((Number) tmpVar[val]).term.toNumeroAvanzato().getVariableY().count() > 0) {
ok[val] = true;
} else {
break;
}
} else {
break;
}
} else {
ok[val] = true;
}
}
}
} else if (tmpVar[val] instanceof Power) {
tmpVar[val] = ((Power) tmpVar[val]).variable1;
} else if (tmpVar[val] instanceof Root) {
ok[val] = true;
} else if (tmpVar[val] instanceof RootSquare) {
ok[val] = true;
} else if (tmpVar[val] instanceof Expression) {
ok[0] = true;
ok[1] = true;
} else if (tmpVar[val] instanceof FunctionTwoValuesBase) {
if (val == 0) {
tmpVar[val] = ((FunctionTwoValuesBase) tmpVar[val]).variable2;
} else {
tmpVar[val] = ((FunctionTwoValuesBase) tmpVar[val]).variable1;
}
} else if (tmpVar[val] instanceof AnteriorFunctionBase) {
tmpVar[val] = ((AnteriorFunctionBase) tmpVar[val]).variable;
}
}
}
if (ok[0] == true && ok[1] == true) {
return false;
} else {
return true;
}
}
}

View File

@ -18,7 +18,7 @@ import org.warp.engine.Display;
import com.rits.cloning.Cloner; import com.rits.cloning.Cloner;
public class Termine extends FunzioneBase { public class Number extends FunctionBase {
protected NumeroAvanzatoVec term = NumeroAvanzatoVec.ZERO; protected NumeroAvanzatoVec term = NumeroAvanzatoVec.ZERO;
protected int width; protected int width;
@ -26,27 +26,27 @@ public class Termine extends FunzioneBase {
protected int line; protected int line;
protected boolean small; protected boolean small;
public Termine(NumeroAvanzatoVec val) { public Number(NumeroAvanzatoVec val) {
term = val; term = val;
} }
public Termine(String s) throws Errore { public Number(String s) throws Error {
term = new NumeroAvanzatoVec(new NumeroAvanzato(Utils.getRational(s), Rational.ONE)); term = new NumeroAvanzatoVec(new NumeroAvanzato(Utils.getRational(s), Rational.ONE));
} }
public Termine(Rational r) { public Number(Rational r) {
term = new NumeroAvanzatoVec(new NumeroAvanzato(r, Rational.ONE)); term = new NumeroAvanzatoVec(new NumeroAvanzato(r, Rational.ONE));
} }
public Termine(BigInteger r) { public Number(BigInteger r) {
term = new NumeroAvanzatoVec(new NumeroAvanzato(new Rational(r, BigInteger.ONE), Rational.ONE)); term = new NumeroAvanzatoVec(new NumeroAvanzato(new Rational(r, BigInteger.ONE), Rational.ONE));
} }
public Termine(BigDecimal r) { public Number(BigDecimal r) {
term = new NumeroAvanzatoVec(new NumeroAvanzato(Utils.getRational(r), Rational.ONE)); term = new NumeroAvanzatoVec(new NumeroAvanzato(Utils.getRational(r), Rational.ONE));
} }
public Termine(NumeroAvanzato numeroAvanzato) { public Number(NumeroAvanzato numeroAvanzato) {
term = new NumeroAvanzatoVec(numeroAvanzato); term = new NumeroAvanzatoVec(numeroAvanzato);
} }
@ -59,42 +59,42 @@ public class Termine extends FunzioneBase {
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
line = calcLine(); //TODO pp line = calcLine(); //TODO pp
height = calcHeight(); height = calcHeight();
width = calcWidth(); width = calcWidth();
} }
@Override @Override
public Termine calcola() { public Number solve() {
return this; return this;
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return toString(); return toString();
} }
public Termine add(Termine f) throws Errore { public Number add(Number f) throws Error {
Termine ret = new Termine(getTerm().add(f.getTerm())); Number ret = new Number(getTerm().add(f.getTerm()));
return ret; return ret;
} }
public Termine multiply(Termine f) throws Errore { public Number multiply(Number f) throws Error {
Termine ret = new Termine(getTerm().multiply(f.getTerm())); Number ret = new Number(getTerm().multiply(f.getTerm()));
return ret; return ret;
} }
public Termine divide(Termine f) throws Errore { public Number divide(Number f) throws Error {
Termine ret = new Termine(getTerm().divide(f.getTerm())); Number ret = new Number(getTerm().divide(f.getTerm()));
return ret; return ret;
} }
public Termine pow(Termine f) throws Errore { public Number pow(Number f) throws Error {
Termine ret = new Termine(NumeroAvanzatoVec.ONE); Number ret = new Number(NumeroAvanzatoVec.ONE);
if (f.getTerm().isBigInteger(true)) { if (f.getTerm().isBigInteger(true)) {
for (BigInteger i = BigInteger.ZERO; i.compareTo(f.getTerm().toBigInteger(true)) < 0; i = i.add(BigInteger.ONE)) { for (BigInteger i = BigInteger.ZERO; i.compareTo(f.getTerm().toBigInteger(true)) < 0; i = i.add(BigInteger.ONE)) {
ret = ret.multiply(new Termine(getTerm())); ret = ret.multiply(new Number(getTerm()));
} }
} else if (getTerm().isRational(true) && f.getTerm().isRational(false) && f.getTerm().toRational(false).compareTo(Rational.HALF) == 0) { } else if (getTerm().isRational(true) && f.getTerm().isRational(false) && f.getTerm().toRational(false).compareTo(Rational.HALF) == 0) {
// Rational originalExponent = f.getTerm().toRational(); // Rational originalExponent = f.getTerm().toRational();
@ -102,12 +102,12 @@ public class Termine extends FunzioneBase {
// originalExponent.numer()); // originalExponent.numer());
Rational numberToRoot = getTerm().toRational(true); Rational numberToRoot = getTerm().toRational(true);
NumeroAvanzato na = new NumeroAvanzato(Rational.ONE, numberToRoot); NumeroAvanzato na = new NumeroAvanzato(Rational.ONE, numberToRoot);
na = na.setIncognitex(getTerm().toNumeroAvanzato().getIncognitey().multiply(getTerm().toNumeroAvanzato().getIncognitez())); na = na.setVariableX(getTerm().toNumeroAvanzato().getVariableY().multiply(getTerm().toNumeroAvanzato().getVariableZ()));
na = na.setIncognitey(new Incognite()); na = na.setVariableY(new Variables());
na = na.setIncognitez(getTerm().toNumeroAvanzato().getIncognitez()); na = na.setVariableZ(getTerm().toNumeroAvanzato().getVariableZ());
ret = new Termine(na); ret = new Number(na);
} else { } else {
ret = new Termine(BigDecimalMath.pow(getTerm().BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2)), f.getTerm().BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2)))); ret = new Number(BigDecimalMath.pow(getTerm().BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2)), f.getTerm().BigDecimalValue(new MathContext(Utils.scale, Utils.scaleMode2))));
} }
return ret; return ret;
} }
@ -346,7 +346,7 @@ public class Termine extends FunzioneBase {
public boolean soloIncognitaSemplice() { public boolean soloIncognitaSemplice() {
if (this.getTerm().isBigInteger(true)) { if (this.getTerm().isBigInteger(true)) {
if (this.getTerm().toBigInteger(true).compareTo(BigInteger.ONE) == 0 && this.getTerm().toNumeroAvanzato().getIncognitey().count() > 0) { if (this.getTerm().toBigInteger(true).compareTo(BigInteger.ONE) == 0 && this.getTerm().toNumeroAvanzato().getVariableY().count() > 0) {
return true; return true;
} }
} }
@ -376,7 +376,7 @@ public class Termine extends FunzioneBase {
} }
@Override @Override
public Termine clone() { public Number clone() {
Cloner cloner = new Cloner(); Cloner cloner = new Cloner();
return cloner.deepClone(this); return cloner.deepClone(this);
} }

View File

@ -1,23 +1,23 @@
package org.warp.picalculator; package org.warp.picalculator;
public class Potenza extends FunzioneDueValoriBase { public class Power extends FunctionTwoValuesBase {
public Potenza(FunzioneBase value1, FunzioneBase value2) { public Power(FunctionBase value1, FunctionBase value2) {
super(value1, value2); super(value1, value2);
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return Simboli.POTENZA; return MathematicalSymbols.POWER;
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable1.setSmall(small); variable1.setSmall(small);
variable1.calcolaGrafica(); variable1.generateGraphics();
variable2.setSmall(true); variable2.setSmall(true);
variable2.calcolaGrafica(); variable2.generateGraphics();
height = variable1.getHeight() + variable2.getHeight() - 4; height = variable1.getHeight() + variable2.getHeight() - 4;
line = variable2.getHeight() - 4 + variable1.getLine(); line = variable2.getHeight() - 4 + variable1.getLine();
@ -25,8 +25,8 @@ public class Potenza extends FunzioneDueValoriBase {
} }
@Override @Override
public Termine calcola() throws NumberFormatException, Errore { public Number solve() throws NumberFormatException, Error {
return getVariable1().calcola().pow(getVariable2().calcola()); return getVariable1().solve().pow(getVariable2().solve());
} }
@Override @Override

View File

@ -0,0 +1,23 @@
package org.warp.picalculator;
public class PrioritaryMultiplication extends FunctionTwoValuesBase {
public PrioritaryMultiplication(FunctionBase value1, FunctionBase value2) {
super(value1, value2);
}
@Override
public String getSymbol() {
return MathematicalSymbols.PRIORITARY_MULTIPLICATION;
}
@Override
public Number solve() throws Error {
return getVariable1().solve().multiply(getVariable2().solve());
}
@Override
public boolean drawSignum() {
return false;
}
}

View File

@ -1,13 +0,0 @@
package org.warp.picalculator;
import java.math.BigInteger;
public class RisultatoEquazione {
public boolean isAnEquation = false;
public Termine LR = new Termine(new BigInteger("0"));
public RisultatoEquazione(Termine LR, boolean isAnEquation) {
this.LR = LR;
this.isAnEquation = isAnEquation;
}
}

View File

@ -4,24 +4,24 @@ import static org.warp.engine.Display.Render.glDrawLine;
import org.nevec.rjm.NumeroAvanzatoVec; import org.nevec.rjm.NumeroAvanzatoVec;
public class Radice extends FunzioneDueValoriBase { public class Root extends FunctionTwoValuesBase {
public Radice(FunzioneBase value1, FunzioneBase value2) { public Root(FunctionBase value1, FunctionBase value2) {
super(value1, value2); super(value1, value2);
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return Simboli.NTH_ROOT; return MathematicalSymbols.NTH_ROOT;
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable1.setSmall(true); variable1.setSmall(true);
variable1.calcolaGrafica(); variable1.generateGraphics();
variable2.setSmall(small); variable2.setSmall(small);
variable2.calcolaGrafica(); variable2.generateGraphics();
width = 1 + variable1.getWidth() + 2 + variable2.getWidth() + 2; width = 1 + variable1.getWidth() + 2 + variable2.getWidth() + 2;
height = variable1.getHeight() + variable2.getHeight() - 2; height = variable1.getHeight() + variable2.getHeight() - 2;
@ -29,10 +29,10 @@ public class Radice extends FunzioneDueValoriBase {
} }
@Override @Override
public Termine calcola() throws NumberFormatException, Errore { public Number solve() throws NumberFormatException, Error {
Termine exponent = new Termine(NumeroAvanzatoVec.ONE); Number exponent = new Number(NumeroAvanzatoVec.ONE);
exponent = exponent.divide(getVariable1().calcola()); exponent = exponent.divide(getVariable1().solve());
return getVariable2().calcola().pow(exponent); return getVariable2().solve().pow(exponent);
} }
@Override @Override

View File

@ -2,21 +2,21 @@ package org.warp.picalculator;
import org.nevec.rjm.Rational; import org.nevec.rjm.Rational;
public class RadiceQuadrata extends FunzioneAnterioreBase { public class RootSquare extends AnteriorFunctionBase {
public RadiceQuadrata(FunzioneBase value) { public RootSquare(FunctionBase value) {
super(value); super(value);
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return Simboli.SQUARE_ROOT; return MathematicalSymbols.SQUARE_ROOT;
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable.setSmall(small); variable.setSmall(small);
variable.calcolaGrafica(); variable.generateGraphics();
height = getVariable().getHeight() + 2; height = getVariable().getHeight() + 2;
width = 1 + 4 + getVariable().getWidth() + 1; width = 1 + 4 + getVariable().getWidth() + 1;
@ -24,17 +24,17 @@ public class RadiceQuadrata extends FunzioneAnterioreBase {
} }
@Override @Override
public Termine calcola() throws Errore { public Number solve() throws Error {
try { try {
Termine result = getVariable().calcola(); Number result = getVariable().solve();
result = result.pow(new Termine(new Rational(1, 2))); result = result.pow(new Number(new Rational(1, 2)));
return result; return result;
} catch(NullPointerException ex) { } catch(NullPointerException ex) {
throw new Errore(Errori.ERROR); throw new Error(Errors.ERROR);
} catch(NumberFormatException ex) { } catch(NumberFormatException ex) {
throw new Errore(Errori.SYNTAX_ERROR); throw new Error(Errors.SYNTAX_ERROR);
} catch(ArithmeticException ex) { } catch(ArithmeticException ex) {
throw new Errore(Errori.NUMBER_TOO_SMALL); throw new Error(Errors.NUMBER_TOO_SMALL);
} }
} }

View File

@ -1,92 +0,0 @@
package org.warp.picalculator;
import static org.warp.engine.Display.Render.glDrawLine;
public class Sistema extends FunzioneMultipla {
static final int spacing = 2;
public Sistema() {
super();
}
public Sistema(Funzione value) {
super(new Funzione[]{value});
}
public Sistema(Funzione[] value) {
super(value);
}
@Override
public String simbolo() {
return null;
}
@Override
public Funzione calcola() throws NumberFormatException, Errore {
// TODO implementare il calcolo dei sistemi
return variables[0].calcola();
}
@Override
public void calcolaGrafica() {
for (Funzione f : variables) {
f.setSmall(false);
f.calcolaGrafica();
}
width = 0;
for (Funzione f : variables) {
if (f.getWidth() > width) {
width = f.getWidth();
}
}
width += 5;
height = 3;
for (Funzione f : variables) {
height += f.getHeight()+spacing;
}
height = height - spacing + 2;
line = height/2;
}
@Override
public void draw(int x, int y) {
final int h = this.getHeight() - 1;
final int paddingTop = 3;
final int spazioSotto = (h - 3 - 2) / 2 + paddingTop;
final int spazioSopra = h - spazioSotto;
int dy = paddingTop;
for (Funzione f : variables) {
f.draw(x + 5, y + dy);
dy+=f.getHeight()+spacing;
}
glDrawLine(x + 2, y + 0, x + 3, y + 0);
glDrawLine(x + 1, y + 1, x + 1, y + spazioSotto / 2);
glDrawLine(x + 2, y + spazioSotto / 2 + 1, x + 2, y + spazioSotto - 1);
glDrawLine(x + 0, y + spazioSotto, x + 1, y + spazioSotto);
glDrawLine(x + 2, y + spazioSotto + 1, x + 2, y + spazioSotto + spazioSopra / 2 - 1);
glDrawLine(x + 1, y + spazioSotto + spazioSopra / 2, x + 1, y + h - 1);
glDrawLine(x + 2, y + h, x + 3, y + h);
}
@Override
public int getWidth() {
return width;
}
@Override
public int getHeight() {
return height;
}
@Override
public int getLine() {
return line;
}
}

View File

@ -0,0 +1,9 @@
package org.warp.picalculator;
import java.util.ArrayList;
public interface SolveMethod {
public static final SolveMethod[] techniques = new SolveMethod[] {};
public abstract ArrayList<Equation> solve(Equation equation);
}

View File

@ -1,19 +0,0 @@
package org.warp.picalculator;
public class Sottrazione extends FunzioneDueValoriBase {
public Sottrazione(FunzioneBase value1, FunzioneBase value2) {
super(value1, value2);
}
@Override
public String simbolo() {
return Simboli.SUBTRACTION;
}
@Override
public Termine calcola() throws Errore {
return getVariable1().calcola().add(getVariable2().calcola().multiply(new Termine("-1")));
}
}

View File

@ -0,0 +1,19 @@
package org.warp.picalculator;
public class Subtraction extends FunctionTwoValuesBase {
public Subtraction(FunctionBase value1, FunctionBase value2) {
super(value1, value2);
}
@Override
public String getSymbol() {
return MathematicalSymbols.SUBTRACTION;
}
@Override
public Number solve() throws Error {
return getVariable1().solve().add(getVariable2().solve().multiply(new Number("-1")));
}
}

View File

@ -6,32 +6,32 @@ import static org.warp.engine.Display.Render.glDrawStringLeft;
import org.warp.device.PIDisplay; import org.warp.device.PIDisplay;
import org.warp.engine.Display; import org.warp.engine.Display;
public class Somma extends FunzioneDueValoriBase { public class Sum extends FunctionTwoValuesBase {
public Somma(FunzioneBase value1, FunzioneBase value2) { public Sum(FunctionBase value1, FunctionBase value2) {
super(value1, value2); super(value1, value2);
} }
@Override @Override
public String simbolo() { public String getSymbol() {
return Simboli.SUM; return MathematicalSymbols.SUM;
} }
@Override @Override
public Termine calcola() throws Errore { public Number solve() throws Error {
Termine val1 = getVariable1().calcola(); Number val1 = getVariable1().solve();
Termine val2 = getVariable2().calcola(); Number val2 = getVariable2().solve();
Termine result = val1.add(val2); Number result = val1.add(val2);
return result; return result;
} }
@Override @Override
public void calcolaGrafica() { public void generateGraphics() {
variable1.setSmall(small); variable1.setSmall(small);
variable1.calcolaGrafica(); variable1.generateGraphics();
variable2.setSmall(small); variable2.setSmall(small);
variable2.calcolaGrafica(); variable2.generateGraphics();
width = calcWidth(); width = calcWidth();
height = calcHeight(); height = calcHeight();
@ -54,8 +54,8 @@ public class Somma extends FunzioneDueValoriBase {
Display.Render.setFont(PIDisplay.fonts[0]); Display.Render.setFont(PIDisplay.fonts[0]);
} }
dx += 1; dx += 1;
glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, simbolo()); glDrawStringLeft(dx + x, ln - Utils.getFontHeight(small) / 2 + y, getSymbol());
dx += getStringWidth(simbolo()); dx += getStringWidth(getSymbol());
variable2.draw(dx + x, ln - variable2.getLine() + y); variable2.draw(dx + x, ln - variable2.getLine() + y);
} }
@ -69,7 +69,7 @@ public class Somma extends FunzioneDueValoriBase {
int dx = 0; int dx = 0;
dx += variable1.getWidth(); dx += variable1.getWidth();
dx += 1; dx += 1;
dx += getStringWidth(simbolo()); dx += getStringWidth(getSymbol());
return dx += variable2.getWidth(); return dx += variable2.getWidth();
} }
} }

View File

@ -1,9 +0,0 @@
package org.warp.picalculator;
import java.util.ArrayList;
public interface Tecnica {
public static final Tecnica[] tecniche = new Tecnica[] {};
public abstract ArrayList<Equazione> risolvi(Equazione equazione);
}

View File

@ -80,15 +80,15 @@ public class Utils {
return c; return c;
} }
public static boolean ciSonoSoloFunzioniImpostateSommeEquazioniESistemi(ArrayList<Funzione> fl) { public static boolean areThereOnlySettedUpFunctionsSumsEquationsAndSystems(ArrayList<Function> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (!(fl.get(i) instanceof Termine || fl.get(i) instanceof Somma || fl.get(i) instanceof Equazione || fl.get(i) instanceof ParteSistema || fl.get(i) instanceof Espressione)) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
if (fl.get(i) instanceof FunzioneAnterioreBase) { if (fl.get(i) instanceof AnteriorFunctionBase) {
if (((FunzioneAnterioreBase) fl.get(i)).variable == null) { if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
return false; return false;
} }
} else if (fl.get(i) instanceof FunzioneDueValoriBase) { } else if (fl.get(i) instanceof FunctionTwoValuesBase) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null || ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null || ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return false; return false;
} }
} else { } else {
@ -99,15 +99,15 @@ public class Utils {
return true; return true;
} }
public static boolean ciSonoSoloFunzioniImpostateSommeMoltiplicazioniEquazioniESistemi(ArrayList<Funzione> fl) { public static boolean areThereOnlySettedUpFunctionsSumsMultiplicationsEquationsAndSystems(ArrayList<Function> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (!(fl.get(i) instanceof Termine || fl.get(i) instanceof Moltiplicazione || fl.get(i) instanceof MoltiplicazionePrioritaria || fl.get(i) instanceof Somma || fl.get(i) instanceof Equazione || fl.get(i) instanceof ParteSistema || fl.get(i) instanceof Espressione)) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Sum || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
if (fl.get(i) instanceof FunzioneAnterioreBase) { if (fl.get(i) instanceof AnteriorFunctionBase) {
if (((FunzioneAnterioreBase) fl.get(i)).variable == null) { if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
return false; return false;
} }
} else if (fl.get(i) instanceof FunzioneDueValoriBase) { } else if (fl.get(i) instanceof FunctionTwoValuesBase) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null || ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null || ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return false; return false;
} }
} else { } else {
@ -118,15 +118,15 @@ public class Utils {
return true; return true;
} }
public static boolean ciSonoSoloFunzioniImpostateEquazioniESistemi(ArrayList<Funzione> fl) { public static boolean areThereOnlySettedUpFunctionsEquationsAndSystems(ArrayList<Function> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (!(fl.get(i) instanceof Termine || fl.get(i) instanceof Equazione || fl.get(i) instanceof ParteSistema || fl.get(i) instanceof Espressione)) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
if (fl.get(i) instanceof FunzioneAnterioreBase) { if (fl.get(i) instanceof AnteriorFunctionBase) {
if (((FunzioneAnterioreBase) fl.get(i)).variable == null) { if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
return false; return false;
} }
} else if (fl.get(i) instanceof FunzioneDueValoriBase) { } else if (fl.get(i) instanceof FunctionTwoValuesBase) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null || ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null || ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return false; return false;
} }
} else { } else {
@ -137,15 +137,15 @@ public class Utils {
return true; return true;
} }
public static boolean ciSonoSoloFunzioniImpostateESistemi(ArrayList<Funzione> fl) { public static boolean areThereOnlySettedUpFunctionsAndSystems(ArrayList<Function> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (!(fl.get(i) instanceof Termine || fl.get(i) instanceof Equazione || fl.get(i) instanceof ParteSistema || fl.get(i) instanceof Espressione)) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Equation || fl.get(i) instanceof EquationsSystemPart || fl.get(i) instanceof Expression)) {
if (fl.get(i) instanceof FunzioneAnterioreBase) { if (fl.get(i) instanceof AnteriorFunctionBase) {
if (((FunzioneAnterioreBase) fl.get(i)).variable == null) { if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
return false; return false;
} }
} else if (fl.get(i) instanceof FunzioneDueValoriBase) { } else if (fl.get(i) instanceof FunctionTwoValuesBase) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null || ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null || ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return false; return false;
} }
} else { } else {
@ -156,10 +156,10 @@ public class Utils {
return true; return true;
} }
public static boolean ciSonoFunzioniSNnonImpostate(ArrayList<FunzioneBase> fl) { public static boolean areThereOnlyEmptySNFunctions(ArrayList<FunctionBase> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (fl.get(i) instanceof FunzioneAnterioreBase) { if (fl.get(i) instanceof AnteriorFunctionBase) {
if (((FunzioneAnterioreBase) fl.get(i)).variable == null) { if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
return true; return true;
} }
} }
@ -167,10 +167,10 @@ public class Utils {
return false; return false;
} }
public static boolean ciSonoFunzioniNSNnonImpostate(ArrayList<FunzioneBase> fl) { public static boolean areThereOnlyEmptyNSNFunctions(ArrayList<FunctionBase> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (fl.get(i) instanceof FunzioneDueValoriBase && !(fl.get(i) instanceof Somma) && !(fl.get(i) instanceof Sottrazione) && !(fl.get(i) instanceof Moltiplicazione) && !(fl.get(i) instanceof MoltiplicazionePrioritaria) && !(fl.get(i) instanceof Divisione)) { if (fl.get(i) instanceof FunctionTwoValuesBase && !(fl.get(i) instanceof Sum) && !(fl.get(i) instanceof Subtraction) && !(fl.get(i) instanceof Multiplication) && !(fl.get(i) instanceof PrioritaryMultiplication) && !(fl.get(i) instanceof Division)) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null && ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return true; return true;
} }
} }
@ -179,10 +179,10 @@ public class Utils {
} }
public static boolean ciSonoMoltiplicazioniPrioritarieNonImpostate(ArrayList<FunzioneBase> funzioniOLD) { public static boolean areThereEmptyPrioritaryMultiplications(ArrayList<FunctionBase> funzioniOLD) {
for (int i = 0; i < funzioniOLD.size(); i++) { for (int i = 0; i < funzioniOLD.size(); i++) {
if (funzioniOLD.get(i) instanceof MoltiplicazionePrioritaria) { if (funzioniOLD.get(i) instanceof PrioritaryMultiplication) {
if (((FunzioneDueValoriBase) funzioniOLD.get(i)).variable1 == null && ((FunzioneDueValoriBase) funzioniOLD.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) funzioniOLD.get(i)).variable1 == null && ((FunctionTwoValuesBase) funzioniOLD.get(i)).variable2 == null) {
return true; return true;
} }
} }
@ -190,10 +190,10 @@ public class Utils {
return false; return false;
} }
public static boolean ciSonoMoltiplicazioniNonImpostate(ArrayList<FunzioneBase> fl) { public static boolean areThereEmptyMultiplications(ArrayList<FunctionBase> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (fl.get(i) instanceof Moltiplicazione || fl.get(i) instanceof Divisione) { if (fl.get(i) instanceof Multiplication || fl.get(i) instanceof Division) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null && ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return true; return true;
} }
} }
@ -201,10 +201,10 @@ public class Utils {
return false; return false;
} }
public static boolean ciSonoSommeNonImpostate(ArrayList<FunzioneBase> fl) { public static boolean areThereEmptySums(ArrayList<FunctionBase> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (fl.get(i) instanceof Somma) { if (fl.get(i) instanceof Sum) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null && ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null && ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return true; return true;
} }
} }
@ -212,10 +212,10 @@ public class Utils {
return false; return false;
} }
public static boolean ciSonoSistemiNonImpostati(ArrayList<Funzione> fl) { public static boolean areThereEmptySystems(ArrayList<Function> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (fl.get(i) instanceof ParteSistema) { if (fl.get(i) instanceof EquationsSystemPart) {
if (((ParteSistema) fl.get(i)).variable == null) { if (((EquationsSystemPart) fl.get(i)).variable == null) {
return true; return true;
} }
} }
@ -223,15 +223,15 @@ public class Utils {
return false; return false;
} }
public static boolean ciSonoAltreFunzioniImpostate(ArrayList<Funzione> fl) { public static boolean areThereOtherSettedUpFunctions(ArrayList<Function> fl) {
for (int i = 0; i < fl.size(); i++) { for (int i = 0; i < fl.size(); i++) {
if (!(fl.get(i) instanceof Termine || fl.get(i) instanceof Somma || fl.get(i) instanceof Espressione || fl.get(i) instanceof FunzioneAnterioreBase || fl.get(i) instanceof Moltiplicazione || fl.get(i) instanceof MoltiplicazionePrioritaria || fl.get(i) instanceof Divisione)) { if (!(fl.get(i) instanceof Number || fl.get(i) instanceof Sum || fl.get(i) instanceof Expression || fl.get(i) instanceof AnteriorFunctionBase || fl.get(i) instanceof Multiplication || fl.get(i) instanceof PrioritaryMultiplication || fl.get(i) instanceof Division)) {
if (fl.get(i) instanceof FunzioneAnterioreBase) { if (fl.get(i) instanceof AnteriorFunctionBase) {
if (((FunzioneAnterioreBase) fl.get(i)).variable == null) { if (((AnteriorFunctionBase) fl.get(i)).variable == null) {
return true; return true;
} }
} else if (fl.get(i) instanceof FunzioneDueValoriBase) { } else if (fl.get(i) instanceof FunctionTwoValuesBase) {
if (((FunzioneDueValoriBase) fl.get(i)).variable1 == null || ((FunzioneDueValoriBase) fl.get(i)).variable2 == null) { if (((FunctionTwoValuesBase) fl.get(i)).variable1 == null || ((FunctionTwoValuesBase) fl.get(i)).variable2 == null) {
return true; return true;
} }
} else { } else {
@ -245,13 +245,13 @@ public class Utils {
public static Rational getRational(BigDecimal str) { public static Rational getRational(BigDecimal str) {
try { try {
return getRational(str.toString()); return getRational(str.toString());
} catch (Errore e) { } catch (Error e) {
//E' IMPOSSIBILE CHE VENGA THROWATO UN ERRORE //E' IMPOSSIBILE CHE VENGA THROWATO UN ERRORE
return new Rational("0"); return new Rational("0");
} }
} }
public static Rational getRational(String str) throws Errore { public static Rational getRational(String str) throws Error {
try { try {
return new Rational(str); return new Rational(str);
} catch (NumberFormatException ex) { } catch (NumberFormatException ex) {
@ -304,11 +304,11 @@ public class Utils {
return BigDecimalMath.divideRound(new BigDecimal(r.numer()).setScale(Utils.scale, Utils.scaleMode), new BigDecimal(r.denom()).setScale(Utils.scale, Utils.scaleMode)); return BigDecimalMath.divideRound(new BigDecimal(r.numer()).setScale(Utils.scale, Utils.scaleMode), new BigDecimal(r.denom()).setScale(Utils.scale, Utils.scaleMode));
} }
public static boolean variabiliUguali(ArrayList<Incognita> variables, ArrayList<Incognita> variables2) { public static boolean equalsVariables(ArrayList<Variable> variables, ArrayList<Variable> variables2) {
if (variables.size() != variables2.size()) { if (variables.size() != variables2.size()) {
return false; return false;
} else { } else {
for (Incognita v : variables) { for (Variable v : variables) {
if (!variables2.contains(v)) { if (!variables2.contains(v)) {
return false; return false;
} }
@ -317,7 +317,7 @@ public class Utils {
} }
} }
public static void writeSquareRoot(Funzione var, int x, int y, boolean small) { public static void writeSquareRoot(Function var, int x, int y, boolean small) {
var.setSmall(small); var.setSmall(small);
int w1 = var.getWidth(); int w1 = var.getWidth();
int h1 = var.getHeight(); int h1 = var.getHeight();

View File

@ -0,0 +1,40 @@
package org.warp.picalculator;
import org.nevec.rjm.Rational;
public class Variable {
public char symbol = 'X';
public Rational exponent = Rational.ONE;
public Variable(char simbolo, Rational esponente) {
this.symbol = simbolo;
this.exponent = esponente;
}
public Variable(char simbolo, int a, int b) {
this.symbol = simbolo;
this.exponent = new Rational(a, b);
}
public Variable(char simbolo) {
this.symbol = simbolo;
this.exponent = new Rational(1, 1);
}
@Override
public boolean equals(Object o) {
if (o instanceof Variable) {
if (this.symbol == ((Variable) o).symbol) {
if (this.exponent == ((Variable) o).exponent) {
return true;
}
}
}
return false;
}
@Override
public int hashCode() {
return Character.getNumericValue(symbol) * 3 + exponent.hashCode();
}
}

View File

@ -0,0 +1,391 @@
package org.warp.picalculator;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.Vector;
import org.nevec.rjm.BigIntegerMath;
import org.nevec.rjm.Rational;
public class Variables {
Vector<Variable> variables;
public Variables() {
variables = new Vector<Variable>();
}
public Variables(Variable[] value) {
this();
for (Variable i : value) {
variables.add(i);
}
}
public Variables(Vector<Variable> value) {
this();
variables = value;
}
public Variables(Variable value) {
this();
variables.add(value);
}
public int count() {
return variables.size();
}
public boolean containsSymbol(char simbolo) {
for (Variable i : variables) {
if (i.symbol == simbolo) {
return true;
}
}
return false;
}
public Rational getExponentOfSymbol(char simbolo) {
for (Variable i : variables) {
if (i.symbol == simbolo) {
return i.exponent;
}
}
return new Rational(0, 1);
}
public void setExponentOfSymbol(char simbolo, Rational esponente) {
for (Variable i : variables) {
if (i.symbol == simbolo) {
i.exponent = esponente;
}
}
}
@SuppressWarnings("unchecked")
@Override
public Variables clone() {
return new Variables((Vector<Variable>) variables.clone()).normalize();
}
public Variables multiply(Variables val) {
Variables result = new Variables();
// Passaggio 1: test vari
// Se il primo gruppo di incognite à nullo allora ritorna il secondo
// gruppo
if (this.count() == 0) {
result = val.clone();
return result;
}
// Se il secondo gruppo di incognite à nullo allora ritorna il primo
// gruppo
if (val.count() == 0) {
result = this.clone();
return result;
}
// Passaggio 2: le incognite doppie vengono raggruppate.
for (Variable i1 : variables) {
for (Variable i2 : val.variables) {
if (i1.symbol == i2.symbol) {
if (!result.containsSymbol(i1.symbol)) {
Variable ir = new Variable(i1.symbol, i1.exponent.add(i2.exponent));
result.variables.add(ir);
}
}
}
}
// Passaggio 3: le incognite non ancora presenti vengono aggiunte.
for (Variable i : variables) {
if (!result.containsSymbol(i.symbol)) {
result.variables.add(i);
}
}
for (Variable i : val.variables) {
if (!result.containsSymbol(i.symbol)) {
result.variables.add(i);
}
}
return result.normalize();
}
public Variables divide(Variables val) {
Variables result = new Variables();
// Passaggio 2: le incognite doppie vengono raggruppate.
for (Variable i1 : variables) {
for (Variable i2 : val.variables) {
if (i1.symbol == i2.symbol) {
if (!result.containsSymbol(i1.symbol)) {
Variable ir = new Variable(i1.symbol, i1.exponent.add(i2.exponent.multiply(new Rational(-1, 1))));
result.variables.add(ir);
}
}
}
}
// Passaggio 3: le incognite non ancora presenti vengono aggiunte.
for (Variable i : variables) {
if (!result.containsSymbol(i.symbol)) {
result.variables.add(i);
}
}
for (Variable i : val.variables) {
if (!result.containsSymbol(i.symbol)) {
result.variables.add(new Variable(i.symbol, i.exponent.multiply(new Rational(-1, 1))));
}
}
return result.normalize();
}
public Variables sqrt() {
Variables result = new Variables();
for (Variable i1 : variables) {
Variable ir = null;
try {
ir = new Variable(i1.symbol, i1.exponent.divide(new Rational(2, 1)));
} catch (Error e) {
e.printStackTrace();
}
result.variables.add(ir);
}
return result.normalize();
}
public Variables normalize() {
Variables result = new Variables();
for (Variable i1 : variables) {
if (i1.exponent.compareTo(Rational.ZERO) != 0) {
result.variables.add(i1);
}
}
result.variables.sort(new Comparator<Variable>() {
@Override
public int compare(Variable o1, Variable o2) {
int index1 = letterIndex(o1.symbol);
int index2 = letterIndex(o2.symbol);
return index1 - index2;
}
});
return result;
}
public byte letterIndex(char l) {
return letterIndex(l, false);
}
public static byte letterIndex(char l, boolean reverse) {
int total = MathematicalSymbols.variables().length - 1;
for (byte x = 0; x < MathematicalSymbols.variables().length; x++) {
if (MathematicalSymbols.variables()[x].equals("" + l)) {
if (reverse) {
return (byte) (total - x);
} else {
return x;
}
}
}
return -1;
}
public boolean compareTo(Variables val) {
if (this.equals(val))
return true;
return false;
}
@Override
public boolean equals(Object val) {
if (val == null)
return false;
if (val instanceof Variables) {
Variables ii2 = (Variables) val;
for (Variable i1 : variables) {
boolean found = false;
for (Variable i2 : ii2.variables) {
if (i1.symbol == i2.symbol) {
if (i1.exponent.compareTo(i2.exponent) != 0)
return false;
found = true;
}
}
if (!found) {
return false;
}
}
for (Variable i1 : ii2.variables) {
boolean found = false;
for (Variable i2 : variables) {
if (i1.symbol == i2.symbol) {
if (i1.exponent.compareTo(i2.exponent) != 0)
return false;
found = true;
}
}
if (!found) {
return false;
}
}
return true;
}
return false;
}
@Override
public String toString() {
String result = "";
if (variables.size() != 1) {
for (Variable i : variables) {
if (i.exponent.compareTo(Rational.ONE) != 0) {
result += "(" + i.symbol + "^" + i.exponent + ")";
} else {
result += i.symbol;
}
}
} else if (variables.size() == 1) {
Variable i = variables.get(0);
if (i.exponent.compareTo(Rational.ONE) != 0) {
result += "" + i.symbol + "^" + i.exponent + "";
} else if (i.exponent.compareTo(Rational.ONE) == 0) {
result += i.symbol;
}
}
return result;
}
public static Variables lcm(Variables val1, Variables val2) {
Variables result = new Variables();
// Passaggio 1: test vari
// Se il primo gruppo di incognite à nullo allora ritorna il secondo
// gruppo
if (val1.count() == 0) {
result = val2.clone();
return result;
}
// Se il secondo gruppo di incognite à nullo allora ritorna il primo
// gruppo
if (val2.count() == 0) {
result = val1.clone();
return result;
}
// Passaggio 2: le incognite doppie vengono raggruppate.
for (Variable i1 : val1.variables) {
for (Variable i2 : val2.variables) {
if (i1.symbol == i2.symbol) {
if (!result.containsSymbol(i1.symbol)) {
Variable ir = new Variable(i1.symbol);
if (i1.exponent.compareTo(i2.exponent) > 0) {
ir.exponent = i1.exponent;
} else {
ir.exponent = i2.exponent;
}
result.variables.add(ir);
}
}
}
}
// Passaggio 3: le incognite non ancora presenti vengono aggiunte.
for (Variable i : val1.variables) {
if (!result.containsSymbol(i.symbol)) {
result.variables.add(i);
}
}
for (Variable i : val2.variables) {
if (!result.containsSymbol(i.symbol)) {
result.variables.add(i);
}
}
return result.normalize();
}
@SuppressWarnings("unchecked")
public Vector<Variable> getVariablesList() {
return (Vector<Variable>) this.variables.clone();
}
public static Variables[] normalizeBigSurdVariables(Variables[] incognitetemp) throws Error {
Variables incognitex = incognitetemp[0].clone();
Variables incognitey = incognitetemp[1].clone();
Variables incognitez = incognitetemp[2].clone();
Variables newincognitex = new Variables();
for (Variable i : incognitex.variables) {
Vector<BigInteger> divisori = BigIntegerMath.divisors(i.exponent.divide(2).denom());
if (divisori.contains(new BigInteger("2"))) {
newincognitex = newincognitex.multiply(new Variables(i));
} else {
incognitey = incognitey.multiply(new Variables(new Variable(i.symbol, i.exponent.divide(2))));
}
}
incognitex = newincognitex;
for (Variable i : incognitey.variables) {
if (i.exponent.signum() < 0) {
incognitey = incognitey.divide(new Variables(i));
incognitez = incognitez.divide(new Variables(i));
}
}
for (Variable i : incognitez.variables) {
if (i.exponent.signum() < 0) {
incognitey = incognitey.divide(new Variables(i));
incognitez = incognitez.divide(new Variables(i));
}
}
// TODO: SPOSTARE LE Y NEGATIVE SOTTO LA FRAZIONE, DALLA Y ALLA Z
Variables incogniteyresult = new Variables();
Variables incognitezresult = new Variables();
// Le incognite doppie vengono tolte
for (Variable i1 : incognitey.variables) {
for (Variable i2 : incognitez.variables) {
if (i1.symbol == i2.symbol) {
if (i1.exponent.compareTo(i2.exponent) > 0) {
incogniteyresult = incogniteyresult.multiply(new Variables(new Variable(i1.symbol, i1.exponent.subtract(i2.exponent))));
} else if (i2.exponent.compareTo(i1.exponent) > 0) {
incognitezresult = incognitezresult.multiply(new Variables(new Variable(i1.symbol, i2.exponent.subtract(i1.exponent))));
}
}
}
}
// Le altre incognite vengono ri-messe
for (Variable i : incognitey.variables) {
if (!incogniteyresult.containsSymbol(i.symbol)) {
incogniteyresult = incogniteyresult.multiply(new Variables(i));
}
}
for (Variable i : incognitez.variables) {
if (!incognitezresult.containsSymbol(i.symbol)) {
incognitezresult = incognitezresult.multiply(new Variables(i));
}
}
incognitey = incogniteyresult;
incognitez = incognitezresult;
return new Variables[] { incognitex, incognitey, incognitez };
}
public static int priority(Variables ii) {
double priorità = 0;
double letterMax = 0;
for (Variable i : ii.variables) {
int lettIndex = letterIndex(i.symbol, true);
if (lettIndex > letterMax) {
letterMax = lettIndex;
}
}
priorità += letterMax * 100000;
for (Variable i : ii.variables) {
int lettIndex = letterIndex(i.symbol, true);
if (letterMax == lettIndex) {
priorità += i.exponent.doubleValue() * 100000;
}
priorità += +i.exponent.doubleValue();
}
return (int) priorità;
}
}

View File

@ -1,8 +1,6 @@
package org.warp.picalculator.screens; package org.warp.picalculator.screens;
import static org.warp.engine.Display.Render.glClearColor; import static org.warp.engine.Display.Render.*;
import static org.warp.engine.Display.Render.glDrawStringLeft;
import static org.warp.engine.Display.Render.setFont;
import java.io.PrintWriter; import java.io.PrintWriter;
import java.io.StringWriter; import java.io.StringWriter;
@ -12,9 +10,9 @@ import org.warp.device.PIDisplay;
import org.warp.engine.Display; import org.warp.engine.Display;
import org.warp.engine.Screen; import org.warp.engine.Screen;
import org.warp.picalculator.Calculator; import org.warp.picalculator.Calculator;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Errori; import org.warp.picalculator.Errors;
import org.warp.picalculator.Funzione; import org.warp.picalculator.Function;
import org.warp.picalculator.Utils; import org.warp.picalculator.Utils;
public class EquationScreen extends Screen { public class EquationScreen extends Screen {
@ -25,8 +23,8 @@ public class EquationScreen extends Screen {
public volatile int caretPos = 0; public volatile int caretPos = 0;
public volatile boolean showCaret = true; public volatile boolean showCaret = true;
public volatile float showCaretDelta = 0f; public volatile float showCaretDelta = 0f;
public Funzione f; public Function f;
public Funzione f2; public Function f2;
public int ew1; public int ew1;
public int ew2; public int ew2;
public int eh2; public int eh2;
@ -37,8 +35,8 @@ public class EquationScreen extends Screen {
public boolean aftersleep; public boolean aftersleep;
public boolean autoscroll; public boolean autoscroll;
public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto public int errorLevel = 0; // 0 = nessuno, 1 = risultato, 2 = tutto
public Errore err1; public Error err1;
public Errore err2; public Error err2;
boolean mustRefresh = true; boolean mustRefresh = true;
public EquationScreen() { public EquationScreen() {
@ -109,7 +107,7 @@ public class EquationScreen extends Screen {
// System.out.println("Time elapsed: " + (double) timeElapsed / // System.out.println("Time elapsed: " + (double) timeElapsed /
// 1000000 + " milliseconds\n"); // 1000000 + " milliseconds\n");
} catch (Errore e) { } catch (Error e) {
glClearColor(0xFFDC3C32); glClearColor(0xFFDC3C32);
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);
@ -120,13 +118,13 @@ public class EquationScreen extends Screen {
} }
} }
public void interpreta(String eqn) throws Errore { public void interpreta(String eqn) throws Error {
equazioneCorrente = eqn; equazioneCorrente = eqn;
f = Calculator.interpreta(equazioneCorrente.replace("sqrt", "").replace("^", "")); f = Calculator.parseString(equazioneCorrente.replace("sqrt", "").replace("^", ""));
f.calcolaGrafica(); f.generateGraphics();
} }
public void solve() throws Errore { public void solve() throws Error {
Calculator.solve(); Calculator.solve();
} }
@ -148,6 +146,7 @@ public class EquationScreen extends Screen {
public void render() { public void render() {
setFont(PIDisplay.fonts[0]); setFont(PIDisplay.fonts[0]);
glClearColor(0xFFCCE7D4); glClearColor(0xFFCCE7D4);
glColor3f(0, 0, 0);
glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length())); glDrawStringLeft(2, 22, nuovaEquazione.substring(0, caretPos)+(showCaret?"|":"")+nuovaEquazione.substring(((showCaret==false||nuovaEquazione.length()<=caretPos)?caretPos:caretPos+1), nuovaEquazione.length()));
if (f != null) if (f != null)
f.draw(2, 22+1+9+1); f.draw(2, 22+1+9+1);
@ -185,9 +184,9 @@ public class EquationScreen extends Screen {
interpreta(nuovaEquazione); interpreta(nuovaEquazione);
solve(); solve();
} catch (Exception ex) { } catch (Exception ex) {
throw new Errore(Errori.ERROR); throw new Error(Errors.ERROR);
} }
} catch (Errore e) { } catch (Error e) {
glClearColor(0xFFDC3C32); glClearColor(0xFFDC3C32);
StringWriter sw = new StringWriter(); StringWriter sw = new StringWriter();
PrintWriter pw = new PrintWriter(sw); PrintWriter pw = new PrintWriter(sw);

View File

@ -21,8 +21,19 @@ public class MarioScreen extends Screen {
private int[] skin; private int[] skin;
private int[] skinSize; private int[] skinSize;
private int[] ground;
private int[] groundSize;
private boolean errored; private boolean errored;
public int posX = 0; public float[] marioPos = new float[]{30,0};
public float[] marioForces = new float[]{0,0};
public float walkAnimation = 0;
public float jumptime = 0;
public boolean walking = false;
public boolean running = false;
public boolean jumping = false;
public boolean flipped = false;
public boolean onGround = true;
public int[] marioSkinPos = new int[]{0,0};
public MarioScreen() { public MarioScreen() {
super(); super();
@ -40,6 +51,14 @@ public class MarioScreen extends Screen {
e.printStackTrace(); e.printStackTrace();
errored = true; errored = true;
} }
try {
img = ImageIO.read(Main.instance.getClass().getResource("/marioground.png"));
ground = getMatrixOfImage(img);
groundSize = new int[] { img.getWidth(), img.getHeight() };
} catch (IOException e) {
e.printStackTrace();
errored = true;
}
} }
@Override @Override
@ -52,9 +71,69 @@ public class MarioScreen extends Screen {
@Override @Override
public void beforeRender(float dt) { public void beforeRender(float dt) {
if (!errored) { if (!errored) {
if (Keyboard.isKeyDown(2, 5)) { //RIGHT walkAnimation += dt;
posX+=1; boolean rightPressed = Keyboard.isKeyDown(2, 5);
boolean leftPressed = Keyboard.isKeyDown(2, 3);
boolean jumpPressed = Keyboard.isKeyDown(2, 1);
if ((leftPressed | rightPressed) == (leftPressed & rightPressed)) {
walking = false;
walkAnimation = 0;
} else {
if (rightPressed) { //RIGHT
if (marioForces[0] < 500f) {
marioForces[0] += dt*500f;
}
walking = true;
flipped = false;
}
if (leftPressed) { //LEFT
if (marioForces[0] > -500f) {
marioForces[0] -= dt*500f;
}
walking = true;
flipped = true;
}
} }
if (jumpPressed) { //JUMP
jumptime+=dt;
if (!jumping && onGround) {
marioForces[1] = dt*(4*1569.6f);
jumping = true;
onGround = false;
} else if (jumptime <= 0.5f) {
marioForces[1] = dt*(4*1569.6f);
}
} else {
jumping = false;
jumptime = 0;
}
if (!walking & !running & !jumping) {
marioSkinPos[0] = 0;
marioSkinPos[1] = 0;
} else if (onGround & walking & !running & !jumping && walkAnimation >= 0.08) {
while(walkAnimation > 0.08) {
walkAnimation -= 0.08;
if (marioSkinPos[0] == 1 & marioSkinPos[1] == 0) {
marioSkinPos[0] += 2;
} else if (marioSkinPos[0] == 3 & marioSkinPos[1] == 0) {
marioSkinPos[0] -= 1;
} else if (marioSkinPos[0] == 2 & marioSkinPos[1] == 0) {
marioSkinPos[0] -= 1;
} else {
marioSkinPos[0] = 1;
marioSkinPos[1] = 0;
}
}
} else if (jumping) {
marioSkinPos[0] = 5;
marioSkinPos[1] = 1;
}
marioForces[1] -= dt*1569.6;
marioPos[0] += dt*marioForces[0];
if (!onGround) {
marioPos[1] -= dt*marioForces[1];
}
marioForces[0] *= 0.75;
} }
} }
@ -64,8 +143,28 @@ public class MarioScreen extends Screen {
glDrawStringLeft(0, 20, "ERROR"); glDrawStringLeft(0, 20, "ERROR");
} else { } else {
setFont(PIDisplay.fonts[0]); setFont(PIDisplay.fonts[0]);
glClearColor(0xFFCCE7D4); glClearColor(0xff9290ff);
glDrawSkin(skinSize[0], skin, posX, 25, 36, 1, 70, 27, true); glDrawSkin(groundSize[0], ground, 0, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*2, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*3, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*4, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*5, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*6, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*7, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*8, 25+25, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 0, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*2, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*3, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*4, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*5, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*6, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*7, 25+25+16, 0, 0, 16, 16, false);
glDrawSkin(groundSize[0], ground, 16*8, 25+25+16, 0, 0, 16, 16, false);
//DRAW MARIO
glDrawSkin(skinSize[0], skin, getPosX()-18, 25+getPosY(), 35*(marioSkinPos[0]+(flipped?2:1)), 27*marioSkinPos[1], 35*(marioSkinPos[0]+(flipped?1:2)), 27*(marioSkinPos[1]+1), true);
} }
} }
@ -83,5 +182,13 @@ public class MarioScreen extends Screen {
public boolean keyPressed(Key k) { public boolean keyPressed(Key k) {
return false; return false;
} }
private int getPosX() {
return (int)marioPos[0];
}
private int getPosY() {
return (int)marioPos[1];
}
} }

View File

@ -1,12 +1,12 @@
package org.warp.picalculator.screens; package org.warp.picalculator.screens;
import static org.warp.engine.Display.Render.glDrawStringCenter; import static org.warp.engine.Display.Render.*;
import org.warp.device.Keyboard.Key; import org.warp.device.Keyboard.Key;
import org.warp.engine.Display; import org.warp.engine.Display;
import org.warp.engine.Screen; import org.warp.engine.Screen;
import org.warp.picalculator.Calculator; import org.warp.picalculator.Calculator;
import org.warp.picalculator.Errore; import org.warp.picalculator.Error;
import org.warp.picalculator.Main; import org.warp.picalculator.Main;
public class SolveEquationScreen extends Screen { public class SolveEquationScreen extends Screen {
@ -30,7 +30,12 @@ public class SolveEquationScreen extends Screen {
@Override @Override
public void render() { public void render() {
glDrawStringCenter(Display.getWidth()/2, 29, "ciaoooooooooooooooooooooooooooooo"); glColor4f(0, 0, 0, 64);
glDrawStringCenter(Main.screenSize[0]/2+1, Main.screenSize[1]/4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
glDrawStringCenter(Main.screenSize[0]/2, Main.screenSize[1]/4+1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
glDrawStringCenter(Main.screenSize[0]/2+1, Main.screenSize[1]/4+1, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
glColor3f(255, 0, 0);
glDrawStringCenter(Main.screenSize[0]/2, Main.screenSize[1]/4, "WORK IN PROGRESS. THIS SCREEN MUST HAVE A GUI TO SELECT THE VARIABLE TO SOLVE.");
} }
@Override @Override
@ -50,7 +55,7 @@ public class SolveEquationScreen extends Screen {
Main.d.goBack(); Main.d.goBack();
try { try {
Calculator.solve('X'); Calculator.solve('X');
} catch (Errore e) { } catch (Error e) {
Screen scr = Main.d.getScreen(); Screen scr = Main.d.getScreen();
if (scr instanceof EquationScreen) { if (scr instanceof EquationScreen) {
EquationScreen escr = (EquationScreen) scr; EquationScreen escr = (EquationScreen) scr;