
(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 (if (<= x 1e-107) (+ x (/ (* y (- z x)) t)) (fma (/ y t) (- z x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 1e-107) {
tmp = x + ((y * (z - x)) / t);
} else {
tmp = fma((y / t), (z - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= 1e-107) tmp = Float64(x + Float64(Float64(y * Float64(z - x)) / t)); else tmp = fma(Float64(y / t), Float64(z - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, 1e-107], N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 10^{-107}:\\
\;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\end{array}
\end{array}
if x < 1e-107Initial program 97.6%
if 1e-107 < x Initial program 93.5%
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.9
Applied rewrites99.9%
(FPCore (x y z t) :precision binary64 (if (<= x -3.5e+22) (- x (/ (* x y) t)) (if (<= x 4e+79) (+ x (/ (* y z) t)) (fma (/ y t) (- x) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.5e+22) {
tmp = x - ((x * y) / t);
} else if (x <= 4e+79) {
tmp = x + ((y * z) / t);
} else {
tmp = fma((y / t), -x, x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (x <= -3.5e+22) tmp = Float64(x - Float64(Float64(x * y) / t)); elseif (x <= 4e+79) tmp = Float64(x + Float64(Float64(y * z) / t)); else tmp = fma(Float64(y / t), Float64(-x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.5e+22], N[(x - N[(N[(x * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4e+79], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.5 \cdot 10^{+22}:\\
\;\;\;\;x - \frac{x \cdot y}{t}\\
\mathbf{elif}\;x \leq 4 \cdot 10^{+79}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\end{array}
\end{array}
if x < -3.5e22Initial program 98.2%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
associate-/l*N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6488.5
Applied rewrites88.5%
if -3.5e22 < x < 3.99999999999999987e79Initial program 96.7%
Taylor expanded in z around inf
lower-*.f6486.6
Applied rewrites86.6%
if 3.99999999999999987e79 < x Initial program 92.7%
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.9
Applied rewrites99.9%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6498.2
Applied rewrites98.2%
Final simplification89.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (/ (- z x) t)))) (if (<= y -4.6e+63) t_1 (if (<= y 2.45e+65) (+ x (/ (* y z) t)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((z - x) / t);
double tmp;
if (y <= -4.6e+63) {
tmp = t_1;
} else if (y <= 2.45e+65) {
tmp = x + ((y * z) / t);
} 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 - x) / t)
if (y <= (-4.6d+63)) then
tmp = t_1
else if (y <= 2.45d+65) then
tmp = x + ((y * z) / t)
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 - x) / t);
double tmp;
if (y <= -4.6e+63) {
tmp = t_1;
} else if (y <= 2.45e+65) {
tmp = x + ((y * z) / t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = y * ((z - x) / t) tmp = 0 if y <= -4.6e+63: tmp = t_1 elif y <= 2.45e+65: tmp = x + ((y * z) / t) else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(z - x) / t)) tmp = 0.0 if (y <= -4.6e+63) tmp = t_1; elseif (y <= 2.45e+65) tmp = Float64(x + Float64(Float64(y * z) / t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = y * ((z - x) / t); tmp = 0.0; if (y <= -4.6e+63) tmp = t_1; elseif (y <= 2.45e+65) tmp = x + ((y * z) / t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.6e+63], t$95$1, If[LessEqual[y, 2.45e+65], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -4.6 \cdot 10^{+63}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 2.45 \cdot 10^{+65}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.59999999999999986e63 or 2.44999999999999978e65 < y Initial program 92.8%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6492.9
Applied rewrites92.9%
if -4.59999999999999986e63 < y < 2.44999999999999978e65Initial program 98.5%
Taylor expanded in z around inf
lower-*.f6486.4
Applied rewrites86.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* y (/ (- z x) t)))) (if (<= y -4.1e+69) t_1 (if (<= y 3e+65) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = y * ((z - x) / t);
double tmp;
if (y <= -4.1e+69) {
tmp = t_1;
} else if (y <= 3e+65) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(y * Float64(Float64(z - x) / t)) tmp = 0.0 if (y <= -4.1e+69) tmp = t_1; elseif (y <= 3e+65) 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[(y * N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[y, -4.1e+69], t$95$1, If[LessEqual[y, 3e+65], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := y \cdot \frac{z - x}{t}\\
\mathbf{if}\;y \leq -4.1 \cdot 10^{+69}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 3 \cdot 10^{+65}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -4.0999999999999999e69 or 3.0000000000000002e65 < y Initial program 92.7%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6492.8
Applied rewrites92.8%
if -4.0999999999999999e69 < y < 3.0000000000000002e65Initial program 98.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.1
Applied rewrites88.1%
Taylor expanded in z around inf
lower-/.f6482.9
Applied rewrites82.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= z -8e-246) t_1 (if (<= z 1.9e-246) (* (/ y t) (- x)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (z <= -8e-246) {
tmp = t_1;
} else if (z <= 1.9e-246) {
tmp = (y / t) * -x;
} 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 <= -8e-246) tmp = t_1; elseif (z <= 1.9e-246) tmp = Float64(Float64(y / t) * Float64(-x)); 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, -8e-246], t$95$1, If[LessEqual[z, 1.9e-246], N[(N[(y / t), $MachinePrecision] * (-x)), $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 -8 \cdot 10^{-246}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-246}:\\
\;\;\;\;\frac{y}{t} \cdot \left(-x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -7.99999999999999965e-246 or 1.89999999999999988e-246 < z Initial program 96.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.4
Applied rewrites92.4%
Taylor expanded in z around inf
lower-/.f6477.5
Applied rewrites77.5%
if -7.99999999999999965e-246 < z < 1.89999999999999988e-246Initial program 87.3%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6470.0
Applied rewrites70.0%
Taylor expanded in z around 0
Applied rewrites69.1%
Applied rewrites85.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= z -8e-246) t_1 (if (<= z 1.9e-246) (/ (* 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 <= -8e-246) {
tmp = t_1;
} else if (z <= 1.9e-246) {
tmp = (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 <= -8e-246) tmp = t_1; elseif (z <= 1.9e-246) tmp = Float64(Float64(x * y) / Float64(-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, -8e-246], t$95$1, If[LessEqual[z, 1.9e-246], N[(N[(x * y), $MachinePrecision] / (-t)), $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 -8 \cdot 10^{-246}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.9 \cdot 10^{-246}:\\
\;\;\;\;\frac{x \cdot y}{-t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -7.99999999999999965e-246 or 1.89999999999999988e-246 < z Initial program 96.7%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.4
Applied rewrites92.4%
Taylor expanded in z around inf
lower-/.f6477.5
Applied rewrites77.5%
if -7.99999999999999965e-246 < z < 1.89999999999999988e-246Initial program 87.3%
Taylor expanded in x around inf
mul-1-negN/A
unsub-negN/A
distribute-lft-out--N/A
*-rgt-identityN/A
associate-/l*N/A
lower--.f64N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f6487.3
Applied rewrites87.3%
Taylor expanded in y around inf
Applied rewrites74.1%
Final simplification77.3%
(FPCore (x y z t) :precision binary64 (if (<= y -2e+55) (fma (/ (- z x) t) y x) (fma (/ y t) (- z x) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -2e+55) {
tmp = fma(((z - x) / t), y, x);
} else {
tmp = fma((y / t), (z - x), x);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (y <= -2e+55) tmp = fma(Float64(Float64(z - x) / t), y, x); else tmp = fma(Float64(y / t), Float64(z - x), x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[y, -2e+55], N[(N[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision] + x), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -2 \cdot 10^{+55}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - x}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, z - x, x\right)\\
\end{array}
\end{array}
if y < -2.00000000000000002e55Initial 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-/.f6499.8
Applied rewrites99.8%
if -2.00000000000000002e55 < y Initial program 97.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-/.f6497.6
Applied rewrites97.6%
(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 96.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.3
Applied rewrites96.3%
(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 96.2%
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-/.f6473.7
Applied rewrites73.7%
(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 96.2%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f6439.6
Applied rewrites39.6%
Applied rewrites40.2%
(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 2024238
(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)))