Re: Is Jep able to calculate min- max- values?

73 views
Skip to first unread message

Richard Morris

unread,
Feb 24, 2013, 6:03:04 AM2/24/13
to jep-...@googlegroups.com
Gio

What you want is Interval arithmetic http://en.wikipedia.org/wiki/Interval_arithmetic 

I've been working on an experimental system which can do Interval arithmetic. You need several parts

A) A class to hold the intervals datatype and do the basic operations on them
B) Parsing rules to recognise the input. The easiest would be just to use two value arrays
C) Redefined operators PostfixMathCommands PFMC's to cope with the new datatype 
D) Register the new PFMCs

A class for Intervals with an implementation of the add operation is below as is the AddInterval PFMC.
you could register this using
jep.getOperatorTable().getAdd().setPFMC(new AddInterval());
you would need to do the same for the other operators and also the List operator which is normall used to make arrays.

I am currently working on a set of jep extensions which add features to jep. These include a system for working with new datatype including intervals. I think the type is a little too specialized to go in the standard jep library though. If you want I could make a custom package with all the necessary code.

Richard

public class Interval implements Serializable {

    private static final long serialVersionUID = 1L;


    double low,high;


    /**

     * @param low

     * @param high

     */

    public Interval(double low, double high) {

    if(low<=high) {

        this.low = low;

        this.high = high;

    }

    else {

            this.low = high;

            this.high = low;

    }

    

    }

    public Interval(double val) {

        double ulp = Math.ulp(val);

        low = val - ulp;

        high = val + ulp;

    }

    public Interval(Number val) {

        this(val.doubleValue());

    }


    boolean contains(double val) {

        return val >= low && val <= high;

    }

    public Interval add(Interval that) {

        return new Interval(this.low+that.low,this.high+that.high);

    }

....

}

class IntervalAdd extends Add {

private static final long serialVersionUID = 1L;


@Override

public Object add(Object l, Object r) throws EvaluationException 

{

if(l instanceof Interval && r instanceof Interval) {

return ((Interval) l).add((Interval) r);

}

else if(l instanceof Interval && r instanceof Number) {

return ((Interval) l).add(((Number) r).doubleValue());

}

else if(l instanceof Number && r instanceof Interval) {

return ((Interval) r).add(((Number) l).doubleValue());

}

return super.add(l, r);

}

On Friday, February 22, 2013 2:16:21 PM UTC, giof...@googlemail.com wrote:
Hallo!

I am looking for a formula interpretor that is running under java and .Net. So Jep seems to be great.

My formula Parser should be able to calculate variables that are not fixed to a value but to an interval:

for Example:

z =  x*y

x = [-inifnite; infinite] (that means unknown)
y = 1;

results to
z ==> [-inifnite; infinite]


but:

y = if(x>0){z = 1;}else{z = 0}
z = y*100;

x = [-inifnite; infinite]

results to
z = [0; 100]


Is there any possibility to do this?

If not, will be such a feature be build in future time?

Thanks,

Gio
Reply all
Reply to author
Forward
0 new messages