Rump.frink

View or download Rump.frink in plain text format


// A test of math using an equation due to Rump and refined in "Global
// Optimization Using Interval Analysis", Hansen and Walster, section
// 1.4.1
f[x,y] := (333.75 - x^2) y^6 + x^2 (11x^2 y^2 - 121 y^4 - 2) + 5.5 y^8 + x/(2y)

// This alternate version shows what happens if we don't use floating-point
// numbers but exact rational numbers.
f2[x,y] := ((333 + 3/4) - x^2) y^6 + x^2 (11x^2 y^2 - 121 y^4 - 2) + (5 + 1/2) y^8 + x/(2y)

x=77617
y=33096

// Note that the equation simplifies to:
// x / (2 y) - 2

setPrecision[38]
println["Correct answer should be:"]
println[x/(2 y)-2.]


// It appears that this doesn't work if precision is set below 37 digits,
// then it works perfectly.
println[x/(2 y)-2.]

setPrecision[20]
println["\nFloating-point: " + f[x,y]]

// Rational example:
println["\nRational:       " + f2[x,y]]

// Interval example:
collapseIntervals[false]
xi = new interval[x,x,x]
yi = new interval[y,y,y]
println["\nInterval:       " + f[xi,yi]]


// Demonstration using Frink's symbolic solver
use Solver.frink
symbolicMode[true]

// Rump equation
r = new Solver[[z === ((333 + 3/4) - x^2) y^6 + x^2 (11x^2 y^2 - 121 y^4 - 2) + (5 + 1/2) y^8 + x/(2y),
                x===77617,
                y===33096]]
println["\n\nSymbolic solution:"]
println[join["\n",r.solveAll[]]]
println[]


View or download Rump.frink in plain text format


This is a program written in the programming language Frink.
For more information, view the Frink Documentation or see More Sample Frink Programs.

Alan Eliasen was born 17864 days, 17 hours, 21 minutes ago.