
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (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 = x + ((y * (z - t)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 10 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t a) :precision binary64 (+ x (/ (* y (- z t)) (- z a))))
double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (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 = x + ((y * (z - t)) / (z - a))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + ((y * (z - t)) / (z - a));
}
def code(x, y, z, t, a): return x + ((y * (z - t)) / (z - a))
function code(x, y, z, t, a) return Float64(x + Float64(Float64(y * Float64(z - t)) / Float64(z - a))) end
function tmp = code(x, y, z, t, a) tmp = x + ((y * (z - t)) / (z - a)); end
code[x_, y_, z_, t_, a_] := N[(x + N[(N[(y * N[(z - t), $MachinePrecision]), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y \cdot \left(z - t\right)}{z - a}
\end{array}
(FPCore (x y z t a) :precision binary64 (+ (/ y (/ (- z a) (- z t))) x))
double code(double x, double y, double z, double t, double a) {
return (y / ((z - a) / (z - t))) + x;
}
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 / ((z - a) / (z - t))) + x
end function
public static double code(double x, double y, double z, double t, double a) {
return (y / ((z - a) / (z - t))) + x;
}
def code(x, y, z, t, a): return (y / ((z - a) / (z - t))) + x
function code(x, y, z, t, a) return Float64(Float64(y / Float64(Float64(z - a) / Float64(z - t))) + x) end
function tmp = code(x, y, z, t, a) tmp = (y / ((z - a) / (z - t))) + x; end
code[x_, y_, z_, t_, a_] := N[(N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\frac{y}{\frac{z - a}{z - t}} + x
\end{array}
Initial program 84.0%
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
clear-numN/A
un-div-invN/A
lower-/.f64N/A
lower-/.f6499.3
Applied rewrites99.3%
Final simplification99.3%
(FPCore (x y z t a) :precision binary64 (if (<= z -2.7e-116) (fma (/ z (- z a)) y x) (if (<= z 7e+42) (fma (/ y (- z a)) (- t) x) (fma (/ (- z t) z) y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -2.7e-116) {
tmp = fma((z / (z - a)), y, x);
} else if (z <= 7e+42) {
tmp = fma((y / (z - a)), -t, x);
} else {
tmp = fma(((z - t) / z), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -2.7e-116) tmp = fma(Float64(z / Float64(z - a)), y, x); elseif (z <= 7e+42) tmp = fma(Float64(y / Float64(z - a)), Float64(-t), x); else tmp = fma(Float64(Float64(z - t) / z), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -2.7e-116], N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 7e+42], N[(N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] * (-t) + x), $MachinePrecision], N[(N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -2.7 \cdot 10^{-116}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{z - a}, -t, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{z}, y, x\right)\\
\end{array}
\end{array}
if z < -2.7e-116Initial program 79.4%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6487.4
Applied rewrites87.4%
if -2.7e-116 < z < 7.00000000000000047e42Initial program 97.1%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6497.2
Applied rewrites97.2%
Taylor expanded in z around 0
mul-1-negN/A
lower-neg.f6490.7
Applied rewrites90.7%
if 7.00000000000000047e42 < z Initial program 68.4%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6496.6
Applied rewrites96.6%
(FPCore (x y z t a) :precision binary64 (if (<= z -4.2e-146) (fma (/ z (- z a)) y x) (if (<= z 6.4e-114) (fma (/ t a) y x) (fma (/ (- z t) z) y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -4.2e-146) {
tmp = fma((z / (z - a)), y, x);
} else if (z <= 6.4e-114) {
tmp = fma((t / a), y, x);
} else {
tmp = fma(((z - t) / z), y, x);
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -4.2e-146) tmp = fma(Float64(z / Float64(z - a)), y, x); elseif (z <= 6.4e-114) tmp = fma(Float64(t / a), y, x); else tmp = fma(Float64(Float64(z - t) / z), y, x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -4.2e-146], N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision], If[LessEqual[z, 6.4e-114], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], N[(N[(N[(z - t), $MachinePrecision] / z), $MachinePrecision] * y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -4.2 \cdot 10^{-146}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{elif}\;z \leq 6.4 \cdot 10^{-114}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;\mathsf{fma}\left(\frac{z - t}{z}, y, x\right)\\
\end{array}
\end{array}
if z < -4.1999999999999998e-146Initial program 80.6%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6487.2
Applied rewrites87.2%
if -4.1999999999999998e-146 < z < 6.4000000000000003e-114Initial program 97.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.5
Applied rewrites98.5%
Taylor expanded in z around 0
lower-/.f6490.5
Applied rewrites90.5%
if 6.4000000000000003e-114 < z Initial program 78.4%
Taylor expanded in a around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6487.9
Applied rewrites87.9%
(FPCore (x y z t a) :precision binary64 (let* ((t_1 (fma (/ z (- z a)) y x))) (if (<= z -4.2e-146) t_1 (if (<= z 8.2e-113) (fma (/ t a) y x) t_1))))
double code(double x, double y, double z, double t, double a) {
double t_1 = fma((z / (z - a)), y, x);
double tmp;
if (z <= -4.2e-146) {
tmp = t_1;
} else if (z <= 8.2e-113) {
tmp = fma((t / a), y, x);
} else {
tmp = t_1;
}
return tmp;
}
function code(x, y, z, t, a) t_1 = fma(Float64(z / Float64(z - a)), y, x) tmp = 0.0 if (z <= -4.2e-146) tmp = t_1; elseif (z <= 8.2e-113) tmp = fma(Float64(t / a), y, x); else tmp = t_1; end return tmp end
code[x_, y_, z_, t_, a_] := Block[{t$95$1 = N[(N[(z / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]}, If[LessEqual[z, -4.2e-146], t$95$1, If[LessEqual[z, 8.2e-113], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], t$95$1]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \mathsf{fma}\left(\frac{z}{z - a}, y, x\right)\\
\mathbf{if}\;z \leq -4.2 \cdot 10^{-146}:\\
\;\;\;\;t\_1\\
\mathbf{elif}\;z \leq 8.2 \cdot 10^{-113}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;t\_1\\
\end{array}
\end{array}
if z < -4.1999999999999998e-146 or 8.1999999999999999e-113 < z Initial program 79.6%
Taylor expanded in t around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f64N/A
lower--.f6485.7
Applied rewrites85.7%
if -4.1999999999999998e-146 < z < 8.1999999999999999e-113Initial program 97.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.5
Applied rewrites98.5%
Taylor expanded in z around 0
lower-/.f6490.5
Applied rewrites90.5%
(FPCore (x y z t a) :precision binary64 (if (<= z -5e-30) (+ y x) (if (<= z 3.4e+42) (fma (/ t a) y x) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -5e-30) {
tmp = y + x;
} else if (z <= 3.4e+42) {
tmp = fma((t / a), y, x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -5e-30) tmp = Float64(y + x); elseif (z <= 3.4e+42) tmp = fma(Float64(t / a), y, x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -5e-30], N[(y + x), $MachinePrecision], If[LessEqual[z, 3.4e+42], N[(N[(t / a), $MachinePrecision] * y + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -5 \cdot 10^{-30}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 3.4 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(\frac{t}{a}, y, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -4.99999999999999972e-30 or 3.39999999999999975e42 < z Initial program 73.5%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6483.8
Applied rewrites83.8%
if -4.99999999999999972e-30 < z < 3.39999999999999975e42Initial program 96.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6498.4
Applied rewrites98.4%
Taylor expanded in z around 0
lower-/.f6479.1
Applied rewrites79.1%
(FPCore (x y z t a) :precision binary64 (if (<= z -1.85e-30) (+ y x) (if (<= z 7e+42) (fma (/ y a) t x) (+ y x))))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (z <= -1.85e-30) {
tmp = y + x;
} else if (z <= 7e+42) {
tmp = fma((y / a), t, x);
} else {
tmp = y + x;
}
return tmp;
}
function code(x, y, z, t, a) tmp = 0.0 if (z <= -1.85e-30) tmp = Float64(y + x); elseif (z <= 7e+42) tmp = fma(Float64(y / a), t, x); else tmp = Float64(y + x); end return tmp end
code[x_, y_, z_, t_, a_] := If[LessEqual[z, -1.85e-30], N[(y + x), $MachinePrecision], If[LessEqual[z, 7e+42], N[(N[(y / a), $MachinePrecision] * t + x), $MachinePrecision], N[(y + x), $MachinePrecision]]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;z \leq -1.85 \cdot 10^{-30}:\\
\;\;\;\;y + x\\
\mathbf{elif}\;z \leq 7 \cdot 10^{+42}:\\
\;\;\;\;\mathsf{fma}\left(\frac{y}{a}, t, x\right)\\
\mathbf{else}:\\
\;\;\;\;y + x\\
\end{array}
\end{array}
if z < -1.8500000000000002e-30 or 7.00000000000000047e42 < z Initial program 73.5%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6483.8
Applied rewrites83.8%
if -1.8500000000000002e-30 < z < 7.00000000000000047e42Initial program 96.0%
Taylor expanded in z around 0
+-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6478.8
Applied rewrites78.8%
(FPCore (x y z t a) :precision binary64 (fma (/ (- z t) (- z a)) y x))
double code(double x, double y, double z, double t, double a) {
return fma(((z - t) / (z - a)), y, x);
}
function code(x, y, z, t, a) return fma(Float64(Float64(z - t) / Float64(z - a)), y, x) end
code[x_, y_, z_, t_, a_] := N[(N[(N[(z - t), $MachinePrecision] / N[(z - a), $MachinePrecision]), $MachinePrecision] * y + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{z - t}{z - a}, y, x\right)
\end{array}
Initial program 84.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6499.2
Applied rewrites99.2%
(FPCore (x y z t a) :precision binary64 (fma (/ y (- z a)) (- z t) x))
double code(double x, double y, double z, double t, double a) {
return fma((y / (z - a)), (z - t), x);
}
function code(x, y, z, t, a) return fma(Float64(y / Float64(z - a)), Float64(z - t), x) end
code[x_, y_, z_, t_, a_] := N[(N[(y / N[(z - a), $MachinePrecision]), $MachinePrecision] * N[(z - t), $MachinePrecision] + x), $MachinePrecision]
\begin{array}{l}
\\
\mathsf{fma}\left(\frac{y}{z - a}, z - t, x\right)
\end{array}
Initial program 84.0%
lift-+.f64N/A
+-commutativeN/A
lift-/.f64N/A
lift-*.f64N/A
*-commutativeN/A
associate-/l*N/A
*-commutativeN/A
lower-fma.f64N/A
lower-/.f6496.0
Applied rewrites96.0%
(FPCore (x y z t a) :precision binary64 (if (<= t 3.6e+189) (+ y x) (* (/ t a) y)))
double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 3.6e+189) {
tmp = y + x;
} else {
tmp = (t / a) * y;
}
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 (t <= 3.6d+189) then
tmp = y + x
else
tmp = (t / a) * y
end if
code = tmp
end function
public static double code(double x, double y, double z, double t, double a) {
double tmp;
if (t <= 3.6e+189) {
tmp = y + x;
} else {
tmp = (t / a) * y;
}
return tmp;
}
def code(x, y, z, t, a): tmp = 0 if t <= 3.6e+189: tmp = y + x else: tmp = (t / a) * y return tmp
function code(x, y, z, t, a) tmp = 0.0 if (t <= 3.6e+189) tmp = Float64(y + x); else tmp = Float64(Float64(t / a) * y); end return tmp end
function tmp_2 = code(x, y, z, t, a) tmp = 0.0; if (t <= 3.6e+189) tmp = y + x; else tmp = (t / a) * y; end tmp_2 = tmp; end
code[x_, y_, z_, t_, a_] := If[LessEqual[t, 3.6e+189], N[(y + x), $MachinePrecision], N[(N[(t / a), $MachinePrecision] * y), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;t \leq 3.6 \cdot 10^{+189}:\\
\;\;\;\;y + x\\
\mathbf{else}:\\
\;\;\;\;\frac{t}{a} \cdot y\\
\end{array}
\end{array}
if t < 3.60000000000000008e189Initial program 84.8%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6474.1
Applied rewrites74.1%
if 3.60000000000000008e189 < t Initial program 73.7%
Taylor expanded in x around 0
associate-/l*N/A
div-subN/A
distribute-lft-out--N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
associate-/l*N/A
*-commutativeN/A
associate-/l*N/A
distribute-rgt-out--N/A
lower-*.f64N/A
lower-/.f64N/A
lower--.f64N/A
lower--.f6478.0
Applied rewrites78.0%
Taylor expanded in z around inf
Applied rewrites46.5%
Taylor expanded in z around 0
Applied rewrites56.4%
Applied rewrites63.1%
(FPCore (x y z t a) :precision binary64 (+ y x))
double code(double x, double y, double z, double t, double a) {
return y + x;
}
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
end function
public static double code(double x, double y, double z, double t, double a) {
return y + x;
}
def code(x, y, z, t, a): return y + x
function code(x, y, z, t, a) return Float64(y + x) end
function tmp = code(x, y, z, t, a) tmp = y + x; end
code[x_, y_, z_, t_, a_] := N[(y + x), $MachinePrecision]
\begin{array}{l}
\\
y + x
\end{array}
Initial program 84.0%
Taylor expanded in z around inf
+-commutativeN/A
lower-+.f6471.1
Applied rewrites71.1%
(FPCore (x y z t a) :precision binary64 (+ x (/ y (/ (- z a) (- z t)))))
double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - 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 - a) / (z - t)))
end function
public static double code(double x, double y, double z, double t, double a) {
return x + (y / ((z - a) / (z - t)));
}
def code(x, y, z, t, a): return x + (y / ((z - a) / (z - t)))
function code(x, y, z, t, a) return Float64(x + Float64(y / Float64(Float64(z - a) / Float64(z - t)))) end
function tmp = code(x, y, z, t, a) tmp = x + (y / ((z - a) / (z - t))); end
code[x_, y_, z_, t_, a_] := N[(x + N[(y / N[(N[(z - a), $MachinePrecision] / N[(z - t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \frac{y}{\frac{z - a}{z - t}}
\end{array}
herbie shell --seed 2024332
(FPCore (x y z t a)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:renderAxisTicks from plot-0.2.3.4, A"
:precision binary64
:alt
(! :herbie-platform default (+ x (/ y (/ (- z a) (- z t)))))
(+ x (/ (* y (- z t)) (- z a))))