
(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 (/ 1.0 (/ (/ t y) (- z x)))))
double code(double x, double y, double z, double t) {
return x + (1.0 / ((t / y) / (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 + (1.0d0 / ((t / y) / (z - x)))
end function
public static double code(double x, double y, double z, double t) {
return x + (1.0 / ((t / y) / (z - x)));
}
def code(x, y, z, t): return x + (1.0 / ((t / y) / (z - x)))
function code(x, y, z, t) return Float64(x + Float64(1.0 / Float64(Float64(t / y) / Float64(z - x)))) end
function tmp = code(x, y, z, t) tmp = x + (1.0 / ((t / y) / (z - x))); end
code[x_, y_, z_, t_] := N[(x + N[(1.0 / N[(N[(t / y), $MachinePrecision] / N[(z - x), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{1}{\frac{\frac{t}{y}}{z - x}}
\end{array}
Initial program 93.0%
associate-*l/99.0%
Simplified99.0%
associate-*l/93.0%
clear-num93.0%
associate-/r*99.2%
Applied egg-rr99.2%
Final simplification99.2%
(FPCore (x y z t) :precision binary64 (if (or (<= x -2.32e+108) (not (<= x 4.2e+49))) (* x (- 1.0 (/ y t))) (+ x (* z (/ y t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -2.32e+108) || !(x <= 4.2e+49)) {
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 <= (-2.32d+108)) .or. (.not. (x <= 4.2d+49))) 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 <= -2.32e+108) || !(x <= 4.2e+49)) {
tmp = x * (1.0 - (y / t));
} else {
tmp = x + (z * (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -2.32e+108) or not (x <= 4.2e+49): 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 <= -2.32e+108) || !(x <= 4.2e+49)) 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 <= -2.32e+108) || ~((x <= 4.2e+49))) 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, -2.32e+108], N[Not[LessEqual[x, 4.2e+49]], $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 -2.32 \cdot 10^{+108} \lor \neg \left(x \leq 4.2 \cdot 10^{+49}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\end{array}
\end{array}
if x < -2.3199999999999999e108 or 4.20000000000000022e49 < x Initial program 90.9%
associate-*l/99.9%
Simplified99.9%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
if -2.3199999999999999e108 < x < 4.20000000000000022e49Initial program 94.2%
associate-*l/98.5%
Simplified98.5%
Taylor expanded in z around inf 86.2%
associate-*l/91.1%
*-commutative91.1%
Simplified91.1%
Final simplification93.0%
(FPCore (x y z t) :precision binary64 (if (<= x -3.35e+108) (- x (/ x (/ t y))) (if (<= x 7.8e+52) (+ x (* z (/ y t))) (* x (- 1.0 (/ y t))))))
double code(double x, double y, double z, double t) {
double tmp;
if (x <= -3.35e+108) {
tmp = x - (x / (t / y));
} else if (x <= 7.8e+52) {
tmp = x + (z * (y / t));
} 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 <= (-3.35d+108)) then
tmp = x - (x / (t / y))
else if (x <= 7.8d+52) then
tmp = x + (z * (y / t))
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 <= -3.35e+108) {
tmp = x - (x / (t / y));
} else if (x <= 7.8e+52) {
tmp = x + (z * (y / t));
} else {
tmp = x * (1.0 - (y / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if x <= -3.35e+108: tmp = x - (x / (t / y)) elif x <= 7.8e+52: tmp = x + (z * (y / t)) else: tmp = x * (1.0 - (y / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if (x <= -3.35e+108) tmp = Float64(x - Float64(x / Float64(t / y))); elseif (x <= 7.8e+52) tmp = Float64(x + Float64(z * Float64(y / t))); 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 <= -3.35e+108) tmp = x - (x / (t / y)); elseif (x <= 7.8e+52) tmp = x + (z * (y / t)); else tmp = x * (1.0 - (y / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[x, -3.35e+108], N[(x - N[(x / N[(t / y), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], If[LessEqual[x, 7.8e+52], N[(x + N[(z * N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x * N[(1.0 - N[(y / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -3.35 \cdot 10^{+108}:\\
\;\;\;\;x - \frac{x}{\frac{t}{y}}\\
\mathbf{elif}\;x \leq 7.8 \cdot 10^{+52}:\\
\;\;\;\;x + z \cdot \frac{y}{t}\\
\mathbf{else}:\\
\;\;\;\;x \cdot \left(1 - \frac{y}{t}\right)\\
\end{array}
\end{array}
if x < -3.35000000000000007e108Initial program 88.5%
associate-*l/99.8%
Simplified99.8%
Taylor expanded in z around 0 87.6%
mul-1-neg87.6%
associate-/l*96.6%
distribute-neg-frac96.6%
Simplified96.6%
if -3.35000000000000007e108 < x < 7.7999999999999999e52Initial program 94.2%
associate-*l/98.5%
Simplified98.5%
Taylor expanded in z around inf 86.2%
associate-*l/91.1%
*-commutative91.1%
Simplified91.1%
if 7.7999999999999999e52 < x Initial program 92.7%
associate-*l/100.0%
Simplified100.0%
Taylor expanded in x around inf 96.5%
mul-1-neg96.5%
unsub-neg96.5%
Simplified96.5%
Final simplification93.0%
(FPCore (x y z t) :precision binary64 (if (or (<= y -4.4e+37) (not (<= y 1.85e+158))) (* x (/ (- y) t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if ((y <= -4.4e+37) || !(y <= 1.85e+158)) {
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 ((y <= (-4.4d+37)) .or. (.not. (y <= 1.85d+158))) 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 ((y <= -4.4e+37) || !(y <= 1.85e+158)) {
tmp = x * (-y / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (y <= -4.4e+37) or not (y <= 1.85e+158): tmp = x * (-y / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((y <= -4.4e+37) || !(y <= 1.85e+158)) tmp = Float64(x * Float64(Float64(-y) / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((y <= -4.4e+37) || ~((y <= 1.85e+158))) tmp = x * (-y / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[y, -4.4e+37], N[Not[LessEqual[y, 1.85e+158]], $MachinePrecision]], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -4.4 \cdot 10^{+37} \lor \neg \left(y \leq 1.85 \cdot 10^{+158}\right):\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if y < -4.4000000000000001e37 or 1.85000000000000005e158 < y Initial program 85.3%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around 0 52.7%
associate-*r/52.7%
neg-mul-152.7%
Simplified52.7%
frac-2neg52.7%
div-inv52.7%
distribute-frac-neg52.7%
remove-double-neg52.7%
clear-num52.8%
add-sqr-sqrt30.2%
sqrt-unprod35.5%
sqr-neg35.5%
sqrt-unprod6.5%
add-sqr-sqrt13.9%
cancel-sign-sub-inv13.9%
add-sqr-sqrt6.5%
sqrt-unprod35.5%
sqr-neg35.5%
sqrt-unprod30.2%
add-sqr-sqrt52.8%
Applied egg-rr52.8%
Taylor expanded in y around inf 41.9%
mul-1-neg41.9%
*-commutative41.9%
associate-/l*47.0%
associate-/r/49.3%
Simplified49.3%
if -4.4000000000000001e37 < y < 1.85000000000000005e158Initial program 97.1%
associate-*l/99.6%
Simplified99.6%
Taylor expanded in y around 0 57.6%
Final simplification54.7%
(FPCore (x y z t) :precision binary64 (if (<= y -5e+37) (* x (/ (- y) t)) (if (<= y 1.8e+158) x (/ (- x) (/ t y)))))
double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5e+37) {
tmp = x * (-y / t);
} else if (y <= 1.8e+158) {
tmp = x;
} else {
tmp = -x / (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 <= (-5d+37)) then
tmp = x * (-y / t)
else if (y <= 1.8d+158) then
tmp = x
else
tmp = -x / (t / y)
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if (y <= -5e+37) {
tmp = x * (-y / t);
} else if (y <= 1.8e+158) {
tmp = x;
} else {
tmp = -x / (t / y);
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if y <= -5e+37: tmp = x * (-y / t) elif y <= 1.8e+158: tmp = x else: tmp = -x / (t / y) return tmp
function code(x, y, z, t) tmp = 0.0 if (y <= -5e+37) tmp = Float64(x * Float64(Float64(-y) / t)); elseif (y <= 1.8e+158) tmp = x; else tmp = Float64(Float64(-x) / Float64(t / y)); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (y <= -5e+37) tmp = x * (-y / t); elseif (y <= 1.8e+158) tmp = x; else tmp = -x / (t / y); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[LessEqual[y, -5e+37], N[(x * N[((-y) / t), $MachinePrecision]), $MachinePrecision], If[LessEqual[y, 1.8e+158], x, N[((-x) / N[(t / y), $MachinePrecision]), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;y \leq -5 \cdot 10^{+37}:\\
\;\;\;\;x \cdot \frac{-y}{t}\\
\mathbf{elif}\;y \leq 1.8 \cdot 10^{+158}:\\
\;\;\;\;x\\
\mathbf{else}:\\
\;\;\;\;\frac{-x}{\frac{t}{y}}\\
\end{array}
\end{array}
if y < -4.99999999999999989e37Initial program 90.5%
associate-/l*99.8%
Simplified99.8%
Taylor expanded in z around 0 50.7%
associate-*r/50.7%
neg-mul-150.7%
Simplified50.7%
frac-2neg50.7%
div-inv50.7%
distribute-frac-neg50.7%
remove-double-neg50.7%
clear-num50.7%
add-sqr-sqrt23.8%
sqrt-unprod34.6%
sqr-neg34.6%
sqrt-unprod9.5%
add-sqr-sqrt17.2%
cancel-sign-sub-inv17.2%
add-sqr-sqrt9.5%
sqrt-unprod34.6%
sqr-neg34.6%
sqrt-unprod23.8%
add-sqr-sqrt50.7%
Applied egg-rr50.7%
Taylor expanded in y around inf 40.8%
mul-1-neg40.8%
*-commutative40.8%
associate-/l*43.7%
associate-/r/45.5%
Simplified45.5%
if -4.99999999999999989e37 < y < 1.79999999999999994e158Initial program 97.1%
associate-*l/99.6%
Simplified99.6%
Taylor expanded in y around 0 57.6%
if 1.79999999999999994e158 < y Initial program 75.5%
associate-/l*99.9%
Simplified99.9%
Taylor expanded in z around 0 56.5%
associate-*r/56.5%
neg-mul-156.5%
Simplified56.5%
frac-2neg56.5%
div-inv56.4%
distribute-frac-neg56.4%
remove-double-neg56.4%
clear-num56.6%
add-sqr-sqrt42.0%
sqrt-unprod37.3%
sqr-neg37.3%
sqrt-unprod1.0%
add-sqr-sqrt7.8%
cancel-sign-sub-inv7.8%
add-sqr-sqrt1.0%
sqrt-unprod37.3%
sqr-neg37.3%
sqrt-unprod42.0%
add-sqr-sqrt56.6%
Applied egg-rr56.6%
Taylor expanded in y around inf 43.8%
mul-1-neg43.8%
*-commutative43.8%
associate-/l*53.2%
associate-/r/56.4%
Simplified56.4%
*-commutative56.4%
clear-num56.4%
un-div-inv56.5%
Applied egg-rr56.5%
Final simplification54.7%
(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 93.0%
associate-*l/99.0%
Simplified99.0%
Final simplification99.0%
(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 93.0%
associate-*l/99.0%
Simplified99.0%
Taylor expanded in x around inf 62.3%
mul-1-neg62.3%
unsub-neg62.3%
Simplified62.3%
Final simplification62.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 93.0%
associate-*l/99.0%
Simplified99.0%
Taylor expanded in y around 0 40.6%
Final simplification40.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 2024014
(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)))