
(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 9 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 93.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-/.f6497.2
Applied rewrites97.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ y t) (- x) x))) (if (<= x -4e-26) t_1 (if (<= x 4.4e+78) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((y / t), -x, x);
double tmp;
if (x <= -4e-26) {
tmp = t_1;
} else if (x <= 4.4e+78) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = fma(Float64(y / t), Float64(-x), x) tmp = 0.0 if (x <= -4e-26) tmp = t_1; elseif (x <= 4.4e+78) 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[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision]}, If[LessEqual[x, -4e-26], t$95$1, If[LessEqual[x, 4.4e+78], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{if}\;x \leq -4 \cdot 10^{-26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 4.4 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -4.0000000000000002e-26 or 4.40000000000000028e78 < x Initial program 90.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.f6491.6
Applied rewrites91.6%
if -4.0000000000000002e-26 < x < 4.40000000000000028e78Initial program 95.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.3
Applied rewrites98.3%
Taylor expanded in z around inf
lower-/.f6488.7
Applied rewrites88.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (- x (/ (* x y) t)))) (if (<= x -4e-26) t_1 (if (<= x 6.2e+78) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = x - ((x * y) / t);
double tmp;
if (x <= -4e-26) {
tmp = t_1;
} else if (x <= 6.2e+78) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(x - Float64(Float64(x * y) / t)) tmp = 0.0 if (x <= -4e-26) tmp = t_1; elseif (x <= 6.2e+78) 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[(N[(x * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]}, If[LessEqual[x, -4e-26], t$95$1, If[LessEqual[x, 6.2e+78], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := x - \frac{x \cdot y}{t}\\
\mathbf{if}\;x \leq -4 \cdot 10^{-26}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;x \leq 6.2 \cdot 10^{+78}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if x < -4.0000000000000002e-26 or 6.2e78 < x Initial program 90.7%
Taylor expanded in z around 0
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.f64N/A
lower-*.f6483.2
Applied rewrites83.2%
if -4.0000000000000002e-26 < x < 6.2e78Initial program 95.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.3
Applied rewrites98.3%
Taylor expanded in z around inf
lower-/.f6488.7
Applied rewrites88.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (* (/ (- z x) t) y))) (if (<= y -2.1e+86) t_1 (if (<= y 1.35e-34) (fma (/ z t) y x) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = ((z - x) / t) * y;
double tmp;
if (y <= -2.1e+86) {
tmp = t_1;
} else if (y <= 1.35e-34) {
tmp = fma((z / t), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t) t_1 = Float64(Float64(Float64(z - x) / t) * y) tmp = 0.0 if (y <= -2.1e+86) tmp = t_1; elseif (y <= 1.35e-34) 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[(N[(z - x), $MachinePrecision] / t), $MachinePrecision] * y), $MachinePrecision]}, If[LessEqual[y, -2.1e+86], t$95$1, If[LessEqual[y, 1.35e-34], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{z - x}{t} \cdot y\\
\mathbf{if}\;y \leq -2.1 \cdot 10^{+86}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;y \leq 1.35 \cdot 10^{-34}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if y < -2.0999999999999999e86 or 1.35000000000000008e-34 < y Initial program 87.3%
Taylor expanded in t around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6476.0
Applied rewrites76.0%
Applied rewrites81.9%
if -2.0999999999999999e86 < y < 1.35000000000000008e-34Initial program 98.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6486.6
Applied rewrites86.6%
Taylor expanded in z around inf
lower-/.f6482.3
Applied rewrites82.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -5.3e-83) t_1 (if (<= t 8.7e-303) (* (- 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 <= -5.3e-83) {
tmp = t_1;
} else if (t <= 8.7e-303) {
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 <= -5.3e-83) tmp = t_1; elseif (t <= 8.7e-303) 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, -5.3e-83], t$95$1, If[LessEqual[t, 8.7e-303], 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 -5.3 \cdot 10^{-83}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 8.7 \cdot 10^{-303}:\\
\;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -5.3e-83 or 8.70000000000000009e-303 < t Initial program 91.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6494.5
Applied rewrites94.5%
Taylor expanded in z around inf
lower-/.f6479.5
Applied rewrites79.5%
if -5.3e-83 < t < 8.70000000000000009e-303Initial program 99.9%
Taylor expanded in t around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f64N/A
lower--.f6491.1
Applied rewrites91.1%
Taylor expanded in z around 0
Applied rewrites66.9%
Applied rewrites68.9%
Final simplification77.7%
(FPCore (x y z t) :precision binary64 (if (<= y -3.6e-116) (* z (/ y t)) (if (<= y 6e-35) (/ (* x t) t) (* (/ z t) y))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3.6e-116) {
tmp = z * (y / t);
} else if (y <= 6e-35) {
tmp = (x * t) / t;
} else {
tmp = (z / t) * y;
}
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) :: tmp
if (y <= (-3.6d-116)) then
tmp = z * (y / t)
else if (y <= 6d-35) then
tmp = (x * t) / t
else
tmp = (z / t) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -3.6e-116) {
tmp = z * (y / t);
} else if (y <= 6e-35) {
tmp = (x * t) / t;
} else {
tmp = (z / t) * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -3.6e-116: tmp = z * (y / t) elif y <= 6e-35: tmp = (x * t) / t else: tmp = (z / t) * y return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -3.6e-116) tmp = Float64(z * Float64(y / t)); elseif (y <= 6e-35) tmp = Float64(Float64(x * t) / t); else tmp = Float64(Float64(z / t) * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -3.6e-116) tmp = z * (y / t); elseif (y <= 6e-35) tmp = (x * t) / t; else tmp = (z / t) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -3.6e-116], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 6e-35], N[(N[(x * t), $MachinePrecision] / t), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.6 \cdot 10^{-116}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{elif}\;y \leq 6 \cdot 10^{-35}:\\
\;\;\;\;\frac{x \cdot t}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot y\\
\end{array}
\end{array}
if y < -3.59999999999999975e-116Initial program 91.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.5
Applied rewrites96.5%
Taylor expanded in z around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6448.6
Applied rewrites48.6%
if -3.59999999999999975e-116 < y < 5.99999999999999978e-35Initial program 99.9%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6483.4
Applied rewrites83.4%
Taylor expanded in z around inf
lower-/.f6483.3
Applied rewrites83.3%
Taylor expanded in t around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6488.4
Applied rewrites88.4%
Taylor expanded in t around inf
Applied rewrites54.1%
if 5.99999999999999978e-35 < y Initial program 86.6%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f6445.1
Applied rewrites45.1%
Applied rewrites49.1%
Final simplification50.8%
(FPCore (x y z t) :precision binary64 (if (<= x -2.05e-194) (* z (/ y t)) (* (/ z t) y)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.05e-194) {
tmp = z * (y / t);
} else {
tmp = (z / t) * y;
}
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) :: tmp
if (x <= (-2.05d-194)) then
tmp = z * (y / t)
else
tmp = (z / t) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.05e-194) {
tmp = z * (y / t);
} else {
tmp = (z / t) * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -2.05e-194: tmp = z * (y / t) else: tmp = (z / t) * y return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -2.05e-194) tmp = Float64(z * Float64(y / t)); else tmp = Float64(Float64(z / t) * y); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -2.05e-194) tmp = z * (y / t); else tmp = (z / t) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -2.05e-194], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.05 \cdot 10^{-194}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot y\\
\end{array}
\end{array}
if x < -2.0500000000000001e-194Initial program 93.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6488.6
Applied rewrites88.6%
Taylor expanded in z around inf
associate-*l/N/A
lower-*.f64N/A
lower-/.f6430.3
Applied rewrites30.3%
if -2.0500000000000001e-194 < x Initial program 93.2%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f6442.3
Applied rewrites42.3%
Applied rewrites46.4%
Final simplification40.1%
(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 93.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.1
Applied rewrites92.1%
Taylor expanded in z around inf
lower-/.f6473.6
Applied rewrites73.6%
(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 93.2%
Taylor expanded in z around inf
lower-/.f64N/A
*-commutativeN/A
lower-*.f6436.9
Applied rewrites36.9%
Applied rewrites38.3%
Final simplification38.3%
(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 2024235
(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)))