Examples.Basics.BasicTests:f1 from sbv-4.4

Percentage Accurate: 100.0% → 100.0%
Time: 728.0ms
Alternatives: 2
Speedup: 1.0×

Specification

?
\[\left(x + y\right) \cdot \left(x - y\right) \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* (+ x y) (- x y)))
double code(double x, double y) {
	return (x + y) * (x - y);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x + y) * (x - y)
end function
public static double code(double x, double y) {
	return (x + y) * (x - y);
}
def code(x, y):
	return (x + y) * (x - y)
function code(x, y)
	return Float64(Float64(x + y) * Float64(x - y))
end
function tmp = code(x, y)
	tmp = (x + y) * (x - y);
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(x + y) * (x - y)
END code
\left(x + y\right) \cdot \left(x - y\right)

Local Percentage Accuracy vs ?

The average percentage accuracy by input value. Horizontal axis shows value of an input variable; the variable is choosen in the title. Vertical axis is accuracy; higher is better. Red represent the original program, while blue represents Herbie's suggestion. These can be toggled with buttons below the plot. The line is an average while dots represent individual samples.

Accuracy vs Speed?

Herbie found 2 alternatives:

AlternativeAccuracySpeedup
The accuracy (vertical axis) and speed (horizontal axis) of each alternatives. Up and to the right is better. The red square shows the initial program, and each blue circle shows an alternative.The line shows the best available speed-accuracy tradeoffs.

Initial Program: 100.0% accurate, 1.0× speedup?

\[\left(x + y\right) \cdot \left(x - y\right) \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* (+ x y) (- x y)))
double code(double x, double y) {
	return (x + y) * (x - y);
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = (x + y) * (x - y)
end function
public static double code(double x, double y) {
	return (x + y) * (x - y);
}
def code(x, y):
	return (x + y) * (x - y)
function code(x, y)
	return Float64(Float64(x + y) * Float64(x - y))
end
function tmp = code(x, y)
	tmp = (x + y) * (x - y);
end
code[x_, y_] := N[(N[(x + y), $MachinePrecision] * N[(x - y), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(x + y) * (x - y)
END code
\left(x + y\right) \cdot \left(x - y\right)

Alternative 1: 61.2% accurate, 1.0× speedup?

\[\left|y\right| \cdot \left(\left|x\right| - \left|y\right|\right) \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (* (fabs y) (- (fabs x) (fabs y))))
double code(double x, double y) {
	return fabs(y) * (fabs(x) - fabs(y));
}
real(8) function code(x, y)
use fmin_fmax_functions
    real(8), intent (in) :: x
    real(8), intent (in) :: y
    code = abs(y) * (abs(x) - abs(y))
end function
public static double code(double x, double y) {
	return Math.abs(y) * (Math.abs(x) - Math.abs(y));
}
def code(x, y):
	return math.fabs(y) * (math.fabs(x) - math.fabs(y))
function code(x, y)
	return Float64(abs(y) * Float64(abs(x) - abs(y)))
end
function tmp = code(x, y)
	tmp = abs(y) * (abs(x) - abs(y));
end
code[x_, y_] := N[(N[Abs[y], $MachinePrecision] * N[(N[Abs[x], $MachinePrecision] - N[Abs[y], $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(abs(y)) * ((abs(x)) - (abs(y)))
END code
\left|y\right| \cdot \left(\left|x\right| - \left|y\right|\right)
Derivation
  1. Initial program 100.0%

    \[\left(x + y\right) \cdot \left(x - y\right) \]
  2. Taylor expanded in x around 0

    \[\leadsto y \cdot \left(x - y\right) \]
  3. Step-by-step derivation
    1. Applied rewrites57.1%

      \[\leadsto y \cdot \left(x - y\right) \]
    2. Add Preprocessing

    Reproduce

    ?
    herbie shell --seed 2026092 
    (FPCore (x y)
      :name "Examples.Basics.BasicTests:f1 from sbv-4.4"
      :precision binary64
      (* (+ x y) (- x y)))