
(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 7 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.3%
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.5
Applied rewrites99.5%
(FPCore (x y z t) :precision binary64 (if (<= z -1.95e-53) (fma (/ z t) y x) (if (<= z 1.35e-37) (fma (/ y t) (- x) x) (+ (/ (* z y) t) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.95e-53) {
tmp = fma((z / t), y, x);
} else if (z <= 1.35e-37) {
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 <= -1.95e-53) tmp = fma(Float64(z / t), y, x); elseif (z <= 1.35e-37) 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, -1.95e-53], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 1.35e-37], 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 -1.95 \cdot 10^{-53}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-37}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot y}{t} + x\\
\end{array}
\end{array}
if z < -1.9500000000000001e-53Initial program 88.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.1
Applied rewrites91.1%
Taylor expanded in x around 0
lower-/.f6485.9
Applied rewrites85.9%
if -1.9500000000000001e-53 < z < 1.35000000000000008e-37Initial 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.0
Applied rewrites99.0%
Taylor expanded in x around inf
mul-1-negN/A
lower-neg.f6487.1
Applied rewrites87.1%
if 1.35000000000000008e-37 < z Initial program 93.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6487.5
Applied rewrites87.5%
Final simplification86.9%
(FPCore (x y z t) :precision binary64 (if (<= z -1.95e-53) (fma (/ z t) y x) (if (<= z 1.35e-37) (* (- 1.0 (/ y t)) x) (+ (/ (* z y) t) x))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.95e-53) {
tmp = fma((z / t), y, x);
} else if (z <= 1.35e-37) {
tmp = (1.0 - (y / t)) * x;
} else {
tmp = ((z * y) / t) + x;
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -1.95e-53) tmp = fma(Float64(z / t), y, x); elseif (z <= 1.35e-37) tmp = Float64(Float64(1.0 - Float64(y / t)) * x); else tmp = Float64(Float64(Float64(z * y) / t) + x); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.95e-53], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 1.35e-37], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision], N[(N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision] + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.95 \cdot 10^{-53}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 1.35 \cdot 10^{-37}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;\frac{z \cdot y}{t} + x\\
\end{array}
\end{array}
if z < -1.9500000000000001e-53Initial program 88.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6491.1
Applied rewrites91.1%
Taylor expanded in x around 0
lower-/.f6485.9
Applied rewrites85.9%
if -1.9500000000000001e-53 < z < 1.35000000000000008e-37Initial program 93.9%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6487.1
Applied rewrites87.1%
if 1.35000000000000008e-37 < z Initial program 93.3%
Taylor expanded in x around 0
*-commutativeN/A
lower-*.f6487.5
Applied rewrites87.5%
Final simplification86.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -1.45e+50) t_1 (if (<= t 1.3e+43) (/ (* (- 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 <= -1.45e+50) {
tmp = t_1;
} else if (t <= 1.3e+43) {
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 <= -1.45e+50) tmp = t_1; elseif (t <= 1.3e+43) tmp = Float64(Float64(Float64(z - 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[t, -1.45e+50], t$95$1, If[LessEqual[t, 1.3e+43], N[(N[(N[(z - x), $MachinePrecision] * 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}\;t \leq -1.45 \cdot 10^{+50}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 1.3 \cdot 10^{+43}:\\
\;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -1.45e50 or 1.3000000000000001e43 < t Initial program 84.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.2
Applied rewrites98.2%
Taylor expanded in x around 0
lower-/.f6492.0
Applied rewrites92.0%
if -1.45e50 < t < 1.3000000000000001e43Initial program 98.1%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6482.4
Applied rewrites82.4%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= z -1.95e-53) t_1 (if (<= z 1.15e+50) (* (- 1.0 (/ 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 <= -1.95e-53) {
tmp = t_1;
} else if (z <= 1.15e+50) {
tmp = (1.0 - (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 <= -1.95e-53) tmp = t_1; elseif (z <= 1.15e+50) tmp = Float64(Float64(1.0 - Float64(y / t)) * 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, -1.95e-53], t$95$1, If[LessEqual[z, 1.15e+50], N[(N[(1.0 - N[(y / t), $MachinePrecision]), $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 -1.95 \cdot 10^{-53}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 1.15 \cdot 10^{+50}:\\
\;\;\;\;\left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -1.9500000000000001e-53 or 1.14999999999999998e50 < z Initial program 89.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6490.9
Applied rewrites90.9%
Taylor expanded in x around 0
lower-/.f6487.7
Applied rewrites87.7%
if -1.9500000000000001e-53 < z < 1.14999999999999998e50Initial program 94.8%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6484.5
Applied rewrites84.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -1.2e-219) t_1 (if (<= t 8e-138) (* z (/ 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 <= -1.2e-219) {
tmp = t_1;
} else if (t <= 8e-138) {
tmp = z * (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 <= -1.2e-219) tmp = t_1; elseif (t <= 8e-138) tmp = Float64(z * 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, -1.2e-219], t$95$1, If[LessEqual[t, 8e-138], N[(z * 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 -1.2 \cdot 10^{-219}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 8 \cdot 10^{-138}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -1.20000000000000007e-219 or 8.00000000000000054e-138 < t Initial program 90.3%
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 x around 0
lower-/.f6479.7
Applied rewrites79.7%
if -1.20000000000000007e-219 < t < 8.00000000000000054e-138Initial program 99.8%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6466.1
Applied rewrites66.1%
Applied rewrites67.9%
Final simplification77.3%
(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.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6438.5
Applied rewrites38.5%
Applied rewrites43.9%
Final simplification43.9%
(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 2024294
(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)))