
(FPCore (x y) :precision binary64 :pre TRUE (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + 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) + ((x * (2)) * y)) + (y * y) END code
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y) :precision binary64 :pre TRUE (+ (+ (* x x) (* (* x 2.0) y)) (* y y)))
double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = ((x * x) + ((x * 2.0d0) * y)) + (y * y)
end function
public static double code(double x, double y) {
return ((x * x) + ((x * 2.0) * y)) + (y * y);
}
def code(x, y): return ((x * x) + ((x * 2.0) * y)) + (y * y)
function code(x, y) return Float64(Float64(Float64(x * x) + Float64(Float64(x * 2.0) * y)) + Float64(y * y)) end
function tmp = code(x, y) tmp = ((x * x) + ((x * 2.0) * y)) + (y * y); end
code[x_, y_] := N[(N[(N[(x * x), $MachinePrecision] + N[(N[(x * 2.0), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision] + 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) + ((x * (2)) * y)) + (y * y) END code
\left(x \cdot x + \left(x \cdot 2\right) \cdot y\right) + y \cdot y
(FPCore (x y) :precision binary64 :pre TRUE (* (+ y x) (+ y x)))
double code(double x, double y) {
return (y + x) * (y + x);
}
real(8) function code(x, y)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
code = (y + x) * (y + x)
end function
public static double code(double x, double y) {
return (y + x) * (y + x);
}
def code(x, y): return (y + x) * (y + x)
function code(x, y) return Float64(Float64(y + x) * Float64(y + x)) end
function tmp = code(x, y) tmp = (y + x) * (y + x); end
code[x_, y_] := N[(N[(y + x), $MachinePrecision] * N[(y + x), $MachinePrecision]), $MachinePrecision]
f(x, y): x in [-inf, +inf], y in [-inf, +inf] code: THEORY BEGIN f(x, y: real): real = (y + x) * (y + x) END code
\left(y + x\right) \cdot \left(y + x\right)
Initial program 93.4%
Applied rewrites100.0%
(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)
Initial program 93.4%
Applied rewrites96.6%
Taylor expanded in x around inf
Applied rewrites54.1%
Applied rewrites54.1%
Taylor expanded in x around 0
Applied rewrites99.0%
(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
Initial program 93.4%
Applied rewrites100.0%
Taylor expanded in x around 0
Applied rewrites57.2%
herbie shell --seed 2026092
(FPCore (x y)
:name "Examples.Basics.ProofTests:f4 from sbv-4.4"
:precision binary64
(+ (+ (* x x) (* (* x 2.0) y)) (* y y)))