
(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 92.4%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.1
Applied rewrites98.1%
(FPCore (x y z t) :precision binary64 (if (<= z -4.2e-38) (fma (/ z t) y x) (if (<= z 1.7e-5) (fma (/ (- x) t) y x) (+ x (/ (* y z) t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -4.2e-38) {
tmp = fma((z / t), y, x);
} else if (z <= 1.7e-5) {
tmp = fma((-x / t), y, x);
} else {
tmp = x + ((y * z) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -4.2e-38) tmp = fma(Float64(z / t), y, x); elseif (z <= 1.7e-5) tmp = fma(Float64(Float64(-x) / t), y, x); else tmp = Float64(x + Float64(Float64(y * z) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -4.2e-38], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 1.7e-5], N[(N[((-x) / t), $MachinePrecision] * y + x), $MachinePrecision], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{-38}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 1.7 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\frac{-x}{t}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\end{array}
\end{array}
if z < -4.20000000000000026e-38Initial 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-/.f6494.1
Applied rewrites94.1%
Taylor expanded in z around inf
lower-/.f6484.0
Applied rewrites84.0%
if -4.20000000000000026e-38 < z < 1.7e-5Initial 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-/.f6499.9
Applied rewrites99.9%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6490.4
Applied rewrites90.4%
if 1.7e-5 < z Initial program 95.4%
Taylor expanded in z around inf
lower-*.f6494.2
Applied rewrites94.2%
(FPCore (x y z t) :precision binary64 (if (<= z -1.35e-37) (fma (/ z t) y x) (if (<= z 2.5e-5) (fma (/ y t) (- x) x) (+ x (/ (* y z) t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -1.35e-37) {
tmp = fma((z / t), y, x);
} else if (z <= 2.5e-5) {
tmp = fma((y / t), -x, x);
} else {
tmp = x + ((y * z) / t);
}
return tmp;
}
function code(x, y, z, t) tmp = 0.0 if (z <= -1.35e-37) tmp = fma(Float64(z / t), y, x); elseif (z <= 2.5e-5) tmp = fma(Float64(y / t), Float64(-x), x); else tmp = Float64(x + Float64(Float64(y * z) / t)); end return tmp end
code[x_, y_, z_, t_] := If[LessEqual[z, -1.35e-37], N[(N[(z / t), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 2.5e-5], N[(N[(y / t), $MachinePrecision] * (-x) + x), $MachinePrecision], N[(x + N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.35 \cdot 10^{-37}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{t}, y, x\right)\\
\mathbf{elif}\;z \leq 2.5 \cdot 10^{-5}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{t}, -x, x\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y \cdot z}{t}\\
\end{array}
\end{array}
if z < -1.35000000000000008e-37Initial 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-/.f6494.1
Applied rewrites94.1%
Taylor expanded in z around inf
lower-/.f6484.0
Applied rewrites84.0%
if -1.35000000000000008e-37 < z < 2.50000000000000012e-5Initial program 90.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-/.f6496.1
Applied rewrites96.1%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6490.4
Applied rewrites90.4%
if 2.50000000000000012e-5 < z Initial program 95.4%
Taylor expanded in z around inf
lower-*.f6494.2
Applied rewrites94.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -3.15e+58) t_1 (if (<= t 7.2e+25) (/ (* y (- z x)) 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 <= -3.15e+58) {
tmp = t_1;
} else if (t <= 7.2e+25) {
tmp = (y * (z - x)) / 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 <= -3.15e+58) tmp = t_1; elseif (t <= 7.2e+25) tmp = Float64(Float64(y * Float64(z - x)) / 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, -3.15e+58], t$95$1, If[LessEqual[t, 7.2e+25], N[(N[(y * N[(z - x), $MachinePrecision]), $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 -3.15 \cdot 10^{+58}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 7.2 \cdot 10^{+25}:\\
\;\;\;\;\frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -3.1499999999999998e58 or 7.20000000000000031e25 < t Initial program 83.8%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
lower-/.f6492.4
Applied rewrites92.4%
if -3.1499999999999998e58 < t < 7.20000000000000031e25Initial program 98.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6492.6
Applied rewrites92.6%
Taylor expanded in t around 0
lower-/.f64N/A
lower-*.f64N/A
lower--.f6483.3
Applied rewrites83.3%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -3.6e+62) t_1 (if (<= t 5.4e+23) (* (/ y t) (- z x)) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (t <= -3.6e+62) {
tmp = t_1;
} else if (t <= 5.4e+23) {
tmp = (y / t) * (z - 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 (t <= -3.6e+62) tmp = t_1; elseif (t <= 5.4e+23) tmp = Float64(Float64(y / t) * Float64(z - 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[t, -3.6e+62], t$95$1, If[LessEqual[t, 5.4e+23], N[(N[(y / t), $MachinePrecision] * N[(z - x), $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 -3.6 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 5.4 \cdot 10^{+23}:\\
\;\;\;\;\frac{y}{t} \cdot \left(z - x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -3.6e62 or 5.3999999999999997e23 < t Initial program 84.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
lower-/.f6492.3
Applied rewrites92.3%
if -3.6e62 < t < 5.3999999999999997e23Initial program 97.4%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6479.9
Applied rewrites79.9%
Applied rewrites82.2%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -3.6e+62) t_1 (if (<= t 5.4e+23) (* y (/ (- z x) 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 <= -3.6e+62) {
tmp = t_1;
} else if (t <= 5.4e+23) {
tmp = y * ((z - x) / 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 <= -3.6e+62) tmp = t_1; elseif (t <= 5.4e+23) tmp = Float64(y * Float64(Float64(z - x) / 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, -3.6e+62], t$95$1, If[LessEqual[t, 5.4e+23], N[(y * N[(N[(z - x), $MachinePrecision] / 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 -3.6 \cdot 10^{+62}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 5.4 \cdot 10^{+23}:\\
\;\;\;\;y \cdot \frac{z - x}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -3.6e62 or 5.3999999999999997e23 < t Initial program 84.5%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
lower-/.f6492.3
Applied rewrites92.3%
if -3.6e62 < t < 5.3999999999999997e23Initial program 97.4%
Taylor expanded in y around inf
div-subN/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f6479.9
Applied rewrites79.9%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (fma (/ z t) y x))) (if (<= t -4.6e-136) t_1 (if (<= t 3.4e-101) (* (/ y t) z) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = fma((z / t), y, x);
double tmp;
if (t <= -4.6e-136) {
tmp = t_1;
} else if (t <= 3.4e-101) {
tmp = (y / t) * z;
} 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 <= -4.6e-136) tmp = t_1; elseif (t <= 3.4e-101) tmp = Float64(Float64(y / t) * z); 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, -4.6e-136], t$95$1, If[LessEqual[t, 3.4e-101], N[(N[(y / t), $MachinePrecision] * z), $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 -4.6 \cdot 10^{-136}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 3.4 \cdot 10^{-101}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -4.59999999999999997e-136 or 3.39999999999999989e-101 < t Initial program 90.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.8
Applied rewrites98.8%
Taylor expanded in z around inf
lower-/.f6479.7
Applied rewrites79.7%
if -4.59999999999999997e-136 < t < 3.39999999999999989e-101Initial program 97.5%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f6460.5
Applied rewrites60.5%
Applied rewrites73.4%
Final simplification77.7%
(FPCore (x y z t) :precision binary64 (let* ((t_1 (/ (* t x) t))) (if (<= t -4.3e+70) t_1 (if (<= t 3e+58) (* (/ y t) z) t_1))))
double code(double x, double y, double z, double t) {
double t_1 = (t * x) / t;
double tmp;
if (t <= -4.3e+70) {
tmp = t_1;
} else if (t <= 3e+58) {
tmp = (y / t) * z;
} 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 = (t * x) / t
if (t <= (-4.3d+70)) then
tmp = t_1
else if (t <= 3d+58) then
tmp = (y / t) * z
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 = (t * x) / t;
double tmp;
if (t <= -4.3e+70) {
tmp = t_1;
} else if (t <= 3e+58) {
tmp = (y / t) * z;
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t): t_1 = (t * x) / t tmp = 0 if t <= -4.3e+70: tmp = t_1 elif t <= 3e+58: tmp = (y / t) * z else: tmp = t_1 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(t * x) / t) tmp = 0.0 if (t <= -4.3e+70) tmp = t_1; elseif (t <= 3e+58) tmp = Float64(Float64(y / t) * z); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (t * x) / t; tmp = 0.0; if (t <= -4.3e+70) tmp = t_1; elseif (t <= 3e+58) tmp = (y / t) * z; else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(t * x), $MachinePrecision] / t), $MachinePrecision]}, If[LessEqual[t, -4.3e+70], t$95$1, If[LessEqual[t, 3e+58], N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \frac{t \cdot x}{t}\\
\mathbf{if}\;t \leq -4.3 \cdot 10^{+70}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t \leq 3 \cdot 10^{+58}:\\
\;\;\;\;\frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if t < -4.3000000000000001e70 or 3.0000000000000002e58 < t Initial program 83.2%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.9
Applied rewrites99.9%
Taylor expanded in z around inf
lower-/.f6491.7
Applied rewrites91.7%
Taylor expanded in t around 0
lower-/.f64N/A
+-commutativeN/A
lower-fma.f64N/A
lower--.f64N/A
*-commutativeN/A
lower-*.f6459.9
Applied rewrites59.9%
Taylor expanded in y around 0
Applied rewrites46.2%
if -4.3000000000000001e70 < t < 3.0000000000000002e58Initial program 97.6%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f6449.8
Applied rewrites49.8%
Applied rewrites56.1%
Final simplification52.6%
(FPCore (x y z t) :precision binary64 (* (/ y t) z))
double code(double x, double y, double z, double t) {
return (y / t) * z;
}
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 = (y / t) * z
end function
public static double code(double x, double y, double z, double t) {
return (y / t) * z;
}
def code(x, y, z, t): return (y / t) * z
function code(x, y, z, t) return Float64(Float64(y / t) * z) end
function tmp = code(x, y, z, t) tmp = (y / t) * z; end
code[x_, y_, z_, t_] := N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{t} \cdot z
\end{array}
Initial program 92.4%
Taylor expanded in x around 0
lower-/.f64N/A
lower-*.f6437.1
Applied rewrites37.1%
Applied rewrites42.2%
Final simplification42.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 2024219
(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)))