
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- a t))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - 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 - t)) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - t));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (a - t))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a - t}
\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)) (- a t))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - 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 - t)) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (a - t));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (a - t))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{a - t}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- a t)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (a - t)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(a - t)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{a - t}, y, x\right)
\end{array}
Initial program 84.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.6
Applied rewrites97.6%
(FPCore (x y z t a)
:precision binary64
(if (<= t -8.6e+166)
(+ y x)
(if (<= t -2.6e+19)
(fma (/ (- z) t) y x)
(if (<= t 7.2e-10) (fma (- z t) (/ y a) x) (+ y x)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -8.6e+166) {
tmp = y + x;
} else if (t <= -2.6e+19) {
tmp = fma((-z / t), y, x);
} else if (t <= 7.2e-10) {
tmp = fma((z - t), (y / a), x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -8.6e+166) tmp = Float64(y + x); elseif (t <= -2.6e+19) tmp = fma(Float64(Float64(-z) / t), y, x); elseif (t <= 7.2e-10) tmp = fma(Float64(z - t), Float64(y / a), x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -8.6e+166], N[(y + x), $MachinePrecision], If[LessEqual[t, -2.6e+19], N[(N[((-z) / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[t, 7.2e-10], N[(N[(z - t), $MachinePrecision] * N[(y / a), $MachinePrecision] + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -8.6 \cdot 10^{+166}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;t \leq -2.6 \cdot 10^{+19}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-z}{t}, y, x\right)\\
\mathbf{elif}\;t \leq 7.2 \cdot 10^{-10}:\\
\;\;\;\;\mathsf{fma}\left(z - t, \frac{y}{a}, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if t < -8.5999999999999999e166 or 7.2e-10 < t Initial program 69.2%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6485.8
Applied rewrites85.8%
if -8.5999999999999999e166 < t < -2.6e19Initial program 80.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.8
Applied rewrites99.8%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f6486.1
Applied rewrites86.1%
Taylor expanded in t around inf
Applied rewrites75.7%
if -2.6e19 < t < 7.2e-10Initial program 96.2%
Taylor expanded in a around inf
+-commutativeN/A
*-commutativeN/A
associate-/l*N/A
lower-fma.f64N/A
lower--.f64N/A
lower-/.f6481.1
Applied rewrites81.1%
(FPCore (x y z t a)
:precision binary64
(if (<= t -8.6e+166)
(+ y x)
(if (<= t -5.9e-40)
(fma (/ (- z) t) y x)
(if (<= t 3.4e-11) (fma (/ z a) y x) (+ y x)))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= -8.6e+166) {
tmp = y + x;
} else if (t <= -5.9e-40) {
tmp = fma((-z / t), y, x);
} else if (t <= 3.4e-11) {
tmp = fma((z / a), y, x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (t <= -8.6e+166) tmp = Float64(y + x); elseif (t <= -5.9e-40) tmp = fma(Float64(Float64(-z) / t), y, x); elseif (t <= 3.4e-11) tmp = fma(Float64(z / a), y, x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, -8.6e+166], N[(y + x), $MachinePrecision], If[LessEqual[t, -5.9e-40], N[(N[((-z) / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[t, 3.4e-11], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -8.6 \cdot 10^{+166}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;t \leq -5.9 \cdot 10^{-40}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-z}{t}, y, x\right)\\
\mathbf{elif}\;t \leq 3.4 \cdot 10^{-11}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if t < -8.5999999999999999e166 or 3.3999999999999999e-11 < t Initial program 69.2%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6485.8
Applied rewrites85.8%
if -8.5999999999999999e166 < t < -5.89999999999999966e-40Initial program 84.3%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f6480.5
Applied rewrites80.5%
Taylor expanded in t around inf
Applied rewrites67.9%
if -5.89999999999999966e-40 < t < 3.3999999999999999e-11Initial program 96.6%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6480.3
Applied rewrites80.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= z -4.5e-49) (not (<= z 1.3e-47))) (fma (/ z (- a t)) y x) (- x (* y (/ t (- a t))))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((z <= -4.5e-49) || !(z <= 1.3e-47)) {
tmp = fma((z / (a - t)), y, x);
} else {
tmp = x - (y * (t / (a - t)));
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((z <= -4.5e-49) || !(z <= 1.3e-47)) tmp = fma(Float64(z / Float64(a - t)), y, x); else tmp = Float64(x - Float64(y * Float64(t / Float64(a - t)))); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[z, -4.5e-49], N[Not[LessEqual[z, 1.3e-47]], $MachinePrecision]], N[(N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], N[(x - N[(y * N[(t / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.5 \cdot 10^{-49} \lor \neg \left(z \leq 1.3 \cdot 10^{-47}\right):\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a - t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x - y \cdot \frac{t}{a - t}\\
\end{array}
\end{array}
if z < -4.5000000000000002e-49 or 1.3e-47 < z Initial program 85.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.5
Applied rewrites97.5%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f6489.1
Applied rewrites89.1%
if -4.5000000000000002e-49 < z < 1.3e-47Initial program 84.2%
Taylor expanded in z around 0
fp-cancel-sign-sub-invN/A
metadata-evalN/A
*-lft-identityN/A
lower--.f64N/A
*-commutativeN/A
associate-/l*N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6491.3
Applied rewrites91.3%
Final simplification89.9%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -8.6e+166) (not (<= t 7.5e+41))) (+ y x) (fma (/ z (- a t)) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -8.6e+166) || !(t <= 7.5e+41)) {
tmp = y + x;
} else {
tmp = fma((z / (a - t)), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -8.6e+166) || !(t <= 7.5e+41)) tmp = Float64(y + x); else tmp = fma(Float64(z / Float64(a - t)), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -8.6e+166], N[Not[LessEqual[t, 7.5e+41]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -8.6 \cdot 10^{+166} \lor \neg \left(t \leq 7.5 \cdot 10^{+41}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a - t}, y, x\right)\\
\end{array}
\end{array}
if t < -8.5999999999999999e166 or 7.50000000000000072e41 < t Initial program 66.1%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6486.9
Applied rewrites86.9%
if -8.5999999999999999e166 < t < 7.50000000000000072e41Initial program 93.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.6
Applied rewrites96.6%
Taylor expanded in z around inf
lower-/.f64N/A
lower--.f6487.5
Applied rewrites87.5%
Final simplification87.3%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -5.2e+31) (not (<= t 3.4e-11))) (+ y x) (+ x (* (/ y a) z))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -5.2e+31) || !(t <= 3.4e-11)) {
tmp = y + x;
} else {
tmp = x + ((y / a) * 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 ((t <= (-5.2d+31)) .or. (.not. (t <= 3.4d-11))) then
tmp = y + x
else
tmp = x + ((y / a) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -5.2e+31) || !(t <= 3.4e-11)) {
tmp = y + x;
} else {
tmp = x + ((y / a) * z);
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (t <= -5.2e+31) or not (t <= 3.4e-11): tmp = y + x else: tmp = x + ((y / a) * z) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -5.2e+31) || !(t <= 3.4e-11)) tmp = Float64(y + x); else tmp = Float64(x + Float64(Float64(y / a) * z)); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((t <= -5.2e+31) || ~((t <= 3.4e-11))) tmp = y + x; else tmp = x + ((y / a) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -5.2e+31], N[Not[LessEqual[t, 3.4e-11]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(x + N[(N[(y / a), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.2 \cdot 10^{+31} \lor \neg \left(t \leq 3.4 \cdot 10^{-11}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{a} \cdot z\\
\end{array}
\end{array}
if t < -5.2e31 or 3.3999999999999999e-11 < t Initial program 72.0%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6478.7
Applied rewrites78.7%
if -5.2e31 < t < 3.3999999999999999e-11Initial program 95.7%
Taylor expanded in t around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6473.7
Applied rewrites73.7%
Applied rewrites75.0%
Final simplification76.7%
(FPCore (x y z t a) :precision binary64 (if (or (<= t -5.8e+31) (not (<= t 3.4e-11))) (+ y x) (fma (/ z a) y x)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((t <= -5.8e+31) || !(t <= 3.4e-11)) {
tmp = y + x;
} else {
tmp = fma((z / a), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if ((t <= -5.8e+31) || !(t <= 3.4e-11)) tmp = Float64(y + x); else tmp = fma(Float64(z / a), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[t, -5.8e+31], N[Not[LessEqual[t, 3.4e-11]], $MachinePrecision]], N[(y + x), $MachinePrecision], N[(N[(z / a), $MachinePrecision] * y + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -5.8 \cdot 10^{+31} \lor \neg \left(t \leq 3.4 \cdot 10^{-11}\right):\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{a}, y, x\right)\\
\end{array}
\end{array}
if t < -5.8000000000000001e31 or 3.3999999999999999e-11 < t Initial program 72.0%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6478.7
Applied rewrites78.7%
if -5.8000000000000001e31 < t < 3.3999999999999999e-11Initial program 95.7%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6475.0
Applied rewrites75.0%
Final simplification76.7%
(FPCore (x y z t a) :precision binary64 (if (<= a 1.22e+178) (+ y x) (* (- x) -1.0)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (a <= 1.22e+178) {
tmp = y + x;
} else {
tmp = -x * -1.0;
}
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.22d+178) then
tmp = y + x
else
tmp = -x * (-1.0d0)
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.22e+178) {
tmp = y + x;
} else {
tmp = -x * -1.0;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if a <= 1.22e+178: tmp = y + x else: tmp = -x * -1.0 return tmp
function code(x, y, z, t, a) tmp = 0.0 if (a <= 1.22e+178) tmp = Float64(y + x); else tmp = Float64(Float64(-x) * -1.0); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (a <= 1.22e+178) tmp = y + x; else tmp = -x * -1.0; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[a, 1.22e+178], N[(y + x), $MachinePrecision], N[((-x) * -1.0), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq 1.22 \cdot 10^{+178}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\left(-x\right) \cdot -1\\
\end{array}
\end{array}
if a < 1.2199999999999999e178Initial program 84.6%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6461.5
Applied rewrites61.5%
if 1.2199999999999999e178 < a Initial program 86.6%
Taylor expanded in x around -inf
associate-*r*N/A
lower-*.f64N/A
mul-1-negN/A
lower-neg.f64N/A
lower--.f64N/A
Applied rewrites95.4%
Taylor expanded in z around 0
Applied rewrites86.5%
Taylor expanded in x around inf
Applied rewrites82.3%
(FPCore (x y z t a) :precision binary64 (+ y x))
double code(double x, double y, double z, double t, double a) {
return y + 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 = y + x
end function
public static double code(double x, double y, double z, double t, double a) {
return y + x;
}
def code(x, y, z, t, a): return y + x
function code(x, y, z, t, a) return Float64(y + x) end
function tmp = code(x, y, z, t, a) tmp = y + x; end
code[x_, y_, z_, t_, a_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
y + x
\end{array}
Initial program 84.8%
Taylor expanded in t around inf
+-commutativeN/A
lower-+.f6461.7
Applied rewrites61.7%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- a t) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((a - t) / (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 / ((a - t) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((a - t) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((a - t) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(a - t) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((a - t) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(a - t), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{a - t}{z - t}}
\end{array}
herbie shell --seed 2024329
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTicks from plot-0.2.3.4, B"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- a t) (- z t)))))
(+ x (/ (* y (- z t)) (- a t))))