
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 4 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (- y z) (- t x))))
double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((y - z) * (t - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - z) * (t - x));
}
def code(x, y, z, t): return x + ((y - z) * (t - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - z) * Float64(t - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y - z) * (t - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - z\right) \cdot \left(t - x\right)
\end{array}
Initial program 100.0%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- y z) (- t x)))) (if (<= (- y z) -1.06e-26) t_1 (if (<= (- y z) 3e-36) (+ x (- y z)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (y - z) * (t - x);
double tmp;
if ((y - z) <= -1.06e-26) {
tmp = t_1;
} else if ((y - z) <= 3e-36) {
tmp = x + (y - z);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t)
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 = (y - z) * (t - x)
if ((y - z) <= (-1.06d-26)) then
tmp = t_1
else if ((y - z) <= 3d-36) then
tmp = x + (y - z)
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 = (y - z) * (t - x);
double tmp;
if ((y - z) <= -1.06e-26) {
tmp = t_1;
} else if ((y - z) <= 3e-36) {
tmp = x + (y - z);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (y - z) * (t - x) tmp = 0 if (y - z) <= -1.06e-26: tmp = t_1 elif (y - z) <= 3e-36: tmp = x + (y - z) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(y - z) * Float64(t - x)) tmp = 0.0 if (Float64(y - z) <= -1.06e-26) tmp = t_1; elseif (Float64(y - z) <= 3e-36) tmp = Float64(x + Float64(y - z)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (y - z) * (t - x); tmp = 0.0; if ((y - z) <= -1.06e-26) tmp = t_1; elseif ((y - z) <= 3e-36) tmp = x + (y - z); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - z), $MachinePrecision] * N[(t - x), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[N[(y - z), $MachinePrecision], -1.06e-26], t$95$1, If[LessEqual[N[(y - z), $MachinePrecision], 3e-36], N[(x + N[(y - z), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y - z\right) \cdot \left(t - x\right)\\
\mathbf{if}\;y - z \leq -1.06 \cdot 10^{-26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y - z \leq 3 \cdot 10^{-36}:\\
\;\;\;\;x + \left(y - z\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if (-.f64 y z) < -1.06000000000000001e-26 or 3.0000000000000002e-36 < (-.f64 y z) Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites96.0%
if -1.06000000000000001e-26 < (-.f64 y z) < 3.0000000000000002e-36Initial program 99.9%
Taylor expanded in x around 0
Applied rewrites63.5%
(FPCore (x y z t) :precision binary64 (+ 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)
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]
\begin{array}{l}
\\
x + \left(y - z\right)
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites14.9%
(FPCore (x y z t) :precision binary64 (- y z))
double code(double x, double y, double z, double t) {
return y - z;
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = y - z
end function
public static double code(double x, double y, double z, double t) {
return y - z;
}
def code(x, y, z, t): return y - z
function code(x, y, z, t) return Float64(y - z) end
function tmp = code(x, y, z, t) tmp = y - z; end
code[x_, y_, z_, t_] := N[(y - z), $MachinePrecision]
\begin{array}{l}
\\
y - z
\end{array}
Initial program 100.0%
Taylor expanded in x around 0
Applied rewrites83.9%
Taylor expanded in x around 0
Applied rewrites3.3%
(FPCore (x y z t) :precision binary64 (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
real(8) function code(x, y, z, t)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
code = x + ((t * (y - z)) + (-x * (y - z)))
end function
public static double code(double x, double y, double z, double t) {
return x + ((t * (y - z)) + (-x * (y - z)));
}
def code(x, y, z, t): return x + ((t * (y - z)) + (-x * (y - z)))
function code(x, y, z, t) return Float64(x + Float64(Float64(t * Float64(y - z)) + Float64(Float64(-x) * Float64(y - z)))) end
function tmp = code(x, y, z, t) tmp = x + ((t * (y - z)) + (-x * (y - z))); end
code[x_, y_, z_, t_] := N[(x + N[(N[(t * N[(y - z), $MachinePrecision]), $MachinePrecision] + N[((-x) * N[(y - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(t \cdot \left(y - z\right) + \left(-x\right) \cdot \left(y - z\right)\right)
\end{array}
herbie shell --seed 2024321
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:pre (TRUE)
:alt
(! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
(+ x (* (- y z) (- t x))))