
(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 8 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 (* z (- t))))
(if (<= z -1.75e+161)
(* x z)
(if (<= z -2.55e-51)
t_1
(if (<= z 5.7e-69) x (if (<= z 3.6e+146) t_1 (* x z)))))))
double code(double x, double y, double z, double t) {
double t_1 = z * -t;
double tmp;
if (z <= -1.75e+161) {
tmp = x * z;
} else if (z <= -2.55e-51) {
tmp = t_1;
} else if (z <= 5.7e-69) {
tmp = x;
} else if (z <= 3.6e+146) {
tmp = t_1;
} else {
tmp = x * z;
}
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 = z * -t
if (z <= (-1.75d+161)) then
tmp = x * z
else if (z <= (-2.55d-51)) then
tmp = t_1
else if (z <= 5.7d-69) then
tmp = x
else if (z <= 3.6d+146) then
tmp = t_1
else
tmp = x * z
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = z * -t;
double tmp;
if (z <= -1.75e+161) {
tmp = x * z;
} else if (z <= -2.55e-51) {
tmp = t_1;
} else if (z <= 5.7e-69) {
tmp = x;
} else if (z <= 3.6e+146) {
tmp = t_1;
} else {
tmp = x * z;
}
return tmp;
}
def code(x, y, z, t): t_1 = z * -t tmp = 0 if z <= -1.75e+161: tmp = x * z elif z <= -2.55e-51: tmp = t_1 elif z <= 5.7e-69: tmp = x elif z <= 3.6e+146: tmp = t_1 else: tmp = x * z return tmp
function code(x, y, z, t) t_1 = Float64(z * Float64(-t)) tmp = 0.0 if (z <= -1.75e+161) tmp = Float64(x * z); elseif (z <= -2.55e-51) tmp = t_1; elseif (z <= 5.7e-69) tmp = x; elseif (z <= 3.6e+146) tmp = t_1; else tmp = Float64(x * z); end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = z * -t; tmp = 0.0; if (z <= -1.75e+161) tmp = x * z; elseif (z <= -2.55e-51) tmp = t_1; elseif (z <= 5.7e-69) tmp = x; elseif (z <= 3.6e+146) tmp = t_1; else tmp = x * z; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(z * (-t)), $MachinePrecision]}, If[LessEqual[z, -1.75e+161], N[(x * z), $MachinePrecision], If[LessEqual[z, -2.55e-51], t$95$1, If[LessEqual[z, 5.7e-69], x, If[LessEqual[z, 3.6e+146], t$95$1, N[(x * z), $MachinePrecision]]]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := z \cdot \left(-t\right)\\
\mathbf{if}\;z \leq -1.75 \cdot 10^{+161}:\\
\;\;\;\;x \cdot z\\
\mathbf{elif}\;z \leq -2.55 \cdot 10^{-51}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 5.7 \cdot 10^{-69}:\\
\;\;\;\;x\\
\mathbf{elif}\;z \leq 3.6 \cdot 10^{+146}:\\
\;\;\;\;t\_1\\
\mathbf{else}:\\
\;\;\;\;x \cdot z\\
\end{array}
\end{array}
if z < -1.74999999999999994e161 or 3.5999999999999998e146 < z Initial program 100.0%
Taylor expanded in y around 0 84.7%
mul-1-neg84.7%
unsub-neg84.7%
Simplified84.7%
Taylor expanded in z around inf 84.7%
Taylor expanded in x around inf 54.5%
if -1.74999999999999994e161 < z < -2.5499999999999999e-51 or 5.7e-69 < z < 3.5999999999999998e146Initial program 100.0%
Taylor expanded in y around 0 59.1%
mul-1-neg59.1%
unsub-neg59.1%
Simplified59.1%
Taylor expanded in x around 0 58.0%
sub-neg58.0%
neg-mul-158.0%
remove-double-neg58.0%
+-commutative58.0%
Simplified58.0%
Taylor expanded in x around 0 37.0%
mul-1-neg37.0%
distribute-rgt-neg-in37.0%
Simplified37.0%
if -2.5499999999999999e-51 < z < 5.7e-69Initial program 100.0%
Taylor expanded in t around inf 78.9%
Taylor expanded in x around inf 40.4%
Final simplification43.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.25e+81) (not (<= x 3.1e+55))) (* x (- (+ z 1.0) y)) (+ x (* (- y z) t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.25e+81) || !(x <= 3.1e+55)) {
tmp = x * ((z + 1.0) - y);
} else {
tmp = x + ((y - z) * t);
}
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) :: tmp
if ((x <= (-1.25d+81)) .or. (.not. (x <= 3.1d+55))) then
tmp = x * ((z + 1.0d0) - y)
else
tmp = x + ((y - z) * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.25e+81) || !(x <= 3.1e+55)) {
tmp = x * ((z + 1.0) - y);
} else {
tmp = x + ((y - z) * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.25e+81) or not (x <= 3.1e+55): tmp = x * ((z + 1.0) - y) else: tmp = x + ((y - z) * t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.25e+81) || !(x <= 3.1e+55)) tmp = Float64(x * Float64(Float64(z + 1.0) - y)); else tmp = Float64(x + Float64(Float64(y - z) * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.25e+81) || ~((x <= 3.1e+55))) tmp = x * ((z + 1.0) - y); else tmp = x + ((y - z) * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.25e+81], N[Not[LessEqual[x, 3.1e+55]], $MachinePrecision]], N[(x * N[(N[(z + 1.0), $MachinePrecision] - y), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y - z), $MachinePrecision] * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.25 \cdot 10^{+81} \lor \neg \left(x \leq 3.1 \cdot 10^{+55}\right):\\
\;\;\;\;x \cdot \left(\left(z + 1\right) - y\right)\\
\mathbf{else}:\\
\;\;\;\;x + \left(y - z\right) \cdot t\\
\end{array}
\end{array}
if x < -1.25e81 or 3.09999999999999994e55 < x Initial program 100.0%
Taylor expanded in t around 0 93.4%
mul-1-neg93.4%
distribute-rgt-neg-in93.4%
sub-neg93.4%
+-commutative93.4%
distribute-neg-in93.4%
remove-double-neg93.4%
sub-neg93.4%
Simplified93.4%
Taylor expanded in x around 0 93.4%
if -1.25e81 < x < 3.09999999999999994e55Initial program 100.0%
Taylor expanded in t around inf 79.7%
Final simplification85.2%
(FPCore (x y z t) :precision binary64 (if (or (<= z -3.3) (not (<= z 0.053))) (* z (- x t)) (+ x (* y t))))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.3) || !(z <= 0.053)) {
tmp = z * (x - t);
} else {
tmp = x + (y * t);
}
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) :: tmp
if ((z <= (-3.3d0)) .or. (.not. (z <= 0.053d0))) then
tmp = z * (x - t)
else
tmp = x + (y * t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -3.3) || !(z <= 0.053)) {
tmp = z * (x - t);
} else {
tmp = x + (y * t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -3.3) or not (z <= 0.053): tmp = z * (x - t) else: tmp = x + (y * t) return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -3.3) || !(z <= 0.053)) tmp = Float64(z * Float64(x - t)); else tmp = Float64(x + Float64(y * t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -3.3) || ~((z <= 0.053))) tmp = z * (x - t); else tmp = x + (y * t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -3.3], N[Not[LessEqual[z, 0.053]], $MachinePrecision]], N[(z * N[(x - t), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \lor \neg \left(z \leq 0.053\right):\\
\;\;\;\;z \cdot \left(x - t\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot t\\
\end{array}
\end{array}
if z < -3.2999999999999998 or 0.0529999999999999985 < z Initial program 100.0%
Taylor expanded in y around 0 75.5%
mul-1-neg75.5%
unsub-neg75.5%
Simplified75.5%
Taylor expanded in z around inf 74.8%
if -3.2999999999999998 < z < 0.0529999999999999985Initial program 100.0%
Taylor expanded in t around inf 78.0%
Taylor expanded in y around inf 72.2%
Final simplification73.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -2.55e-51) (not (<= z 5.7e-69))) (* z (- x t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.55e-51) || !(z <= 5.7e-69)) {
tmp = z * (x - t);
} else {
tmp = x;
}
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) :: tmp
if ((z <= (-2.55d-51)) .or. (.not. (z <= 5.7d-69))) then
tmp = z * (x - t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -2.55e-51) || !(z <= 5.7e-69)) {
tmp = z * (x - t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -2.55e-51) or not (z <= 5.7e-69): tmp = z * (x - t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -2.55e-51) || !(z <= 5.7e-69)) tmp = Float64(z * Float64(x - t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -2.55e-51) || ~((z <= 5.7e-69))) tmp = z * (x - t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -2.55e-51], N[Not[LessEqual[z, 5.7e-69]], $MachinePrecision]], N[(z * N[(x - t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.55 \cdot 10^{-51} \lor \neg \left(z \leq 5.7 \cdot 10^{-69}\right):\\
\;\;\;\;z \cdot \left(x - t\right)\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -2.5499999999999999e-51 or 5.7e-69 < z Initial program 100.0%
Taylor expanded in y around 0 70.3%
mul-1-neg70.3%
unsub-neg70.3%
Simplified70.3%
Taylor expanded in z around inf 68.0%
if -2.5499999999999999e-51 < z < 5.7e-69Initial program 100.0%
Taylor expanded in t around inf 78.9%
Taylor expanded in x around inf 40.4%
Final simplification58.0%
(FPCore (x y z t) :precision binary64 (if (or (<= z -6.2) (not (<= z 0.05))) (* x z) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.2) || !(z <= 0.05)) {
tmp = x * z;
} else {
tmp = x;
}
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) :: tmp
if ((z <= (-6.2d0)) .or. (.not. (z <= 0.05d0))) then
tmp = x * z
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -6.2) || !(z <= 0.05)) {
tmp = x * z;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -6.2) or not (z <= 0.05): tmp = x * z else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -6.2) || !(z <= 0.05)) tmp = Float64(x * z); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -6.2) || ~((z <= 0.05))) tmp = x * z; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -6.2], N[Not[LessEqual[z, 0.05]], $MachinePrecision]], N[(x * z), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.2 \lor \neg \left(z \leq 0.05\right):\\
\;\;\;\;x \cdot z\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -6.20000000000000018 or 0.050000000000000003 < z Initial program 100.0%
Taylor expanded in y around 0 74.7%
mul-1-neg74.7%
unsub-neg74.7%
Simplified74.7%
Taylor expanded in z around inf 74.1%
Taylor expanded in x around inf 40.6%
if -6.20000000000000018 < z < 0.050000000000000003Initial program 100.0%
Taylor expanded in t around inf 78.0%
Taylor expanded in x around inf 34.2%
Final simplification37.7%
(FPCore (x y z t) :precision binary64 (if (or (<= z -9200.0) (not (<= z 5.8e+100))) (* z t) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9200.0) || !(z <= 5.8e+100)) {
tmp = z * t;
} else {
tmp = x;
}
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) :: tmp
if ((z <= (-9200.0d0)) .or. (.not. (z <= 5.8d+100))) then
tmp = z * t
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((z <= -9200.0) || !(z <= 5.8e+100)) {
tmp = z * t;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (z <= -9200.0) or not (z <= 5.8e+100): tmp = z * t else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((z <= -9200.0) || !(z <= 5.8e+100)) tmp = Float64(z * t); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((z <= -9200.0) || ~((z <= 5.8e+100))) tmp = z * t; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[z, -9200.0], N[Not[LessEqual[z, 5.8e+100]], $MachinePrecision]], N[(z * t), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9200 \lor \neg \left(z \leq 5.8 \cdot 10^{+100}\right):\\
\;\;\;\;z \cdot t\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if z < -9200 or 5.8000000000000001e100 < z Initial program 100.0%
Taylor expanded in y around 0 79.6%
mul-1-neg79.6%
unsub-neg79.6%
Simplified79.6%
Taylor expanded in x around 0 72.5%
sub-neg72.5%
neg-mul-172.5%
remove-double-neg72.5%
+-commutative72.5%
Simplified72.5%
Taylor expanded in x around 0 40.9%
mul-1-neg40.9%
distribute-rgt-neg-in40.9%
Simplified40.9%
add-sqr-sqrt23.2%
sqrt-unprod30.9%
sqr-neg30.9%
sqrt-unprod6.0%
add-sqr-sqrt12.4%
pow112.4%
*-commutative12.4%
Applied egg-rr12.4%
unpow112.4%
Simplified12.4%
if -9200 < z < 5.8000000000000001e100Initial program 100.0%
Taylor expanded in t around inf 73.2%
Taylor expanded in x around inf 28.3%
Final simplification21.2%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return 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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 100.0%
Taylor expanded in t around inf 65.5%
Taylor expanded in x around inf 16.9%
(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 2024165
(FPCore (x y z t)
:name "Data.Metrics.Snapshot:quantile from metrics-0.3.0.2"
:precision binary64
:alt
(! :herbie-platform default (+ x (+ (* t (- y z)) (* (- x) (- y z)))))
(+ x (* (- y z) (- t x))))