
(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 (+ x (* (/ y t) (- z x))))
double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - 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 + ((y / t) * (z - x))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y / t) * (z - x));
}
def code(x, y, z, t): return x + ((y / t) * (z - x))
function code(x, y, z, t) return Float64(x + Float64(Float64(y / t) * Float64(z - x))) end
function tmp = code(x, y, z, t) tmp = x + ((y / t) * (z - x)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y / t), $MachinePrecision] * N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{t} \cdot \left(z - x\right)
\end{array}
Initial program 93.9%
associate-*l/98.1%
Simplified98.1%
Final simplification98.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.95e-19) (not (<= x 18000000000.0))) (- x (* x (/ y t))) (+ x (* (/ y t) z))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.95e-19) || !(x <= 18000000000.0)) {
tmp = x - (x * (y / t));
} else {
tmp = x + ((y / t) * z);
}
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.95d-19)) .or. (.not. (x <= 18000000000.0d0))) then
tmp = x - (x * (y / t))
else
tmp = x + ((y / t) * z)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.95e-19) || !(x <= 18000000000.0)) {
tmp = x - (x * (y / t));
} else {
tmp = x + ((y / t) * z);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.95e-19) or not (x <= 18000000000.0): tmp = x - (x * (y / t)) else: tmp = x + ((y / t) * z) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.95e-19) || !(x <= 18000000000.0)) tmp = Float64(x - Float64(x * Float64(y / t))); else tmp = Float64(x + Float64(Float64(y / t) * z)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.95e-19) || ~((x <= 18000000000.0))) tmp = x - (x * (y / t)); else tmp = x + ((y / t) * z); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.95e-19], N[Not[LessEqual[x, 18000000000.0]], $MachinePrecision]], N[(x - N[(x * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.95 \cdot 10^{-19} \lor \neg \left(x \leq 18000000000\right):\\
\;\;\;\;x - x \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\end{array}
\end{array}
if x < -1.94999999999999998e-19 or 1.8e10 < x Initial program 93.5%
associate-/l*93.5%
Simplified93.5%
Taylor expanded in z around 0 83.4%
associate-*r/83.4%
neg-mul-183.4%
Simplified83.4%
frac-2neg83.4%
div-inv83.4%
distribute-frac-neg83.4%
remove-double-neg83.4%
clear-num83.4%
add-sqr-sqrt37.5%
sqrt-unprod56.6%
sqr-neg56.6%
sqrt-unprod21.9%
add-sqr-sqrt42.1%
cancel-sign-sub-inv42.1%
clear-num42.1%
div-inv42.1%
associate-/r/45.8%
*-commutative45.8%
add-sqr-sqrt23.3%
sqrt-unprod58.7%
sqr-neg58.7%
sqrt-unprod41.8%
add-sqr-sqrt89.1%
Applied egg-rr89.1%
if -1.94999999999999998e-19 < x < 1.8e10Initial program 94.4%
associate-*l/96.2%
Simplified96.2%
Taylor expanded in z around inf 83.5%
associate-*l/85.3%
*-commutative85.3%
Simplified85.3%
Final simplification87.3%
(FPCore (x y z t) :precision binary64 (if (<= t -1.9e-24) x (if (<= t 5.4e+23) (* y (/ (- x) t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.9e-24) {
tmp = x;
} else if (t <= 5.4e+23) {
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 (t <= (-1.9d-24)) then
tmp = x
else if (t <= 5.4d+23) 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 (t <= -1.9e-24) {
tmp = x;
} else if (t <= 5.4e+23) {
tmp = y * (-x / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -1.9e-24: tmp = x elif t <= 5.4e+23: tmp = y * (-x / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -1.9e-24) tmp = x; elseif (t <= 5.4e+23) tmp = Float64(y * Float64(Float64(-x) / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -1.9e-24) tmp = x; elseif (t <= 5.4e+23) tmp = y * (-x / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -1.9e-24], x, If[LessEqual[t, 5.4e+23], N[(y * N[((-x) / t), $MachinePrecision]), $MachinePrecision], x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.9 \cdot 10^{-24}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.4 \cdot 10^{+23}:\\
\;\;\;\;y \cdot \frac{-x}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -1.90000000000000013e-24 or 5.3999999999999997e23 < t Initial program 89.5%
associate-*l/98.6%
Simplified98.6%
Taylor expanded in z around inf 81.2%
associate-*l/85.5%
*-commutative85.5%
Simplified85.5%
Taylor expanded in x around inf 56.2%
if -1.90000000000000013e-24 < t < 5.3999999999999997e23Initial program 99.0%
associate-/l*91.1%
Simplified91.1%
Taylor expanded in z around 0 57.0%
associate-*r/57.0%
neg-mul-157.0%
Simplified57.0%
frac-2neg57.0%
div-inv57.1%
distribute-frac-neg57.1%
remove-double-neg57.1%
clear-num57.1%
add-sqr-sqrt26.0%
sqrt-unprod34.3%
sqr-neg34.3%
sqrt-unprod7.5%
add-sqr-sqrt15.2%
cancel-sign-sub-inv15.2%
clear-num15.2%
div-inv15.2%
associate-/r/25.6%
*-commutative25.6%
add-sqr-sqrt13.0%
sqrt-unprod38.9%
sqr-neg38.9%
sqrt-unprod30.7%
add-sqr-sqrt64.2%
Applied egg-rr64.2%
Taylor expanded in x around 0 62.6%
*-commutative62.6%
associate-*r/57.1%
Simplified57.1%
Taylor expanded in y around inf 48.8%
associate-*r/48.8%
*-commutative48.8%
neg-mul-148.8%
distribute-rgt-neg-out48.8%
associate-*r/46.8%
Simplified46.8%
Final simplification51.8%
(FPCore (x y z t) :precision binary64 (if (<= t -1.46e-21) x (if (<= t 5.4e+23) (- (/ (* x y) t)) x)))
double code(double x, double y, double z, double t) {
double tmp;
if (t <= -1.46e-21) {
tmp = x;
} else if (t <= 5.4e+23) {
tmp = -((x * y) / 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 (t <= (-1.46d-21)) then
tmp = x
else if (t <= 5.4d+23) then
tmp = -((x * y) / 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 (t <= -1.46e-21) {
tmp = x;
} else if (t <= 5.4e+23) {
tmp = -((x * y) / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if t <= -1.46e-21: tmp = x elif t <= 5.4e+23: tmp = -((x * y) / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if (t <= -1.46e-21) tmp = x; elseif (t <= 5.4e+23) tmp = Float64(-Float64(Float64(x * y) / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (t <= -1.46e-21) tmp = x; elseif (t <= 5.4e+23) tmp = -((x * y) / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[t, -1.46e-21], x, If[LessEqual[t, 5.4e+23], (-N[(N[(x * y), $MachinePrecision] / t), $MachinePrecision]), x]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq -1.46 \cdot 10^{-21}:\\
\;\;\;\;x\\
\mathbf{elif}\;t \leq 5.4 \cdot 10^{+23}:\\
\;\;\;\;-\frac{x \cdot y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if t < -1.46000000000000006e-21 or 5.3999999999999997e23 < t Initial program 89.5%
associate-*l/98.6%
Simplified98.6%
Taylor expanded in z around inf 81.2%
associate-*l/85.5%
*-commutative85.5%
Simplified85.5%
Taylor expanded in x around inf 56.2%
if -1.46000000000000006e-21 < t < 5.3999999999999997e23Initial program 99.0%
associate-/l*91.1%
Simplified91.1%
Taylor expanded in z around 0 57.0%
associate-*r/57.0%
neg-mul-157.0%
Simplified57.0%
frac-2neg57.0%
div-inv57.1%
distribute-frac-neg57.1%
remove-double-neg57.1%
clear-num57.1%
add-sqr-sqrt26.0%
sqrt-unprod34.3%
sqr-neg34.3%
sqrt-unprod7.5%
add-sqr-sqrt15.2%
cancel-sign-sub-inv15.2%
clear-num15.2%
div-inv15.2%
associate-/r/25.6%
*-commutative25.6%
add-sqr-sqrt13.0%
sqrt-unprod38.9%
sqr-neg38.9%
sqrt-unprod30.7%
add-sqr-sqrt64.2%
Applied egg-rr64.2%
Taylor expanded in x around 0 62.6%
*-commutative62.6%
associate-*r/57.1%
Simplified57.1%
Taylor expanded in y around inf 48.8%
Final simplification52.8%
(FPCore (x y z t) :precision binary64 (if (<= x 2.3e+247) (+ x (* (/ y t) z)) (* y (/ (- x) t))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2.3e+247) {
tmp = x + ((y / t) * z);
} else {
tmp = y * (-x / 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 <= 2.3d+247) then
tmp = x + ((y / t) * z)
else
tmp = y * (-x / t)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (x <= 2.3e+247) {
tmp = x + ((y / t) * z);
} else {
tmp = y * (-x / t);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= 2.3e+247: tmp = x + ((y / t) * z) else: tmp = y * (-x / t) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= 2.3e+247) tmp = Float64(x + Float64(Float64(y / t) * z)); else tmp = Float64(y * Float64(Float64(-x) / t)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (x <= 2.3e+247) tmp = x + ((y / t) * z); else tmp = y * (-x / t); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, 2.3e+247], N[(x + N[(N[(y / t), $MachinePrecision] * z), $MachinePrecision]), $MachinePrecision], N[(y * N[((-x) / t), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq 2.3 \cdot 10^{+247}:\\
\;\;\;\;x + \frac{y}{t} \cdot z\\
\mathbf{else}:\\
\;\;\;\;y \cdot \frac{-x}{t}\\
\end{array}
\end{array}
if x < 2.29999999999999991e247Initial program 94.0%
associate-*l/98.0%
Simplified98.0%
Taylor expanded in z around inf 72.4%
associate-*l/75.5%
*-commutative75.5%
Simplified75.5%
if 2.29999999999999991e247 < x Initial program 93.4%
associate-/l*100.0%
Simplified100.0%
Taylor expanded in z around 0 100.0%
associate-*r/100.0%
neg-mul-1100.0%
Simplified100.0%
frac-2neg100.0%
div-inv100.0%
distribute-frac-neg100.0%
remove-double-neg100.0%
clear-num100.0%
add-sqr-sqrt46.2%
sqrt-unprod53.9%
sqr-neg53.9%
sqrt-unprod15.4%
add-sqr-sqrt30.8%
cancel-sign-sub-inv30.8%
clear-num30.8%
div-inv30.8%
associate-/r/30.8%
*-commutative30.8%
add-sqr-sqrt15.4%
sqrt-unprod53.9%
sqr-neg53.9%
sqrt-unprod46.2%
add-sqr-sqrt100.0%
Applied egg-rr100.0%
Taylor expanded in x around 0 93.4%
*-commutative93.4%
associate-*r/100.0%
Simplified100.0%
Taylor expanded in y around inf 63.5%
associate-*r/63.5%
*-commutative63.5%
neg-mul-163.5%
distribute-rgt-neg-out63.5%
associate-*r/67.7%
Simplified67.7%
Final simplification75.1%
(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 93.9%
associate-*l/98.1%
Simplified98.1%
Taylor expanded in z around inf 70.3%
associate-*l/73.4%
*-commutative73.4%
Simplified73.4%
Taylor expanded in x around inf 37.6%
Final simplification37.6%
(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 2023298
(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)))