
(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 91.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-/.f6497.9
Applied rewrites97.9%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (fma (/ z t) y x)))
(if (<= t -9e-123)
t_1
(if (<= t -6.2e-259)
(* z (/ y t))
(if (<= t 6.6e-254) (* (- 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 <= -9e-123) {
tmp = t_1;
} else if (t <= -6.2e-259) {
tmp = z * (y / t);
} else if (t <= 6.6e-254) {
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 (t <= -9e-123) tmp = t_1; elseif (t <= -6.2e-259) tmp = Float64(z * Float64(y / t)); elseif (t <= 6.6e-254) tmp = Float64(Float64(-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, -9e-123], t$95$1, If[LessEqual[t, -6.2e-259], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[t, 6.6e-254], N[((-x) * 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 -9 \cdot 10^{-123}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq -6.2 \cdot 10^{-259}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{elif}\;t \leq 6.6 \cdot 10^{-254}:\\
\;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -8.99999999999999986e-123 or 6.60000000000000033e-254 < t Initial program 90.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6495.2
Applied rewrites95.2%
Taylor expanded in x around 0
lower-/.f6480.6
Applied rewrites80.6%
if -8.99999999999999986e-123 < t < -6.1999999999999995e-259Initial program 96.6%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6458.2
Applied rewrites58.2%
Applied rewrites67.5%
if -6.1999999999999995e-259 < t < 6.60000000000000033e-254Initial program 91.8%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.9
Applied rewrites91.9%
Taylor expanded in x around inf
Applied rewrites83.6%
Final simplification79.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -7e-8) t_1 (if (<= t 6600000.0) (/ (* (- 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 <= -7e-8) {
tmp = t_1;
} else if (t <= 6600000.0) {
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 <= -7e-8) tmp = t_1; elseif (t <= 6600000.0) 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, -7e-8], t$95$1, If[LessEqual[t, 6600000.0], 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 -7 \cdot 10^{-8}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 6600000:\\
\;\;\;\;\frac{\left(z - x\right) \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -7.00000000000000048e-8 or 6.6e6 < t Initial program 85.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
Taylor expanded in x around 0
lower-/.f6490.5
Applied rewrites90.5%
if -7.00000000000000048e-8 < t < 6.6e6Initial program 97.5%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6486.9
Applied rewrites86.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (- 1.0 (/ y t)) x))) (if (<= x -1.9e-34) t_1 (if (<= x 7.4e+61) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (1.0 - (y / t)) * x;
double tmp;
if (x <= -1.9e-34) {
tmp = t_1;
} else if (x <= 7.4e+61) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(1.0 - Float64(y / t)) * x) tmp = 0.0 if (x <= -1.9e-34) tmp = t_1; elseif (x <= 7.4e+61) 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[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * x), $MachinePrecision]}, If[LessEqual[x, -1.9e-34], t$95$1, If[LessEqual[x, 7.4e+61], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(1 - \frac{y}{t}\right) \cdot x\\
\mathbf{if}\;x \leq -1.9 \cdot 10^{-34}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 7.4 \cdot 10^{+61}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -1.9000000000000001e-34 or 7.40000000000000005e61 < x Initial program 90.6%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f6488.3
Applied rewrites88.3%
if -1.9000000000000001e-34 < x < 7.40000000000000005e61Initial program 92.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.2
Applied rewrites94.2%
Taylor expanded in x around 0
lower-/.f6483.5
Applied rewrites83.5%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -9e-123) t_1 (if (<= t 2.4e-144) (* 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 <= -9e-123) {
tmp = t_1;
} else if (t <= 2.4e-144) {
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 <= -9e-123) tmp = t_1; elseif (t <= 2.4e-144) 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, -9e-123], t$95$1, If[LessEqual[t, 2.4e-144], 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 -9 \cdot 10^{-123}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 2.4 \cdot 10^{-144}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -8.99999999999999986e-123 or 2.39999999999999994e-144 < t 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-/.f6497.3
Applied rewrites97.3%
Taylor expanded in x around 0
lower-/.f6482.3
Applied rewrites82.3%
if -8.99999999999999986e-123 < t < 2.39999999999999994e-144Initial program 95.8%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6458.0
Applied rewrites58.0%
Applied rewrites61.9%
Final simplification76.6%
(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 91.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6436.2
Applied rewrites36.2%
Applied rewrites40.2%
Final simplification40.2%
(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 91.3%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6436.2
Applied rewrites36.2%
Applied rewrites34.8%
Final simplification34.8%
(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 2024296
(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)))