
(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 8 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 (+ x (/ (- z x) (/ t y))))
double code(double x, double y, double z, double t) {
return x + ((z - x) / (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 = x + ((z - x) / (t / y))
end function
public static double code(double x, double y, double z, double t) {
return x + ((z - x) / (t / y));
}
def code(x, y, z, t): return x + ((z - x) / (t / y))
function code(x, y, z, t) return Float64(x + Float64(Float64(z - x) / Float64(t / y))) end
function tmp = code(x, y, z, t) tmp = x + ((z - x) / (t / y)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(z - x), $MachinePrecision] / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{z - x}{\frac{t}{y}}
\end{array}
Initial program 92.2%
associate-*l/97.3%
Simplified97.3%
*-commutative97.3%
clear-num97.3%
un-div-inv97.3%
Applied egg-rr97.3%
Final simplification97.3%
(FPCore (x y z t) :precision binary64 (if (or (<= x -5.3e+24) (not (<= x 1.15e+71))) (* x (- 1.0 (/ y t))) (+ x (* z (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -5.3e+24) || !(x <= 1.15e+71)) {
tmp = x * (1.0 - (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 ((x <= (-5.3d+24)) .or. (.not. (x <= 1.15d+71))) then
tmp = x * (1.0d0 - (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 ((x <= -5.3e+24) || !(x <= 1.15e+71)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -5.3e+24) or not (x <= 1.15e+71): tmp = x * (1.0 - (y / t)) else: tmp = x + (z * (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -5.3e+24) || !(x <= 1.15e+71)) tmp = Float64(x * Float64(1.0 - 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 ((x <= -5.3e+24) || ~((x <= 1.15e+71))) tmp = x * (1.0 - (y / t)); else tmp = x + (z * (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -5.3e+24], N[Not[LessEqual[x, 1.15e+71]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -5.3 \cdot 10^{+24} \lor \neg \left(x \leq 1.15 \cdot 10^{+71}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -5.2999999999999999e24 or 1.1500000000000001e71 < x Initial program 87.9%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 93.3%
mul-1-neg93.3%
unsub-neg93.3%
Simplified93.3%
if -5.2999999999999999e24 < x < 1.1500000000000001e71Initial program 95.2%
associate-*l/95.3%
Simplified95.3%
Taylor expanded in z around inf 80.6%
associate-*l/84.1%
*-commutative84.1%
Simplified84.1%
Final simplification88.0%
(FPCore (x y z t) :precision binary64 (if (or (<= x -2.25e+26) (not (<= x 1.2e+71))) (* x (- 1.0 (/ y t))) (+ x (/ z (/ t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.25e+26) || !(x <= 1.2e+71)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (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.25d+26)) .or. (.not. (x <= 1.2d+71))) then
tmp = x * (1.0d0 - (y / t))
else
tmp = x + (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.25e+26) || !(x <= 1.2e+71)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z / (t / y));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -2.25e+26) or not (x <= 1.2e+71): tmp = x * (1.0 - (y / t)) else: tmp = x + (z / (t / y)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -2.25e+26) || !(x <= 1.2e+71)) tmp = Float64(x * Float64(1.0 - Float64(y / t))); else tmp = Float64(x + Float64(z / Float64(t / y))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -2.25e+26) || ~((x <= 1.2e+71))) tmp = x * (1.0 - (y / t)); else tmp = x + (z / (t / y)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -2.25e+26], N[Not[LessEqual[x, 1.2e+71]], $MachinePrecision]], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -2.25 \cdot 10^{+26} \lor \neg \left(x \leq 1.2 \cdot 10^{+71}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\end{array}
\end{array}
if x < -2.24999999999999989e26 or 1.1999999999999999e71 < x Initial program 87.9%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 93.3%
mul-1-neg93.3%
unsub-neg93.3%
Simplified93.3%
if -2.24999999999999989e26 < x < 1.1999999999999999e71Initial program 95.2%
associate-*l/95.3%
Simplified95.3%
Taylor expanded in z around inf 80.6%
associate-*l/84.1%
*-commutative84.1%
Simplified84.1%
clear-num84.1%
div-inv84.2%
Applied egg-rr84.2%
Final simplification88.0%
(FPCore (x y z t) :precision binary64 (if (<= x -1.1e+26) (- x (/ x (/ t y))) (if (<= x 4.2e+72) (+ x (/ z (/ t y))) (* x (- 1.0 (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.1e+26) {
tmp = x - (x / (t / y));
} else if (x <= 4.2e+72) {
tmp = x + (z / (t / y));
} else {
tmp = x * (1.0 - (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 (x <= (-1.1d+26)) then
tmp = x - (x / (t / y))
else if (x <= 4.2d+72) then
tmp = x + (z / (t / y))
else
tmp = x * (1.0d0 - (y / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= -1.1e+26) {
tmp = x - (x / (t / y));
} else if (x <= 4.2e+72) {
tmp = x + (z / (t / y));
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -1.1e+26: tmp = x - (x / (t / y)) elif x <= 4.2e+72: tmp = x + (z / (t / y)) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -1.1e+26) tmp = Float64(x - Float64(x / Float64(t / y))); elseif (x <= 4.2e+72) tmp = Float64(x + Float64(z / Float64(t / y))); else tmp = Float64(x * Float64(1.0 - Float64(y / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= -1.1e+26) tmp = x - (x / (t / y)); elseif (x <= 4.2e+72) tmp = x + (z / (t / y)); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -1.1e+26], N[(x - N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 4.2e+72], N[(x + N[(z / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.1 \cdot 10^{+26}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\
\mathbf{elif}\;x \leq 4.2 \cdot 10^{+72}:\\
\;\;\;\;x + \frac{z}{\frac{t}{y}}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if x < -1.10000000000000004e26Initial program 84.3%
Taylor expanded in z around 0 77.2%
mul-1-neg77.2%
distribute-lft-neg-out77.2%
*-commutative77.2%
Simplified77.2%
div-inv77.2%
add-sqr-sqrt77.1%
sqrt-unprod56.6%
sqr-neg56.6%
sqrt-unprod0.0%
add-sqr-sqrt35.2%
remove-double-neg35.2%
distribute-rgt-neg-out35.2%
cancel-sign-sub-inv35.2%
*-commutative35.2%
associate-*l*42.0%
add-sqr-sqrt42.0%
sqrt-unprod15.8%
sqr-neg15.8%
sqrt-unprod0.0%
add-sqr-sqrt91.2%
div-inv91.2%
clear-num91.2%
div-inv91.2%
Applied egg-rr91.2%
if -1.10000000000000004e26 < x < 4.2000000000000003e72Initial program 95.2%
associate-*l/95.3%
Simplified95.3%
Taylor expanded in z around inf 80.6%
associate-*l/84.1%
*-commutative84.1%
Simplified84.1%
clear-num84.1%
div-inv84.2%
Applied egg-rr84.2%
if 4.2000000000000003e72 < x Initial program 92.3%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 95.9%
mul-1-neg95.9%
unsub-neg95.9%
Simplified95.9%
Final simplification88.1%
(FPCore (x y z t) :precision binary64 (if (or (<= y -3.15e-27) (not (<= y 7.6e+83))) (* (- y) (/ x t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.15e-27) || !(y <= 7.6e+83)) {
tmp = -y * (x / t);
} else {
tmp = x;
}
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.15d-27)) .or. (.not. (y <= 7.6d+83))) then
tmp = -y * (x / t)
else
tmp = x
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -3.15e-27) || !(y <= 7.6e+83)) {
tmp = -y * (x / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -3.15e-27) or not (y <= 7.6e+83): tmp = -y * (x / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -3.15e-27) || !(y <= 7.6e+83)) tmp = Float64(Float64(-y) * Float64(x / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -3.15e-27) || ~((y <= 7.6e+83))) tmp = -y * (x / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -3.15e-27], N[Not[LessEqual[y, 7.6e+83]], $MachinePrecision]], N[((-y) * N[(x / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -3.15 \cdot 10^{-27} \lor \neg \left(y \leq 7.6 \cdot 10^{+83}\right):\\
\;\;\;\;\left(-y\right) \cdot \frac{x}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -3.15000000000000005e-27 or 7.6000000000000004e83 < y Initial program 87.2%
Taylor expanded in z around 0 54.5%
mul-1-neg54.5%
distribute-lft-neg-out54.5%
*-commutative54.5%
Simplified54.5%
div-inv54.4%
add-sqr-sqrt28.2%
sqrt-unprod30.0%
sqr-neg30.0%
sqrt-unprod5.8%
add-sqr-sqrt10.0%
remove-double-neg10.0%
distribute-rgt-neg-out10.0%
cancel-sign-sub-inv10.0%
*-commutative10.0%
associate-*l*17.3%
add-sqr-sqrt8.2%
sqrt-unprod27.5%
sqr-neg27.5%
sqrt-unprod27.8%
add-sqr-sqrt61.2%
div-inv61.1%
clear-num61.2%
div-inv61.2%
Applied egg-rr61.2%
associate-/r/63.2%
Applied egg-rr63.2%
Taylor expanded in t around 0 48.0%
mul-1-neg48.0%
associate-*l/51.4%
distribute-rgt-neg-out51.4%
*-commutative51.4%
Simplified51.4%
if -3.15000000000000005e-27 < y < 7.6000000000000004e83Initial program 96.9%
associate-*l/98.4%
Simplified98.4%
Taylor expanded in y around 0 57.2%
Final simplification54.4%
(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 92.2%
associate-*l/97.3%
Simplified97.3%
Final simplification97.3%
(FPCore (x y z t) :precision binary64 (* x (- 1.0 (/ y t))))
double code(double x, double y, double z, double t) {
return x * (1.0 - (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 * (1.0d0 - (y / t))
end function
public static double code(double x, double y, double z, double t) {
return x * (1.0 - (y / t));
}
def code(x, y, z, t): return x * (1.0 - (y / t))
function code(x, y, z, t) return Float64(x * Float64(1.0 - Float64(y / t))) end
function tmp = code(x, y, z, t) tmp = x * (1.0 - (y / t)); end
code[x_, y_, z_, t_] := N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x \cdot \left(1 - \frac{y}{t}\right)
\end{array}
Initial program 92.2%
associate-*l/97.3%
Simplified97.3%
Taylor expanded in x around inf 65.3%
mul-1-neg65.3%
unsub-neg65.3%
Simplified65.3%
Final simplification65.3%
(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 92.2%
associate-*l/97.3%
Simplified97.3%
Taylor expanded in y around 0 35.8%
Final simplification35.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 2024018
(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)))