
(FPCore (x) :precision binary64 :pre TRUE (- (+ x x) 1.0))
double code(double x) {
return (x + x) - 1.0;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x + x) - 1.0d0
end function
public static double code(double x) {
return (x + x) - 1.0;
}
def code(x): return (x + x) - 1.0
function code(x) return Float64(Float64(x + x) - 1.0) end
function tmp = code(x) tmp = (x + x) - 1.0; end
code[x_] := N[(N[(x + x), $MachinePrecision] - 1.0), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x + x) - (1) END code
\left(x + x\right) - 1
Herbie found 3 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x) :precision binary64 :pre TRUE (- (+ x x) 1.0))
double code(double x) {
return (x + x) - 1.0;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = (x + x) - 1.0d0
end function
public static double code(double x) {
return (x + x) - 1.0;
}
def code(x): return (x + x) - 1.0
function code(x) return Float64(Float64(x + x) - 1.0) end
function tmp = code(x) tmp = (x + x) - 1.0; end
code[x_] := N[(N[(x + x), $MachinePrecision] - 1.0), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = (x + x) - (1) END code
\left(x + x\right) - 1
(FPCore (x) :precision binary64 :pre TRUE (fma 2.0 x -1.0))
double code(double x) {
return fma(2.0, x, -1.0);
}
function code(x) return fma(2.0, x, -1.0) end
code[x_] := N[(2.0 * x + -1.0), $MachinePrecision]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = ((2) * x) + (-1) END code
\mathsf{fma}\left(2, x, -1\right)
Initial program 100.0%
Applied rewrites100.0%
(FPCore (x) :precision binary64 :pre TRUE (if (<= (+ x x) -33.059492225077506) (+ x x) (if (<= (+ x x) 1169.9967764307803) -1.0 (+ x x))))
double code(double x) {
double tmp;
if ((x + x) <= -33.059492225077506) {
tmp = x + x;
} else if ((x + x) <= 1169.9967764307803) {
tmp = -1.0;
} else {
tmp = x + x;
}
return tmp;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8) :: tmp
if ((x + x) <= (-33.059492225077506d0)) then
tmp = x + x
else if ((x + x) <= 1169.9967764307803d0) then
tmp = -1.0d0
else
tmp = x + x
end if
code = tmp
end function
public static double code(double x) {
double tmp;
if ((x + x) <= -33.059492225077506) {
tmp = x + x;
} else if ((x + x) <= 1169.9967764307803) {
tmp = -1.0;
} else {
tmp = x + x;
}
return tmp;
}
def code(x): tmp = 0 if (x + x) <= -33.059492225077506: tmp = x + x elif (x + x) <= 1169.9967764307803: tmp = -1.0 else: tmp = x + x return tmp
function code(x) tmp = 0.0 if (Float64(x + x) <= -33.059492225077506) tmp = Float64(x + x); elseif (Float64(x + x) <= 1169.9967764307803) tmp = -1.0; else tmp = Float64(x + x); end return tmp end
function tmp_2 = code(x) tmp = 0.0; if ((x + x) <= -33.059492225077506) tmp = x + x; elseif ((x + x) <= 1169.9967764307803) tmp = -1.0; else tmp = x + x; end tmp_2 = tmp; end
code[x_] := If[LessEqual[N[(x + x), $MachinePrecision], -33.059492225077506], N[(x + x), $MachinePrecision], If[LessEqual[N[(x + x), $MachinePrecision], 1169.9967764307803], -1.0, N[(x + x), $MachinePrecision]]]
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = LET tmp_1 = IF ((x + x) <= (116999677643078030087053775787353515625e-35)) THEN (-1) ELSE (x + x) ENDIF IN LET tmp = IF ((x + x) <= (-330594922250775056227212189696729183197021484375e-46)) THEN (x + x) ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;x + x \leq -33.059492225077506:\\
\;\;\;\;x + x\\
\mathbf{elif}\;x + x \leq 1169.9967764307803:\\
\;\;\;\;-1\\
\mathbf{else}:\\
\;\;\;\;x + x\\
\end{array}
if (+.f64 x x) < -33.059492225077506 or 1169.9967764307803 < (+.f64 x x) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.9%
Taylor expanded in x around inf
Applied rewrites50.6%
Applied rewrites50.6%
if -33.059492225077506 < (+.f64 x x) < 1169.9967764307803Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.9%
(FPCore (x) :precision binary64 :pre TRUE -1.0)
double code(double x) {
return -1.0;
}
real(8) function code(x)
use fmin_fmax_functions
real(8), intent (in) :: x
code = -1.0d0
end function
public static double code(double x) {
return -1.0;
}
def code(x): return -1.0
function code(x) return -1.0 end
function tmp = code(x) tmp = -1.0; end
code[x_] := -1.0
f(x): x in [-inf, +inf] code: THEORY BEGIN f(x: real): real = -1 END code
-1
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites50.9%
herbie shell --seed 2026092
(FPCore (x)
:name "Data.Random.Distribution.Normal:doubleStdNormalZ from random-fu-0.2.6.2"
:precision binary64
(- (+ x x) 1.0))