
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- z a)))))
double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (y * ((z - t) / (z - a)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
def code(x, y, z, t, a): return x + (y * ((z - t) / (z - a)))
function code(x, y, z, t, a) return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(z - a)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y * ((z - t) / (z - a))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{z - t}{z - a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 9 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- z a)))))
double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (y * ((z - t) / (z - a)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
def code(x, y, z, t, a): return x + (y * ((z - t) / (z - a)))
function code(x, y, z, t, a) return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(z - a)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y * ((z - t) / (z - a))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{z - t}{z - a}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma y (/ (- z t) (- z a)) x))
double code(double x, double y, double z, double t, double a) {
return fma(y, ((z - t) / (z - a)), x);
}
function code(x, y, z, t, a) return fma(y, Float64(Float64(z - t) / Float64(z - a)), x) end
code[x_, y_, z_, t_, a_] := N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(y, \frac{z - t}{z - a}, x\right)
\end{array}
Initial program 99.9%
+-commutative99.9%
fma-def99.9%
Simplified99.9%
Final simplification99.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -2.4e-5) (not (<= z 4100000.0))) (+ x (* y (- 1.0 (/ t z)))) (+ x (/ y (/ a t)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -2.4e-5) || !(z <= 4100000.0)) {
tmp = x + (y * (1.0 - (t / z)));
} else {
tmp = x + (y / (a / t));
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((z <= (-2.4d-5)) .or. (.not. (z <= 4100000.0d0))) then
tmp = x + (y * (1.0d0 - (t / z)))
else
tmp = x + (y / (a / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -2.4e-5) || !(z <= 4100000.0)) {
tmp = x + (y * (1.0 - (t / z)));
} else {
tmp = x + (y / (a / t));
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (z <= -2.4e-5) or not (z <= 4100000.0): tmp = x + (y * (1.0 - (t / z))) else: tmp = x + (y / (a / t)) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -2.4e-5) || !(z <= 4100000.0)) tmp = Float64(x + Float64(y * Float64(1.0 - Float64(t / z)))); else tmp = Float64(x + Float64(y / Float64(a / t))); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((z <= -2.4e-5) || ~((z <= 4100000.0))) tmp = x + (y * (1.0 - (t / z))); else tmp = x + (y / (a / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -2.4e-5], N[Not[LessEqual[z, 4100000.0]], $MachinePrecision]], N[(x + N[(y * N[(1.0 - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.4 \cdot 10^{-5} \lor \neg \left(z \leq 4100000\right):\\
\;\;\;\;x + y \cdot \left(1 - \frac{t}{z}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{\frac{a}{t}}\\
\end{array}
\end{array}
if z < -2.4000000000000001e-5 or 4.1e6 < z Initial program 99.9%
Taylor expanded in a around 0 88.8%
div-sub88.9%
*-inverses88.9%
Simplified88.9%
if -2.4000000000000001e-5 < z < 4.1e6Initial program 99.9%
Taylor expanded in z around 0 77.4%
associate-/l*84.8%
Simplified84.8%
Final simplification86.9%
(FPCore (x y z t a) :precision binary64 (if (<= z -0.00016) (+ x (* y (- 1.0 (/ t z)))) (if (<= z 9e-87) (+ x (* y (/ t a))) (+ x (* y (/ z (- z a)))))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -0.00016) {
tmp = x + (y * (1.0 - (t / z)));
} else if (z <= 9e-87) {
tmp = x + (y * (t / a));
} else {
tmp = x + (y * (z / (z - a)));
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (z <= (-0.00016d0)) then
tmp = x + (y * (1.0d0 - (t / z)))
else if (z <= 9d-87) then
tmp = x + (y * (t / a))
else
tmp = x + (y * (z / (z - a)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -0.00016) {
tmp = x + (y * (1.0 - (t / z)));
} else if (z <= 9e-87) {
tmp = x + (y * (t / a));
} else {
tmp = x + (y * (z / (z - a)));
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if z <= -0.00016: tmp = x + (y * (1.0 - (t / z))) elif z <= 9e-87: tmp = x + (y * (t / a)) else: tmp = x + (y * (z / (z - a))) return tmp
function code(x, y, z, t, a) tmp = 0.0 if (z <= -0.00016) tmp = Float64(x + Float64(y * Float64(1.0 - Float64(t / z)))); elseif (z <= 9e-87) tmp = Float64(x + Float64(y * Float64(t / a))); else tmp = Float64(x + Float64(y * Float64(z / Float64(z - a)))); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (z <= -0.00016) tmp = x + (y * (1.0 - (t / z))); elseif (z <= 9e-87) tmp = x + (y * (t / a)); else tmp = x + (y * (z / (z - a))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -0.00016], N[(x + N[(y * N[(1.0 - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 9e-87], N[(x + N[(y * N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -0.00016:\\
\;\;\;\;x + y \cdot \left(1 - \frac{t}{z}\right)\\
\mathbf{elif}\;z \leq 9 \cdot 10^{-87}:\\
\;\;\;\;x + y \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z}{z - a}\\
\end{array}
\end{array}
if z < -1.60000000000000013e-4Initial program 99.8%
Taylor expanded in a around 0 91.7%
div-sub91.7%
*-inverses91.7%
Simplified91.7%
if -1.60000000000000013e-4 < z < 8.99999999999999915e-87Initial program 99.9%
Taylor expanded in z around 0 89.5%
if 8.99999999999999915e-87 < z Initial program 99.9%
Taylor expanded in t around 0 85.8%
Final simplification88.8%
(FPCore (x y z t a) :precision binary64 (if (<= z -7.2e-8) (+ y x) (if (<= z 55000000000000.0) (+ x (* y (/ t a))) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -7.2e-8) {
tmp = y + x;
} else if (z <= 55000000000000.0) {
tmp = x + (y * (t / a));
} else {
tmp = y + x;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (z <= (-7.2d-8)) then
tmp = y + x
else if (z <= 55000000000000.0d0) then
tmp = x + (y * (t / a))
else
tmp = y + x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -7.2e-8) {
tmp = y + x;
} else if (z <= 55000000000000.0) {
tmp = x + (y * (t / a));
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if z <= -7.2e-8: tmp = y + x elif z <= 55000000000000.0: tmp = x + (y * (t / a)) else: tmp = y + x return tmp
function code(x, y, z, t, a) tmp = 0.0 if (z <= -7.2e-8) tmp = Float64(y + x); elseif (z <= 55000000000000.0) tmp = Float64(x + Float64(y * Float64(t / a))); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (z <= -7.2e-8) tmp = y + x; elseif (z <= 55000000000000.0) tmp = x + (y * (t / a)); else tmp = y + x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -7.2e-8], N[(y + x), $MachinePrecision], If[LessEqual[z, 55000000000000.0], N[(x + N[(y * N[(t / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -7.2 \cdot 10^{-8}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 55000000000000:\\
\;\;\;\;x + y \cdot \frac{t}{a}\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -7.19999999999999962e-8 or 5.5e13 < z Initial program 99.9%
Taylor expanded in z around inf 78.0%
if -7.19999999999999962e-8 < z < 5.5e13Initial program 99.9%
Taylor expanded in z around 0 84.8%
Final simplification81.3%
(FPCore (x y z t a) :precision binary64 (if (<= z -6.5e-6) (+ y x) (if (<= z 14200000000.0) (+ x (/ y (/ a t))) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -6.5e-6) {
tmp = y + x;
} else if (z <= 14200000000.0) {
tmp = x + (y / (a / t));
} else {
tmp = y + x;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (z <= (-6.5d-6)) then
tmp = y + x
else if (z <= 14200000000.0d0) then
tmp = x + (y / (a / t))
else
tmp = y + x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -6.5e-6) {
tmp = y + x;
} else if (z <= 14200000000.0) {
tmp = x + (y / (a / t));
} else {
tmp = y + x;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if z <= -6.5e-6: tmp = y + x elif z <= 14200000000.0: tmp = x + (y / (a / t)) else: tmp = y + x return tmp
function code(x, y, z, t, a) tmp = 0.0 if (z <= -6.5e-6) tmp = Float64(y + x); elseif (z <= 14200000000.0) tmp = Float64(x + Float64(y / Float64(a / t))); else tmp = Float64(y + x); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (z <= -6.5e-6) tmp = y + x; elseif (z <= 14200000000.0) tmp = x + (y / (a / t)); else tmp = y + x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -6.5e-6], N[(y + x), $MachinePrecision], If[LessEqual[z, 14200000000.0], N[(x + N[(y / N[(a / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.5 \cdot 10^{-6}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 14200000000:\\
\;\;\;\;x + \frac{y}{\frac{a}{t}}\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -6.4999999999999996e-6 or 1.42e10 < z Initial program 99.9%
Taylor expanded in z around inf 78.0%
if -6.4999999999999996e-6 < z < 1.42e10Initial program 99.9%
Taylor expanded in z around 0 77.4%
associate-/l*84.8%
Simplified84.8%
Final simplification81.3%
(FPCore (x y z t a) :precision binary64 (+ x (* y (/ (- z t) (- z a)))))
double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (y * ((z - t) / (z - a)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y * ((z - t) / (z - a)));
}
def code(x, y, z, t, a): return x + (y * ((z - t) / (z - a)))
function code(x, y, z, t, a) return Float64(x + Float64(y * Float64(Float64(z - t) / Float64(z - a)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y * ((z - t) / (z - a))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y * N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + y \cdot \frac{z - t}{z - a}
\end{array}
Initial program 99.9%
Final simplification99.9%
(FPCore (x y z t a) :precision binary64 (if (<= y 7e+153) (+ y x) (* y (- 1.0 (/ t z)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (y <= 7e+153) {
tmp = y + x;
} else {
tmp = y * (1.0 - (t / z));
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (y <= 7d+153) then
tmp = y + x
else
tmp = y * (1.0d0 - (t / z))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (y <= 7e+153) {
tmp = y + x;
} else {
tmp = y * (1.0 - (t / z));
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if y <= 7e+153: tmp = y + x else: tmp = y * (1.0 - (t / z)) return tmp
function code(x, y, z, t, a) tmp = 0.0 if (y <= 7e+153) tmp = Float64(y + x); else tmp = Float64(y * Float64(1.0 - Float64(t / z))); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (y <= 7e+153) tmp = y + x; else tmp = y * (1.0 - (t / z)); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[y, 7e+153], N[(y + x), $MachinePrecision], N[(y * N[(1.0 - N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq 7 \cdot 10^{+153}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;y \cdot \left(1 - \frac{t}{z}\right)\\
\end{array}
\end{array}
if y < 6.9999999999999998e153Initial program 99.9%
Taylor expanded in z around inf 67.1%
if 6.9999999999999998e153 < y Initial program 99.8%
Taylor expanded in a around 0 42.0%
+-commutative42.0%
*-commutative42.0%
associate-/l*68.6%
Simplified68.6%
Taylor expanded in y around inf 65.0%
Final simplification66.8%
(FPCore (x y z t a) :precision binary64 (if (<= a -1.12e+164) x (if (<= a 3.7e+205) (+ y x) x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.12e+164) {
tmp = x;
} else if (a <= 3.7e+205) {
tmp = y + x;
} else {
tmp = x;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if (a <= (-1.12d+164)) then
tmp = x
else if (a <= 3.7d+205) then
tmp = y + x
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= -1.12e+164) {
tmp = x;
} else if (a <= 3.7e+205) {
tmp = y + x;
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if a <= -1.12e+164: tmp = x elif a <= 3.7e+205: tmp = y + x else: tmp = x return tmp
function code(x, y, z, t, a) tmp = 0.0 if (a <= -1.12e+164) tmp = x; elseif (a <= 3.7e+205) tmp = Float64(y + x); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (a <= -1.12e+164) tmp = x; elseif (a <= 3.7e+205) tmp = y + x; else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, -1.12e+164], x, If[LessEqual[a, 3.7e+205], N[(y + x), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1.12 \cdot 10^{+164}:\\
\;\;\;\;x\\
\mathbf{elif}\;a \leq 3.7 \cdot 10^{+205}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if a < -1.12000000000000006e164 or 3.69999999999999981e205 < a Initial program 99.9%
Taylor expanded in x around inf 78.8%
if -1.12000000000000006e164 < a < 3.69999999999999981e205Initial program 99.9%
Taylor expanded in z around inf 66.6%
Final simplification68.9%
(FPCore (x y z t a) :precision binary64 x)
double code(double x, double y, double z, double t, double a) {
return x;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x
end function
public static double code(double x, double y, double z, double t, double a) {
return x;
}
def code(x, y, z, t, a): return x
function code(x, y, z, t, a) return x end
function tmp = code(x, y, z, t, a) tmp = x; end
code[x_, y_, z_, t_, a_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 99.9%
Taylor expanded in x around inf 50.9%
Final simplification50.9%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- z a) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = x + (y / ((z - a) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((z - a) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(z - a) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((z - a) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{z - a}{z - t}}
\end{array}
herbie shell --seed 2023195
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisLine from plot-0.2.3.4, A"
:precision binary64
:herbie-target
(+ x (/ y (/ (- z a) (- z t))))
(+ x (* y (/ (- z t) (- z a)))))