
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
double code(double x, double y, double z, double t) {
return x + ((y - x) * (z / 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 - x) * (z / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - x) * (z / t));
}
def code(x, y, z, t): return x + ((y - x) * (z / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - x) * Float64(z / t))) end
function tmp = code(x, y, z, t) tmp = x + ((y - x) * (z / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot \frac{z}{t}
\end{array}
Sampling outcomes in binary64 precision:
Herbie found 6 alternatives:
| Alternative | Accuracy | Speedup |
|---|
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
double code(double x, double y, double z, double t) {
return x + ((y - x) * (z / 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 - x) * (z / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - x) * (z / t));
}
def code(x, y, z, t): return x + ((y - x) * (z / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - x) * Float64(z / t))) end
function tmp = code(x, y, z, t) tmp = x + ((y - x) * (z / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot \frac{z}{t}
\end{array}
(FPCore (x y z t) :precision binary64 (+ x (* (- y x) (/ z t))))
double code(double x, double y, double z, double t) {
return x + ((y - x) * (z / 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 - x) * (z / t))
end function
public static double code(double x, double y, double z, double t) {
return x + ((y - x) * (z / t));
}
def code(x, y, z, t): return x + ((y - x) * (z / t))
function code(x, y, z, t) return Float64(x + Float64(Float64(y - x) * Float64(z / t))) end
function tmp = code(x, y, z, t) tmp = x + ((y - x) * (z / t)); end
code[x_, y_, z_, t_] := N[(x + N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]
\begin{array}{l}
\\
x + \left(y - x\right) \cdot \frac{z}{t}
\end{array}
Initial program 97.2%
(FPCore (x y z t) :precision binary64 (if (or (<= (/ z t) -4e-27) (not (<= (/ z t) 5e-47))) (* y (/ z t)) x))
double code(double x, double y, double z, double t) {
double tmp;
if (((z / t) <= -4e-27) || !((z / t) <= 5e-47)) {
tmp = y * (z / 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 (((z / t) <= (-4d-27)) .or. (.not. ((z / t) <= 5d-47))) then
tmp = y * (z / 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 (((z / t) <= -4e-27) || !((z / t) <= 5e-47)) {
tmp = y * (z / t);
} else {
tmp = x;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if ((z / t) <= -4e-27) or not ((z / t) <= 5e-47): tmp = y * (z / t) else: tmp = x return tmp
function code(x, y, z, t) tmp = 0.0 if ((Float64(z / t) <= -4e-27) || !(Float64(z / t) <= 5e-47)) tmp = Float64(y * Float64(z / t)); else tmp = x; end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if (((z / t) <= -4e-27) || ~(((z / t) <= 5e-47))) tmp = y * (z / t); else tmp = x; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[N[(z / t), $MachinePrecision], -4e-27], N[Not[LessEqual[N[(z / t), $MachinePrecision], 5e-47]], $MachinePrecision]], N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision], x]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;\frac{z}{t} \leq -4 \cdot 10^{-27} \lor \neg \left(\frac{z}{t} \leq 5 \cdot 10^{-47}\right):\\
\;\;\;\;y \cdot \frac{z}{t}\\
\mathbf{else}:\\
\;\;\;\;x\\
\end{array}
\end{array}
if (/.f64 z t) < -4.0000000000000002e-27 or 5.00000000000000011e-47 < (/.f64 z t) Initial program 97.8%
Taylor expanded in y around inf 74.8%
mul-1-neg74.8%
remove-double-neg74.8%
mul-1-neg74.8%
distribute-neg-in74.8%
*-commutative74.8%
times-frac83.9%
distribute-rgt-out91.1%
Simplified91.1%
Taylor expanded in z around 0 89.2%
associate-*r/89.2%
associate-*r*89.2%
sub-neg89.2%
metadata-eval89.2%
associate-*r/89.8%
associate-*l/91.1%
*-commutative91.1%
neg-mul-191.1%
distribute-rgt-neg-in91.1%
distribute-lft-neg-in91.1%
cancel-sign-sub-inv91.1%
*-commutative91.1%
associate-*l/89.8%
associate-/l*86.3%
associate-*r*85.9%
*-commutative85.9%
+-commutative85.9%
Simplified85.9%
Taylor expanded in x around 0 57.5%
associate-/l*60.2%
Simplified60.2%
if -4.0000000000000002e-27 < (/.f64 z t) < 5.00000000000000011e-47Initial program 96.5%
Taylor expanded in z around 0 73.2%
Final simplification66.1%
(FPCore (x y z t) :precision binary64 (if (or (<= x -1.65e-15) (not (<= x 2.2e+91))) (/ x (/ t (- t z))) (+ x (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.65e-15) || !(x <= 2.2e+91)) {
tmp = x / (t / (t - z));
} else {
tmp = x + (y * (z / 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.65d-15)) .or. (.not. (x <= 2.2d+91))) then
tmp = x / (t / (t - z))
else
tmp = x + (y * (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -1.65e-15) || !(x <= 2.2e+91)) {
tmp = x / (t / (t - z));
} else {
tmp = x + (y * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -1.65e-15) or not (x <= 2.2e+91): tmp = x / (t / (t - z)) else: tmp = x + (y * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -1.65e-15) || !(x <= 2.2e+91)) tmp = Float64(x / Float64(t / Float64(t - z))); else tmp = Float64(x + Float64(y * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -1.65e-15) || ~((x <= 2.2e+91))) tmp = x / (t / (t - z)); else tmp = x + (y * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -1.65e-15], N[Not[LessEqual[x, 2.2e+91]], $MachinePrecision]], N[(x / N[(t / N[(t - z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -1.65 \cdot 10^{-15} \lor \neg \left(x \leq 2.2 \cdot 10^{+91}\right):\\
\;\;\;\;\frac{x}{\frac{t}{t - z}}\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if x < -1.65e-15 or 2.19999999999999999e91 < x Initial program 99.9%
Taylor expanded in x around inf 88.1%
mul-1-neg88.1%
unsub-neg88.1%
Simplified88.1%
Taylor expanded in t around 0 88.1%
clear-num88.1%
un-div-inv88.2%
Applied egg-rr88.2%
if -1.65e-15 < x < 2.19999999999999999e91Initial program 95.5%
Taylor expanded in y around inf 86.8%
associate-*r/87.2%
Simplified87.2%
Final simplification87.6%
(FPCore (x y z t) :precision binary64 (if (or (<= x -8.2e-17) (not (<= x 1.2e+91))) (* x (- 1.0 (/ z t))) (+ x (* y (/ z t)))))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8.2e-17) || !(x <= 1.2e+91)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + (y * (z / 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 <= (-8.2d-17)) .or. (.not. (x <= 1.2d+91))) then
tmp = x * (1.0d0 - (z / t))
else
tmp = x + (y * (z / t))
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -8.2e-17) || !(x <= 1.2e+91)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = x + (y * (z / t));
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -8.2e-17) or not (x <= 1.2e+91): tmp = x * (1.0 - (z / t)) else: tmp = x + (y * (z / t)) return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -8.2e-17) || !(x <= 1.2e+91)) tmp = Float64(x * Float64(1.0 - Float64(z / t))); else tmp = Float64(x + Float64(y * Float64(z / t))); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -8.2e-17) || ~((x <= 1.2e+91))) tmp = x * (1.0 - (z / t)); else tmp = x + (y * (z / t)); end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -8.2e-17], N[Not[LessEqual[x, 1.2e+91]], $MachinePrecision]], N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(x + N[(y * N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -8.2 \cdot 10^{-17} \lor \neg \left(x \leq 1.2 \cdot 10^{+91}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;x + y \cdot \frac{z}{t}\\
\end{array}
\end{array}
if x < -8.2000000000000001e-17 or 1.19999999999999991e91 < x Initial program 99.9%
Taylor expanded in x around inf 88.1%
mul-1-neg88.1%
unsub-neg88.1%
Simplified88.1%
if -8.2000000000000001e-17 < x < 1.19999999999999991e91Initial program 95.5%
Taylor expanded in y around inf 86.8%
associate-*r/87.2%
Simplified87.2%
Final simplification87.5%
(FPCore (x y z t) :precision binary64 (if (or (<= x -4.8e-226) (not (<= x 3.4e-115))) (* x (- 1.0 (/ z t))) (/ (* y z) t)))
double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.8e-226) || !(x <= 3.4e-115)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = (y * z) / 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 <= (-4.8d-226)) .or. (.not. (x <= 3.4d-115))) then
tmp = x * (1.0d0 - (z / t))
else
tmp = (y * z) / t
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double tmp;
if ((x <= -4.8e-226) || !(x <= 3.4e-115)) {
tmp = x * (1.0 - (z / t));
} else {
tmp = (y * z) / t;
}
return tmp;
}
def code(x, y, z, t): tmp = 0 if (x <= -4.8e-226) or not (x <= 3.4e-115): tmp = x * (1.0 - (z / t)) else: tmp = (y * z) / t return tmp
function code(x, y, z, t) tmp = 0.0 if ((x <= -4.8e-226) || !(x <= 3.4e-115)) tmp = Float64(x * Float64(1.0 - Float64(z / t))); else tmp = Float64(Float64(y * z) / t); end return tmp end
function tmp_2 = code(x, y, z, t) tmp = 0.0; if ((x <= -4.8e-226) || ~((x <= 3.4e-115))) tmp = x * (1.0 - (z / t)); else tmp = (y * z) / t; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := If[Or[LessEqual[x, -4.8e-226], N[Not[LessEqual[x, 3.4e-115]], $MachinePrecision]], N[(x * N[(1.0 - N[(z / t), $MachinePrecision]), $MachinePrecision]), $MachinePrecision], N[(N[(y * z), $MachinePrecision] / t), $MachinePrecision]]
\begin{array}{l}
\\
\begin{array}{l}
\mathbf{if}\;x \leq -4.8 \cdot 10^{-226} \lor \neg \left(x \leq 3.4 \cdot 10^{-115}\right):\\
\;\;\;\;x \cdot \left(1 - \frac{z}{t}\right)\\
\mathbf{else}:\\
\;\;\;\;\frac{y \cdot z}{t}\\
\end{array}
\end{array}
if x < -4.7999999999999999e-226 or 3.3999999999999998e-115 < x Initial program 98.8%
Taylor expanded in x around inf 75.9%
mul-1-neg75.9%
unsub-neg75.9%
Simplified75.9%
if -4.7999999999999999e-226 < x < 3.3999999999999998e-115Initial program 93.3%
Taylor expanded in y around inf 80.5%
mul-1-neg80.5%
remove-double-neg80.5%
mul-1-neg80.5%
distribute-neg-in80.5%
*-commutative80.5%
times-frac88.1%
distribute-rgt-out93.3%
Simplified93.3%
Taylor expanded in z around 0 94.6%
associate-*r/94.6%
associate-*r*94.6%
sub-neg94.6%
metadata-eval94.6%
associate-*r/93.3%
associate-*l/93.3%
*-commutative93.3%
neg-mul-193.3%
distribute-rgt-neg-in93.3%
distribute-lft-neg-in93.3%
cancel-sign-sub-inv93.3%
*-commutative93.3%
associate-*l/93.3%
associate-/l*92.0%
associate-*r*91.4%
*-commutative91.4%
+-commutative91.4%
Simplified91.4%
Taylor expanded in x around 0 76.5%
Final simplification76.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 97.2%
Taylor expanded in z around 0 36.5%
(FPCore (x y z t)
:precision binary64
(let* ((t_1 (* (- y x) (/ z t))) (t_2 (+ x (/ (- y x) (/ t z)))))
(if (< t_1 -1013646692435.8867)
t_2
(if (< t_1 0.0) (+ x (/ (* (- y x) z) t)) t_2))))
double code(double x, double y, double z, double t) {
double t_1 = (y - x) * (z / t);
double t_2 = x + ((y - x) / (t / z));
double tmp;
if (t_1 < -1013646692435.8867) {
tmp = t_2;
} else if (t_1 < 0.0) {
tmp = x + (((y - x) * z) / t);
} else {
tmp = t_2;
}
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) :: t_1
real(8) :: t_2
real(8) :: tmp
t_1 = (y - x) * (z / t)
t_2 = x + ((y - x) / (t / z))
if (t_1 < (-1013646692435.8867d0)) then
tmp = t_2
else if (t_1 < 0.0d0) then
tmp = x + (((y - x) * z) / t)
else
tmp = t_2
end if
code = tmp
end function
public static double code(double x, double y, double z, double t) {
double t_1 = (y - x) * (z / t);
double t_2 = x + ((y - x) / (t / z));
double tmp;
if (t_1 < -1013646692435.8867) {
tmp = t_2;
} else if (t_1 < 0.0) {
tmp = x + (((y - x) * z) / t);
} else {
tmp = t_2;
}
return tmp;
}
def code(x, y, z, t): t_1 = (y - x) * (z / t) t_2 = x + ((y - x) / (t / z)) tmp = 0 if t_1 < -1013646692435.8867: tmp = t_2 elif t_1 < 0.0: tmp = x + (((y - x) * z) / t) else: tmp = t_2 return tmp
function code(x, y, z, t) t_1 = Float64(Float64(y - x) * Float64(z / t)) t_2 = Float64(x + Float64(Float64(y - x) / Float64(t / z))) tmp = 0.0 if (t_1 < -1013646692435.8867) tmp = t_2; elseif (t_1 < 0.0) tmp = Float64(x + Float64(Float64(Float64(y - x) * z) / t)); else tmp = t_2; end return tmp end
function tmp_2 = code(x, y, z, t) t_1 = (y - x) * (z / t); t_2 = x + ((y - x) / (t / z)); tmp = 0.0; if (t_1 < -1013646692435.8867) tmp = t_2; elseif (t_1 < 0.0) tmp = x + (((y - x) * z) / t); else tmp = t_2; end tmp_2 = tmp; end
code[x_, y_, z_, t_] := Block[{t$95$1 = N[(N[(y - x), $MachinePrecision] * N[(z / t), $MachinePrecision]), $MachinePrecision]}, Block[{t$95$2 = N[(x + N[(N[(y - x), $MachinePrecision] / N[(t / z), $MachinePrecision]), $MachinePrecision]), $MachinePrecision]}, If[Less[t$95$1, -1013646692435.8867], t$95$2, If[Less[t$95$1, 0.0], N[(x + N[(N[(N[(y - x), $MachinePrecision] * z), $MachinePrecision] / t), $MachinePrecision]), $MachinePrecision], t$95$2]]]]
\begin{array}{l}
\\
\begin{array}{l}
t_1 := \left(y - x\right) \cdot \frac{z}{t}\\
t_2 := x + \frac{y - x}{\frac{t}{z}}\\
\mathbf{if}\;t\_1 < -1013646692435.8867:\\
\;\;\;\;t\_2\\
\mathbf{elif}\;t\_1 < 0:\\
\;\;\;\;x + \frac{\left(y - x\right) \cdot z}{t}\\
\mathbf{else}:\\
\;\;\;\;t\_2\\
\end{array}
\end{array}
herbie shell --seed 2024091
(FPCore (x y z t)
:name "Graphics.Rendering.Plot.Render.Plot.Axis:tickPosition from plot-0.2.3.4"
:precision binary64
:alt
(if (< (* (- y x) (/ z t)) -1013646692435.8867) (+ x (/ (- y x) (/ t z))) (if (< (* (- y x) (/ z t)) 0.0) (+ x (/ (* (- y x) z) t)) (+ x (/ (- y x) (/ t z)))))
(+ x (* (- y x) (/ z t))))