
(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)
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(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)
(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 100.0%
Applied rewrites96.6%
Taylor expanded in x around inf
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 100.0%
Taylor expanded in x around 0
Applied rewrites57.2%
herbie shell --seed 2026092
(FPCore (x y)
:name "Examples.Basics.BasicTests:f3 from sbv-4.4"
:precision binary64
(* (+ x y) (+ x y)))