
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (x + y) - (((z - t) * y) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
function code(x, y, z, t, a) return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = (x + y) - (((z - t) * y) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (- (+ x y) (/ (* (- z t) y) (- a t))))
double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (x + y) - (((z - t) * y) / (a - t))
end function
public static double code(double x, double y, double z, double t, double a) {
return (x + y) - (((z - t) * y) / (a - t));
}
def code(x, y, z, t, a): return (x + y) - (((z - t) * y) / (a - t))
function code(x, y, z, t, a) return Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) end
function tmp = code(x, y, z, t, a) tmp = (x + y) - (((z - t) * y) / (a - t)); end
code[x_, y_, z_, t_, a_] := N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}
\end{array}
(FPCore (x y z t a) :precision binary64 (fma (/ (- t z) (- a t)) y (+ y x)))
double code(double x, double y, double z, double t, double a) {
return fma(((t - z) / (a - t)), y, (y + x));
}
function code(x, y, z, t, a) return fma(Float64(Float64(t - z) / Float64(a - t)), y, Float64(y + x)) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(t - z), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision] * y + N[(y + x), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{t - z}{a - t}, y, y + x\right)
\end{array}
Initial program 79.7%
sub-neg79.7%
distribute-frac-neg79.7%
distribute-rgt-neg-out79.7%
+-commutative79.7%
associate-*l/83.4%
distribute-rgt-neg-in83.4%
distribute-lft-neg-in83.4%
distribute-frac-neg83.4%
fma-def83.4%
sub-neg83.4%
distribute-neg-in83.4%
remove-double-neg83.4%
+-commutative83.4%
sub-neg83.4%
Simplified83.4%
Final simplification83.4%
(FPCore (x y z t a) :precision binary64 (if (or (<= a -1e-78) (not (<= a 8.3e-107))) (- (+ y x) (* y (/ z a))) (- (+ y x) (* y (- 1.0 (/ z t))))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -1e-78) || !(a <= 8.3e-107)) {
tmp = (y + x) - (y * (z / a));
} else {
tmp = (y + x) - (y * (1.0 - (z / t)));
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: tmp
if ((a <= (-1d-78)) .or. (.not. (a <= 8.3d-107))) then
tmp = (y + x) - (y * (z / a))
else
tmp = (y + x) - (y * (1.0d0 - (z / t)))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if ((a <= -1e-78) || !(a <= 8.3e-107)) {
tmp = (y + x) - (y * (z / a));
} else {
tmp = (y + x) - (y * (1.0 - (z / t)));
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if (a <= -1e-78) or not (a <= 8.3e-107): tmp = (y + x) - (y * (z / a)) else: tmp = (y + x) - (y * (1.0 - (z / t))) return tmp
function code(x, y, z, t, a) tmp = 0.0 if ((a <= -1e-78) || !(a <= 8.3e-107)) tmp = Float64(Float64(y + x) - Float64(y * Float64(z / a))); else tmp = Float64(Float64(y + x) - Float64(y * Float64(1.0 - Float64(z / t)))); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if ((a <= -1e-78) || ~((a <= 8.3e-107))) tmp = (y + x) - (y * (z / a)); else tmp = (y + x) - (y * (1.0 - (z / t))); end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[Or[LessEqual[a, -1e-78], N[Not[LessEqual[a, 8.3e-107]], $MachinePrecision]], N[(N[(y + x), $MachinePrecision] - N[(y * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y + x), $MachinePrecision] - N[(y * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;a \leq -1 \cdot 10^{-78} \lor \neg \left(a \leq 8.3 \cdot 10^{-107}\right):\\
\;\;\;\;\left(y + x\right) - y \cdot \frac{z}{a}\\
\mathbf{else}:\\
\;\;\;\;\left(y + x\right) - y \cdot \left(1 - \frac{z}{t}\right)\\
\end{array}
\end{array}
if a < -9.99999999999999999e-79 or 8.29999999999999974e-107 < a Initial program 85.1%
associate-*l/91.7%
Simplified91.7%
Taylor expanded in t around 0 86.8%
if -9.99999999999999999e-79 < a < 8.29999999999999974e-107Initial program 69.9%
associate-*l/67.9%
Simplified67.9%
Taylor expanded in a around 0 60.0%
mul-1-neg60.0%
div-sub60.0%
sub-neg60.0%
*-inverses60.0%
metadata-eval60.0%
distribute-neg-in60.0%
mul-1-neg60.0%
metadata-eval60.0%
+-commutative60.0%
mul-1-neg60.0%
unsub-neg60.0%
Simplified60.0%
Final simplification77.4%
(FPCore (x y z t a) :precision binary64 (- (+ y x) (* y (/ (- z t) (- a t)))))
double code(double x, double y, double z, double t, double a) {
return (y + x) - (y * ((z - t) / (a - t)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (y + x) - (y * ((z - t) / (a - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return (y + x) - (y * ((z - t) / (a - t)));
}
def code(x, y, z, t, a): return (y + x) - (y * ((z - t) / (a - t)))
function code(x, y, z, t, a) return Float64(Float64(y + x) - Float64(y * Float64(Float64(z - t) / Float64(a - t)))) end
function tmp = code(x, y, z, t, a) tmp = (y + x) - (y * ((z - t) / (a - t))); end
code[x_, y_, z_, t_, a_] := N[(N[(y + x), $MachinePrecision] - N[(y * N[(N[(z - t), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y \cdot \frac{z - t}{a - t}
\end{array}
Initial program 79.7%
associate-*l/83.4%
Simplified83.4%
Final simplification83.4%
(FPCore (x y z t a) :precision binary64 (- (+ y x) (* y (/ z (- a t)))))
double code(double x, double y, double z, double t, double a) {
return (y + x) - (y * (z / (a - t)));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (y + x) - (y * (z / (a - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return (y + x) - (y * (z / (a - t)));
}
def code(x, y, z, t, a): return (y + x) - (y * (z / (a - t)))
function code(x, y, z, t, a) return Float64(Float64(y + x) - Float64(y * Float64(z / Float64(a - t)))) end
function tmp = code(x, y, z, t, a) tmp = (y + x) - (y * (z / (a - t))); end
code[x_, y_, z_, t_, a_] := N[(N[(y + x), $MachinePrecision] - N[(y * N[(z / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y \cdot \frac{z}{a - t}
\end{array}
Initial program 79.7%
associate-*l/83.4%
Simplified83.4%
Taylor expanded in z around inf 81.2%
Final simplification81.2%
(FPCore (x y z t a) :precision binary64 (- (+ y x) (* y (/ z a))))
double code(double x, double y, double z, double t, double a) {
return (y + x) - (y * (z / a));
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (y + x) - (y * (z / a))
end function
public static double code(double x, double y, double z, double t, double a) {
return (y + x) - (y * (z / a));
}
def code(x, y, z, t, a): return (y + x) - (y * (z / a))
function code(x, y, z, t, a) return Float64(Float64(y + x) - Float64(y * Float64(z / a))) end
function tmp = code(x, y, z, t, a) tmp = (y + x) - (y * (z / a)); end
code[x_, y_, z_, t_, a_] := N[(N[(y + x), $MachinePrecision] - N[(y * N[(z / a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y \cdot \frac{z}{a}
\end{array}
Initial program 79.7%
associate-*l/83.4%
Simplified83.4%
Taylor expanded in t around 0 70.0%
Final simplification70.0%
(FPCore (x y z t a) :precision binary64 (- (+ y x) y))
double code(double x, double y, double z, double t, double a) {
return (y + x) - y;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
code = (y + x) - y
end function
public static double code(double x, double y, double z, double t, double a) {
return (y + x) - y;
}
def code(x, y, z, t, a): return (y + x) - y
function code(x, y, z, t, a) return Float64(Float64(y + x) - y) end
function tmp = code(x, y, z, t, a) tmp = (y + x) - y; end
code[x_, y_, z_, t_, a_] := N[(N[(y + x), $MachinePrecision] - y), $MachinePrecision]
\begin{array}{l}
\\
\left(y + x\right) - y
\end{array}
Initial program 79.7%
associate-*l/83.4%
Simplified83.4%
Taylor expanded in t around inf 46.8%
Final simplification46.8%
(FPCore (x y z t a)
:precision binary64
(let* ((t_1 (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)))
(t_2 (- (+ x y) (/ (* (- z t) y) (- a t)))))
(if (< t_2 -1.3664970889390727e-7)
t_1
(if (< t_2 1.4754293444577233e-239)
(/ (- (* y (- a z)) (* x t)) (- a t))
t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = (y + x) - (((z - t) * (1.0 / (a - t))) * y);
double t_2 = (x + y) - (((z - t) * y) / (a - t));
double tmp;
if (t_2 < -1.3664970889390727e-7) {
tmp = t_1;
} else if (t_2 < 1.4754293444577233e-239) {
tmp = ((y * (a - z)) - (x * t)) / (a - t);
} else {
tmp = t_1;
}
return tmp;
}
real(8) function code(x, y, z, t, a)
real(8), intent (in) :: x
real(8), intent (in) :: y
real(8), intent (in) :: z
real(8), intent (in) :: t
real(8), intent (in) :: a
real(8) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (y + x) - (((z - t) * (1.0d0 / (a - t))) * y)
t_2 = (x + y) - (((z - t) * y) / (a - t))
if (t_2 < (-1.3664970889390727d-7)) then
tmp = t_1
else if (t_2 < 1.4754293444577233d-239) then
tmp = ((y * (a - z)) - (x * t)) / (a - t)
else
tmp = t_1
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double t_1 = (y + x) - (((z - t) * (1.0 / (a - t))) * y);
double t_2 = (x + y) - (((z - t) * y) / (a - t));
double tmp;
if (t_2 < -1.3664970889390727e-7) {
tmp = t_1;
} else if (t_2 < 1.4754293444577233e-239) {
tmp = ((y * (a - z)) - (x * t)) / (a - t);
} else {
tmp = t_1;
}
return tmp;
}
def code(x, y, z, t, a): t_1 = (y + x) - (((z - t) * (1.0 / (a - t))) * y) t_2 = (x + y) - (((z - t) * y) / (a - t)) tmp = 0 if t_2 < -1.3664970889390727e-7: tmp = t_1 elif t_2 < 1.4754293444577233e-239: tmp = ((y * (a - z)) - (x * t)) / (a - t) else: tmp = t_1 return tmp
function code(x, y, z, t, a) t_1 = Float64(Float64(y + x) - Float64(Float64(Float64(z - t) * Float64(1.0 / Float64(a - t))) * y)) t_2 = Float64(Float64(x + y) - Float64(Float64(Float64(z - t) * y) / Float64(a - t))) tmp = 0.0 if (t_2 < -1.3664970889390727e-7) tmp = t_1; elseif (t_2 < 1.4754293444577233e-239) tmp = Float64(Float64(Float64(y * Float64(a - z)) - Float64(x * t)) / Float64(a - t)); else tmp = t_1; end return tmp end
function tmp_2 = code(x, y, z, t, a) t_1 = (y + x) - (((z - t) * (1.0 / (a - t))) * y); t_2 = (x + y) - (((z - t) * y) / (a - t)); tmp = 0.0; if (t_2 < -1.3664970889390727e-7) tmp = t_1; elseif (t_2 < 1.4754293444577233e-239) tmp = ((y * (a - z)) - (x * t)) / (a - t); else tmp = t_1; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(y + x), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * N[(1.0 / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] * y), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(N[(x + y), $MachinePrecision] - N[(N[(N[(z - t), $MachinePrecision] * y), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$2, -1.3664970889390727e-7], t$95$1, If[Less[t$95$2, 1.4754293444577233e-239], N[(N[(N[(y * N[(a - z), $MachinePrecision]), $MachinePrecision] - N[(x * t), $MachinePrecision]), $MachinePrecision] / N[(a - t), $MachinePrecision]), $MachinePrecision], t$95$1]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y + x\right) - \left(\left(z - t\right) \cdot \frac{1}{a - t}\right) \cdot y\\
t_2 := \left(x + y\right) - \frac{\left(z - t\right) \cdot y}{a - t}\\
\mathbf{if}\;t\_2 < -1.3664970889390727 \cdot 10^{-7}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;t\_2 < 1.4754293444577233 \cdot 10^{-239}:\\
\;\;\;\;\frac{y \cdot \left(a - z\right) - x \cdot t}{a - t}\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
herbie shell --seed 2024034
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTick from plot-0.2.3.4, B"
:precision binary64
:herbie-target
(if (< (- (+ x y) (/ (* (- z t) y) (- a t))) -1.3664970889390727e-7) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y)) (if (< (- (+ x y) (/ (* (- z t) y) (- a t))) 1.4754293444577233e-239) (/ (- (* y (- a z)) (* x t)) (- a t)) (- (+ y x) (* (* (- z t) (/ 1.0 (- a t))) y))))
(- (+ x y) (/ (* (- z t) y) (- a t))))