
(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 6 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 (if (<= z -5e-147) (+ x (/ (* y (- z x)) t)) (+ x (* (- z x) (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5e-147) {
tmp = x + ((y * (z - x)) / t);
} else {
tmp = x + ((z - x) * (y / t));
}
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 (z <= (-5d-147)) then
tmp = x + ((y * (z - x)) / t)
else
tmp = x + ((z - x) * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -5e-147) {
tmp = x + ((y * (z - x)) / t);
} else {
tmp = x + ((z - x) * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -5e-147: tmp = x + ((y * (z - x)) / t) else: tmp = x + ((z - x) * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -5e-147) tmp = Float64(x + Float64(Float64(y * Float64(z - x)) / t)); else tmp = Float64(x + Float64(Float64(z - x) * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -5e-147) tmp = x + ((y * (z - x)) / t); else tmp = x + ((z - x) * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -5e-147], N[(x + N[(N[(y * N[(z - x), $MachinePrecision]), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-147}:\\
\;\;\;\;x + \frac{y \cdot \left(z - x\right)}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \left(z - x\right) \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -5.00000000000000013e-147Initial program 99.0%
if -5.00000000000000013e-147 < z Initial program 93.3%
associate-*l/98.6%
Simplified98.6%
Final simplification98.8%
(FPCore (x y z t) :precision binary64 (if (<= z -6.8e-37) (+ x (/ (* z y) t)) (if (<= z 4e-69) (- x (* x (/ y t))) (+ x (* z (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.8e-37) {
tmp = x + ((z * y) / t);
} else if (z <= 4e-69) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z * (y / t));
}
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 (z <= (-6.8d-37)) then
tmp = x + ((z * y) / t)
else if (z <= 4d-69) then
tmp = x - (x * (y / t))
else
tmp = x + (z * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -6.8e-37) {
tmp = x + ((z * y) / t);
} else if (z <= 4e-69) {
tmp = x - (x * (y / t));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -6.8e-37: tmp = x + ((z * y) / t) elif z <= 4e-69: tmp = x - (x * (y / t)) else: tmp = x + (z * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -6.8e-37) tmp = Float64(x + Float64(Float64(z * y) / t)); elseif (z <= 4e-69) tmp = Float64(x - Float64(x * Float64(y / t))); else tmp = Float64(x + Float64(z * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -6.8e-37) tmp = x + ((z * y) / t); elseif (z <= 4e-69) tmp = x - (x * (y / t)); else tmp = x + (z * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -6.8e-37], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 4e-69], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -6.8 \cdot 10^{-37}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\mathbf{elif}\;z \leq 4 \cdot 10^{-69}:\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -6.80000000000000037e-37Initial program 98.8%
associate-*l/95.1%
Simplified95.1%
Taylor expanded in z around inf 88.7%
if -6.80000000000000037e-37 < z < 3.9999999999999999e-69Initial program 96.3%
associate-/l*94.0%
Simplified94.0%
Taylor expanded in z around 0 85.1%
associate-*r/85.1%
neg-mul-185.1%
Simplified85.1%
clear-num85.1%
associate-/r/84.0%
clear-num84.0%
add-sqr-sqrt34.5%
sqrt-unprod58.2%
sqr-neg58.2%
sqrt-unprod29.1%
add-sqr-sqrt44.6%
Applied egg-rr44.6%
frac-2neg44.6%
distribute-frac-neg44.6%
add-sqr-sqrt19.7%
sqrt-unprod50.1%
sqr-neg50.1%
sqrt-unprod41.9%
add-sqr-sqrt84.0%
frac-2neg84.0%
cancel-sign-sub-inv84.0%
associate-/r/88.4%
div-inv88.4%
clear-num88.4%
Applied egg-rr88.4%
if 3.9999999999999999e-69 < z Initial program 90.0%
associate-*l/98.3%
Simplified98.3%
Taylor expanded in z around inf 86.6%
associate-*l/93.2%
*-commutative93.2%
Simplified93.2%
Final simplification89.6%
(FPCore (x y z t) :precision binary64 (if (<= z -9.2e-39) (+ x (/ (* z y) t)) (if (<= z 1.4e-64) (- x (/ x (/ t y))) (+ x (* z (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.2e-39) {
tmp = x + ((z * y) / t);
} else if (z <= 1.4e-64) {
tmp = x - (x / (t / y));
} else {
tmp = x + (z * (y / t));
}
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 (z <= (-9.2d-39)) then
tmp = x + ((z * y) / t)
else if (z <= 1.4d-64) then
tmp = x - (x / (t / y))
else
tmp = x + (z * (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (z <= -9.2e-39) {
tmp = x + ((z * y) / t);
} else if (z <= 1.4e-64) {
tmp = x - (x / (t / y));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if z <= -9.2e-39: tmp = x + ((z * y) / t) elif z <= 1.4e-64: tmp = x - (x / (t / y)) else: tmp = x + (z * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (z <= -9.2e-39) tmp = Float64(x + Float64(Float64(z * y) / t)); elseif (z <= 1.4e-64) tmp = Float64(x - Float64(x / Float64(t / y))); else tmp = Float64(x + Float64(z * Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (z <= -9.2e-39) tmp = x + ((z * y) / t); elseif (z <= 1.4e-64) tmp = x - (x / (t / y)); else tmp = x + (z * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[z, -9.2e-39], N[(x + N[(N[(z * y), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[z, 1.4e-64], N[(x - N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -9.2 \cdot 10^{-39}:\\
\;\;\;\;x + \frac{z \cdot y}{t}\\
\mathbf{elif}\;z \leq 1.4 \cdot 10^{-64}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if z < -9.20000000000000033e-39Initial program 98.8%
associate-*l/95.1%
Simplified95.1%
Taylor expanded in z around inf 88.7%
if -9.20000000000000033e-39 < z < 1.40000000000000002e-64Initial program 96.3%
associate-/l*94.0%
Simplified94.0%
Taylor expanded in z around 0 85.1%
associate-*r/85.1%
neg-mul-185.1%
Simplified85.1%
clear-num85.1%
associate-/r/84.0%
clear-num84.0%
add-sqr-sqrt34.5%
sqrt-unprod58.2%
sqr-neg58.2%
sqrt-unprod29.1%
add-sqr-sqrt44.6%
Applied egg-rr44.6%
frac-2neg44.6%
distribute-frac-neg44.6%
add-sqr-sqrt19.7%
sqrt-unprod50.1%
sqr-neg50.1%
sqrt-unprod41.9%
add-sqr-sqrt84.0%
frac-2neg84.0%
cancel-sign-sub-inv84.0%
associate-/r/88.4%
div-inv88.4%
clear-num88.4%
Applied egg-rr88.4%
clear-num88.4%
div-inv88.4%
Applied egg-rr88.4%
if 1.40000000000000002e-64 < z Initial program 90.0%
associate-*l/98.3%
Simplified98.3%
Taylor expanded in z around inf 86.6%
associate-*l/93.2%
*-commutative93.2%
Simplified93.2%
Final simplification89.6%
(FPCore (x y z t) :precision binary64 (+ x (* (- z x) (/ y t))))
double code(double x, double y, double z, double t) {
return x + ((z - x) * (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 + ((z - x) * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) * (y / t));
}
def code(x, y, z, t): return x + ((z - x) * (y / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(z - x\right) \cdot \frac{y}{t}
\end{array}
Initial program 95.7%
associate-*l/97.1%
Simplified97.1%
Final simplification97.1%
(FPCore (x y z t) :precision binary64 (+ x (* z (/ y t))))
double code(double x, double y, double z, double t) {
return x + (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 + (z * (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x + (z * (y / t));
}
def code(x, y, z, t): return x + (z * (y / t))
function code(x, y, z, t) return Float64(x + Float64(z * Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x + (z * (y / t)); end
code[x_, y_, z_, t_] := N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + z \cdot \frac{y}{t}
\end{array}
Initial program 95.7%
associate-*l/97.1%
Simplified97.1%
Taylor expanded in z around inf 74.5%
associate-*l/76.5%
*-commutative76.5%
Simplified76.5%
Final simplification76.5%
(FPCore (x y z t) :precision binary64 x)
double code(double x, double y, double z, double t) {
return x;
}
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
end function
public static double code(double x, double y, double z, double t) {
return x;
}
def code(x, y, z, t): return x
function code(x, y, z, t) return x end
function tmp = code(x, y, z, t) tmp = x; end
code[x_, y_, z_, t_] := x
\begin{array}{l}
\\
x
\end{array}
Initial program 95.7%
associate-/l*93.3%
Simplified93.3%
Taylor expanded in z around 0 61.5%
associate-*r/61.5%
neg-mul-161.5%
Simplified61.5%
clear-num61.4%
associate-/r/61.0%
clear-num61.0%
add-sqr-sqrt31.2%
sqrt-unprod47.6%
sqr-neg47.6%
sqrt-unprod17.2%
add-sqr-sqrt37.9%
Applied egg-rr37.9%
Taylor expanded in t around inf 37.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 2023310
(FPCore (x y z t)
:name "Optimisation.CirclePacking:place from circle-packing-0.1.0.4, D"
:precision binary64
:herbie-target
(- x (+ (* x (/ y t)) (* (- z) (/ y t))))
(+ x (/ (* y (- z x)) t)))