
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (/ (* y (- z x)) t)))
double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
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 - x)) / t)
end function
public static double code(double x, double y, double z, double t) {
return x + ((y * (z - x)) / t);
}
def code(x, y, z, t): return x + ((y * (z - x)) / t)
function code(x, y, z, t) return Float64(x + Float64(Float64(y * Float64(z - x)) / t)) end
function tmp = code(x, y, z, t) tmp = x + ((y * (z - x)) / t); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - x\right)}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (fma (/ y t) (- z x) x))
double code(double x, double y, double z, double t) {
return fma((y / t), (z - x), x);
}
function code(x, y, z, t) return fma(Float64(y / t), Float64(z - x), x) end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)
\end{array}
Initial program 92.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.8
Applied rewrites98.8%
(FPCore (x y z t) :precision binary64 (if (<= z -3.8e-14) (fma (/ z t) y x) (if (<= z 5.6e-55) (fma (/ y t) (- x) x) (+ (/ (* z y) t) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.8e-14) {
tmp = fma((z / t), y, x);
} else if (z <= 5.6e-55) {
tmp = fma((y / t), -x, x);
} else {
tmp = ((z * y) / t) + x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.8e-14) tmp = fma(Float64(z / t), y, x); elseif (z <= 5.6e-55) tmp = fma(Float64(y / t), Float64(-x), x); else tmp = Float64(Float64(Float64(z * y) / t) + x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.8e-14], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 5.6e-55], N[(N[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.8 \cdot 10^{-14}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 5.6 \cdot 10^{-55}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot y}{t} + x\\
\end{array}
\end{array}
if z < -3.8000000000000002e-14Initial program 87.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.8
Applied rewrites91.8%
Taylor expanded in z around inf
lower-/.f6486.9
Applied rewrites86.9%
if -3.8000000000000002e-14 < z < 5.59999999999999968e-55Initial program 93.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.1
Applied rewrites99.1%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6493.1
Applied rewrites93.1%
if 5.59999999999999968e-55 < z Initial program 93.3%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6485.5
Applied rewrites85.5%
Final simplification89.1%
(FPCore (x y z t) :precision binary64 (if (<= z -3.3e-15) (fma (/ z t) y x) (if (<= z 2e-86) (- x (/ (* x y) t)) (+ (/ (* z y) t) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -3.3e-15) {
tmp = fma((z / t), y, x);
} else if (z <= 2e-86) {
tmp = x - ((x * y) / t);
} else {
tmp = ((z * y) / t) + x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -3.3e-15) tmp = fma(Float64(z / t), y, x); elseif (z <= 2e-86) tmp = Float64(x - Float64(Float64(x * y) / t)); else tmp = Float64(Float64(Float64(z * y) / t) + x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -3.3e-15], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 2e-86], N[(x - N[(N[(x * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -3.3 \cdot 10^{-15}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-86}:\\
\;\;\;\;x - \frac{x \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot y}{t} + x\\
\end{array}
\end{array}
if z < -3.3e-15Initial program 87.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.8
Applied rewrites91.8%
Taylor expanded in z around inf
lower-/.f6486.9
Applied rewrites86.9%
if -3.3e-15 < z < 2.00000000000000017e-86Initial program 95.3%
Taylor expanded in z around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6490.9
Applied rewrites90.9%
if 2.00000000000000017e-86 < z Initial program 91.7%
Taylor expanded in z around inf
*-commutativeN/A
lower-*.f6485.1
Applied rewrites85.1%
Final simplification87.8%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= z -3.3e-15) t_1 (if (<= z 2e-86) (- x (/ (* x y) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (z <= -3.3e-15) {
tmp = t_1;
} else if (z <= 2e-86) {
tmp = x - ((x * y) / t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(z / t), y, x) tmp = 0.0 if (z <= -3.3e-15) tmp = t_1; elseif (z <= 2e-86) tmp = Float64(x - Float64(Float64(x * y) / t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[z, -3.3e-15], t$95$1, If[LessEqual[z, 2e-86], N[(x - N[(N[(x * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{if}\;z \leq -3.3 \cdot 10^{-15}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 2 \cdot 10^{-86}:\\
\;\;\;\;x - \frac{x \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -3.3e-15 or 2.00000000000000017e-86 < z Initial program 89.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.1
Applied rewrites93.1%
Taylor expanded in z around inf
lower-/.f6485.1
Applied rewrites85.1%
if -3.3e-15 < z < 2.00000000000000017e-86Initial program 95.3%
Taylor expanded in z around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6490.9
Applied rewrites90.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -3.1e-89) t_1 (if (<= t 6e-25) (* (- z x) (/ y t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (t <= -3.1e-89) {
tmp = t_1;
} else if (t <= 6e-25) {
tmp = (z - x) * (y / t);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(z / t), y, x) tmp = 0.0 if (t <= -3.1e-89) tmp = t_1; elseif (t <= 6e-25) tmp = Float64(Float64(z - x) * Float64(y / t)); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[t, -3.1e-89], t$95$1, If[LessEqual[t, 6e-25], N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{if}\;t \leq -3.1 \cdot 10^{-89}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 6 \cdot 10^{-25}:\\
\;\;\;\;\left(z - x\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -3.09999999999999996e-89 or 5.9999999999999995e-25 < t Initial program 88.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.1
Applied rewrites97.1%
Taylor expanded in z around inf
lower-/.f6483.2
Applied rewrites83.2%
if -3.09999999999999996e-89 < t < 5.9999999999999995e-25Initial program 97.9%
Taylor expanded in t around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6489.4
Applied rewrites89.4%
Applied rewrites89.6%
Final simplification85.6%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- x) (/ y t)))) (if (<= y -3.2e+209) t_1 (if (<= y 2.32e+120) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = -x * (y / t);
double tmp;
if (y <= -3.2e+209) {
tmp = t_1;
} else if (y <= 2.32e+120) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(-x) * Float64(y / t)) tmp = 0.0 if (y <= -3.2e+209) tmp = t_1; elseif (y <= 2.32e+120) tmp = fma(Float64(z / t), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[((-x) * N[(y / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -3.2e+209], t$95$1, If[LessEqual[y, 2.32e+120], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(-x\right) \cdot \frac{y}{t}\\
\mathbf{if}\;y \leq -3.2 \cdot 10^{+209}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.32 \cdot 10^{+120}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -3.1999999999999999e209 or 2.32000000000000006e120 < y Initial program 90.0%
Taylor expanded in t around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.2
Applied rewrites86.2%
Applied rewrites94.2%
Taylor expanded in z around 0
Applied rewrites70.6%
if -3.1999999999999999e209 < y < 2.32000000000000006e120Initial program 92.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.5
Applied rewrites91.5%
Taylor expanded in z around inf
lower-/.f6478.8
Applied rewrites78.8%
Final simplification76.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (/ (- x) t) y))) (if (<= y -2.02e+214) t_1 (if (<= y 2.32e+120) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (-x / t) * y;
double tmp;
if (y <= -2.02e+214) {
tmp = t_1;
} else if (y <= 2.32e+120) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(-x) / t) * y) tmp = 0.0 if (y <= -2.02e+214) tmp = t_1; elseif (y <= 2.32e+120) tmp = fma(Float64(z / t), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[((-x) / t), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2.02e+214], t$95$1, If[LessEqual[y, 2.32e+120], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{-x}{t} \cdot y\\
\mathbf{if}\;y \leq -2.02 \cdot 10^{+214}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.32 \cdot 10^{+120}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.01999999999999999e214 or 2.32000000000000006e120 < y Initial program 89.6%
Taylor expanded in t around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6485.7
Applied rewrites85.7%
Taylor expanded in z around 0
Applied rewrites66.0%
if -2.01999999999999999e214 < y < 2.32000000000000006e120Initial program 92.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.6
Applied rewrites91.6%
Taylor expanded in z around inf
lower-/.f6478.5
Applied rewrites78.5%
(FPCore (x y z t) :precision binary64 (fma (/ z t) y x))
double code(double x, double y, double z, double t) {
return fma((z / t), y, x);
}
function code(x, y, z, t) return fma(Float64(z / t), y, x) end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z}{t}, y, x\right)
\end{array}
Initial program 92.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.0
Applied rewrites93.0%
Taylor expanded in z around inf
lower-/.f6471.2
Applied rewrites71.2%
(FPCore (x y z t) :precision binary64 (* z (/ y t)))
double code(double x, double y, double z, double t) {
return z * (y / t);
}
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 = z * (y / t)
end function
public static double code(double x, double y, double z, double t) {
return z * (y / t);
}
def code(x, y, z, t): return z * (y / t)
function code(x, y, z, t) return Float64(z * Float64(y / t)) end
function tmp = code(x, y, z, t) tmp = z * (y / t); end
code[x_, y_, z_, t_] := N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
z \cdot \frac{y}{t}
\end{array}
Initial program 92.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6493.0
Applied rewrites93.0%
Taylor expanded in z around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6437.3
Applied rewrites37.3%
Final simplification37.3%
(FPCore (x y z t) :precision binary64 (* (/ z t) y))
double code(double x, double y, double z, double t) {
return (z / t) * y;
}
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 = (z / t) * y
end function
public static double code(double x, double y, double z, double t) {
return (z / t) * y;
}
def code(x, y, z, t): return (z / t) * y
function code(x, y, z, t) return Float64(Float64(z / t) * y) end
function tmp = code(x, y, z, t) tmp = (z / t) * y; end
code[x_, y_, z_, t_] := N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]
\begin{array}{l}
\\
\frac{z}{t} \cdot y
\end{array}
Initial program 92.1%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f6433.1
Applied rewrites33.1%
Applied rewrites35.6%
(FPCore (x y z t) :precision binary64 (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
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 - ((x * (y / t)) + (-z * (y / t)))
end function
public static double code(double x, double y, double z, double t) {
return x - ((x * (y / t)) + (-z * (y / t)));
}
def code(x, y, z, t): return x - ((x * (y / t)) + (-z * (y / t)))
function code(x, y, z, t) return Float64(x - Float64(Float64(x * Float64(y / t)) + Float64(Float64(-z) * Float64(y / t)))) end
function tmp = code(x, y, z, t) tmp = x - ((x * (y / t)) + (-z * (y / t))); end
code[x_, y_, z_, t_] := N[(x - N[(N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision] + N[((-z) * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x - \left(x \cdot \frac{y}{t} + \left(-z\right) \cdot \frac{y}{t}\right)
\end{array}
herbie shell --seed 2024249
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:alt
(! :herbie-platform default (- x (+ (* x (/ y t)) (* (- z) (/ y t)))))
(+ x (/ (* y (- z x)) t)))