
(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 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 (* (- 1.0 (/ y t)) 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 = (1.0 - (y / t)) * 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 = Float64(Float64(1.0 - Float64(y / t)) * 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[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision] * 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 := \left(1 - \frac{y}{t}\right) \cdot x\\
\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%
Taylor expanded in x around inf
*-commutativeN/A
lower-*.f64N/A
mul-1-negN/A
unsub-negN/A
lower--.f64N/A
lower-/.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 (fma (/ z t) y x))) (if (<= t -5.1e-83) t_1 (if (<= t 2.2e-302) (* (- 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.1e-83) {
tmp = t_1;
} else if (t <= 2.2e-302) {
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.1e-83) tmp = t_1; elseif (t <= 2.2e-302) 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.1e-83], t$95$1, If[LessEqual[t, 2.2e-302], 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.1 \cdot 10^{-83}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 2.2 \cdot 10^{-302}:\\
\;\;\;\;\left(-x\right) \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -5.10000000000000036e-83 or 2.20000000000000007e-302 < 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.10000000000000036e-83 < t < 2.20000000000000007e-302Initial program 99.9%
Taylor expanded in y around inf
div-subN/A
associate-/l*N/A
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 -5.7e-117) (* z (/ y t)) (if (<= y 1.16e-33) (/ (* x t) t) (* (/ z t) y))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5.7e-117) {
tmp = z * (y / t);
} else if (y <= 1.16e-33) {
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 <= (-5.7d-117)) then
tmp = z * (y / t)
else if (y <= 1.16d-33) 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 <= -5.7e-117) {
tmp = z * (y / t);
} else if (y <= 1.16e-33) {
tmp = (x * t) / t;
} else {
tmp = (z / t) * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -5.7e-117: tmp = z * (y / t) elif y <= 1.16e-33: tmp = (x * t) / t else: tmp = (z / t) * y return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -5.7e-117) tmp = Float64(z * Float64(y / t)); elseif (y <= 1.16e-33) 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 <= -5.7e-117) tmp = z * (y / t); elseif (y <= 1.16e-33) tmp = (x * t) / t; else tmp = (z / t) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -5.7e-117], N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.16e-33], N[(N[(x * t), $MachinePrecision] / t), $MachinePrecision], N[(N[(z / t), $MachinePrecision] * y), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5.7 \cdot 10^{-117}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{elif}\;y \leq 1.16 \cdot 10^{-33}:\\
\;\;\;\;\frac{x \cdot t}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot y\\
\end{array}
\end{array}
if y < -5.6999999999999999e-117Initial program 91.1%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6446.6
Applied rewrites46.6%
Applied rewrites48.6%
if -5.6999999999999999e-117 < y < 1.1600000000000001e-33Initial 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 t around 0
lower-/.f64N/A
+-commutativeN/A
*-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
lower-*.f6488.4
Applied rewrites88.4%
Taylor expanded in y around 0
Applied rewrites54.1%
if 1.1600000000000001e-33 < y Initial program 86.6%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.6
Applied rewrites98.6%
Taylor expanded in z around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6449.1
Applied rewrites49.1%
Final simplification50.8%
(FPCore (x y z t) :precision binary64 (if (<= x -2.15e-194) (* z (/ y t)) (* (/ z t) y)))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -2.15e-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.15d-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.15e-194) {
tmp = z * (y / t);
} else {
tmp = (z / t) * y;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -2.15e-194: tmp = z * (y / t) else: tmp = (z / t) * y return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -2.15e-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.15e-194) tmp = z * (y / t); else tmp = (z / t) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -2.15e-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.15 \cdot 10^{-194}:\\
\;\;\;\;z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;\frac{z}{t} \cdot y\\
\end{array}
\end{array}
if x < -2.15000000000000003e-194Initial program 93.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6428.5
Applied rewrites28.5%
Applied rewrites30.3%
if -2.15000000000000003e-194 < x 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-/.f6494.3
Applied rewrites94.3%
Taylor expanded in z around inf
*-commutativeN/A
associate-*l/N/A
lower-*.f64N/A
lower-/.f6446.4
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 (/ 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 93.2%
Taylor expanded in x around 0
lower-/.f64N/A
*-commutativeN/A
lower-*.f6436.9
Applied rewrites36.9%
Applied rewrites37.5%
Final simplification37.5%
(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)))