
(FPCore (x y z t) :precision binary64 :pre TRUE (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (((y * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
public static double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
def code(x, y, z, t): return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) end
function tmp = code(x, y, z, t) tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = x - (((y * (2)) * z) / (((z * (2)) * z) - (y * t))) END code
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 :pre TRUE (- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))
double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (((y * 2.0d0) * z) / (((z * 2.0d0) * z) - (y * t)))
end function
public static double code(double x, double y, double z, double t) {
return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)));
}
def code(x, y, z, t): return x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t)))) end
function tmp = code(x, y, z, t) tmp = x - (((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = x - (((y * (2)) * z) / (((z * (2)) * z) - (y * t))) END code
x - \frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t}
(FPCore (x y z t) :precision binary64 :pre TRUE (if (<= (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t))) 5e+224) (fma z (/ (+ y y) (fma -2.0 (* z z) (* t y))) x) (- x (/ y z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((((y * 2.0) * z) / (((z * 2.0) * z) - (y * t))) <= 5e+224) {
tmp = fma(z, ((y + y) / fma(-2.0, (z * z), (t * y))), x);
} else {
tmp = x - (y / z);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (Float64(Float64(Float64(y * 2.0) * z) / Float64(Float64(Float64(z * 2.0) * z) - Float64(y * t))) <= 5e+224) tmp = fma(z, Float64(Float64(y + y) / fma(-2.0, Float64(z * z), Float64(t * y))), x); else tmp = Float64(x - Float64(y / z)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[N[(N[(N[(y * 2.0), $MachinePrecision] * z), $MachinePrecision] / N[(N[(N[(z * 2.0), $MachinePrecision] * z), $MachinePrecision] - N[(y * t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], 5e+224], N[(z * N[(N[(y + y), $MachinePrecision] / N[(-2.0 * N[(z * z), $MachinePrecision] + N[(t * y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision], N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = LET tmp = IF ((((y * (2)) * z) / (((z * (2)) * z) - (y * t))) <= (499999999999999964227111724318263497804707306223243456268197521522525585749208789151208295153553467188676004711794318067127242311470730588919109020314930679307514026089293096804165265079253323065443524458327730161833343975424)) THEN ((z * ((y + y) / (((-2) * (z * z)) + (t * y)))) + x) ELSE (x - (y / z)) ENDIF IN tmp END code
\begin{array}{l}
\mathbf{if}\;\frac{\left(y \cdot 2\right) \cdot z}{\left(z \cdot 2\right) \cdot z - y \cdot t} \leq 5 \cdot 10^{+224}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{y + y}{\mathsf{fma}\left(-2, z \cdot z, t \cdot y\right)}, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - \frac{y}{z}\\
\end{array}
if (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))) < 4.9999999999999996e224Initial program 81.5%
Applied rewrites90.3%
if 4.9999999999999996e224 < (/.f64 (*.f64 (*.f64 y #s(literal 2 binary64)) z) (-.f64 (*.f64 (*.f64 z #s(literal 2 binary64)) z) (*.f64 y t))) Initial program 81.5%
Taylor expanded in y around 0
Applied rewrites63.2%
(FPCore (x y z t)
:precision binary64
:pre TRUE
(let* ((t_1 (- x (/ y z))))
(if (<= z -4.7517252514640575e-51)
t_1
(if (<= z 2.530602361761182e-18) (- x (* -2.0 (/ z t))) t_1))))double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -4.7517252514640575e-51) {
tmp = t_1;
} else if (z <= 2.530602361761182e-18) {
tmp = x - (-2.0 * (z / t));
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8) :: t_1
real(8) :: tmp
t_1 = x - (y / z)
if (z <= (-4.7517252514640575d-51)) then
tmp = t_1
else if (z <= 2.530602361761182d-18) then
tmp = x - ((-2.0d0) * (z / t))
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -4.7517252514640575e-51) {
tmp = t_1;
} else if (z <= 2.530602361761182e-18) {
tmp = x - (-2.0 * (z / t));
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = x - (y / z) tmp = 0 if z <= -4.7517252514640575e-51: tmp = t_1 elif z <= 2.530602361761182e-18: tmp = x - (-2.0 * (z / t)) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -4.7517252514640575e-51) tmp = t_1; elseif (z <= 2.530602361761182e-18) tmp = Float64(x - Float64(-2.0 * Float64(z / t))); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = x - (y / z); tmp = 0.0; if (z <= -4.7517252514640575e-51) tmp = t_1; elseif (z <= 2.530602361761182e-18) tmp = x - (-2.0 * (z / t)); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4.7517252514640575e-51], t$95$1, If[LessEqual[z, 2.530602361761182e-18], N[(x - N[(-2.0 * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], t$95$1]]]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = LET t_1 = (x - (y / z)) IN LET tmp_1 = IF (z <= (25306023617611818642487936766263350008500203008692495953990686530232778750360012054443359375e-109)) THEN (x - ((-2) * (z / t))) ELSE t_1 ENDIF IN LET tmp = IF (z <= (-47517252514640574709340682892707614207666252737264753948897617690316581059762296295005391603421749531157242891306368187248135846224850187269339585327543318271636962890625e-220)) THEN t_1 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -4.7517252514640575 \cdot 10^{-51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.530602361761182 \cdot 10^{-18}:\\
\;\;\;\;x - -2 \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if z < -4.7517252514640575e-51 or 2.5306023617611819e-18 < z Initial program 81.5%
Taylor expanded in y around 0
Applied rewrites63.2%
if -4.7517252514640575e-51 < z < 2.5306023617611819e-18Initial program 81.5%
Taylor expanded in y around inf
Applied rewrites62.8%
(FPCore (x y z t)
:precision binary64
:pre TRUE
(let* ((t_1 (- x (/ y z))))
(if (<= z -4.7517252514640575e-51)
t_1
(if (<= z 2.530602361761182e-18) (fma z (/ 2.0 t) x) t_1))))double code(double x, double y, double z, double t) {
double t_1 = x - (y / z);
double tmp;
if (z <= -4.7517252514640575e-51) {
tmp = t_1;
} else if (z <= 2.530602361761182e-18) {
tmp = fma(z, (2.0 / t), x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(y / z)) tmp = 0.0 if (z <= -4.7517252514640575e-51) tmp = t_1; elseif (z <= 2.530602361761182e-18) tmp = fma(z, Float64(2.0 / t), x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[z, -4.7517252514640575e-51], t$95$1, If[LessEqual[z, 2.530602361761182e-18], N[(z * N[(2.0 / t), $MachinePrecision] + x), $MachinePrecision], t$95$1]]]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = LET t_1 = (x - (y / z)) IN LET tmp_1 = IF (z <= (25306023617611818642487936766263350008500203008692495953990686530232778750360012054443359375e-109)) THEN ((z * ((2) / t)) + x) ELSE t_1 ENDIF IN LET tmp = IF (z <= (-47517252514640574709340682892707614207666252737264753948897617690316581059762296295005391603421749531157242891306368187248135846224850187269339585327543318271636962890625e-220)) THEN t_1 ELSE tmp_1 ENDIF IN tmp END code
\begin{array}{l}
t_1 := x - \frac{y}{z}\\
\mathbf{if}\;z \leq -4.7517252514640575 \cdot 10^{-51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2.530602361761182 \cdot 10^{-18}:\\
\;\;\;\;\mathsf{fma}\left(z, \frac{2}{t}, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
if z < -4.7517252514640575e-51 or 2.5306023617611819e-18 < z Initial program 81.5%
Taylor expanded in y around 0
Applied rewrites63.2%
if -4.7517252514640575e-51 < z < 2.5306023617611819e-18Initial program 81.5%
Applied rewrites90.3%
Taylor expanded in y around inf
Applied rewrites62.8%
(FPCore (x y z t) :precision binary64 :pre TRUE (- x (/ y z)))
double code(double x, double y, double z, double t) {
return x - (y / z);
}
real(8) function code(x, y, z, t)
use fmin_fmax_functions
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x - (y / z)
end function
public static double code(double x, double y, double z, double t) {
return x - (y / z);
}
def code(x, y, z, t): return x - (y / z)
function code(x, y, z, t) return Float64(x - Float64(y / z)) end
function tmp = code(x, y, z, t) tmp = x - (y / z); end
code[x_, y_, z_, t_] := N[(x - N[(y / z), $MachinePrecision]), $MachinePrecision]
f(x, y, z, t): x in [-inf, +inf], y in [-inf, +inf], z in [-inf, +inf], t in [-inf, +inf] code: THEORY BEGIN f(x, y, z, t: real): real = x - (y / z) END code
x - \frac{y}{z}
Initial program 81.5%
Taylor expanded in y around 0
Applied rewrites63.2%
herbie shell --seed 2026092
(FPCore (x y z t)
:name "Numeric.AD.Rank1.Halley:findZero from ad-4.2.4"
:precision binary64
(- x (/ (* (* y 2.0) z) (- (* (* z 2.0) z) (* y t)))))