Examples.Basics.BasicTests:f3 from sbv-4.4

Percentage Accurate: 100.0% → 100.0%
Time: 1.1s
Alternatives: 3
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 3 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: 99.0% accurate, 1.0× speedup?

\[\mathsf{fma}\left(x, x, y \cdot y\right) \]
(FPCore (x y)
  :precision binary64
  :pre TRUE
  (fma x x (* y y)))
double code(double x, double y) {
	return fma(x, x, (y * y));
}
function code(x, y)
	return fma(x, x, Float64(y * y))
end
code[x_, y_] := N[(x * x + N[(y * y), $MachinePrecision]), $MachinePrecision]
f(x, y):
	x in [-inf, +inf],
	y in [-inf, +inf]
code: THEORY
BEGIN
f(x, y: real): real =
	(x * x) + (y * y)
END code
\mathsf{fma}\left(x, x, y \cdot y\right)
Derivation
  1. Initial program 100.0%

    \[\left(x + y\right) \cdot \left(x + y\right) \]
  2. Step-by-step derivation
    1. Applied rewrites96.6%

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot \mathsf{fma}\left(2, x, y\right)\right) \]
    2. Taylor expanded in x around inf

      \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(2 \cdot x\right)\right) \]
    3. Step-by-step derivation
      1. Applied rewrites54.1%

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot \left(2 \cdot x\right)\right) \]
      2. Taylor expanded in x around 0

        \[\leadsto \mathsf{fma}\left(x, x, y \cdot y\right) \]
      3. Step-by-step derivation
        1. Applied rewrites99.0%

          \[\leadsto \mathsf{fma}\left(x, x, y \cdot y\right) \]
        2. Add Preprocessing

        Alternative 2: 57.2% accurate, 2.3× speedup?

        \[y \cdot y \]
        (FPCore (x y)
          :precision binary64
          :pre TRUE
          (* y y))
        double code(double x, double y) {
        	return y * y;
        }
        
        real(8) function code(x, y)
        use fmin_fmax_functions
            real(8), intent (in) :: x
            real(8), intent (in) :: y
            code = y * y
        end function
        
        public static double code(double x, double y) {
        	return y * y;
        }
        
        def code(x, y):
        	return y * y
        
        function code(x, y)
        	return Float64(y * y)
        end
        
        function tmp = code(x, y)
        	tmp = y * y;
        end
        
        code[x_, y_] := N[(y * y), $MachinePrecision]
        
        f(x, y):
        	x in [-inf, +inf],
        	y in [-inf, +inf]
        code: THEORY
        BEGIN
        f(x, y: real): real =
        	y * y
        END code
        y \cdot y
        
        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 y \]
        3. Step-by-step derivation
          1. Applied rewrites57.2%

            \[\leadsto y \cdot y \]
          2. Add Preprocessing

          Reproduce

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